-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.py
More file actions
82 lines (45 loc) · 2.37 KB
/
example.py
File metadata and controls
82 lines (45 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from sgwsapi import *
from global_secrets import api_get_url,api_password,api_username,api_default_group,tenant_account_for_test
import json
#This is an example of how to use the API calls:
# Get environment variables
# SSO username and password with admin rights
api_url = api_get_url()
api_user = api_username()
api_passwd= api_password()
#Get auth token:
resp = get_auth_token(api_user,api_passwd)
if resp.status_code != 200:
raise Exception('POST /authorize/ {}'.format(resp.status_code) + " Error: "+resp.json()["message"]["text"] )
print('Auth Token {}'.format(resp.json()["data"]))
auth_token=resp.json()["data"]
# Get grid health:
print (json.dumps(get_health(auth_token).json(), indent=1))
# Get grid alarms:
print (json.dumps(get_alarms(auth_token).json(), indent=1))
# Get health topology:
print (json.dumps(get_health_topology(auth_token).json(), indent=1))
# Get list of admin users:
print (json.dumps(get_admin_users(auth_token).json(), indent=1))
#Get the list of accounts"
response = get_tenants_accounts(auth_token)
if response.status_code != 200:
raise Exception('POST //api/v3/grid/accounts?limit=25 {}'.format(response.status_code) + " Error: "+response.json()["message"]["text"] )
#For each tenant account get the bucket usage:
for items in response.json()['data']:
print('Account id: {}, account Name: {}'.format(items['id'], items['name']))
tenantid='{}'.format(items['id'])
buckets_response=get_storage_usage_in_tenant( tenantid , auth_token)
if buckets_response.status_code != 200:
raise Exception('POST /api/v3/grid/accounts/id/usage {}'.format(buckets_response.status_code) + " Error: "+buckets_response.json()["message"]["text"] )
for buckets in buckets_response.json()['data']['buckets']:
print('{} size: {} TB numbers of ojects:{}'.format(buckets['name'], buckets['dataBytes']/1099511627776, buckets['objectCount']))
print ("---------------------------------------------- ")
#Get tenant auth token:
resp = get_tenant_token(api_user,api_passwd,tenant_account_for_test())
if resp.status_code != 200:
raise Exception('POST /authorize/ {}'.format(resp.status_code) + " Error: "+resp.json()["message"]["text"] )
print('Auth Token for tenant {}'.format(resp.json()["data"]))
auth_token_tenant=resp.json()["data"]
# Get tenant space usage:
print (json.dumps(get_usage(auth_token_tenant).json(), indent=1))