This repository was archived by the owner on Apr 28, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetProjectNetwork.py
More file actions
70 lines (65 loc) · 1.87 KB
/
Copy pathGetProjectNetwork.py
File metadata and controls
70 lines (65 loc) · 1.87 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
#region headers
# escript-template v20190611 / stephane.bourdeaud@nutanix.com
# * author: stephane.bourdeaud@nutanix.com
# * version: 2019/09/20
# task_name: GetNetworkProject
# description: Given a project UUID, returns the first AHV network assigned to
# that project.
# output vars: ahv_subnet
# endregion
#region capture Calm variables
project_name = "@@{calm_project_name}@@"
api_server = "@@{pc_ip}@@"
username = "@@{pc.username}@@"
username_secret = "@@{pc.secret}@@"
#endregion
#region prepare api call (get projects)
api_server_port = "9440"
api_server_endpoint = "/api/nutanix/v3/projects/list"
length = 100
url = "https://{}:{}{}".format(
api_server,
api_server_port,
api_server_endpoint
)
method = "POST"
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
payload = {
"kind": "project",
"length":length,
"offset":0
}
# endregion
#region make the api call
print("Making a {} API call to {}".format(method, url))
resp = urlreq(
url,
verb=method,
auth='BASIC',
user=username,
passwd=username_secret,
params=json.dumps(payload),
headers=headers,
verify=False
)
# endregion
#region process the results
if resp.ok:
print ("Request status code {} on {}".format(resp.status_code,resp.request.url))
json_resp = json.loads(resp.content)
for project in json_resp['entities']:
if project_name == project['status']['name']:
ahv_subnet = project['spec']['resources']['subnet_reference_list'][0]['name']
print ("ahv_subnet={}".format(ahv_subnet))
exit(0)
else:
#api call failed
print("Request failed: {}".format(resp.status_code))
#print("Headers: {}".format(headers))
#print('Status code: {}'.format(resp.status_code))
#print('Response: {}'.format(json.dumps(json.loads(resp.content), indent=4)))
exit(1)
# endregion