blob: ab1d8d07f0194f4b37697166ae4a442967103f0d [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
Ruoyu Yingf8229d02019-09-29 19:55:47 +080036 cloud_create_string = 'oclip cloud-create -e {} -b {} -x {} -y {} -j {} -w {} -l {} -url {} -n {} -q {} \
37 -r {} -Q {} -i {} -g {} -z {} -k {} -c {} -m {} -u {} -p {}'.format( values.get("esr-system-info-id"), \
38 values.get("user-name"), parameters["cloud-owner"], cloud_region, values.get("password"), \
39 values.get("cloud-region-version"), values.get("default-tenant"), values.get("service-url"), \
40 parameters["complex_name"], values.get("cloud-type"), parameters["owner-defined-type"], values.get("system-type"),\
41 values.get("identity-url"), parameters["cloud-zone"], values.get("ssl-insecure"), values.get("system-status"), \
42 values.get("cloud-domain"), parameters["aai_url"], parameters["aai_username"], parameters["aai_password"])
root@rancher6c68bee2019-05-01 16:39:12 -070043
44
45 os.system(cloud_create_string)
46
47 #Associate Cloud with complex
48 complex_associate_string = "oclip complex-associate -x {} -y {} -z {} -m {} -u {} -p {}".format(parameters["complex_name"], \
49 cloud_region, parameters["cloud-owner"], parameters["aai_url"], parameters["aai_username"], parameters["aai_password"])
50 os.system(complex_associate_string)
51
52 #Register Cloud with Multicloud
53 multicloud_register_string = "oclip multicloud-register-cloud -y {} -x {} -m {}".format(parameters["cloud-owner"], \
54 cloud_region, parameters["multicloud_url"])
55 os.system(multicloud_register_string)
Itohan1f3c8d62019-05-24 23:52:26 +000056 time.sleep(2)
root@rancher6c68bee2019-05-01 16:39:12 -070057
58def register_all_clouds(parameters):
59 cloud_dictionary = parameters["cloud_region_data"]
60 for cloud_region, cloud_region_values in cloud_dictionary.iteritems():
61 register_cloud_helper(cloud_region, cloud_region_values, parameters)
62
63def create_service_type(parameters):
64 create_string = "oclip service-type-create -x {} -m {} -u {} -p {}".format( parameters["service_name"], \
65 parameters["aai_url"], parameters["aai_username"], parameters["aai_password"])
66 os.system(create_string)
67
68def create_customer(parameters):
69 create_string = "oclip customer-create -x {} -y {} -m {} -u {} -p {}".format( parameters["customer_name"], \
70 parameters["subscriber_name"], parameters["aai_url"], parameters["aai_username"], parameters["aai_password"])
71 os.system(create_string)
72
73def add_customer_subscription(parameters):
74 subscription_check = 0
75 for cloud_region, cloud_region_values in (parameters["cloud_region_data"]).iteritems():
76 if subscription_check == 0 :
77 subscription_string = "oclip subscription-create -x {} -c {} -z {} -e {} -y {} -r {} -m {} -u {} -p {}".format(\
78 parameters["customer_name"], cloud_region_values.get("tenant-id"), parameters["cloud-owner"], parameters["service_name"],\
79 cloud_region_values.get("default-tenant"), cloud_region, parameters["aai_url"], parameters["aai_username"], parameters["aai_password"] )
80 else:
81 subscription_string = "oclip subscription-cloud-add -x {} -c {} -z {} -e {} -y {} -r {} -m {} -u {} -p {}".format(\
82 parameters["customer_name"], cloud_region_values.get("tenant-id"), parameters["cloud-owner"], parameters["service_name"],\
83 cloud_region_values.get("default-tenant"), cloud_region, parameters["aai_url"], parameters["aai_username"], parameters["aai_password"] )
84 os.system(subscription_string)
85 subscription_check+=1
86
87def get_out_helper(in_string):
88 out_list = (((in_string.replace('-','')).replace('|', '')).replace('+', '')).split()
89 return out_list
90
91def get_out_helper_2(in_string):
92 out_list = ((in_string.replace('|', '')).replace('+', '')).split()
93 return out_list
94
95#ONBOARDING SECTION
96def create_vlm(parameters):
97 vlm_create_string = "oclip vlm-create -x {} -u {} -p {} -m {}".format(parameters["vendor-name"], \
98 parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_onboarding_url"])
99 command_out = (os.popen(vlm_create_string)).read()
100 out_list = get_out_helper(command_out)
101 vlm_id = out_list[3]
102 vlm_version = out_list[5]
103
Ruoyu Yingf8229d02019-09-29 19:55:47 +0800104
105 entitlement_string = "oclip vlm-entitlement-pool-create -x {} -y {} -e {} -k {} -g {} -l {} -u {} -p {} -m {}".format( \
106 parameters["entitlement-pool-name"], vlm_id, vlm_version, parameters["vendor-name"], parameters["expiry-date"], \
107 parameters["start-date"], parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_onboarding_url"])
root@rancher6c68bee2019-05-01 16:39:12 -0700108 command_out = (os.popen(entitlement_string)).read()
109 entitlement_id = (get_out_helper(command_out))[3]
110
root@rancher6c68bee2019-05-01 16:39:12 -0700111 key_group_string = "oclip vlm-key-group-create -c {} -e {} -x {} -y {} -u {} -p {} -m {}".format(vlm_id, vlm_version, \
112 parameters["key-group-name"], parameters["key-group-type"], parameters["sdc_creator"], parameters["sdc_password"], \
113 parameters["sdc_onboarding_url"])
114 command_out = (os.popen(key_group_string)).read()
115 key_group_id = (get_out_helper(command_out))[3]
116
Ruoyu Yingf8229d02019-09-29 19:55:47 +0800117 feature_group_string = "oclip vlm-feature-group-create -x {} -y {} -e {} -g {} -b {} -c {} -u {} -p {} -m {}".format(
118 parameters["feature-grp-name"], vlm_id, vlm_version, key_group_id, entitlement_id, \
root@rancher6c68bee2019-05-01 16:39:12 -0700119 parameters["part-no"], parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_onboarding_url"])
120 command_out = (os.popen(feature_group_string)).read()
121 feature_group_id = (get_out_helper(command_out))[3]
122
Ruoyu Yingf8229d02019-09-29 19:55:47 +0800123 agreement_string = "oclip vlm-aggreement-create -x {} -y {} -e {} -g {} -u {} -p {} -m {}".format(parameters["agreement-name"], \
124 vlm_id, vlm_version, feature_group_id, parameters["sdc_creator"], parameters["sdc_password"], \
root@rancher6c68bee2019-05-01 16:39:12 -0700125 parameters["sdc_onboarding_url"])
126 command_out = (os.popen(agreement_string)).read()
127 agreement_id = (get_out_helper(command_out))[3]
128
Ruoyu Yingf8229d02019-09-29 19:55:47 +0800129
root@rancher6c68bee2019-05-01 16:39:12 -0700130 submit_string = "oclip vlm-submit -x {} -y {} -u {} -p {} -m {}".format(vlm_id, vlm_version, parameters["sdc_creator"], \
131 parameters["sdc_password"], parameters["sdc_onboarding_url"])
132 os.system(submit_string)
133
134 output = [feature_group_id, agreement_id, vlm_version, vlm_id ]
Ruoyu Yingf8229d02019-09-29 19:55:47 +0800135
root@rancher6c68bee2019-05-01 16:39:12 -0700136 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]
Ruoyu Yingf8229d02019-09-29 19:55:47 +0800145 vsp_version = out_list[7]
root@rancher6c68bee2019-05-01 16:39:12 -0700146
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
Ruoyu Yingf8229d02019-09-29 19:55:47 +0800159
root@rancher6c68bee2019-05-01 16:39:12 -0700160 return vsp_id
161
162
163def create_vf_model(parameters, vsp_id):
164 create_string = "oclip vf-model-create -y {} -g {} -x {} -z {} -b {} -u {} -p {} -m {}".format(parameters["vf-description"], \
165 parameters["vsp-version"], parameters["vf-name"], parameters["vendor-name"], vsp_id, parameters["sdc_creator"], \
166 parameters["sdc_password"], parameters["sdc_catalog_url"])
167 os.system(create_string)
168
169 output = (os.popen("oclip vf-model-list -m {} -u {} -p {} | grep {}".format(parameters["sdc_catalog_url"], \
170 parameters["sdc_creator"], parameters["sdc_password"], parameters["vf-name"]))).read()
171 output = (get_out_helper_2(output))
172
Itohan454b2792019-05-06 23:18:34 +0000173 vf_unique_id = output[1]
174
175 os.system("oclip vf-model-certify -b {} -r {} -u {} -p {} -m {}".format(vf_unique_id, parameters["vf-remarks"], \
176 parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"]))
177
178 #Check for new parameters after certification
179 output = (os.popen("oclip vf-model-list -m {} -u {} -p {} | grep {}".format(parameters["sdc_catalog_url"], \
180 parameters["sdc_creator"], parameters["sdc_password"], parameters["vf-name"]))).read()
181 output = (get_out_helper_2(output))
182
root@rancher6c68bee2019-05-01 16:39:12 -0700183 vf_id = output[0]
184 vf_unique_id = output[1]
185 vf_model_invariant_uuid = output[2]
186 vf_model_version = output[4]
187
root@rancher6c68bee2019-05-01 16:39:12 -0700188 out_dict = {}
189 out_dict["vf_id"] = vf_id
190 out_dict["vf_unique_id"] = vf_unique_id
191 out_dict["vf_model_invariant_uuid"] = vf_model_invariant_uuid
192 out_dict["vf_model_version"] = vf_model_version
193
194 return out_dict
195
196
197def create_service_model(parameters, vf_unique_id):
Ruoyu Yingf8229d02019-09-29 19:55:47 +0800198 create_string = "oclip service-model-create -z {} -y {} -e {} -x {} -c {} -b {} -u {} -p {} -m {} |grep -i ID".format(parameters["project-code"], \
Itohan8ec5f1f2019-05-04 00:21:47 +0000199 parameters["service-model-desc"], parameters["icon-id"], parameters["service-model-name"], parameters["category-display"], \
200 parameters["category"],parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"])
root@rancher6c68bee2019-05-01 16:39:12 -0700201
202 service_model_id = (get_out_helper_2((os.popen(create_string)).read()))[1]
203
Itohan8ec5f1f2019-05-04 00:21:47 +0000204 os.system("oclip service-model-add-vf -x {} -b {} -y {} -z {} -u {} -p {} -m {}".format(service_model_id, parameters["vf-version"], \
205 vf_unique_id, parameters["vf-name"], parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"] ))
root@rancher6c68bee2019-05-01 16:39:12 -0700206
207 os.system("oclip service-model-test-request -b {} -r {} -u {} -p {} -m {}".format(service_model_id, parameters["service-test-remarks"], \
208 parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"]))
209
210 os.system("oclip service-model-test-start -b {} -u {} -p {} -m {}".format(service_model_id, parameters["sdc_tester"], \
211 parameters["sdc_password"], parameters["sdc_catalog_url"]))
212
213 os.system("oclip service-model-test-accept -b {} -r {} -u {} -p {} -m {}".format(service_model_id, parameters["service-accept-remarks"], \
214 parameters["sdc_tester"], parameters["sdc_password"], parameters["sdc_catalog_url"]))
215
Itohan8ec5f1f2019-05-04 00:21:47 +0000216 #Get uniqueId for the service model
217 service_model_values = (os.popen("oclip service-model-list -u {} -p {} -m {} |grep {}".format(parameters["sdc_creator"], \
root@rancher6c68bee2019-05-01 16:39:12 -0700218 parameters["sdc_password"], parameters["sdc_catalog_url"], parameters["service-model-name"]))).read()
Itohan8ec5f1f2019-05-04 00:21:47 +0000219 service_model_values = get_out_helper_2(service_model_values)
220 service_model_uniqueId = (service_model_values)[1]
root@rancher6c68bee2019-05-01 16:39:12 -0700221
Itohan8ec5f1f2019-05-04 00:21:47 +0000222 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 -0700223 parameters["sdc_governor"], parameters["sdc_password"], parameters["sdc_catalog_url"]))
224
Itohan8ec5f1f2019-05-04 00:21:47 +0000225 os.system("oclip service-model-distribute -b {} -u {} -p {} -m {}".format(service_model_uniqueId, parameters["sdc_operator"], \
root@rancher6c68bee2019-05-01 16:39:12 -0700226 parameters["sdc_password"], parameters["sdc_catalog_url"]))
227
Itohan8ec5f1f2019-05-04 00:21:47 +0000228 return service_model_values
root@rancher6c68bee2019-05-01 16:39:12 -0700229
230
231#VNF Deployment Section
Itohane2f489f2019-06-03 23:53:15 +0000232def upload_policy_models(parameters):
Itohan Ukponmwan63929cf2019-09-13 00:08:39 +0000233 os.system("python insert_policy_models_heat.py {} {} {}".format(parameters["policy_db_ip"], \
Itohane2f489f2019-06-03 23:53:15 +0000234 parameters["policy_db_user"], parameters["policy_db_password"]))
root@rancher6c68bee2019-05-01 16:39:12 -0700235
root@rancher6c68bee2019-05-01 16:39:12 -0700236def add_policies(parameters):
237 resource_string = (os.popen("oclip get-resource-module-name -u {} -p {} -m {} |grep {}".format(\
238 parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"], \
Itohan1f3c8d62019-05-24 23:52:26 +0000239 parameters["vf-name"] ))).read()
root@rancher6c68bee2019-05-01 16:39:12 -0700240 resource_module_name = (get_out_helper_2(resource_string))[1]
241
Itohan454b2792019-05-06 23:18:34 +0000242 #Put in the right resource module name in all policies located in parameters["policy_directory"]
243 os.system("find {}/ -type f -exec sed -i 's/{}/{}/g' {{}} \;".format(
244 parameters["policy_directory"], parameters["temp_resource_module_name"], resource_module_name))
245
root@rancher6c68bee2019-05-01 16:39:12 -0700246 #Loop through policy, put in resource_model_name and create policies
247 for policy in os.listdir(parameters["policy_directory"]):
Itohanecd1ebd2019-06-05 20:18:48 +0000248
Itohan8ec5f1f2019-05-04 00:21:47 +0000249 policy_file = (os.path.join(parameters["policy_directory"], policy))
Itohan1f3c8d62019-05-24 23:52:26 +0000250
Itohanecd1ebd2019-06-05 20:18:48 +0000251 #Get policy name from policy file
252 policy_contents = open(policy_file, 'r').read()
253 start_string = '"policyName\\":\\"'
254 end_string = '\\",\\"ver'
255 policy_name = policy_contents[policy_contents.find(start_string)+len(start_string):policy_contents.rfind(end_string)]
256
257
Itohan1f3c8d62019-05-24 23:52:26 +0000258 #Create policy
Itohan8ec5f1f2019-05-04 00:21:47 +0000259 os.system("oclip policy-create-outdated -m {} -u {} -p {} -x {} -S {} -T {} -o {} -b $(cat {})".format(parameters["policy_url"],\
260 parameters["policy_username"], parameters["policy_password"], policy_name, parameters["policy_scope"], \
261 parameters["policy_config_type"], parameters["policy_onapName"], policy_file))
root@rancher6c68bee2019-05-01 16:39:12 -0700262
263 #Push policy
264 os.system("oclip policy-push-outdated -m {} -u {} -p {} -x {} -b {} -c {}".format(parameters["policy_url"], \
265 parameters["policy_username"], parameters["policy_password"], policy_name, parameters["policy_config_type"],\
266 parameters["policy_pdp_group"]))
267
268
269def create_service_instance(parameters, sevice_model_list):
270 #Get Required parameters
271 service_uuid = service_model_list[0]
Itohan8ec5f1f2019-05-04 00:21:47 +0000272 service_invariant_uuid = service_model_list[2]
273 service_version = service_model_list[4]
root@rancher6c68bee2019-05-01 16:39:12 -0700274
275 owning_entity_values = (os.popen("oclip owning-entity-list -u {} -p {} -m {} |grep {}".format(parameters["aai_username"], \
276 parameters["aai_password"], parameters["aai_url"], parameters["owning-entity-name"]))).read()
277 owning_entity_id = (get_out_helper_2(owning_entity_values))[1]
278
279 #Create service instance
280 instance_output = (os.popen("oclip service-create -w {} -la {} -lo {} -o {} -A {} -i {} -y {} -x {} -q {} -O {} -k {}-{} -P {} \
281 -H {} -n {} -e {} -j {} -S {} -g {} -z {} -c {} -u {} -p {} -m {} |grep service-id".format(parameters["service_name"], \
282 parameters["customer-latitude"], parameters["customer-longitude"], parameters["orchestrator"], parameters["a-la-carte"], \
283 parameters["service-model-name"], parameters["company-name"], parameters["projectName"], parameters["requestor-id"], \
Itohan8ec5f1f2019-05-04 00:21:47 +0000284 parameters["owning-entity-name"], parameters["instance-name"], parameters["service_name"], parameters["test-api"], parameters["homing-solution"], \
root@rancher6c68bee2019-05-01 16:39:12 -0700285 service_uuid, service_invariant_uuid, service_version, parameters["subscriber_name"], service_uuid, owning_entity_id, \
286 parameters["customer_name"], parameters["so_username"], parameters["so_password"], parameters["so_url"] ))).read()
287
288 service_instance_id = (get_out_helper_2(instance_output))[1]
289 output_dict = {}
290
291 output_dict["service_instance_id"] = service_instance_id
292 output_dict["service_uuid"] = service_uuid
293 output_dict["service_invariant_uuid"] = service_invariant_uuid
294 output_dict["service_version"] = service_version
295
296
297 return output_dict
298
Itohan8ec5f1f2019-05-04 00:21:47 +0000299def query_db(parameters, service_model_uuid, vf_model_uuid):
root@rancher6c68bee2019-05-01 16:39:12 -0700300
301 out_dictionary = {}
302 #Query DB Certain parameters required
Ruoyu Yingf8229d02019-09-29 19:55:47 +0800303 mariadb_connection = mariadb.connect(user='{}'.format(parameters["so_mariadb_user"]), host='{}'.format(parameters["mariadb_host"]),
root@rancher6c68bee2019-05-01 16:39:12 -0700304 password='{}'.format(parameters["so_mariadb_password"]), database='{}'.format(parameters["so_mariadb_db"]))
305 values = mariadb_connection.cursor()
306
307 #Get vf model customization values
308 values.execute('SELECT MODEL_INSTANCE_NAME, MODEL_CUSTOMIZATION_UUID FROM vnf_resource_customization WHERE \
Itohan8ec5f1f2019-05-04 00:21:47 +0000309 SERVICE_MODEL_UUID = "{}"'.format(service_model_uuid))
root@rancher6c68bee2019-05-01 16:39:12 -0700310 vf_customization_values = values.fetchall()
311
312 out_dictionary["vf_model_customization_name"] = vf_customization_values[0][0]
313 out_dictionary["vf_model_customization_id"] = vf_customization_values[0][1]
314
315 values.execute('SELECT MODEL_INVARIANT_UUID, MODEL_UUID, MODEL_NAME, MODEL_VERSION FROM vf_module WHERE \
316 VNF_RESOURCE_MODEL_UUID = "{}"'.format(vf_model_uuid))
317
318 vf_module_values = values.fetchall()
319 out_dictionary["vf_module_model_invariant_id"] = vf_module_values[0][0]
320 out_dictionary["vf_module_model_id"] = vf_module_values[0][1]
321 out_dictionary["vf_module_model_name"] = vf_module_values[0][2]
322 out_dictionary["vf_module_model_version"] = vf_module_values[0][3]
323
324 values.execute('SELECT MODEL_CUSTOMIZATION_UUID FROM vf_module_customization WHERE \
Itohan8ec5f1f2019-05-04 00:21:47 +0000325 VF_MODULE_MODEL_UUID = "{}"'.format(out_dictionary["vf_module_model_id"]))
root@rancher6c68bee2019-05-01 16:39:12 -0700326 vf_module_customization = values.fetchall()
327
328 out_dictionary["vf_module_customization_id"] = vf_module_customization[0][0]
329 values.close()
330 mariadb_connection.close()
331
332 return out_dictionary
333
334
335
336def create_vnf(parameters, service_dict, db_dict, vf_model_dict):
337
338 vf_model_uuid = vf_model_dict["vf_id"]
339 vf_model_invariant_uuid = vf_model_dict["vf_model_invariant_uuid"]
340 vf_model_version = vf_model_dict["vf_model_version"]
341
root@rancher6c68bee2019-05-01 16:39:12 -0700342 vf_model_customization_name = db_dict["vf_model_customization_name"]
343 vf_model_customization_id = db_dict["vf_model_customization_id"]
344
345 #Put in any cloud region, OOF will select the right one
346 cloud_region = next(iter(parameters["cloud_region_data"]))
347 tenant_id = ((parameters["cloud_region_data"])[cloud_region])["tenant-id"]
348
349 service_invariant_uuid = service_dict["service_invariant_uuid"]
350 service_uuid = service_dict["service_uuid"]
351 service_instance_id = service_dict["service_instance_id"]
352 service_version = service_dict["service_version"]
353
354 #Create vnf
355 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 +0000356 -w {} -pn {} -lob {} -u {} -p {} -m {} |grep vf-id".format(service_invariant_uuid, parameters["service-model-name"], \
357 service_uuid, cloud_region, service_instance_id, tenant_id, parameters["requestor-id"], vf_model_uuid, \
358 parameters["generic-vnf-name"], parameters["vf-name"], vf_model_version, vf_model_invariant_uuid, service_version, \
359 vf_model_customization_id, vf_model_customization_name, parameters["service_name"], parameters["platform-name"], \
360 parameters["lob-name"], parameters["so_username"], parameters["so_password"], parameters["so_url"]))).read()
root@rancher6c68bee2019-05-01 16:39:12 -0700361
362 vnf_instance_id = (get_out_helper_2(vnf_create_out))[1]
363
364 vf_model_dict["vnf_instance_id"] = vnf_instance_id
365
366 return vf_model_dict
367
368def sdnc_preload(parameters, db_dict, service_dict):
369
370
371 preload_file = parameters["sdnc_preload_file"]
372
373 #Replace values gotten from the service instance, vnf, vf in preload file, other values such as ip addresses
374 #should be directly changed in the preload file
375 #Items to search and replace in file
376 replace_dict = {
377 '"generic-vnf-name"' : ' "generic-vnf-name": "{}",\n'.format(parameters["generic-vnf-name"]),
378 '"generic-vnf-type"' : ' "generic-vnf-type": "{}",\n'.format(db_dict["vf_model_customization_name"]),
379 '"service-type"' : ' "service-type": "{}",\n'.format(service_dict["service_instance_id"]),
380 '"vnf-name"' : ' "vnf-name": "{}",\n'.format(parameters["vf-module-name"]),
381 '"vnf-type"' : ' "vnf-type": "{}"\n'.format(db_dict["vf_module_model_name"]),
382 '"vf_module_id"' : ' "vnf-parameter-value": "{}"\n'.format(db_dict["vf_module_model_name"])
383 }
384
385 with open(preload_file, 'r') as file:
386 preload_data = file.readlines()
387
388 for key, val in replace_dict.iteritems():
389 for line in range(len(preload_data)):
390
391 if key in preload_data[line] and key == '"vf_module_id"':
392 preload_data[line + 1] = val
393 break
394
395 elif key in preload_data[line] and key != '"vf_module_id"':
396 preload_data[line] = val
397 break
398 with open(preload_file, 'w') as file:
399 file.writelines(preload_data)
400
401 os.system("oclip vf-preload -u {} -p {} -y {} -m {}".format(parameters["sdnc_user"], parameters["sdnc_password"], \
402 preload_file, parameters["sdnc_url"]))
403
404
405
406def create_vf_module(parameters, service_dict, vnf_dict, db_dict):
407
408 #vf module parameters
409 vf_module_model_name = db_dict["vf_module_model_name"]
410 vf_module_model_invariant_id = db_dict["vf_module_model_invariant_id"]
411 vf_module_model_version = db_dict["vf_module_model_version"]
412 vf_module_model_version_id = db_dict["vf_module_model_id"]
413 vf_module_customization_id = db_dict["vf_module_customization_id"]
414
415 #service parameters
416 service_invariant_uuid = service_dict["service_invariant_uuid"]
417 service_uuid = service_dict["service_uuid"]
418 service_instance_id = service_dict["service_instance_id"]
419 service_version = service_dict["service_version"]
420
421 #vnf parameters
422 vnf_instance_id = vnf_dict["vnf_instance_id"]
423 vf_model_id = vnf_dict["vf_id"]
424 vf_model_invariant_uuid = vnf_dict["vf_model_invariant_uuid"]
425 vf_model_version = vnf_dict["vf_model_version"]
426 vf_model_customization_name = db_dict["vf_model_customization_name"]
427 vf_model_customization_id = db_dict["vf_model_customization_id"]
428
429 #Put in any cloud region, OOF will select the right one
430 cloud_region = next(iter(parameters["cloud_region_data"]))
431 tenant_id = ((parameters["cloud_region_data"])[cloud_region])["tenant-id"]
432
433
434 os.system("oclip vf-module-create -w {} -mn '{}' -x {} -l {} -sv {} -vc {} -vm {} -mv {} -i {} -vf {} -vi {} -r {} \
Itohan454b2792019-05-06 23:18:34 +0000435 -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 +0000436 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 -0700437 vf_model_version, parameters["vf-module-name"], parameters["vf-name"], vf_module_model_invariant_id, parameters["supress-rollback"], \
438 vf_model_customization_id, parameters["test-api"], vf_model_invariant_uuid, vf_model_id, vnf_instance_id, parameters["requestor-id"], \
439 service_uuid, parameters["use-preload"], service_invariant_uuid, parameters["service-model-name"], vf_module_model_name, \
Itohan454b2792019-05-06 23:18:34 +0000440 vf_module_model_version_id, parameters["cloud-owner"], parameters["so_username"], parameters["so_password"], parameters["so_url"]))
root@rancher6c68bee2019-05-01 16:39:12 -0700441
442
443
444
445
446
447#Run Functions
448
Ruoyu Yingf8229d02019-09-29 19:55:47 +0800449config_file_path = "/root/integration/test/hpa_automation/heat/hpa_automation_config.json"
root@rancher6c68bee2019-05-01 16:39:12 -0700450config_file = open(config_file_path)
Itohane2f489f2019-06-03 23:53:15 +0000451
452#Get required parameters from hpa config file
root@rancher6c68bee2019-05-01 16:39:12 -0700453parameters = get_parameters(config_file)
Itohane2f489f2019-06-03 23:53:15 +0000454
455#Set CLI env variables
root@rancher6c68bee2019-05-01 16:39:12 -0700456set_open_cli_env(parameters)
457create_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"]
Itohan76ea9742019-10-07 21:21:19 +0000486time.sleep(2)
Itohan8ec5f1f2019-05-04 00:21:47 +0000487db_dict = query_db(parameters, service_model_uuid, vf_id)
Itohane2f489f2019-06-03 23:53:15 +0000488
489#Wait for Service instance to be created then create VNF Instance
490while True:
491 #Check if service instance has been created"
Itohan Ukponmwan63929cf2019-09-13 00:08:39 +0000492 check_service_instance = os.popen("oclip service-instance-list -u {} -p {} -m {} |grep {}-{}".format(parameters["aai_username"], \
493 parameters["aai_password"], parameters["aai_url"], parameters["instance-name"], parameters["service_name"])).read()
Itohane2f489f2019-06-03 23:53:15 +0000494 if check_service_instance:
495 print "service instance created successfully"
496 #Create VNF Instance
497 vnf_dict = create_vnf(parameters, service_dict, db_dict, vf_model_dict)
498 time.sleep(10)
499 print "vnf instance parameters={}".format(vnf_dict)
500 break
501 print "service instance create in progress"
502 time.sleep(30)
503
504#Preload VF module and create VF module
root@rancher6c68bee2019-05-01 16:39:12 -0700505sdnc_preload(parameters, db_dict, service_dict)
506create_vf_module(parameters, service_dict, vnf_dict, db_dict)
Itohanecd1ebd2019-06-05 20:18:48 +0000507print "Deployment complete!!!, check cloud to confirm that vf module has been created"