blob: a5b8b4d0cd9d3449ceecc0ee0b589c233afc7e8d [file] [log] [blame]
root@rancher6c68bee2019-05-01 16:39:12 -07001#!/usr/bin/python
2
3#Prerequisites for machine to run this
4#Put in required parameters in hpa_automation_config.json
5#Install python-pip (apt install python-pip)
6#Install python mysql.connector (pip install mysql-connector-python)
7#Install ONAP CLI
8#Must have connectivity to the ONAP, a k8s vm already running is recommended
9#Create Preload File, the script will modify the parameters required from serivce model, service instance
10#and vnf instance
11#Create policies for homing
12#Put in CSAR file
13#modify so-bpmn configmap and change version to v2
14
15import json
16import os
17import mysql.connector as mariadb
18import time
19
20
21def get_parameters(file):
22 parameters = json.load(file)
23 return parameters
24
25def set_open_cli_env(parameters):
26 os.environ["OPEN_CLI_PRODUCT_IN_USE"] = parameters["open_cli_product"]
27 os.environ["OPEN_CLI_HOME"] = parameters["open_cli_home"]
28
29def create_complex(parameters):
30 complex_create_string = "oclip complex-create -j {} -r {} -x {} -y {} -lt {} -l {} -i {} -lo {} \
31 -S {} -la {} -g {} -w {} -z {} -k {} -o {} -q {} -m {} -u {} -p {}".format(parameters["street2"], \
32 parameters["physical_location"], parameters["complex_name"], \
33 parameters["data_center_code"], parameters["latitude"], parameters["region"], \
34 parameters["street1"], parameters["longitude"], parameters["state"], \
35 parameters["lata"], parameters["city"], parameters["postal-code"], \
36 parameters["complex_name"], parameters["country"], parameters["elevation"], \
37 parameters["identity_url"], parameters["aai_url"], parameters["aai_username"], \
38 parameters["aai_password"])
39
40 os.system(complex_create_string)
41
42
43def register_cloud_helper(cloud_region, values, parameters):
44 #Create Cloud
45 cloud_create_string = 'oclip cloud-create -e {} -b {} -I {{\\\\\\"openstack-region-id\\\\\\":\\\\\\"{}\\\\\\"}} \
46 -x {} -y {} -j {} -w {} -l {} -url {} -n {} -q {} -r {} -Q {} -i {} -g {} -z {} -k {} -c {} -m {} -u {} -p {}'.format(
47 values.get("esr-system-info-id"), values.get("user-name"), cloud_region, parameters["cloud-owner"], \
48 cloud_region, values.get("password"), values.get("cloud-region-version"), values.get("default-tenant"), \
49 values.get("service-url"), parameters["complex_name"], values.get("cloud-type"), parameters["owner-defined-type"], \
50 values.get("system-type"), values.get("identity-url"), parameters["cloud-zone"], values.get("ssl-insecure"), \
51 values.get("system-status"), values.get("cloud-domain"), parameters["aai_url"], parameters["aai_username"], \
52 parameters["aai_password"])
53
54
55 os.system(cloud_create_string)
56
57 #Associate Cloud with complex
58 complex_associate_string = "oclip complex-associate -x {} -y {} -z {} -m {} -u {} -p {}".format(parameters["complex_name"], \
59 cloud_region, parameters["cloud-owner"], parameters["aai_url"], parameters["aai_username"], parameters["aai_password"])
60 os.system(complex_associate_string)
61
62 #Register Cloud with Multicloud
63 multicloud_register_string = "oclip multicloud-register-cloud -y {} -x {} -m {}".format(parameters["cloud-owner"], \
64 cloud_region, parameters["multicloud_url"])
65 os.system(multicloud_register_string)
66
67def register_all_clouds(parameters):
68 cloud_dictionary = parameters["cloud_region_data"]
69 for cloud_region, cloud_region_values in cloud_dictionary.iteritems():
70 register_cloud_helper(cloud_region, cloud_region_values, parameters)
71
72def create_service_type(parameters):
73 create_string = "oclip service-type-create -x {} -m {} -u {} -p {}".format( parameters["service_name"], \
74 parameters["aai_url"], parameters["aai_username"], parameters["aai_password"])
75 os.system(create_string)
76
77def create_customer(parameters):
78 create_string = "oclip customer-create -x {} -y {} -m {} -u {} -p {}".format( parameters["customer_name"], \
79 parameters["subscriber_name"], parameters["aai_url"], parameters["aai_username"], parameters["aai_password"])
80 os.system(create_string)
81
82def add_customer_subscription(parameters):
83 subscription_check = 0
84 for cloud_region, cloud_region_values in (parameters["cloud_region_data"]).iteritems():
85 if subscription_check == 0 :
86 subscription_string = "oclip subscription-create -x {} -c {} -z {} -e {} -y {} -r {} -m {} -u {} -p {}".format(\
87 parameters["customer_name"], cloud_region_values.get("tenant-id"), parameters["cloud-owner"], parameters["service_name"],\
88 cloud_region_values.get("default-tenant"), cloud_region, parameters["aai_url"], parameters["aai_username"], parameters["aai_password"] )
89 else:
90 subscription_string = "oclip subscription-cloud-add -x {} -c {} -z {} -e {} -y {} -r {} -m {} -u {} -p {}".format(\
91 parameters["customer_name"], cloud_region_values.get("tenant-id"), parameters["cloud-owner"], parameters["service_name"],\
92 cloud_region_values.get("default-tenant"), cloud_region, parameters["aai_url"], parameters["aai_username"], parameters["aai_password"] )
93 os.system(subscription_string)
94 subscription_check+=1
95
96def get_out_helper(in_string):
97 out_list = (((in_string.replace('-','')).replace('|', '')).replace('+', '')).split()
98 return out_list
99
100def get_out_helper_2(in_string):
101 out_list = ((in_string.replace('|', '')).replace('+', '')).split()
102 return out_list
103
104#ONBOARDING SECTION
105def create_vlm(parameters):
106 vlm_create_string = "oclip vlm-create -x {} -u {} -p {} -m {}".format(parameters["vendor-name"], \
107 parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_onboarding_url"])
108 command_out = (os.popen(vlm_create_string)).read()
109 out_list = get_out_helper(command_out)
110 vlm_id = out_list[3]
111 vlm_version = out_list[5]
112
113 entitlement_string = "oclip vlm-entitlement-pool-create -x {} -y {} -e {} -z {} -k {} -g {} -l {} -u {} -p {} -m {}".format( \
114 parameters["entitlement-pool-name"], vlm_id, vlm_version, parameters["entitlement-description"], parameters["vendor-name"], \
115 parameters["expiry-date"], parameters["start-date"], parameters["sdc_creator"], parameters["sdc_password"], \
116 parameters["sdc_onboarding_url"])
117 command_out = (os.popen(entitlement_string)).read()
118 entitlement_id = (get_out_helper(command_out))[3]
119
120
121 key_group_string = "oclip vlm-key-group-create -c {} -e {} -x {} -y {} -u {} -p {} -m {}".format(vlm_id, vlm_version, \
122 parameters["key-group-name"], parameters["key-group-type"], parameters["sdc_creator"], parameters["sdc_password"], \
123 parameters["sdc_onboarding_url"])
124 command_out = (os.popen(key_group_string)).read()
125 key_group_id = (get_out_helper(command_out))[3]
126
127 feature_group_string = "oclip vlm-feature-group-create -x {} -y {} -e {} -z {} -g {} -b {} -c {} -u {} -p {} -m {}".format(
128 parameters["feature-grp-name"], vlm_id, vlm_version, parameters["feature-grp-desc"], key_group_id, entitlement_id, \
129 parameters["part-no"], parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_onboarding_url"])
130 command_out = (os.popen(feature_group_string)).read()
131 feature_group_id = (get_out_helper(command_out))[3]
132
133 agreement_string = "oclip vlm-aggreement-create -x {} -y {} -e {} -z {} -g {} -u {} -p {} -m {}".format(parameters["agreement-name"], \
134 vlm_id, vlm_version, parameters["agreement-desc"], feature_group_id, parameters["sdc_creator"], parameters["sdc_password"], \
135 parameters["sdc_onboarding_url"])
136 command_out = (os.popen(agreement_string)).read()
137 agreement_id = (get_out_helper(command_out))[3]
138
139 submit_string = "oclip vlm-submit -x {} -y {} -u {} -p {} -m {}".format(vlm_id, vlm_version, parameters["sdc_creator"], \
140 parameters["sdc_password"], parameters["sdc_onboarding_url"])
141 os.system(submit_string)
142
143 output = [feature_group_id, agreement_id, vlm_version, vlm_id ]
144 return output
145
146def create_vsp(parameters, in_list):
147 create_string = "oclip vsp-create -j {} -o {} -e {} -x {} -y {} -i {} -c {} -g {} -u {} -p {} -m {}".format( in_list[0], \
148 parameters["onboarding-method"], parameters["vendor-name" ], parameters["vsp-name"], parameters["vsp-desc"], in_list[1], \
149 in_list[2], in_list[3], parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_onboarding_url"] )
150 command_out = (os.popen(create_string)).read()
151 out_list = get_out_helper(command_out)
152 vsp_id = out_list[3]
153 vsp_version = out_list[5]
154
155 os.system("oclip vsp-add-artifact -x {} -y {} -z {} -u {} -p {} -m {}".format(vsp_id, vsp_version, parameters["csar-file-path"], \
156 parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_onboarding_url"]))
157
158 os.system("oclip vsp-validate -x {} -y {} -u {} -p {} -m {}".format(vsp_id, vsp_version, parameters["sdc_creator"], \
159 parameters["sdc_password"], parameters["sdc_onboarding_url"]))
160
161 os.system("oclip vsp-submit -x {} -y {} -u {} -p {} -m {}".format(vsp_id, vsp_version, parameters["sdc_creator"], \
162 parameters["sdc_password"], parameters["sdc_onboarding_url"]))
163
164 os.system("oclip vsp-package -x {} -y {} -u {} -p {} -m {}".format(vsp_id, vsp_version, parameters["sdc_creator"], \
165 parameters["sdc_password"], parameters["sdc_onboarding_url"]))
166
167 return vsp_id
168
169
170def create_vf_model(parameters, vsp_id):
171 create_string = "oclip vf-model-create -y {} -g {} -x {} -z {} -b {} -u {} -p {} -m {}".format(parameters["vf-description"], \
172 parameters["vsp-version"], parameters["vf-name"], parameters["vendor-name"], vsp_id, parameters["sdc_creator"], \
173 parameters["sdc_password"], parameters["sdc_catalog_url"])
174 os.system(create_string)
175
176 output = (os.popen("oclip vf-model-list -m {} -u {} -p {} | grep {}".format(parameters["sdc_catalog_url"], \
177 parameters["sdc_creator"], parameters["sdc_password"], parameters["vf-name"]))).read()
178 output = (get_out_helper_2(output))
179
180 vf_id = output[0]
181 vf_unique_id = output[1]
182 vf_model_invariant_uuid = output[2]
183 vf_model_version = output[4]
184
185 os.system("oclip vf-model-certify -b {} -r {} -u {} -p {} -m {}".format(vf_unique_id, parameters["vf-remarks"], \
186 parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"]))
187
188 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):
198 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 +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
232
233
234def add_policies(parameters):
235 resource_string = (os.popen("oclip get-resource-module-name -u {} -p {} -m {} |grep {}".format(\
236 parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"], \
Itohan8ec5f1f2019-05-04 00:21:47 +0000237 parameters["service-model-name"] ))).read()
root@rancher6c68bee2019-05-01 16:39:12 -0700238 resource_module_name = (get_out_helper_2(resource_string))[1]
239
240 #Upload policy models
241 for model in os.listdir(parameters["policy_models_directory"]):
242 os.system("oclip policy-type-create -x {} -u {} -p {} -m {}".format(model, parameters["policy_username"], \
243 parameters["policy_password"], parameters["policy_url"]))
244 time.sleep(0.5)
245
Itohan8ec5f1f2019-05-04 00:21:47 +0000246 print("Put in the resourceModuleName {} in your policy files in {}. ".format(resource_module_name, \
247 (parameters["policy_directory"])))
248 raw_input("Press Enter to continue...")
root@rancher6c68bee2019-05-01 16:39:12 -0700249
250 #Loop through policy, put in resource_model_name and create policies
251 for policy in os.listdir(parameters["policy_directory"]):
252 policy_name = "{}.{}".format(parameters["policy_scope"], os.path.splitext(policy)[0])
Itohan8ec5f1f2019-05-04 00:21:47 +0000253 policy_file = (os.path.join(parameters["policy_directory"], policy))
root@rancher6c68bee2019-05-01 16:39:12 -0700254 #Create policy
Itohan8ec5f1f2019-05-04 00:21:47 +0000255 os.system("oclip policy-create-outdated -m {} -u {} -p {} -x {} -S {} -T {} -o {} -b $(cat {})".format(parameters["policy_url"],\
256 parameters["policy_username"], parameters["policy_password"], policy_name, parameters["policy_scope"], \
257 parameters["policy_config_type"], parameters["policy_onapName"], policy_file))
root@rancher6c68bee2019-05-01 16:39:12 -0700258
259 #Push policy
260 os.system("oclip policy-push-outdated -m {} -u {} -p {} -x {} -b {} -c {}".format(parameters["policy_url"], \
261 parameters["policy_username"], parameters["policy_password"], policy_name, parameters["policy_config_type"],\
262 parameters["policy_pdp_group"]))
263
264
265def create_service_instance(parameters, sevice_model_list):
266 #Get Required parameters
267 service_uuid = service_model_list[0]
Itohan8ec5f1f2019-05-04 00:21:47 +0000268 service_invariant_uuid = service_model_list[2]
269 service_version = service_model_list[4]
root@rancher6c68bee2019-05-01 16:39:12 -0700270
271 owning_entity_values = (os.popen("oclip owning-entity-list -u {} -p {} -m {} |grep {}".format(parameters["aai_username"], \
272 parameters["aai_password"], parameters["aai_url"], parameters["owning-entity-name"]))).read()
273 owning_entity_id = (get_out_helper_2(owning_entity_values))[1]
274
275 #Create service instance
276 instance_output = (os.popen("oclip service-create -w {} -la {} -lo {} -o {} -A {} -i {} -y {} -x {} -q {} -O {} -k {}-{} -P {} \
277 -H {} -n {} -e {} -j {} -S {} -g {} -z {} -c {} -u {} -p {} -m {} |grep service-id".format(parameters["service_name"], \
278 parameters["customer-latitude"], parameters["customer-longitude"], parameters["orchestrator"], parameters["a-la-carte"], \
279 parameters["service-model-name"], parameters["company-name"], parameters["projectName"], parameters["requestor-id"], \
Itohan8ec5f1f2019-05-04 00:21:47 +0000280 parameters["owning-entity-name"], parameters["instance-name"], parameters["service_name"], parameters["test-api"], parameters["homing-solution"], \
root@rancher6c68bee2019-05-01 16:39:12 -0700281 service_uuid, service_invariant_uuid, service_version, parameters["subscriber_name"], service_uuid, owning_entity_id, \
282 parameters["customer_name"], parameters["so_username"], parameters["so_password"], parameters["so_url"] ))).read()
283
284 service_instance_id = (get_out_helper_2(instance_output))[1]
285 output_dict = {}
286
287 output_dict["service_instance_id"] = service_instance_id
288 output_dict["service_uuid"] = service_uuid
289 output_dict["service_invariant_uuid"] = service_invariant_uuid
290 output_dict["service_version"] = service_version
291
292
293 return output_dict
294
Itohan8ec5f1f2019-05-04 00:21:47 +0000295def query_db(parameters, service_model_uuid, vf_model_uuid):
root@rancher6c68bee2019-05-01 16:39:12 -0700296
297 out_dictionary = {}
298 #Query DB Certain parameters required
299 mariadb_connection = mariadb.connect(user='{}'.format(parameters["so_mariadb_user"]), host='{}'.format(parameters["so_mariadb_host"]),
300 password='{}'.format(parameters["so_mariadb_password"]), database='{}'.format(parameters["so_mariadb_db"]))
301 values = mariadb_connection.cursor()
302
303 #Get vf model customization values
304 values.execute('SELECT MODEL_INSTANCE_NAME, MODEL_CUSTOMIZATION_UUID FROM vnf_resource_customization WHERE \
Itohan8ec5f1f2019-05-04 00:21:47 +0000305 SERVICE_MODEL_UUID = "{}"'.format(service_model_uuid))
root@rancher6c68bee2019-05-01 16:39:12 -0700306 vf_customization_values = values.fetchall()
307
308 out_dictionary["vf_model_customization_name"] = vf_customization_values[0][0]
309 out_dictionary["vf_model_customization_id"] = vf_customization_values[0][1]
310
311 values.execute('SELECT MODEL_INVARIANT_UUID, MODEL_UUID, MODEL_NAME, MODEL_VERSION FROM vf_module WHERE \
312 VNF_RESOURCE_MODEL_UUID = "{}"'.format(vf_model_uuid))
313
314 vf_module_values = values.fetchall()
315 out_dictionary["vf_module_model_invariant_id"] = vf_module_values[0][0]
316 out_dictionary["vf_module_model_id"] = vf_module_values[0][1]
317 out_dictionary["vf_module_model_name"] = vf_module_values[0][2]
318 out_dictionary["vf_module_model_version"] = vf_module_values[0][3]
319
320 values.execute('SELECT MODEL_CUSTOMIZATION_UUID FROM vf_module_customization WHERE \
Itohan8ec5f1f2019-05-04 00:21:47 +0000321 VF_MODULE_MODEL_UUID = "{}"'.format(out_dictionary["vf_module_model_id"]))
root@rancher6c68bee2019-05-01 16:39:12 -0700322 vf_module_customization = values.fetchall()
323
324 out_dictionary["vf_module_customization_id"] = vf_module_customization[0][0]
325 values.close()
326 mariadb_connection.close()
327
328 return out_dictionary
329
330
331
332def create_vnf(parameters, service_dict, db_dict, vf_model_dict):
333
334 vf_model_uuid = vf_model_dict["vf_id"]
335 vf_model_invariant_uuid = vf_model_dict["vf_model_invariant_uuid"]
336 vf_model_version = vf_model_dict["vf_model_version"]
337
338
339
340 vf_model_customization_name = db_dict["vf_model_customization_name"]
341 vf_model_customization_id = db_dict["vf_model_customization_id"]
342
343 #Put in any cloud region, OOF will select the right one
344 cloud_region = next(iter(parameters["cloud_region_data"]))
345 tenant_id = ((parameters["cloud_region_data"])[cloud_region])["tenant-id"]
346
347 service_invariant_uuid = service_dict["service_invariant_uuid"]
348 service_uuid = service_dict["service_uuid"]
349 service_instance_id = service_dict["service_instance_id"]
350 service_version = service_dict["service_version"]
351
352 #Create vnf
353 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 +0000354 -w {} -pn {} -lob {} -u {} -p {} -m {} |grep vf-id".format(service_invariant_uuid, parameters["service-model-name"], \
355 service_uuid, cloud_region, service_instance_id, tenant_id, parameters["requestor-id"], vf_model_uuid, \
356 parameters["generic-vnf-name"], parameters["vf-name"], vf_model_version, vf_model_invariant_uuid, service_version, \
357 vf_model_customization_id, vf_model_customization_name, parameters["service_name"], parameters["platform-name"], \
358 parameters["lob-name"], parameters["so_username"], parameters["so_password"], parameters["so_url"]))).read()
root@rancher6c68bee2019-05-01 16:39:12 -0700359
360 vnf_instance_id = (get_out_helper_2(vnf_create_out))[1]
361
362 vf_model_dict["vnf_instance_id"] = vnf_instance_id
363
364 return vf_model_dict
365
366def sdnc_preload(parameters, db_dict, service_dict):
367
368
369 preload_file = parameters["sdnc_preload_file"]
370
371 #Replace values gotten from the service instance, vnf, vf in preload file, other values such as ip addresses
372 #should be directly changed in the preload file
373 #Items to search and replace in file
374 replace_dict = {
375 '"generic-vnf-name"' : ' "generic-vnf-name": "{}",\n'.format(parameters["generic-vnf-name"]),
376 '"generic-vnf-type"' : ' "generic-vnf-type": "{}",\n'.format(db_dict["vf_model_customization_name"]),
377 '"service-type"' : ' "service-type": "{}",\n'.format(service_dict["service_instance_id"]),
378 '"vnf-name"' : ' "vnf-name": "{}",\n'.format(parameters["vf-module-name"]),
379 '"vnf-type"' : ' "vnf-type": "{}"\n'.format(db_dict["vf_module_model_name"]),
380 '"vf_module_id"' : ' "vnf-parameter-value": "{}"\n'.format(db_dict["vf_module_model_name"])
381 }
382
383 with open(preload_file, 'r') as file:
384 preload_data = file.readlines()
385
386 for key, val in replace_dict.iteritems():
387 for line in range(len(preload_data)):
388
389 if key in preload_data[line] and key == '"vf_module_id"':
390 preload_data[line + 1] = val
391 break
392
393 elif key in preload_data[line] and key != '"vf_module_id"':
394 preload_data[line] = val
395 break
396 with open(preload_file, 'w') as file:
397 file.writelines(preload_data)
398
399 os.system("oclip vf-preload -u {} -p {} -y {} -m {}".format(parameters["sdnc_user"], parameters["sdnc_password"], \
400 preload_file, parameters["sdnc_url"]))
401
402
403
404def create_vf_module(parameters, service_dict, vnf_dict, db_dict):
405
406 #vf module parameters
407 vf_module_model_name = db_dict["vf_module_model_name"]
408 vf_module_model_invariant_id = db_dict["vf_module_model_invariant_id"]
409 vf_module_model_version = db_dict["vf_module_model_version"]
410 vf_module_model_version_id = db_dict["vf_module_model_id"]
411 vf_module_customization_id = db_dict["vf_module_customization_id"]
412
413 #service parameters
414 service_invariant_uuid = service_dict["service_invariant_uuid"]
415 service_uuid = service_dict["service_uuid"]
416 service_instance_id = service_dict["service_instance_id"]
417 service_version = service_dict["service_version"]
418
419 #vnf parameters
420 vnf_instance_id = vnf_dict["vnf_instance_id"]
421 vf_model_id = vnf_dict["vf_id"]
422 vf_model_invariant_uuid = vnf_dict["vf_model_invariant_uuid"]
423 vf_model_version = vnf_dict["vf_model_version"]
424 vf_model_customization_name = db_dict["vf_model_customization_name"]
425 vf_model_customization_id = db_dict["vf_model_customization_id"]
426
427 #Put in any cloud region, OOF will select the right one
428 cloud_region = next(iter(parameters["cloud_region_data"]))
429 tenant_id = ((parameters["cloud_region_data"])[cloud_region])["tenant-id"]
430
431
432 os.system("oclip vf-module-create -w {} -mn '{}' -x {} -l {} -sv {} -vc {} -vm {} -mv {} -i {} -vf {} -vi {} -r {} \
Itohan8ec5f1f2019-05-04 00:21:47 +0000433 -mc {} -api {} -mi {} -vid {} -y {} -R {} -si {} -up {} -sd {} -z {} -vn {} -vv {} -u {} -p {} -m {}".format(tenant_id, \
434 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 -0700435 vf_model_version, parameters["vf-module-name"], parameters["vf-name"], vf_module_model_invariant_id, parameters["supress-rollback"], \
436 vf_model_customization_id, parameters["test-api"], vf_model_invariant_uuid, vf_model_id, vnf_instance_id, parameters["requestor-id"], \
437 service_uuid, parameters["use-preload"], service_invariant_uuid, parameters["service-model-name"], vf_module_model_name, \
438 vf_module_model_version_id, parameters["so_username"], parameters["so_password"], parameters["so_url"]))
439
440
441
442
443
444
445#Run Functions
446
447config_file_path = "/root/automation_stuff/hpa_automation_config.json"
448config_file = open(config_file_path)
449parameters = get_parameters(config_file)
450set_open_cli_env(parameters)
451create_complex(parameters)
452register_all_clouds(parameters)
453create_service_type(parameters)
454create_customer(parameters)
455add_customer_subscription(parameters)
456output = create_vlm(parameters)
457vsp_id = create_vsp(parameters, output)
458vf_model_dict = create_vf_model(parameters, vsp_id)
459vf_id = vf_model_dict["vf_id"]
460vf_unique_id = vf_model_dict["vf_unique_id"]
Itohan8ec5f1f2019-05-04 00:21:47 +0000461service_model_list = create_service_model(parameters, vf_unique_id)
root@rancher6c68bee2019-05-01 16:39:12 -0700462
Itohan8ec5f1f2019-05-04 00:21:47 +0000463#add_policies function not currently working, using curl commands
464#add_policies(parameters)
465
root@rancher6c68bee2019-05-01 16:39:12 -0700466service_dict = create_service_instance(parameters, service_model_list)
Itohan8ec5f1f2019-05-04 00:21:47 +0000467service_model_uuid = service_dict["service_uuid"]
468db_dict = query_db(parameters, service_model_uuid, vf_id)
root@rancher6c68bee2019-05-01 16:39:12 -0700469vnf_dict = create_vnf(parameters, service_dict, db_dict, vf_model_dict)
470sdnc_preload(parameters, db_dict, service_dict)
471create_vf_module(parameters, service_dict, vnf_dict, db_dict)