blob: 1bbf3a40daa6f28bfcbf3032fdd9feb0e258385c [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
Itohan454b2792019-05-06 23:18:34 +0000180 vf_unique_id = output[1]
181
182 os.system("oclip vf-model-certify -b {} -r {} -u {} -p {} -m {}".format(vf_unique_id, parameters["vf-remarks"], \
183 parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"]))
184
185 #Check for new parameters after certification
186 output = (os.popen("oclip vf-model-list -m {} -u {} -p {} | grep {}".format(parameters["sdc_catalog_url"], \
187 parameters["sdc_creator"], parameters["sdc_password"], parameters["vf-name"]))).read()
188 output = (get_out_helper_2(output))
189
root@rancher6c68bee2019-05-01 16:39:12 -0700190 vf_id = output[0]
191 vf_unique_id = output[1]
192 vf_model_invariant_uuid = output[2]
193 vf_model_version = output[4]
194
root@rancher6c68bee2019-05-01 16:39:12 -0700195 out_dict = {}
196 out_dict["vf_id"] = vf_id
197 out_dict["vf_unique_id"] = vf_unique_id
198 out_dict["vf_model_invariant_uuid"] = vf_model_invariant_uuid
199 out_dict["vf_model_version"] = vf_model_version
200
201 return out_dict
202
203
204def create_service_model(parameters, vf_unique_id):
205 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 +0000206 parameters["service-model-desc"], parameters["icon-id"], parameters["service-model-name"], parameters["category-display"], \
207 parameters["category"],parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"])
root@rancher6c68bee2019-05-01 16:39:12 -0700208
209 service_model_id = (get_out_helper_2((os.popen(create_string)).read()))[1]
210
Itohan8ec5f1f2019-05-04 00:21:47 +0000211 os.system("oclip service-model-add-vf -x {} -b {} -y {} -z {} -u {} -p {} -m {}".format(service_model_id, parameters["vf-version"], \
212 vf_unique_id, parameters["vf-name"], parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"] ))
root@rancher6c68bee2019-05-01 16:39:12 -0700213
214 os.system("oclip service-model-test-request -b {} -r {} -u {} -p {} -m {}".format(service_model_id, parameters["service-test-remarks"], \
215 parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"]))
216
217 os.system("oclip service-model-test-start -b {} -u {} -p {} -m {}".format(service_model_id, parameters["sdc_tester"], \
218 parameters["sdc_password"], parameters["sdc_catalog_url"]))
219
220 os.system("oclip service-model-test-accept -b {} -r {} -u {} -p {} -m {}".format(service_model_id, parameters["service-accept-remarks"], \
221 parameters["sdc_tester"], parameters["sdc_password"], parameters["sdc_catalog_url"]))
222
Itohan8ec5f1f2019-05-04 00:21:47 +0000223 #Get uniqueId for the service model
224 service_model_values = (os.popen("oclip service-model-list -u {} -p {} -m {} |grep {}".format(parameters["sdc_creator"], \
root@rancher6c68bee2019-05-01 16:39:12 -0700225 parameters["sdc_password"], parameters["sdc_catalog_url"], parameters["service-model-name"]))).read()
Itohan8ec5f1f2019-05-04 00:21:47 +0000226 service_model_values = get_out_helper_2(service_model_values)
227 service_model_uniqueId = (service_model_values)[1]
root@rancher6c68bee2019-05-01 16:39:12 -0700228
Itohan8ec5f1f2019-05-04 00:21:47 +0000229 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 -0700230 parameters["sdc_governor"], parameters["sdc_password"], parameters["sdc_catalog_url"]))
231
Itohan8ec5f1f2019-05-04 00:21:47 +0000232 os.system("oclip service-model-distribute -b {} -u {} -p {} -m {}".format(service_model_uniqueId, parameters["sdc_operator"], \
root@rancher6c68bee2019-05-01 16:39:12 -0700233 parameters["sdc_password"], parameters["sdc_catalog_url"]))
234
Itohan8ec5f1f2019-05-04 00:21:47 +0000235 return service_model_values
root@rancher6c68bee2019-05-01 16:39:12 -0700236
237
238#VNF Deployment Section
239
240
241def add_policies(parameters):
242 resource_string = (os.popen("oclip get-resource-module-name -u {} -p {} -m {} |grep {}".format(\
243 parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"], \
Itohan8ec5f1f2019-05-04 00:21:47 +0000244 parameters["service-model-name"] ))).read()
root@rancher6c68bee2019-05-01 16:39:12 -0700245 resource_module_name = (get_out_helper_2(resource_string))[1]
246
Itohan454b2792019-05-06 23:18:34 +0000247 #Put in the right resource module name in all policies located in parameters["policy_directory"]
248 os.system("find {}/ -type f -exec sed -i 's/{}/{}/g' {{}} \;".format(
249 parameters["policy_directory"], parameters["temp_resource_module_name"], resource_module_name))
250
251 #Upload policy models
root@rancher6c68bee2019-05-01 16:39:12 -0700252 for model in os.listdir(parameters["policy_models_directory"]):
253 os.system("oclip policy-type-create -x {} -u {} -p {} -m {}".format(model, parameters["policy_username"], \
254 parameters["policy_password"], parameters["policy_url"]))
255 time.sleep(0.5)
256
Itohan454b2792019-05-06 23:18:34 +0000257 #print("Put in the resourceModuleName {} in your policy files in {}. ".format(resource_module_name, \
258 #(parameters["policy_directory"])))
259 #raw_input("Press Enter to continue...")
260
root@rancher6c68bee2019-05-01 16:39:12 -0700261
262 #Loop through policy, put in resource_model_name and create policies
263 for policy in os.listdir(parameters["policy_directory"]):
264 policy_name = "{}.{}".format(parameters["policy_scope"], os.path.splitext(policy)[0])
Itohan8ec5f1f2019-05-04 00:21:47 +0000265 policy_file = (os.path.join(parameters["policy_directory"], policy))
root@rancher6c68bee2019-05-01 16:39:12 -0700266 #Create policy
Itohan8ec5f1f2019-05-04 00:21:47 +0000267 os.system("oclip policy-create-outdated -m {} -u {} -p {} -x {} -S {} -T {} -o {} -b $(cat {})".format(parameters["policy_url"],\
268 parameters["policy_username"], parameters["policy_password"], policy_name, parameters["policy_scope"], \
269 parameters["policy_config_type"], parameters["policy_onapName"], policy_file))
root@rancher6c68bee2019-05-01 16:39:12 -0700270
271 #Push policy
272 os.system("oclip policy-push-outdated -m {} -u {} -p {} -x {} -b {} -c {}".format(parameters["policy_url"], \
273 parameters["policy_username"], parameters["policy_password"], policy_name, parameters["policy_config_type"],\
274 parameters["policy_pdp_group"]))
275
276
277def create_service_instance(parameters, sevice_model_list):
278 #Get Required parameters
279 service_uuid = service_model_list[0]
Itohan8ec5f1f2019-05-04 00:21:47 +0000280 service_invariant_uuid = service_model_list[2]
281 service_version = service_model_list[4]
root@rancher6c68bee2019-05-01 16:39:12 -0700282
283 owning_entity_values = (os.popen("oclip owning-entity-list -u {} -p {} -m {} |grep {}".format(parameters["aai_username"], \
284 parameters["aai_password"], parameters["aai_url"], parameters["owning-entity-name"]))).read()
285 owning_entity_id = (get_out_helper_2(owning_entity_values))[1]
286
287 #Create service instance
288 instance_output = (os.popen("oclip service-create -w {} -la {} -lo {} -o {} -A {} -i {} -y {} -x {} -q {} -O {} -k {}-{} -P {} \
289 -H {} -n {} -e {} -j {} -S {} -g {} -z {} -c {} -u {} -p {} -m {} |grep service-id".format(parameters["service_name"], \
290 parameters["customer-latitude"], parameters["customer-longitude"], parameters["orchestrator"], parameters["a-la-carte"], \
291 parameters["service-model-name"], parameters["company-name"], parameters["projectName"], parameters["requestor-id"], \
Itohan8ec5f1f2019-05-04 00:21:47 +0000292 parameters["owning-entity-name"], parameters["instance-name"], parameters["service_name"], parameters["test-api"], parameters["homing-solution"], \
root@rancher6c68bee2019-05-01 16:39:12 -0700293 service_uuid, service_invariant_uuid, service_version, parameters["subscriber_name"], service_uuid, owning_entity_id, \
294 parameters["customer_name"], parameters["so_username"], parameters["so_password"], parameters["so_url"] ))).read()
295
296 service_instance_id = (get_out_helper_2(instance_output))[1]
297 output_dict = {}
298
299 output_dict["service_instance_id"] = service_instance_id
300 output_dict["service_uuid"] = service_uuid
301 output_dict["service_invariant_uuid"] = service_invariant_uuid
302 output_dict["service_version"] = service_version
303
304
305 return output_dict
306
Itohan8ec5f1f2019-05-04 00:21:47 +0000307def query_db(parameters, service_model_uuid, vf_model_uuid):
root@rancher6c68bee2019-05-01 16:39:12 -0700308
309 out_dictionary = {}
310 #Query DB Certain parameters required
311 mariadb_connection = mariadb.connect(user='{}'.format(parameters["so_mariadb_user"]), host='{}'.format(parameters["so_mariadb_host"]),
312 password='{}'.format(parameters["so_mariadb_password"]), database='{}'.format(parameters["so_mariadb_db"]))
313 values = mariadb_connection.cursor()
314
315 #Get vf model customization values
316 values.execute('SELECT MODEL_INSTANCE_NAME, MODEL_CUSTOMIZATION_UUID FROM vnf_resource_customization WHERE \
Itohan8ec5f1f2019-05-04 00:21:47 +0000317 SERVICE_MODEL_UUID = "{}"'.format(service_model_uuid))
root@rancher6c68bee2019-05-01 16:39:12 -0700318 vf_customization_values = values.fetchall()
319
320 out_dictionary["vf_model_customization_name"] = vf_customization_values[0][0]
321 out_dictionary["vf_model_customization_id"] = vf_customization_values[0][1]
322
323 values.execute('SELECT MODEL_INVARIANT_UUID, MODEL_UUID, MODEL_NAME, MODEL_VERSION FROM vf_module WHERE \
324 VNF_RESOURCE_MODEL_UUID = "{}"'.format(vf_model_uuid))
325
326 vf_module_values = values.fetchall()
327 out_dictionary["vf_module_model_invariant_id"] = vf_module_values[0][0]
328 out_dictionary["vf_module_model_id"] = vf_module_values[0][1]
329 out_dictionary["vf_module_model_name"] = vf_module_values[0][2]
330 out_dictionary["vf_module_model_version"] = vf_module_values[0][3]
331
332 values.execute('SELECT MODEL_CUSTOMIZATION_UUID FROM vf_module_customization WHERE \
Itohan8ec5f1f2019-05-04 00:21:47 +0000333 VF_MODULE_MODEL_UUID = "{}"'.format(out_dictionary["vf_module_model_id"]))
root@rancher6c68bee2019-05-01 16:39:12 -0700334 vf_module_customization = values.fetchall()
335
336 out_dictionary["vf_module_customization_id"] = vf_module_customization[0][0]
337 values.close()
338 mariadb_connection.close()
339
340 return out_dictionary
341
342
343
344def create_vnf(parameters, service_dict, db_dict, vf_model_dict):
345
346 vf_model_uuid = vf_model_dict["vf_id"]
347 vf_model_invariant_uuid = vf_model_dict["vf_model_invariant_uuid"]
348 vf_model_version = vf_model_dict["vf_model_version"]
349
350
351
352 vf_model_customization_name = db_dict["vf_model_customization_name"]
353 vf_model_customization_id = db_dict["vf_model_customization_id"]
354
355 #Put in any cloud region, OOF will select the right one
356 cloud_region = next(iter(parameters["cloud_region_data"]))
357 tenant_id = ((parameters["cloud_region_data"])[cloud_region])["tenant-id"]
358
359 service_invariant_uuid = service_dict["service_invariant_uuid"]
360 service_uuid = service_dict["service_uuid"]
361 service_instance_id = service_dict["service_instance_id"]
362 service_version = service_dict["service_version"]
363
364 #Create vnf
365 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 +0000366 -w {} -pn {} -lob {} -u {} -p {} -m {} |grep vf-id".format(service_invariant_uuid, parameters["service-model-name"], \
367 service_uuid, cloud_region, service_instance_id, tenant_id, parameters["requestor-id"], vf_model_uuid, \
368 parameters["generic-vnf-name"], parameters["vf-name"], vf_model_version, vf_model_invariant_uuid, service_version, \
369 vf_model_customization_id, vf_model_customization_name, parameters["service_name"], parameters["platform-name"], \
370 parameters["lob-name"], parameters["so_username"], parameters["so_password"], parameters["so_url"]))).read()
root@rancher6c68bee2019-05-01 16:39:12 -0700371
372 vnf_instance_id = (get_out_helper_2(vnf_create_out))[1]
373
374 vf_model_dict["vnf_instance_id"] = vnf_instance_id
375
376 return vf_model_dict
377
378def sdnc_preload(parameters, db_dict, service_dict):
379
380
381 preload_file = parameters["sdnc_preload_file"]
382
383 #Replace values gotten from the service instance, vnf, vf in preload file, other values such as ip addresses
384 #should be directly changed in the preload file
385 #Items to search and replace in file
386 replace_dict = {
387 '"generic-vnf-name"' : ' "generic-vnf-name": "{}",\n'.format(parameters["generic-vnf-name"]),
388 '"generic-vnf-type"' : ' "generic-vnf-type": "{}",\n'.format(db_dict["vf_model_customization_name"]),
389 '"service-type"' : ' "service-type": "{}",\n'.format(service_dict["service_instance_id"]),
390 '"vnf-name"' : ' "vnf-name": "{}",\n'.format(parameters["vf-module-name"]),
391 '"vnf-type"' : ' "vnf-type": "{}"\n'.format(db_dict["vf_module_model_name"]),
392 '"vf_module_id"' : ' "vnf-parameter-value": "{}"\n'.format(db_dict["vf_module_model_name"])
393 }
394
395 with open(preload_file, 'r') as file:
396 preload_data = file.readlines()
397
398 for key, val in replace_dict.iteritems():
399 for line in range(len(preload_data)):
400
401 if key in preload_data[line] and key == '"vf_module_id"':
402 preload_data[line + 1] = val
403 break
404
405 elif key in preload_data[line] and key != '"vf_module_id"':
406 preload_data[line] = val
407 break
408 with open(preload_file, 'w') as file:
409 file.writelines(preload_data)
410
411 os.system("oclip vf-preload -u {} -p {} -y {} -m {}".format(parameters["sdnc_user"], parameters["sdnc_password"], \
412 preload_file, parameters["sdnc_url"]))
413
414
415
416def create_vf_module(parameters, service_dict, vnf_dict, db_dict):
417
418 #vf module parameters
419 vf_module_model_name = db_dict["vf_module_model_name"]
420 vf_module_model_invariant_id = db_dict["vf_module_model_invariant_id"]
421 vf_module_model_version = db_dict["vf_module_model_version"]
422 vf_module_model_version_id = db_dict["vf_module_model_id"]
423 vf_module_customization_id = db_dict["vf_module_customization_id"]
424
425 #service parameters
426 service_invariant_uuid = service_dict["service_invariant_uuid"]
427 service_uuid = service_dict["service_uuid"]
428 service_instance_id = service_dict["service_instance_id"]
429 service_version = service_dict["service_version"]
430
431 #vnf parameters
432 vnf_instance_id = vnf_dict["vnf_instance_id"]
433 vf_model_id = vnf_dict["vf_id"]
434 vf_model_invariant_uuid = vnf_dict["vf_model_invariant_uuid"]
435 vf_model_version = vnf_dict["vf_model_version"]
436 vf_model_customization_name = db_dict["vf_model_customization_name"]
437 vf_model_customization_id = db_dict["vf_model_customization_id"]
438
439 #Put in any cloud region, OOF will select the right one
440 cloud_region = next(iter(parameters["cloud_region_data"]))
441 tenant_id = ((parameters["cloud_region_data"])[cloud_region])["tenant-id"]
442
443
444 os.system("oclip vf-module-create -w {} -mn '{}' -x {} -l {} -sv {} -vc {} -vm {} -mv {} -i {} -vf {} -vi {} -r {} \
Itohan454b2792019-05-06 23:18:34 +0000445 -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 +0000446 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 -0700447 vf_model_version, parameters["vf-module-name"], parameters["vf-name"], vf_module_model_invariant_id, parameters["supress-rollback"], \
448 vf_model_customization_id, parameters["test-api"], vf_model_invariant_uuid, vf_model_id, vnf_instance_id, parameters["requestor-id"], \
449 service_uuid, parameters["use-preload"], service_invariant_uuid, parameters["service-model-name"], vf_module_model_name, \
Itohan454b2792019-05-06 23:18:34 +0000450 vf_module_model_version_id, parameters["cloud-owner"], parameters["so_username"], parameters["so_password"], parameters["so_url"]))
root@rancher6c68bee2019-05-01 16:39:12 -0700451
452
453
454
455
456
457#Run Functions
458
459config_file_path = "/root/automation_stuff/hpa_automation_config.json"
460config_file = open(config_file_path)
461parameters = get_parameters(config_file)
462set_open_cli_env(parameters)
463create_complex(parameters)
464register_all_clouds(parameters)
465create_service_type(parameters)
466create_customer(parameters)
467add_customer_subscription(parameters)
468output = create_vlm(parameters)
469vsp_id = create_vsp(parameters, output)
470vf_model_dict = create_vf_model(parameters, vsp_id)
471vf_id = vf_model_dict["vf_id"]
472vf_unique_id = vf_model_dict["vf_unique_id"]
Itohan8ec5f1f2019-05-04 00:21:47 +0000473service_model_list = create_service_model(parameters, vf_unique_id)
root@rancher6c68bee2019-05-01 16:39:12 -0700474
Itohan8ec5f1f2019-05-04 00:21:47 +0000475#add_policies function not currently working, using curl commands
476#add_policies(parameters)
477
root@rancher6c68bee2019-05-01 16:39:12 -0700478service_dict = create_service_instance(parameters, service_model_list)
Itohan8ec5f1f2019-05-04 00:21:47 +0000479service_model_uuid = service_dict["service_uuid"]
480db_dict = query_db(parameters, service_model_uuid, vf_id)
root@rancher6c68bee2019-05-01 16:39:12 -0700481vnf_dict = create_vnf(parameters, service_dict, db_dict, vf_model_dict)
482sdnc_preload(parameters, db_dict, service_dict)
483create_vf_module(parameters, service_dict, vnf_dict, db_dict)