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

Brocade Network Advisor REST API Guide
13
53-1003160-01
Creating a sample Python client
2
connection = http.client.HTTPConnection("10.24.41.138")
###########################
# Log in to Network Advisor
###########################
# Send login requrest
connection.request('POST', 'http://10.24.41.138/rest/login',
headers={"WSUsername":"Administrator",
"WSPassword":"password",
"Accept":"application/vnd.brocade.networkadvisor+json;version=v1"})
print()
print("Sending login request to Network Advisor...")
# Get the response
response = connection.getresponse()
# Display the response status
print()
print ("Status= ", response.status)
# If successful (status = 200), display the returned Network Advisor session
token
if response.status == 200:
WStoken = response.getheader('WStoken')
print()
print("Login successful!")
print("WStoken: ", WStoken)
else:
print()
print (response.status, response.reason)
connection.close()
###########################
# Retrieve fabrics
###########################
# Send GET requrest
connection.connect()
connection.request('GET',
'http://10.24.41.138/rest/resourcegroups/All/fcfabrics',
headers={"WStoken":WStoken,
"Accept":"application/vnd.brocade.networkadvisor+json;version=v1"})
print()
print("--------------------------------------------------------------------")
print("Getting list of all fabrics...")
# 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