Advertisement
Guest User

Untitled

a guest
Nov 1st, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. #!/usr/bin/python
  2. import requests
  3. import getpass
  4. import json
  5. from pprint import pprint
  6.  
  7. from requests.packages.urllib3.exceptions import InsecureRequestWarning
  8. requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
  9.  
  10. def login(session):
  11. url = "http://" + host + "/rest/login"
  12. #print url
  13. try:
  14. response = session.post(url=url)
  15. #print dir(response)
  16. #print response
  17. #print response.headers
  18. except:
  19. print "Unable to login to CMCNE"
  20. return None
  21. return response.headers['WStoken']
  22.  
  23. def get_fabrics(session,host):
  24. url = "https://" + host + "/rest/resourcegroups/All/fcfabrics"
  25. #print url
  26. try:
  27. response = session.get(url=url)
  28. #print response
  29. return json.loads(response.content)
  30. except:
  31. print "Failed to list fabrics"
  32. return None
  33. return response.content
  34.  
  35.  
  36. def get_fcswitches(session,host):
  37. url = "https://" + host + "/rest/resourcegroups/All/fcfabrics/"+fabric_key+"/fcswitches"
  38. print url
  39. try:
  40. response = session.get(url=url)
  41. #print response
  42. return json.loads(response.content)
  43. except:
  44. print "Failed to list switches"
  45. return None
  46. return response.content
  47.  
  48.  
  49.  
  50. #10.188.131.20 for Crit/FlexDC/Backup
  51. #10.185.55.41 for Prod/Colo12
  52. host = raw_input("Enter CMCNE host IP: ")
  53. print "Enter your credentials"
  54. username = raw_input("Enter your username: ")
  55. password = getpass.getpass("Enter your password: ")
  56. session = requests.Session()
  57. session.verify = False
  58. session.headers.update({"WSUsername":"%s" % username ,"WSPassword":"%s" % password,"Accept":"application/vnd.brocade.networkadvisor+json;version=v1"})
  59. session.auth = (username,password)
  60. token = login(session)
  61. session.headers.update({"WStoken":"%s" % token})
  62.  
  63. content = get_fabrics(session,host)
  64. print json.dumps(content,indent=4)
  65.  
  66. fabric_key = raw_input("Enter the Fabric WWN of principle switch: ")
  67. content = get_fcswitches(session,host)
  68. #print("Displaying the list of switches in fabric "+fabric_key+"...")
  69. print json.dumps(content,indent=4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement