Aruba Central API Demo – Replace AP configuration

通过API来实现重复工作,例如修改AP名称。

video
play-rounded-fill
Central API - AP Rename Demo

代码示例

"""
This script use to update AP device name,uplink-vlan,swarm-mode.
Reference:
https://github.com/aruba/pycentral
https://developer.arubanetworks.com/aruba-central/reference/ap-configuration-2

"""

from pycentral.base import ArubaCentralBase
import xlsxwriter
import xlrd

token = input("Paste Access Token:")
vlan = input("Input Uplink vlan:")
# Create an instance of ArubaCentralBase using API access token
# or API Gateway credentials.
central_info = {
    "base_url": "https://apigw.central.arubanetworks.com.cn/",
    "token": {
        "access_token": token
    }
}
ssl_verify = True
central = ArubaCentralBase(central_info=central_info,
                           ssl_verify=ssl_verify)
#Read the source data Excel,MAC must be lowercase.
data = xlrd.open_workbook('/Users/haoliu/csv_file2.xlsx')
sheet = data.sheet_by_name('sheet1')
snlist = sheet.col_values(0,1,)
maclist = sheet.col_values(1,1,)
apnamelist = sheet.col_values(2,1,)
#Write failure data into new excel
workbook = xlsxwriter.Workbook('Failed_AP_Setting.xlsx')
worksheet = workbook.add_worksheet()
headings = ['SERIAL','MAC','DEVICE NAME']
worksheet.write_row('A1',headings)
failed_aps = 0
success_aps = 0

for index, sn in enumerate(snlist):
        apiMethod = "POST"
        apiPath = "/configuration/v1/ap_settings_cli/" + sn
        apiParams = {
        "clis": [
            "per-ap-settings " + maclist[index],
            "hostname " + apnamelist[index],
            #"uplink-vlan 'vlan'",
            #"swarm-mode standalone"
                ]
                    }
        base_resp = central.command(apiMethod=apiMethod,
                                    apiPath=apiPath,
                                    apiData=apiParams)
        if base_resp["code"] == 200:
            success_aps = success_aps+1
            print("API call successful to update settings for AP %s" % sn)
        else:
            print("Failed to update ap settings for AP %s" % sn)
            failed_aps = failed_aps+1
            #print(base_resp)
            n_row = 1 + index
            worksheet.write(f"A{n_row}",sn)
workbook.close()
print("Number of successful:%s " % success_aps,"Number of failed:%s" % failed_aps)

发表回复

您的电子邮箱地址不会被公开。