Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import requests as r
- import sys
- import getpass as getpass
- from requests.packages.urllib3.exceptions import InsecureRequestWarning
- #Variables with Integers
- allocated = 0.
- written = 0
- cl_num = 0
- #site variables
- NED = 'https://10.3.34.190:443'
- SED = 'https://10.4.34.160:443'
- #Empty lists
- volumes = []
- hosts = []
- # Parameters
- user = input('Username: ')
- password = getpass.getpass(prompt='Password: ', stream=None)
- #password = input('Password: ')
- uri = eval(input('NED or SED:'))
- headers = {
- 'Content-Type': 'application/json',
- 'Accept': 'application/json',
- 'Accept-Charset': 'utf-8',
- 'Accept-Encoding': 'gzip',
- 'Connection': 'Keep-Alive',
- }
- r.packages.urllib3.disable_warnings(InsecureRequestWarning)
- # Get Cluster ID
- C_ID = r.get(
- url=(uri) + '/api/rest/clusters',
- auth=(user, password), headers=headers, verify=False)
- cluster = C_ID.json()
- search_cg = input('Cluster: ')
- for x in cluster['result']:
- if x['name'] == search_cg:
- cl_num = x['id']
- for h in x['hosts']:
- host = h['name']
- hosts.append(host)
- if not cl_num:
- sys.exit("Cluster not found. Please verify and run again.")
- CV_ID = r.get(
- url=uri + '/api/rest/clusters/' + str(cl_num) + '/luns',
- auth=(user, password), headers=headers, verify=False)
- vol_id = CV_ID.json()
- for v in vol_id['result']:
- vol = v['volume_id']
- volumes.append(vol)
- for v in volumes:
- C_Size = r.get(
- url=uri + '/api/rest/volumes/' + str(v),
- auth=(user, password), headers=headers, verify=False)
- # JSON Math
- done = C_Size.json()
- # print(json.dumps(done, sort_keys=True, indent=4))
- allocated += done['result']['size']
- written += done['result']['allocated']
- print("Hosts in cluster: " + (", ".join(hosts)))
- print("# of volumes: " + str(len(volumes)))
- print("Presented: " + str(round(allocated / 1000 / 1000 / 1000 / 1000, 2)) + str
- (" TB"), end="")
- print(" Used: " + str(round(written / 1000 / 1000 / 1000 / 1000, 2)) + str(" TB"))
Add Comment
Please, Sign In to add comment