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 pathNewCalmProject.py
More file actions
140 lines (134 loc) · 4.02 KB
/
Copy pathNewCalmProject.py
File metadata and controls
140 lines (134 loc) · 4.02 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#region headers
# escript-template v20190611 / stephane.bourdeaud@nutanix.com
# * author: MITU Bogdan Nicolae (EEAS-EXT) <Bogdan-Nicolae.MITU@ext.eeas.europa.eu>
# * version: 2019/09/17
# task_name: NewCalmProject
# description: Create a new project in different sizes: small, medium, large, configured with an unique VlanID, with project owner having the "Project Admin role".
# output vars: project_name, project_uuid
# endregion
#region capture Calm variables
username = "@@{pc.username}@@"
username_secret = "@@{pc.secret}@@"
api_server = "@@{pc_ip}@@"
rand_num = "@@{calm_unique}@@"
calm_user_upn = "@@{calm_username}@@"
nutanix_calm_user_uuid = "@@{nutanix_calm_user_uuid}@@"
ahv_network_uuid = "@@{ahv_network_uuid}@@"
project_vlan_id = "@@{project_vlan_id}@@"
project_size = "@@{project_size}@@"
environment_uuid = "@@{environment_uuid}@@"
#input from user
user_project_name = "@@{user_project_name}@@"
#endregion
#region define variables
project_name = "{0}_VPC{1}_{2}".format(user_project_name,project_vlan_id,rand_num)
max_vcpu = 4
max_memory = 16*1073741824
max_storage = 200*1073741824
medium_multiplier = 2
large_multiplier = 4
if project_size == "medium":
max_vcpu = max_vcpu*medium_multiplier
max_memory = max_memory*medium_multiplier
max_storage = max_storage*medium_multiplier
if project_size == "large":
max_vcpu = max_vcpu*large_multiplier
max_memory = max_memory*large_multiplier
max_storage = max_storage*large_multiplier
# endregion
#region prepare api call
api_server_port = "9440"
api_server_endpoint = "/api/nutanix/v3/projects_internal"
length = 100
url = "https://{}:{}{}".format(
api_server,
api_server_port,
api_server_endpoint
)
method = "POST"
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
# Compose the json payload
payload = {
"api_version":"3.1.0",
"metadata":{
"kind":"project",
"owner_reference": {
"kind": "user",
"uuid": nutanix_calm_user_uuid,
"name": calm_user_upn
}
},
"spec":{
"project_detail":{
"name":project_name,
"description":"Created for {}".format(calm_user_upn),
"resources":{
"subnet_reference_list":[
{
"kind":"subnet",
"uuid":ahv_network_uuid
}
],
"resource_domain":{
"resources":[
{
"limit":max_vcpu,
"resource_type":"VCPUS"
},
{
"limit":max_storage,
"resource_type":"STORAGE"
},
{
"limit":max_memory,
"resource_type":"MEMORY"
}
]
},
"user_reference_list":[],
"external_user_group_reference_list":[],
"environment_reference_list": [
{
"kind": "environment",
"uuid": environment_uuid
}
],
}
},
"user_list": [],
"user_group_list": [],
"access_control_policy_list": []
}
}
# 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 json.dumps(json.loads(resp.content), indent=4)
print "project_name={0}".format(json.loads(resp.content)['spec']['project_detail']['name'])
print "project_uuid={0}".format(json.loads(resp.content)['metadata']['uuid'])
exit(0)
else:
#api call failed
print("Request failed")
print("Headers: {}".format(headers))
print("Payload: {}".format(json.dumps(payload)))
print('Status code: {}'.format(resp.status_code))
print('Response: {}'.format(json.dumps(json.loads(resp.content), indent=4)))
exit(1)
# endregion