-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi-shutdown-cluster.py
51 lines (36 loc) · 1.29 KB
/
api-shutdown-cluster.py
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
import requests
import jsbeautifier
import sys
# disable warnings from SSL Check
if not sys.warnoptions:
import warnings
warnings.simplefilter("ignore")
# POST BODY
creds = ('administrator@vsphere.local', 'VxR@il1!')
runtype = {"dryrun": "false"} # if true only does pre-checks
headers = {'Content-type': 'application/json'}
shut_resp = requests.post('https://172.168.10.150/rest/vxm/v1/cluster/shutdown',
verify=False,
headers=headers,
auth=creds,
json=runtype)
shut__resp_code = shut_resp.status_code
# assign a dict type to the response
job_id = shut_resp.json()
req_id = job_id.get('request_id')
print(f'''
#######################
# API CALL SUBMITTED #
#######################
Shutdown Cluster API Submitted. Response Code is: {shut__resp_code} and request_id is: {req_id}
''')
# we check now the request status from previous call
resp_get_id = requests.request('GET', 'https://172.168.10.150/rest/vxm/v1/requests/' + req_id,
verify=False,
auth=creds)
beauty = jsbeautifier.beautify(resp_get_id.text)
print('''
##################################
# The Status of the API CALL is: #
##################################
''', beauty)