blob: 5ac65b4f529059c14a84ea5c044d838f7cbb59dc [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"]):
247 policy_name = "{}.{}".format(parameters["policy_scope"], os.path.splitext(policy)[0])
Itohan8ec5f1f2019-05-04 00:21:47 +0000248 policy_file = (os.path.join(parameters["policy_directory"], policy))
Itohan1f3c8d62019-05-24 23:52:26 +0000249
250 #Create policy
Itohan8ec5f1f2019-05-04 00:21:47 +0000251 os.system("oclip policy-create-outdated -m {} -u {} -p {} -x {} -S {} -T {} -o {} -b $(cat {})".format(parameters["policy_url"],\
252 parameters["policy_username"], parameters["policy_password"], policy_name, parameters["policy_scope"], \
253 parameters["policy_config_type"], parameters["policy_onapName"], policy_file))
root@rancher6c68bee2019-05-01 16:39:12 -0700254
255 #Push policy
256 os.system("oclip policy-push-outdated -m {} -u {} -p {} -x {} -b {} -c {}".format(parameters["policy_url"], \
257 parameters["policy_username"], parameters["policy_password"], policy_name, parameters["policy_config_type"],\
258 parameters["policy_pdp_group"]))
259
260
261def create_service_instance(parameters, sevice_model_list):
262 #Get Required parameters
263 service_uuid = service_model_list[0]
Itohan8ec5f1f2019-05-04 00:21:47 +0000264 service_invariant_uuid = service_model_list[2]
265 service_version = service_model_list[4]
root@rancher6c68bee2019-05-01 16:39:12 -0700266
267 owning_entity_values = (os.popen("oclip owning-entity-list -u {} -p {} -m {} |grep {}".format(parameters["aai_username"], \
268 parameters["aai_password"], parameters["aai_url"], parameters["owning-entity-name"]))).read()
269 owning_entity_id = (get_out_helper_2(owning_entity_values))[1]
270
271 #Create service instance
272 instance_output = (os.popen("oclip service-create -w {} -la {} -lo {} -o {} -A {} -i {} -y {} -x {} -q {} -O {} -k {}-{} -P {} \
273 -H {} -n {} -e {} -j {} -S {} -g {} -z {} -c {} -u {} -p {} -m {} |grep service-id".format(parameters["service_name"], \
274 parameters["customer-latitude"], parameters["customer-longitude"], parameters["orchestrator"], parameters["a-la-carte"], \
275 parameters["service-model-name"], parameters["company-name"], parameters["projectName"], parameters["requestor-id"], \
Itohan8ec5f1f2019-05-04 00:21:47 +0000276 parameters["owning-entity-name"], parameters["instance-name"], parameters["service_name"], parameters["test-api"], parameters["homing-solution"], \
root@rancher6c68bee2019-05-01 16:39:12 -0700277 service_uuid, service_invariant_uuid, service_version, parameters["subscriber_name"], service_uuid, owning_entity_id, \
278 parameters["customer_name"], parameters["so_username"], parameters["so_password"], parameters["so_url"] ))).read()
279
280 service_instance_id = (get_out_helper_2(instance_output))[1]
281 output_dict = {}
282
283 output_dict["service_instance_id"] = service_instance_id
284 output_dict["service_uuid"] = service_uuid
285 output_dict["service_invariant_uuid"] = service_invariant_uuid
286 output_dict["service_version"] = service_version
287
288
289 return output_dict
290
Itohan8ec5f1f2019-05-04 00:21:47 +0000291def query_db(parameters, service_model_uuid, vf_model_uuid):
root@rancher6c68bee2019-05-01 16:39:12 -0700292
293 out_dictionary = {}
294 #Query DB Certain parameters required
295 mariadb_connection = mariadb.connect(user='{}'.format(parameters["so_mariadb_user"]), host='{}'.format(parameters["so_mariadb_host"]),
296 password='{}'.format(parameters["so_mariadb_password"]), database='{}'.format(parameters["so_mariadb_db"]))
297 values = mariadb_connection.cursor()
298
299 #Get vf model customization values
300 values.execute('SELECT MODEL_INSTANCE_NAME, MODEL_CUSTOMIZATION_UUID FROM vnf_resource_customization WHERE \
Itohan8ec5f1f2019-05-04 00:21:47 +0000301 SERVICE_MODEL_UUID = "{}"'.format(service_model_uuid))
root@rancher6c68bee2019-05-01 16:39:12 -0700302 vf_customization_values = values.fetchall()
303
304 out_dictionary["vf_model_customization_name"] = vf_customization_values[0][0]
305 out_dictionary["vf_model_customization_id"] = vf_customization_values[0][1]
306
307 values.execute('SELECT MODEL_INVARIANT_UUID, MODEL_UUID, MODEL_NAME, MODEL_VERSION FROM vf_module WHERE \
308 VNF_RESOURCE_MODEL_UUID = "{}"'.format(vf_model_uuid))
309
310 vf_module_values = values.fetchall()
311 out_dictionary["vf_module_model_invariant_id"] = vf_module_values[0][0]
312 out_dictionary["vf_module_model_id"] = vf_module_values[0][1]
313 out_dictionary["vf_module_model_name"] = vf_module_values[0][2]
314 out_dictionary["vf_module_model_version"] = vf_module_values[0][3]
315
316 values.execute('SELECT MODEL_CUSTOMIZATION_UUID FROM vf_module_customization WHERE \
Itohan8ec5f1f2019-05-04 00:21:47 +0000317 VF_MODULE_MODEL_UUID = "{}"'.format(out_dictionary["vf_module_model_id"]))
root@rancher6c68bee2019-05-01 16:39:12 -0700318 vf_module_customization = values.fetchall()
319
320 out_dictionary["vf_module_customization_id"] = vf_module_customization[0][0]
321 values.close()
322 mariadb_connection.close()
323
324 return out_dictionary
325
326
327
328def create_vnf(parameters, service_dict, db_dict, vf_model_dict):
329
330 vf_model_uuid = vf_model_dict["vf_id"]
331 vf_model_invariant_uuid = vf_model_dict["vf_model_invariant_uuid"]
332 vf_model_version = vf_model_dict["vf_model_version"]
333
root@rancher6c68bee2019-05-01 16:39:12 -0700334 vf_model_customization_name = db_dict["vf_model_customization_name"]
335 vf_model_customization_id = db_dict["vf_model_customization_id"]
336
337 #Put in any cloud region, OOF will select the right one
338 cloud_region = next(iter(parameters["cloud_region_data"]))
339 tenant_id = ((parameters["cloud_region_data"])[cloud_region])["tenant-id"]
340
341 service_invariant_uuid = service_dict["service_invariant_uuid"]
342 service_uuid = service_dict["service_uuid"]
343 service_instance_id = service_dict["service_instance_id"]
344 service_version = service_dict["service_version"]
345
346 #Create vnf
347 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 +0000348 -w {} -pn {} -lob {} -u {} -p {} -m {} |grep vf-id".format(service_invariant_uuid, parameters["service-model-name"], \
349 service_uuid, cloud_region, service_instance_id, tenant_id, parameters["requestor-id"], vf_model_uuid, \
350 parameters["generic-vnf-name"], parameters["vf-name"], vf_model_version, vf_model_invariant_uuid, service_version, \
351 vf_model_customization_id, vf_model_customization_name, parameters["service_name"], parameters["platform-name"], \
352 parameters["lob-name"], parameters["so_username"], parameters["so_password"], parameters["so_url"]))).read()
root@rancher6c68bee2019-05-01 16:39:12 -0700353
354 vnf_instance_id = (get_out_helper_2(vnf_create_out))[1]
355
356 vf_model_dict["vnf_instance_id"] = vnf_instance_id
357
358 return vf_model_dict
359
360def sdnc_preload(parameters, db_dict, service_dict):
361
362
363 preload_file = parameters["sdnc_preload_file"]
364
365 #Replace values gotten from the service instance, vnf, vf in preload file, other values such as ip addresses
366 #should be directly changed in the preload file
367 #Items to search and replace in file
368 replace_dict = {
369 '"generic-vnf-name"' : ' "generic-vnf-name": "{}",\n'.format(parameters["generic-vnf-name"]),
370 '"generic-vnf-type"' : ' "generic-vnf-type": "{}",\n'.format(db_dict["vf_model_customization_name"]),
371 '"service-type"' : ' "service-type": "{}",\n'.format(service_dict["service_instance_id"]),
372 '"vnf-name"' : ' "vnf-name": "{}",\n'.format(parameters["vf-module-name"]),
373 '"vnf-type"' : ' "vnf-type": "{}"\n'.format(db_dict["vf_module_model_name"]),
374 '"vf_module_id"' : ' "vnf-parameter-value": "{}"\n'.format(db_dict["vf_module_model_name"])
375 }
376
377 with open(preload_file, 'r') as file:
378 preload_data = file.readlines()
379
380 for key, val in replace_dict.iteritems():
381 for line in range(len(preload_data)):
382
383 if key in preload_data[line] and key == '"vf_module_id"':
384 preload_data[line + 1] = val
385 break
386
387 elif key in preload_data[line] and key != '"vf_module_id"':
388 preload_data[line] = val
389 break
390 with open(preload_file, 'w') as file:
391 file.writelines(preload_data)
392
393 os.system("oclip vf-preload -u {} -p {} -y {} -m {}".format(parameters["sdnc_user"], parameters["sdnc_password"], \
394 preload_file, parameters["sdnc_url"]))
395
396
397
398def create_vf_module(parameters, service_dict, vnf_dict, db_dict):
399
400 #vf module parameters
401 vf_module_model_name = db_dict["vf_module_model_name"]
402 vf_module_model_invariant_id = db_dict["vf_module_model_invariant_id"]
403 vf_module_model_version = db_dict["vf_module_model_version"]
404 vf_module_model_version_id = db_dict["vf_module_model_id"]
405 vf_module_customization_id = db_dict["vf_module_customization_id"]
406
407 #service parameters
408 service_invariant_uuid = service_dict["service_invariant_uuid"]
409 service_uuid = service_dict["service_uuid"]
410 service_instance_id = service_dict["service_instance_id"]
411 service_version = service_dict["service_version"]
412
413 #vnf parameters
414 vnf_instance_id = vnf_dict["vnf_instance_id"]
415 vf_model_id = vnf_dict["vf_id"]
416 vf_model_invariant_uuid = vnf_dict["vf_model_invariant_uuid"]
417 vf_model_version = vnf_dict["vf_model_version"]
418 vf_model_customization_name = db_dict["vf_model_customization_name"]
419 vf_model_customization_id = db_dict["vf_model_customization_id"]
420
421 #Put in any cloud region, OOF will select the right one
422 cloud_region = next(iter(parameters["cloud_region_data"]))
423 tenant_id = ((parameters["cloud_region_data"])[cloud_region])["tenant-id"]
424
425
426 os.system("oclip vf-module-create -w {} -mn '{}' -x {} -l {} -sv {} -vc {} -vm {} -mv {} -i {} -vf {} -vi {} -r {} \
Itohan454b2792019-05-06 23:18:34 +0000427 -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 +0000428 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 -0700429 vf_model_version, parameters["vf-module-name"], parameters["vf-name"], vf_module_model_invariant_id, parameters["supress-rollback"], \
430 vf_model_customization_id, parameters["test-api"], vf_model_invariant_uuid, vf_model_id, vnf_instance_id, parameters["requestor-id"], \
431 service_uuid, parameters["use-preload"], service_invariant_uuid, parameters["service-model-name"], vf_module_model_name, \
Itohan454b2792019-05-06 23:18:34 +0000432 vf_module_model_version_id, parameters["cloud-owner"], parameters["so_username"], parameters["so_password"], parameters["so_url"]))
root@rancher6c68bee2019-05-01 16:39:12 -0700433
434
435
436
437
438
439#Run Functions
440
441config_file_path = "/root/automation_stuff/hpa_automation_config.json"
442config_file = open(config_file_path)
Itohane2f489f2019-06-03 23:53:15 +0000443
444#Get required parameters from hpa config file
root@rancher6c68bee2019-05-01 16:39:12 -0700445parameters = get_parameters(config_file)
Itohane2f489f2019-06-03 23:53:15 +0000446
447#Set CLI env variables
root@rancher6c68bee2019-05-01 16:39:12 -0700448set_open_cli_env(parameters)
Itohane2f489f2019-06-03 23:53:15 +0000449
root@rancher6c68bee2019-05-01 16:39:12 -0700450create_complex(parameters)
451register_all_clouds(parameters)
452create_service_type(parameters)
453create_customer(parameters)
454add_customer_subscription(parameters)
Itohane2f489f2019-06-03 23:53:15 +0000455
456vlm_output = create_vlm(parameters)
457print "vlm parameters={}".format(vlm_output)
458
459vsp_id = create_vsp(parameters, vlm_output)
460print "vsp id={}".format(vsp_id)
461
root@rancher6c68bee2019-05-01 16:39:12 -0700462vf_model_dict = create_vf_model(parameters, vsp_id)
Itohane2f489f2019-06-03 23:53:15 +0000463print "vf model parameters={}".format(vf_model_dict)
root@rancher6c68bee2019-05-01 16:39:12 -0700464vf_id = vf_model_dict["vf_id"]
465vf_unique_id = vf_model_dict["vf_unique_id"]
Itohane2f489f2019-06-03 23:53:15 +0000466
Itohan8ec5f1f2019-05-04 00:21:47 +0000467service_model_list = create_service_model(parameters, vf_unique_id)
Itohane2f489f2019-06-03 23:53:15 +0000468print "service model parameters={}".format(service_model_list)
469
470upload_policy_models(parameters)
Itohan1f3c8d62019-05-24 23:52:26 +0000471add_policies(parameters)
Itohane2f489f2019-06-03 23:53:15 +0000472
root@rancher6c68bee2019-05-01 16:39:12 -0700473service_dict = create_service_instance(parameters, service_model_list)
Itohane2f489f2019-06-03 23:53:15 +0000474print "service instance parameters={}".format(service_dict)
Itohan8ec5f1f2019-05-04 00:21:47 +0000475service_model_uuid = service_dict["service_uuid"]
Itohane2f489f2019-06-03 23:53:15 +0000476
Itohan8ec5f1f2019-05-04 00:21:47 +0000477db_dict = query_db(parameters, service_model_uuid, vf_id)
Itohane2f489f2019-06-03 23:53:15 +0000478
479#Wait for Service instance to be created then create VNF Instance
480while True:
481 #Check if service instance has been created"
482 check_service_instance = os.popen("oclip service-instance-list -u {} -p {} -m {} |grep {}".format(parameters["aai_username"], \
483 parameters["aai_password"], parameters["aai_url"], parameters["instance-name"])).read()
484 if check_service_instance:
485 print "service instance created successfully"
486 #Create VNF Instance
487 vnf_dict = create_vnf(parameters, service_dict, db_dict, vf_model_dict)
488 time.sleep(10)
489 print "vnf instance parameters={}".format(vnf_dict)
490 break
491 print "service instance create in progress"
492 time.sleep(30)
493
494#Preload VF module and create VF module
root@rancher6c68bee2019-05-01 16:39:12 -0700495sdnc_preload(parameters, db_dict, service_dict)
496create_vf_module(parameters, service_dict, vnf_dict, db_dict)