blob: 86c908adfa0f73da062367e1d478cb37acd0114a [file] [log] [blame]
root@rancher6c68bee2019-05-01 16:39:12 -07001#!/usr/bin/python
2
Itohan1f3c8d62019-05-24 23:52:26 +00003'''
4Read the README file before running this script
5'''
root@rancher6c68bee2019-05-01 16:39:12 -07006
7import json
8import os
9import mysql.connector as mariadb
10import time
11
root@rancher6c68bee2019-05-01 16:39:12 -070012def get_parameters(file):
13 parameters = json.load(file)
14 return parameters
15
16def set_open_cli_env(parameters):
17 os.environ["OPEN_CLI_PRODUCT_IN_USE"] = parameters["open_cli_product"]
18 os.environ["OPEN_CLI_HOME"] = parameters["open_cli_home"]
19
20def create_complex(parameters):
21 complex_create_string = "oclip complex-create -j {} -r {} -x {} -y {} -lt {} -l {} -i {} -lo {} \
22 -S {} -la {} -g {} -w {} -z {} -k {} -o {} -q {} -m {} -u {} -p {}".format(parameters["street2"], \
23 parameters["physical_location"], parameters["complex_name"], \
24 parameters["data_center_code"], parameters["latitude"], parameters["region"], \
25 parameters["street1"], parameters["longitude"], parameters["state"], \
26 parameters["lata"], parameters["city"], parameters["postal-code"], \
27 parameters["complex_name"], parameters["country"], parameters["elevation"], \
28 parameters["identity_url"], parameters["aai_url"], parameters["aai_username"], \
29 parameters["aai_password"])
30
31 os.system(complex_create_string)
32
33
34def register_cloud_helper(cloud_region, values, parameters):
35 #Create Cloud
36 cloud_create_string = 'oclip cloud-create -e {} -b {} -I {{\\\\\\"openstack-region-id\\\\\\":\\\\\\"{}\\\\\\"}} \
37 -x {} -y {} -j {} -w {} -l {} -url {} -n {} -q {} -r {} -Q {} -i {} -g {} -z {} -k {} -c {} -m {} -u {} -p {}'.format(
38 values.get("esr-system-info-id"), values.get("user-name"), cloud_region, parameters["cloud-owner"], \
39 cloud_region, values.get("password"), values.get("cloud-region-version"), values.get("default-tenant"), \
40 values.get("service-url"), parameters["complex_name"], values.get("cloud-type"), parameters["owner-defined-type"], \
41 values.get("system-type"), values.get("identity-url"), parameters["cloud-zone"], values.get("ssl-insecure"), \
42 values.get("system-status"), values.get("cloud-domain"), parameters["aai_url"], parameters["aai_username"], \
43 parameters["aai_password"])
44
45
46 os.system(cloud_create_string)
47
48 #Associate Cloud with complex
49 complex_associate_string = "oclip complex-associate -x {} -y {} -z {} -m {} -u {} -p {}".format(parameters["complex_name"], \
50 cloud_region, parameters["cloud-owner"], parameters["aai_url"], parameters["aai_username"], parameters["aai_password"])
51 os.system(complex_associate_string)
52
53 #Register Cloud with Multicloud
54 multicloud_register_string = "oclip multicloud-register-cloud -y {} -x {} -m {}".format(parameters["cloud-owner"], \
55 cloud_region, parameters["multicloud_url"])
56 os.system(multicloud_register_string)
Itohan1f3c8d62019-05-24 23:52:26 +000057 time.sleep(2)
root@rancher6c68bee2019-05-01 16:39:12 -070058
59def register_all_clouds(parameters):
60 cloud_dictionary = parameters["cloud_region_data"]
61 for cloud_region, cloud_region_values in cloud_dictionary.iteritems():
62 register_cloud_helper(cloud_region, cloud_region_values, parameters)
63
64def create_service_type(parameters):
65 create_string = "oclip service-type-create -x {} -m {} -u {} -p {}".format( parameters["service_name"], \
66 parameters["aai_url"], parameters["aai_username"], parameters["aai_password"])
67 os.system(create_string)
68
69def create_customer(parameters):
70 create_string = "oclip customer-create -x {} -y {} -m {} -u {} -p {}".format( parameters["customer_name"], \
71 parameters["subscriber_name"], parameters["aai_url"], parameters["aai_username"], parameters["aai_password"])
72 os.system(create_string)
73
74def add_customer_subscription(parameters):
75 subscription_check = 0
76 for cloud_region, cloud_region_values in (parameters["cloud_region_data"]).iteritems():
77 if subscription_check == 0 :
78 subscription_string = "oclip subscription-create -x {} -c {} -z {} -e {} -y {} -r {} -m {} -u {} -p {}".format(\
79 parameters["customer_name"], cloud_region_values.get("tenant-id"), parameters["cloud-owner"], parameters["service_name"],\
80 cloud_region_values.get("default-tenant"), cloud_region, parameters["aai_url"], parameters["aai_username"], parameters["aai_password"] )
81 else:
82 subscription_string = "oclip subscription-cloud-add -x {} -c {} -z {} -e {} -y {} -r {} -m {} -u {} -p {}".format(\
83 parameters["customer_name"], cloud_region_values.get("tenant-id"), parameters["cloud-owner"], parameters["service_name"],\
84 cloud_region_values.get("default-tenant"), cloud_region, parameters["aai_url"], parameters["aai_username"], parameters["aai_password"] )
85 os.system(subscription_string)
86 subscription_check+=1
87
88def get_out_helper(in_string):
89 out_list = (((in_string.replace('-','')).replace('|', '')).replace('+', '')).split()
90 return out_list
91
92def get_out_helper_2(in_string):
93 out_list = ((in_string.replace('|', '')).replace('+', '')).split()
94 return out_list
95
96#ONBOARDING SECTION
97def create_vlm(parameters):
98 vlm_create_string = "oclip vlm-create -x {} -u {} -p {} -m {}".format(parameters["vendor-name"], \
99 parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_onboarding_url"])
100 command_out = (os.popen(vlm_create_string)).read()
101 out_list = get_out_helper(command_out)
102 vlm_id = out_list[3]
103 vlm_version = out_list[5]
104
105 entitlement_string = "oclip vlm-entitlement-pool-create -x {} -y {} -e {} -z {} -k {} -g {} -l {} -u {} -p {} -m {}".format( \
106 parameters["entitlement-pool-name"], vlm_id, vlm_version, parameters["entitlement-description"], parameters["vendor-name"], \
107 parameters["expiry-date"], parameters["start-date"], parameters["sdc_creator"], parameters["sdc_password"], \
108 parameters["sdc_onboarding_url"])
109 command_out = (os.popen(entitlement_string)).read()
110 entitlement_id = (get_out_helper(command_out))[3]
111
112
113 key_group_string = "oclip vlm-key-group-create -c {} -e {} -x {} -y {} -u {} -p {} -m {}".format(vlm_id, vlm_version, \
114 parameters["key-group-name"], parameters["key-group-type"], parameters["sdc_creator"], parameters["sdc_password"], \
115 parameters["sdc_onboarding_url"])
116 command_out = (os.popen(key_group_string)).read()
117 key_group_id = (get_out_helper(command_out))[3]
118
119 feature_group_string = "oclip vlm-feature-group-create -x {} -y {} -e {} -z {} -g {} -b {} -c {} -u {} -p {} -m {}".format(
120 parameters["feature-grp-name"], vlm_id, vlm_version, parameters["feature-grp-desc"], key_group_id, entitlement_id, \
121 parameters["part-no"], parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_onboarding_url"])
122 command_out = (os.popen(feature_group_string)).read()
123 feature_group_id = (get_out_helper(command_out))[3]
124
125 agreement_string = "oclip vlm-aggreement-create -x {} -y {} -e {} -z {} -g {} -u {} -p {} -m {}".format(parameters["agreement-name"], \
126 vlm_id, vlm_version, parameters["agreement-desc"], feature_group_id, parameters["sdc_creator"], parameters["sdc_password"], \
127 parameters["sdc_onboarding_url"])
128 command_out = (os.popen(agreement_string)).read()
129 agreement_id = (get_out_helper(command_out))[3]
130
131 submit_string = "oclip vlm-submit -x {} -y {} -u {} -p {} -m {}".format(vlm_id, vlm_version, parameters["sdc_creator"], \
132 parameters["sdc_password"], parameters["sdc_onboarding_url"])
133 os.system(submit_string)
134
135 output = [feature_group_id, agreement_id, vlm_version, vlm_id ]
136 return output
137
138def create_vsp(parameters, in_list):
139 create_string = "oclip vsp-create -j {} -o {} -e {} -x {} -y {} -i {} -c {} -g {} -u {} -p {} -m {}".format( in_list[0], \
140 parameters["onboarding-method"], parameters["vendor-name" ], parameters["vsp-name"], parameters["vsp-desc"], in_list[1], \
141 in_list[2], in_list[3], parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_onboarding_url"] )
142 command_out = (os.popen(create_string)).read()
143 out_list = get_out_helper(command_out)
144 vsp_id = out_list[3]
145 vsp_version = out_list[5]
146
147 os.system("oclip vsp-add-artifact -x {} -y {} -z {} -u {} -p {} -m {}".format(vsp_id, vsp_version, parameters["csar-file-path"], \
148 parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_onboarding_url"]))
149
150 os.system("oclip vsp-validate -x {} -y {} -u {} -p {} -m {}".format(vsp_id, vsp_version, parameters["sdc_creator"], \
151 parameters["sdc_password"], parameters["sdc_onboarding_url"]))
152
153 os.system("oclip vsp-submit -x {} -y {} -u {} -p {} -m {}".format(vsp_id, vsp_version, parameters["sdc_creator"], \
154 parameters["sdc_password"], parameters["sdc_onboarding_url"]))
155
156 os.system("oclip vsp-package -x {} -y {} -u {} -p {} -m {}".format(vsp_id, vsp_version, parameters["sdc_creator"], \
157 parameters["sdc_password"], parameters["sdc_onboarding_url"]))
158
159 return vsp_id
160
161
162def create_vf_model(parameters, vsp_id):
163 create_string = "oclip vf-model-create -y {} -g {} -x {} -z {} -b {} -u {} -p {} -m {}".format(parameters["vf-description"], \
164 parameters["vsp-version"], parameters["vf-name"], parameters["vendor-name"], vsp_id, parameters["sdc_creator"], \
165 parameters["sdc_password"], parameters["sdc_catalog_url"])
166 os.system(create_string)
167
168 output = (os.popen("oclip vf-model-list -m {} -u {} -p {} | grep {}".format(parameters["sdc_catalog_url"], \
169 parameters["sdc_creator"], parameters["sdc_password"], parameters["vf-name"]))).read()
170 output = (get_out_helper_2(output))
171
Itohan454b2792019-05-06 23:18:34 +0000172 vf_unique_id = output[1]
173
174 os.system("oclip vf-model-certify -b {} -r {} -u {} -p {} -m {}".format(vf_unique_id, parameters["vf-remarks"], \
175 parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"]))
176
177 #Check for new parameters after certification
178 output = (os.popen("oclip vf-model-list -m {} -u {} -p {} | grep {}".format(parameters["sdc_catalog_url"], \
179 parameters["sdc_creator"], parameters["sdc_password"], parameters["vf-name"]))).read()
180 output = (get_out_helper_2(output))
181
root@rancher6c68bee2019-05-01 16:39:12 -0700182 vf_id = output[0]
183 vf_unique_id = output[1]
184 vf_model_invariant_uuid = output[2]
185 vf_model_version = output[4]
186
root@rancher6c68bee2019-05-01 16:39:12 -0700187 out_dict = {}
188 out_dict["vf_id"] = vf_id
189 out_dict["vf_unique_id"] = vf_unique_id
190 out_dict["vf_model_invariant_uuid"] = vf_model_invariant_uuid
191 out_dict["vf_model_version"] = vf_model_version
192
193 return out_dict
194
195
196def create_service_model(parameters, vf_unique_id):
197 create_string = "oclip service-model-create -z {} -y {} -e {} -x {} -c {} -b {} -u {} -p {} -m {} |grep ID".format(parameters["project-code"], \
Itohan8ec5f1f2019-05-04 00:21:47 +0000198 parameters["service-model-desc"], parameters["icon-id"], parameters["service-model-name"], parameters["category-display"], \
199 parameters["category"],parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"])
root@rancher6c68bee2019-05-01 16:39:12 -0700200
201 service_model_id = (get_out_helper_2((os.popen(create_string)).read()))[1]
202
Itohan8ec5f1f2019-05-04 00:21:47 +0000203 os.system("oclip service-model-add-vf -x {} -b {} -y {} -z {} -u {} -p {} -m {}".format(service_model_id, parameters["vf-version"], \
204 vf_unique_id, parameters["vf-name"], parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"] ))
root@rancher6c68bee2019-05-01 16:39:12 -0700205
206 os.system("oclip service-model-test-request -b {} -r {} -u {} -p {} -m {}".format(service_model_id, parameters["service-test-remarks"], \
207 parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"]))
208
209 os.system("oclip service-model-test-start -b {} -u {} -p {} -m {}".format(service_model_id, parameters["sdc_tester"], \
210 parameters["sdc_password"], parameters["sdc_catalog_url"]))
211
212 os.system("oclip service-model-test-accept -b {} -r {} -u {} -p {} -m {}".format(service_model_id, parameters["service-accept-remarks"], \
213 parameters["sdc_tester"], parameters["sdc_password"], parameters["sdc_catalog_url"]))
214
Itohan8ec5f1f2019-05-04 00:21:47 +0000215 #Get uniqueId for the service model
216 service_model_values = (os.popen("oclip service-model-list -u {} -p {} -m {} |grep {}".format(parameters["sdc_creator"], \
root@rancher6c68bee2019-05-01 16:39:12 -0700217 parameters["sdc_password"], parameters["sdc_catalog_url"], parameters["service-model-name"]))).read()
Itohan8ec5f1f2019-05-04 00:21:47 +0000218 service_model_values = get_out_helper_2(service_model_values)
219 service_model_uniqueId = (service_model_values)[1]
root@rancher6c68bee2019-05-01 16:39:12 -0700220
Itohan8ec5f1f2019-05-04 00:21:47 +0000221 os.system("oclip service-model-approve -b {} -r {} -u {} -p {} -m {}".format(service_model_uniqueId, parameters["service-approve-remarks"], \
root@rancher6c68bee2019-05-01 16:39:12 -0700222 parameters["sdc_governor"], parameters["sdc_password"], parameters["sdc_catalog_url"]))
223
Itohan8ec5f1f2019-05-04 00:21:47 +0000224 os.system("oclip service-model-distribute -b {} -u {} -p {} -m {}".format(service_model_uniqueId, parameters["sdc_operator"], \
root@rancher6c68bee2019-05-01 16:39:12 -0700225 parameters["sdc_password"], parameters["sdc_catalog_url"]))
226
Itohan8ec5f1f2019-05-04 00:21:47 +0000227 return service_model_values
root@rancher6c68bee2019-05-01 16:39:12 -0700228
229
230#VNF Deployment Section
Itohane2f489f2019-06-03 23:53:15 +0000231def upload_policy_models(parameters):
232 os.system("python insert_policy_models.py {} {} {}".format(parameters["policy_db_ip"], \
233 parameters["policy_db_user"], parameters["policy_db_password"]))
root@rancher6c68bee2019-05-01 16:39:12 -0700234
root@rancher6c68bee2019-05-01 16:39:12 -0700235def add_policies(parameters):
236 resource_string = (os.popen("oclip get-resource-module-name -u {} -p {} -m {} |grep {}".format(\
237 parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"], \
Itohan1f3c8d62019-05-24 23:52:26 +0000238 parameters["vf-name"] ))).read()
root@rancher6c68bee2019-05-01 16:39:12 -0700239 resource_module_name = (get_out_helper_2(resource_string))[1]
240
Itohan454b2792019-05-06 23:18:34 +0000241 #Put in the right resource module name in all policies located in parameters["policy_directory"]
242 os.system("find {}/ -type f -exec sed -i 's/{}/{}/g' {{}} \;".format(
243 parameters["policy_directory"], parameters["temp_resource_module_name"], resource_module_name))
244
root@rancher6c68bee2019-05-01 16:39:12 -0700245 #Loop through policy, put in resource_model_name and create policies
246 for policy in os.listdir(parameters["policy_directory"]):
Itohanecd1ebd2019-06-05 20:18:48 +0000247
Itohan8ec5f1f2019-05-04 00:21:47 +0000248 policy_file = (os.path.join(parameters["policy_directory"], policy))
Itohan1f3c8d62019-05-24 23:52:26 +0000249
Itohanecd1ebd2019-06-05 20:18:48 +0000250 #Get policy name from policy file
251 policy_contents = open(policy_file, 'r').read()
252 start_string = '"policyName\\":\\"'
253 end_string = '\\",\\"ver'
254 policy_name = policy_contents[policy_contents.find(start_string)+len(start_string):policy_contents.rfind(end_string)]
255
256
Itohan1f3c8d62019-05-24 23:52:26 +0000257 #Create policy
Itohan8ec5f1f2019-05-04 00:21:47 +0000258 os.system("oclip policy-create-outdated -m {} -u {} -p {} -x {} -S {} -T {} -o {} -b $(cat {})".format(parameters["policy_url"],\
259 parameters["policy_username"], parameters["policy_password"], policy_name, parameters["policy_scope"], \
260 parameters["policy_config_type"], parameters["policy_onapName"], policy_file))
root@rancher6c68bee2019-05-01 16:39:12 -0700261
262 #Push policy
263 os.system("oclip policy-push-outdated -m {} -u {} -p {} -x {} -b {} -c {}".format(parameters["policy_url"], \
264 parameters["policy_username"], parameters["policy_password"], policy_name, parameters["policy_config_type"],\
265 parameters["policy_pdp_group"]))
266
267
268def create_service_instance(parameters, sevice_model_list):
269 #Get Required parameters
270 service_uuid = service_model_list[0]
Itohan8ec5f1f2019-05-04 00:21:47 +0000271 service_invariant_uuid = service_model_list[2]
272 service_version = service_model_list[4]
root@rancher6c68bee2019-05-01 16:39:12 -0700273
274 owning_entity_values = (os.popen("oclip owning-entity-list -u {} -p {} -m {} |grep {}".format(parameters["aai_username"], \
275 parameters["aai_password"], parameters["aai_url"], parameters["owning-entity-name"]))).read()
276 owning_entity_id = (get_out_helper_2(owning_entity_values))[1]
277
278 #Create service instance
279 instance_output = (os.popen("oclip service-create -w {} -la {} -lo {} -o {} -A {} -i {} -y {} -x {} -q {} -O {} -k {}-{} -P {} \
280 -H {} -n {} -e {} -j {} -S {} -g {} -z {} -c {} -u {} -p {} -m {} |grep service-id".format(parameters["service_name"], \
281 parameters["customer-latitude"], parameters["customer-longitude"], parameters["orchestrator"], parameters["a-la-carte"], \
282 parameters["service-model-name"], parameters["company-name"], parameters["projectName"], parameters["requestor-id"], \
Itohan8ec5f1f2019-05-04 00:21:47 +0000283 parameters["owning-entity-name"], parameters["instance-name"], parameters["service_name"], parameters["test-api"], parameters["homing-solution"], \
root@rancher6c68bee2019-05-01 16:39:12 -0700284 service_uuid, service_invariant_uuid, service_version, parameters["subscriber_name"], service_uuid, owning_entity_id, \
285 parameters["customer_name"], parameters["so_username"], parameters["so_password"], parameters["so_url"] ))).read()
286
287 service_instance_id = (get_out_helper_2(instance_output))[1]
288 output_dict = {}
289
290 output_dict["service_instance_id"] = service_instance_id
291 output_dict["service_uuid"] = service_uuid
292 output_dict["service_invariant_uuid"] = service_invariant_uuid
293 output_dict["service_version"] = service_version
294
295
296 return output_dict
297
Itohan8ec5f1f2019-05-04 00:21:47 +0000298def query_db(parameters, service_model_uuid, vf_model_uuid):
root@rancher6c68bee2019-05-01 16:39:12 -0700299
300 out_dictionary = {}
301 #Query DB Certain parameters required
302 mariadb_connection = mariadb.connect(user='{}'.format(parameters["so_mariadb_user"]), host='{}'.format(parameters["so_mariadb_host"]),
303 password='{}'.format(parameters["so_mariadb_password"]), database='{}'.format(parameters["so_mariadb_db"]))
304 values = mariadb_connection.cursor()
305
306 #Get vf model customization values
307 values.execute('SELECT MODEL_INSTANCE_NAME, MODEL_CUSTOMIZATION_UUID FROM vnf_resource_customization WHERE \
Itohan8ec5f1f2019-05-04 00:21:47 +0000308 SERVICE_MODEL_UUID = "{}"'.format(service_model_uuid))
root@rancher6c68bee2019-05-01 16:39:12 -0700309 vf_customization_values = values.fetchall()
310
311 out_dictionary["vf_model_customization_name"] = vf_customization_values[0][0]
312 out_dictionary["vf_model_customization_id"] = vf_customization_values[0][1]
313
314 values.execute('SELECT MODEL_INVARIANT_UUID, MODEL_UUID, MODEL_NAME, MODEL_VERSION FROM vf_module WHERE \
315 VNF_RESOURCE_MODEL_UUID = "{}"'.format(vf_model_uuid))
316
317 vf_module_values = values.fetchall()
318 out_dictionary["vf_module_model_invariant_id"] = vf_module_values[0][0]
319 out_dictionary["vf_module_model_id"] = vf_module_values[0][1]
320 out_dictionary["vf_module_model_name"] = vf_module_values[0][2]
321 out_dictionary["vf_module_model_version"] = vf_module_values[0][3]
322
323 values.execute('SELECT MODEL_CUSTOMIZATION_UUID FROM vf_module_customization WHERE \
Itohan8ec5f1f2019-05-04 00:21:47 +0000324 VF_MODULE_MODEL_UUID = "{}"'.format(out_dictionary["vf_module_model_id"]))
root@rancher6c68bee2019-05-01 16:39:12 -0700325 vf_module_customization = values.fetchall()
326
327 out_dictionary["vf_module_customization_id"] = vf_module_customization[0][0]
328 values.close()
329 mariadb_connection.close()
330
331 return out_dictionary
332
333
334
335def create_vnf(parameters, service_dict, db_dict, vf_model_dict):
336
337 vf_model_uuid = vf_model_dict["vf_id"]
338 vf_model_invariant_uuid = vf_model_dict["vf_model_invariant_uuid"]
339 vf_model_version = vf_model_dict["vf_model_version"]
340
root@rancher6c68bee2019-05-01 16:39:12 -0700341 vf_model_customization_name = db_dict["vf_model_customization_name"]
342 vf_model_customization_id = db_dict["vf_model_customization_id"]
343
344 #Put in any cloud region, OOF will select the right one
345 cloud_region = next(iter(parameters["cloud_region_data"]))
346 tenant_id = ((parameters["cloud_region_data"])[cloud_region])["tenant-id"]
347
348 service_invariant_uuid = service_dict["service_invariant_uuid"]
349 service_uuid = service_dict["service_uuid"]
350 service_instance_id = service_dict["service_instance_id"]
351 service_version = service_dict["service_version"]
352
353 #Create vnf
354 vnf_create_out = (os.popen("oclip vnf-create -j {} -q {} -k {} -l {} -y {} -z {} -r {} -c {} -o {} -e {} -g {} -b {} -n {} -i {} -vn '{}'\
Itohan8ec5f1f2019-05-04 00:21:47 +0000355 -w {} -pn {} -lob {} -u {} -p {} -m {} |grep vf-id".format(service_invariant_uuid, parameters["service-model-name"], \
356 service_uuid, cloud_region, service_instance_id, tenant_id, parameters["requestor-id"], vf_model_uuid, \
357 parameters["generic-vnf-name"], parameters["vf-name"], vf_model_version, vf_model_invariant_uuid, service_version, \
358 vf_model_customization_id, vf_model_customization_name, parameters["service_name"], parameters["platform-name"], \
359 parameters["lob-name"], parameters["so_username"], parameters["so_password"], parameters["so_url"]))).read()
root@rancher6c68bee2019-05-01 16:39:12 -0700360
361 vnf_instance_id = (get_out_helper_2(vnf_create_out))[1]
362
363 vf_model_dict["vnf_instance_id"] = vnf_instance_id
364
365 return vf_model_dict
366
367def sdnc_preload(parameters, db_dict, service_dict):
368
369
370 preload_file = parameters["sdnc_preload_file"]
371
372 #Replace values gotten from the service instance, vnf, vf in preload file, other values such as ip addresses
373 #should be directly changed in the preload file
374 #Items to search and replace in file
375 replace_dict = {
376 '"generic-vnf-name"' : ' "generic-vnf-name": "{}",\n'.format(parameters["generic-vnf-name"]),
377 '"generic-vnf-type"' : ' "generic-vnf-type": "{}",\n'.format(db_dict["vf_model_customization_name"]),
378 '"service-type"' : ' "service-type": "{}",\n'.format(service_dict["service_instance_id"]),
379 '"vnf-name"' : ' "vnf-name": "{}",\n'.format(parameters["vf-module-name"]),
380 '"vnf-type"' : ' "vnf-type": "{}"\n'.format(db_dict["vf_module_model_name"]),
381 '"vf_module_id"' : ' "vnf-parameter-value": "{}"\n'.format(db_dict["vf_module_model_name"])
382 }
383
384 with open(preload_file, 'r') as file:
385 preload_data = file.readlines()
386
387 for key, val in replace_dict.iteritems():
388 for line in range(len(preload_data)):
389
390 if key in preload_data[line] and key == '"vf_module_id"':
391 preload_data[line + 1] = val
392 break
393
394 elif key in preload_data[line] and key != '"vf_module_id"':
395 preload_data[line] = val
396 break
397 with open(preload_file, 'w') as file:
398 file.writelines(preload_data)
399
400 os.system("oclip vf-preload -u {} -p {} -y {} -m {}".format(parameters["sdnc_user"], parameters["sdnc_password"], \
401 preload_file, parameters["sdnc_url"]))
402
403
404
405def create_vf_module(parameters, service_dict, vnf_dict, db_dict):
406
407 #vf module parameters
408 vf_module_model_name = db_dict["vf_module_model_name"]
409 vf_module_model_invariant_id = db_dict["vf_module_model_invariant_id"]
410 vf_module_model_version = db_dict["vf_module_model_version"]
411 vf_module_model_version_id = db_dict["vf_module_model_id"]
412 vf_module_customization_id = db_dict["vf_module_customization_id"]
413
414 #service parameters
415 service_invariant_uuid = service_dict["service_invariant_uuid"]
416 service_uuid = service_dict["service_uuid"]
417 service_instance_id = service_dict["service_instance_id"]
418 service_version = service_dict["service_version"]
419
420 #vnf parameters
421 vnf_instance_id = vnf_dict["vnf_instance_id"]
422 vf_model_id = vnf_dict["vf_id"]
423 vf_model_invariant_uuid = vnf_dict["vf_model_invariant_uuid"]
424 vf_model_version = vnf_dict["vf_model_version"]
425 vf_model_customization_name = db_dict["vf_model_customization_name"]
426 vf_model_customization_id = db_dict["vf_model_customization_id"]
427
428 #Put in any cloud region, OOF will select the right one
429 cloud_region = next(iter(parameters["cloud_region_data"]))
430 tenant_id = ((parameters["cloud_region_data"])[cloud_region])["tenant-id"]
431
432
433 os.system("oclip vf-module-create -w {} -mn '{}' -x {} -l {} -sv {} -vc {} -vm {} -mv {} -i {} -vf {} -vi {} -r {} \
Itohan454b2792019-05-06 23:18:34 +0000434 -mc {} -api {} -mi {} -vid {} -y {} -R {} -si {} -up {} -sd {} -z {} -vn {} -vv {} -co {} -u {} -p {} -m {}".format(tenant_id, \
Itohan8ec5f1f2019-05-04 00:21:47 +0000435 vf_model_customization_name, service_instance_id, cloud_region, service_version, vf_module_customization_id, vf_module_model_version,\
root@rancher6c68bee2019-05-01 16:39:12 -0700436 vf_model_version, parameters["vf-module-name"], parameters["vf-name"], vf_module_model_invariant_id, parameters["supress-rollback"], \
437 vf_model_customization_id, parameters["test-api"], vf_model_invariant_uuid, vf_model_id, vnf_instance_id, parameters["requestor-id"], \
438 service_uuid, parameters["use-preload"], service_invariant_uuid, parameters["service-model-name"], vf_module_model_name, \
Itohan454b2792019-05-06 23:18:34 +0000439 vf_module_model_version_id, parameters["cloud-owner"], parameters["so_username"], parameters["so_password"], parameters["so_url"]))
root@rancher6c68bee2019-05-01 16:39:12 -0700440
441
442
443
444
445
446#Run Functions
447
448config_file_path = "/root/automation_stuff/hpa_automation_config.json"
449config_file = open(config_file_path)
Itohane2f489f2019-06-03 23:53:15 +0000450
451#Get required parameters from hpa config file
root@rancher6c68bee2019-05-01 16:39:12 -0700452parameters = get_parameters(config_file)
Itohane2f489f2019-06-03 23:53:15 +0000453
454#Set CLI env variables
root@rancher6c68bee2019-05-01 16:39:12 -0700455set_open_cli_env(parameters)
Itohane2f489f2019-06-03 23:53:15 +0000456
root@rancher6c68bee2019-05-01 16:39:12 -0700457create_complex(parameters)
458register_all_clouds(parameters)
Itohanecd1ebd2019-06-05 20:18:48 +0000459
root@rancher6c68bee2019-05-01 16:39:12 -0700460create_service_type(parameters)
Itohanecd1ebd2019-06-05 20:18:48 +0000461
root@rancher6c68bee2019-05-01 16:39:12 -0700462create_customer(parameters)
463add_customer_subscription(parameters)
Itohane2f489f2019-06-03 23:53:15 +0000464
465vlm_output = create_vlm(parameters)
466print "vlm parameters={}".format(vlm_output)
467
468vsp_id = create_vsp(parameters, vlm_output)
469print "vsp id={}".format(vsp_id)
470
root@rancher6c68bee2019-05-01 16:39:12 -0700471vf_model_dict = create_vf_model(parameters, vsp_id)
Itohane2f489f2019-06-03 23:53:15 +0000472print "vf model parameters={}".format(vf_model_dict)
root@rancher6c68bee2019-05-01 16:39:12 -0700473vf_id = vf_model_dict["vf_id"]
474vf_unique_id = vf_model_dict["vf_unique_id"]
Itohane2f489f2019-06-03 23:53:15 +0000475
Itohan8ec5f1f2019-05-04 00:21:47 +0000476service_model_list = create_service_model(parameters, vf_unique_id)
Itohane2f489f2019-06-03 23:53:15 +0000477print "service model parameters={}".format(service_model_list)
478
479upload_policy_models(parameters)
Itohan1f3c8d62019-05-24 23:52:26 +0000480add_policies(parameters)
Itohane2f489f2019-06-03 23:53:15 +0000481
Itohanecd1ebd2019-06-05 20:18:48 +0000482#Create Service Instance
root@rancher6c68bee2019-05-01 16:39:12 -0700483service_dict = create_service_instance(parameters, service_model_list)
Itohane2f489f2019-06-03 23:53:15 +0000484print "service instance parameters={}".format(service_dict)
Itohan8ec5f1f2019-05-04 00:21:47 +0000485service_model_uuid = service_dict["service_uuid"]
486db_dict = query_db(parameters, service_model_uuid, vf_id)
Itohane2f489f2019-06-03 23:53:15 +0000487
488#Wait for Service instance to be created then create VNF Instance
489while True:
490 #Check if service instance has been created"
491 check_service_instance = os.popen("oclip service-instance-list -u {} -p {} -m {} |grep {}".format(parameters["aai_username"], \
492 parameters["aai_password"], parameters["aai_url"], parameters["instance-name"])).read()
493 if check_service_instance:
494 print "service instance created successfully"
495 #Create VNF Instance
496 vnf_dict = create_vnf(parameters, service_dict, db_dict, vf_model_dict)
497 time.sleep(10)
498 print "vnf instance parameters={}".format(vnf_dict)
499 break
500 print "service instance create in progress"
501 time.sleep(30)
502
503#Preload VF module and create VF module
root@rancher6c68bee2019-05-01 16:39:12 -0700504sdnc_preload(parameters, db_dict, service_dict)
505create_vf_module(parameters, service_dict, vnf_dict, db_dict)
Itohanecd1ebd2019-06-05 20:18:48 +0000506
507print "Deployment complete!!!, check cloud to confirm that vf module has been created"