Brocade Network Advisor REST API Guide (Supporting Network Advisor 12.3.0) User Manual
Page 29

Brocade Network Advisor REST API Guide
15
53-1003160-01
Creating a sample Python client
2
connection.connect()
connection.request('GET',
'http://10.24.41.138/rest/resourcegroups/All/fcfabrics/'+fabric_key+'/fcswitc
hes',
headers={"WStoken":WStoken,
"Accept":"application/vnd.brocade.networkadvisor+json;version=v1"})
print()
print("--------------------------------------------------------------------")
print("Get the list of switches under fabric "+fabric_key+" ...")
# Get the response
response = connection.getresponse()
# Display the response status
print()
print ("Status= ", response.status)
# If successful (status = 200), display the returned list in JSON format
if response.status == 200:
print()
print("List of switches:")
json_response_bytes = response.read()
json_response_string = str(json_response_bytes, encoding='utf8')
list_of_fabric_switches_dict=json.loads(json_response_string)
print(json.dumps(list_of_fabric_switches_dict, indent=4))
else:
print()
print (response.status, response.reason)
connection.close()
3. Save the file as
my_na_client.py
.
4. Run the program by entering the following command at the command prompt:
C:\Python33>python my_na_client.py
If successful, you should see output similar to the following:
Sending login request to Network Advisor...
Status= 200
Login successful!
WStoken: RPTZz0z5ayVkvqIuy7quIEbjap8=
-----------------------------------------------------------------------------
Getting list of all fabrics...
Status= 200
List of fabrics:
{
"fcFabrics": [
{
"seedSwitchWwn": "10:00:00:05:33:A6:B6:17",
"name": "10:00:00:05:33:A6:B6:17",
"secure": false,