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

14
Brocade Network Advisor REST API Guide
53-1003160-01
Creating a sample Python client
2
if response.status == 200:
print()
print("List of fabrics:")
json_response_bytes = response.read()
json_response_string = str(json_response_bytes, encoding='utf8')
list_of_fabrics_dict=json.loads(json_response_string)
print(json.dumps(list_of_fabrics_dict, indent=4))
print("Number of FC fabrics: ", len(list_of_fabrics_dict["fcFabrics"]))
else:
print()
print (response.status, response.reason)
connection.close()
##############################
# Retrieve details of a fabric
##############################
# Get the key of the first fabric in the list
fabric_key = list_of_fabrics_dict["fcFabrics"][0]["key"]
# Send GET requrest
connection.connect()
connection.request('GET',
'http://10.24.41.138/rest/resourcegroups/All/fcfabrics/'+fabric_key,
headers={"WStoken":WStoken,
"Accept":"application/vnd.brocade.networkadvisor+json;version=v1"})
print()
print("--------------------------------------------------------------------")
print("Get fabric '+fabric_key+'details...")
# 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("Fabric details:")
json_response_bytes = response.read()
json_response_string = str(json_response_bytes, encoding='utf8')
fabric_details_dict=json.loads(json_response_string)
print(json.dumps(fabric_details_dict, indent=4))
else:
print()
print (response.status, response.reason)
connection.close()
######################################################
# Retrieve list of switches in the context of a fabric
######################################################
# Send GET requrest