Advertisement
Guest User

Untitled

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