Advertisement
Guest User

Untitled

a guest
Nov 1st, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 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. def find_switch(switches, wwn):
  49. for switch in switches:
  50. if switch['key'] == wwn:
  51. return switch
  52. else print "WWN does not exist"
  53.  
  54. #10.188.131.20 for Crit/FlexDC/Backup
  55. #10.185.55.41 for Prod/Colo12
  56. host = raw_input("Enter CMCNE host IP: ")
  57. print "Enter your credentials"
  58. username = raw_input("Enter your username: ")
  59. password = getpass.getpass("Enter your password: ")
  60. session = requests.Session()
  61. session.verify = False
  62. session.headers.update({"WSUsername":"%s" % username ,"WSPassword":"%s" % password,"Accept":"application/vnd.brocade.networkadvisor+json;version=v1"})
  63. session.auth = (username,password)
  64. token = login(session)
  65. session.headers.update({"WStoken":"%s" % token})
  66.  
  67. content = get_fabrics(session,host)
  68. print json.dumps(content,indent=4)
  69.  
  70. fabric_key = raw_input("Enter the Fabric WWN of principle switch: ")
  71. content = get_fcswitches(session,host)
  72. print("Displaying the list of switches in fabric "+fabric_key+"...")
  73. print json.dumps(content,indent=4)
  74. wwn = raw_input("Enter the WWN of end device: ")
  75. find_switch(content, wwn)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement