Guest User

Untitled

a guest
Feb 25th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import requests as r
  3. import sys
  4. import getpass as getpass
  5. from requests.packages.urllib3.exceptions import InsecureRequestWarning
  6. #Variables with Integers
  7. allocated = 0.
  8. written = 0
  9. cl_num = 0
  10. #site variables
  11. NED = 'https://10.3.34.190:443'
  12. SED = 'https://10.4.34.160:443'
  13. #Empty lists
  14. volumes = []
  15. hosts = []
  16. # Parameters
  17. user = input('Username: ')
  18. password = getpass.getpass(prompt='Password: ', stream=None)
  19. #password = input('Password: ')
  20. uri = eval(input('NED or SED:'))
  21. headers = {
  22. 'Content-Type': 'application/json',
  23. 'Accept': 'application/json',
  24. 'Accept-Charset': 'utf-8',
  25. 'Accept-Encoding': 'gzip',
  26. 'Connection': 'Keep-Alive',
  27. }
  28. r.packages.urllib3.disable_warnings(InsecureRequestWarning)
  29. # Get Cluster ID
  30. C_ID = r.get(
  31. url=(uri) + '/api/rest/clusters',
  32. auth=(user, password), headers=headers, verify=False)
  33. cluster = C_ID.json()
  34. search_cg = input('Cluster: ')
  35. for x in cluster['result']:
  36. if x['name'] == search_cg:
  37. cl_num = x['id']
  38. for h in x['hosts']:
  39. host = h['name']
  40. hosts.append(host)
  41. if not cl_num:
  42. sys.exit("Cluster not found. Please verify and run again.")
  43. CV_ID = r.get(
  44. url=uri + '/api/rest/clusters/' + str(cl_num) + '/luns',
  45. auth=(user, password), headers=headers, verify=False)
  46. vol_id = CV_ID.json()
  47. for v in vol_id['result']:
  48. vol = v['volume_id']
  49. volumes.append(vol)
  50. for v in volumes:
  51. C_Size = r.get(
  52. url=uri + '/api/rest/volumes/' + str(v),
  53. auth=(user, password), headers=headers, verify=False)
  54. # JSON Math
  55. done = C_Size.json()
  56. # print(json.dumps(done, sort_keys=True, indent=4))
  57. allocated += done['result']['size']
  58. written += done['result']['allocated']
  59. print("Hosts in cluster: " + (", ".join(hosts)))
  60. print("# of volumes: " + str(len(volumes)))
  61. print("Presented: " + str(round(allocated / 1000 / 1000 / 1000 / 1000, 2)) + str
  62. (" TB"), end="")
  63. print(" Used: " + str(round(written / 1000 / 1000 / 1000 / 1000, 2)) + str(" TB"))
Add Comment
Please, Sign In to add comment