Extreme API with Python

Table Of Contents
Extreme API with Python
Page | 138
Part no.9036931-00 Rev AA February 2021
def restGet(endpoint):
try:
r = requests.get(baseURL + endpoint, verify=False, headers=myHeaders, timeout=5)
except requests.exceptions.Timeout:
print("Timeout!")
return None
if r.status_code != 200:
print("Cannot access XCC REST API! Error code: {}".format(r.status_code))
print(r.content)
return None
return r.json()
data = restGet('/management/v1/aps')
if data:
print(len(data))
Executing the script results in the following:
C:\Extreme API with Python> xcc.py
35
You can also modify your code to count the number of AP models.
data = restGet('/management/v1/aps')
if data:
APList = []
print(len(data))
for ap in data:
APList.append(ap.get('platformName'))
for count, model in sorted(((APList).count(ap), ap) for ap in set(APList)):
print("{} {}".format(model, count))
You should see the following:
C:\Extreme API with Python> xcc.py
35
AP310 1
AP3917 1
AP460 1
AP3912 3