Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import requests
- import getpass
- import json
- from pprint import pprint
- from requests.packages.urllib3.exceptions import InsecureRequestWarning
- requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
- def login(session):
- url = "http://" + host + "/rest/login"
- #print url
- try:
- response = session.post(url=url)
- #print dir(response)
- #print response
- #print response.headers
- except:
- print "Unable to login to CMCNE"
- return None
- return response.headers['WStoken']
- def get_fabrics(session,host):
- url = "https://" + host + "/rest/resourcegroups/All/fcfabrics"
- #print url
- try:
- response = session.get(url=url)
- #print response
- return json.loads(response.content)
- except:
- print "Failed to list fabrics"
- return None
- return response.content
- def get_fcswitches(session,host):
- url = "https://" + host + "/rest/resourcegroups/All/fcfabrics/"+fabric_key+"/fcswitches"
- print url
- try:
- response = session.get(url=url)
- #print response
- return json.loads(response.content)
- except:
- print "Failed to list switches"
- return None
- return response.content
- #10.188.131.20 for Crit/FlexDC/Backup
- #10.185.55.41 for Prod/Colo12
- host = raw_input("Enter CMCNE host IP: ")
- print "Enter your credentials"
- username = raw_input("Enter your username: ")
- password = getpass.getpass("Enter your password: ")
- session = requests.Session()
- session.verify = False
- session.headers.update({"WSUsername":"%s" % username ,"WSPassword":"%s" % password,"Accept":"application/vnd.brocade.networkadvisor+json;version=v1"})
- session.auth = (username,password)
- token = login(session)
- session.headers.update({"WStoken":"%s" % token})
- content = get_fabrics(session,host)
- print json.dumps(content,indent=4)
- fabric_key = raw_input("Enter the Fabric WWN of principle switch: ")
- content = get_fcswitches(session,host)
- #print("Displaying the list of switches in fabric "+fabric_key+"...")
- print json.dumps(content,indent=4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement