root@rancher | 6c68bee | 2019-05-01 16:39:12 -0700 | [diff] [blame] | 1 | #!/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 | |
| 15 | import json |
| 16 | import os |
| 17 | import mysql.connector as mariadb |
| 18 | import time |
| 19 | |
| 20 | |
| 21 | def get_parameters(file): |
| 22 | parameters = json.load(file) |
| 23 | return parameters |
| 24 | |
| 25 | def 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 | |
| 29 | def 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 | |
| 43 | def 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 | |
| 67 | def 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 | |
| 72 | def 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 | |
| 77 | def 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 | |
| 82 | def 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 | |
| 96 | def get_out_helper(in_string): |
| 97 | out_list = (((in_string.replace('-','')).replace('|', '')).replace('+', '')).split() |
| 98 | return out_list |
| 99 | |
| 100 | def get_out_helper_2(in_string): |
| 101 | out_list = ((in_string.replace('|', '')).replace('+', '')).split() |
| 102 | return out_list |
| 103 | |
| 104 | #ONBOARDING SECTION |
| 105 | def 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 | |
| 146 | def 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 | |
| 170 | def 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 | |
| 197 | def 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"], \ |
| 199 | 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"]) |
| 201 | |
| 202 | service_model_id = (get_out_helper_2((os.popen(create_string)).read()))[1] |
| 203 | |
| 204 | add_string = "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"] ) |
| 206 | |
| 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 | |
| 216 | #Get new Id for the service model |
| 217 | new_service_model_values = (os.popen("oclip service-model-list -u {} -p {} -m {} |grep {}".format(parameters["sdc_creator"], \ |
| 218 | parameters["sdc_password"], parameters["sdc_catalog_url"], parameters["service-model-name"]))).read() |
| 219 | new_service_model_values = get_out_helper_2(new_service_model_values) |
| 220 | new_service_model_id = (new_service_model_values)[0] |
| 221 | |
| 222 | |
| 223 | os.system("oclip service-model-approve -b {} -r {} -u {} -p {} -m {}".format(new_service_model_id, parameters["service-approve-remarks"], \ |
| 224 | parameters["sdc_governor"], parameters["sdc_password"], parameters["sdc_catalog_url"])) |
| 225 | |
| 226 | os.system("oclip service-model-distribute -b {} -u {} -p {} -m {}".format(new_service_model_id, parameters["sdc_operator"], \ |
| 227 | parameters["sdc_password"], parameters["sdc_catalog_url"])) |
| 228 | |
| 229 | return new_service_model_values |
| 230 | |
| 231 | |
| 232 | #VNF Deployment Section |
| 233 | |
| 234 | |
| 235 | def 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"], \ |
| 238 | parameters["vsp-name"] ))).read() |
| 239 | resource_module_name = (get_out_helper_2(resource_string))[1] |
| 240 | |
| 241 | #Upload policy models |
| 242 | for model in os.listdir(parameters["policy_models_directory"]): |
| 243 | os.system("oclip policy-type-create -x {} -u {} -p {} -m {}".format(model, parameters["policy_username"], \ |
| 244 | parameters["policy_password"], parameters["policy_url"])) |
| 245 | time.sleep(0.5) |
| 246 | |
| 247 | print("Put in the resourceModuleName {} in your policy files in {}. ".format(resource_module_name, \ |
| 248 | (parameters["policy_models_directory"]))) |
| 249 | raw_input("Press Enter to continue...") |
| 250 | |
| 251 | #Loop through policy, put in resource_model_name and create policies |
| 252 | for policy in os.listdir(parameters["policy_directory"]): |
| 253 | policy_name = "{}.{}".format(parameters["policy_scope"], os.path.splitext(policy)[0]) |
| 254 | |
| 255 | #Create policy |
| 256 | os.system("oclip policy-create-outdated -m {} -u {} -p {} -x {} -S {} -T {} -o {} -b $(cat {})".format(parameters["policy_url"]),\ |
| 257 | parameters["policy_username"], policy["policy_password"], policy_name, parameters["policy_scope"], \ |
| 258 | parameters["policy_config_type"], parameters["policy_onapName"], os.path.join(parameters["policy_models_directory"], policy) ) |
| 259 | |
| 260 | #Push policy |
| 261 | os.system("oclip policy-push-outdated -m {} -u {} -p {} -x {} -b {} -c {}".format(parameters["policy_url"], \ |
| 262 | parameters["policy_username"], parameters["policy_password"], policy_name, parameters["policy_config_type"],\ |
| 263 | parameters["policy_pdp_group"])) |
| 264 | |
| 265 | |
| 266 | def create_service_instance(parameters, sevice_model_list): |
| 267 | #Get Required parameters |
| 268 | service_uuid = service_model_list[0] |
| 269 | service_invariant_uuid = service_model_list[1] |
| 270 | service_version = service_model_list[3] |
| 271 | |
| 272 | owning_entity_values = (os.popen("oclip owning-entity-list -u {} -p {} -m {} |grep {}".format(parameters["aai_username"], \ |
| 273 | parameters["aai_password"], parameters["aai_url"], parameters["owning-entity-name"]))).read() |
| 274 | owning_entity_id = (get_out_helper_2(owning_entity_values))[1] |
| 275 | |
| 276 | #Create service instance |
| 277 | instance_output = (os.popen("oclip service-create -w {} -la {} -lo {} -o {} -A {} -i {} -y {} -x {} -q {} -O {} -k {}-{} -P {} \ |
| 278 | -H {} -n {} -e {} -j {} -S {} -g {} -z {} -c {} -u {} -p {} -m {} |grep service-id".format(parameters["service_name"], \ |
| 279 | parameters["customer-latitude"], parameters["customer-longitude"], parameters["orchestrator"], parameters["a-la-carte"], \ |
| 280 | parameters["service-model-name"], parameters["company-name"], parameters["projectName"], parameters["requestor-id"], \ |
| 281 | parameters["owning-entity-name"], parameters["instance-name"], service_type, parameters["test-api"], parameters["homing-solution"], \ |
| 282 | service_uuid, service_invariant_uuid, service_version, parameters["subscriber_name"], service_uuid, owning_entity_id, \ |
| 283 | parameters["customer_name"], parameters["so_username"], parameters["so_password"], parameters["so_url"] ))).read() |
| 284 | |
| 285 | service_instance_id = (get_out_helper_2(instance_output))[1] |
| 286 | output_dict = {} |
| 287 | |
| 288 | output_dict["service_instance_id"] = service_instance_id |
| 289 | output_dict["service_uuid"] = service_uuid |
| 290 | output_dict["service_invariant_uuid"] = service_invariant_uuid |
| 291 | output_dict["service_version"] = service_version |
| 292 | |
| 293 | |
| 294 | return output_dict |
| 295 | |
| 296 | def query_db(parameters, vf_model_uuid): |
| 297 | |
| 298 | out_dictionary = {} |
| 299 | #Query DB Certain parameters required |
| 300 | mariadb_connection = mariadb.connect(user='{}'.format(parameters["so_mariadb_user"]), host='{}'.format(parameters["so_mariadb_host"]), |
| 301 | password='{}'.format(parameters["so_mariadb_password"]), database='{}'.format(parameters["so_mariadb_db"])) |
| 302 | values = mariadb_connection.cursor() |
| 303 | |
| 304 | #Get vf model customization values |
| 305 | values.execute('SELECT MODEL_INSTANCE_NAME, MODEL_CUSTOMIZATION_UUID FROM vnf_resource_customization WHERE \ |
| 306 | VNF_RESOURCE_MODEL_UUID = "{}"'.format(vf_model_uuid)) |
| 307 | vf_customization_values = values.fetchall() |
| 308 | |
| 309 | out_dictionary["vf_model_customization_name"] = vf_customization_values[0][0] |
| 310 | out_dictionary["vf_model_customization_id"] = vf_customization_values[0][1] |
| 311 | |
| 312 | values.execute('SELECT MODEL_INVARIANT_UUID, MODEL_UUID, MODEL_NAME, MODEL_VERSION FROM vf_module WHERE \ |
| 313 | VNF_RESOURCE_MODEL_UUID = "{}"'.format(vf_model_uuid)) |
| 314 | |
| 315 | vf_module_values = values.fetchall() |
| 316 | out_dictionary["vf_module_model_invariant_id"] = vf_module_values[0][0] |
| 317 | out_dictionary["vf_module_model_id"] = vf_module_values[0][1] |
| 318 | out_dictionary["vf_module_model_name"] = vf_module_values[0][2] |
| 319 | out_dictionary["vf_module_model_version"] = vf_module_values[0][3] |
| 320 | |
| 321 | values.execute('SELECT MODEL_CUSTOMIZATION_UUID FROM vf_module_customization WHERE \ |
| 322 | VF_MODULE_MODEL_UUID = "{}"'.format(out_dictionary[vf_module_model_id])) |
| 323 | vf_module_customization = values.fetchall() |
| 324 | |
| 325 | out_dictionary["vf_module_customization_id"] = vf_module_customization[0][0] |
| 326 | values.close() |
| 327 | mariadb_connection.close() |
| 328 | |
| 329 | return out_dictionary |
| 330 | |
| 331 | |
| 332 | |
| 333 | def create_vnf(parameters, service_dict, db_dict, vf_model_dict): |
| 334 | |
| 335 | vf_model_uuid = vf_model_dict["vf_id"] |
| 336 | vf_model_invariant_uuid = vf_model_dict["vf_model_invariant_uuid"] |
| 337 | vf_model_version = vf_model_dict["vf_model_version"] |
| 338 | |
| 339 | |
| 340 | |
| 341 | vf_model_customization_name = db_dict["vf_model_customization_name"] |
| 342 | vf_model_customization_id = db_dict["vf_model_customization_id"] |
| 343 | |
| 344 | #Put in any cloud region, OOF will select the right one |
| 345 | cloud_region = next(iter(parameters["cloud_region_data"])) |
| 346 | tenant_id = ((parameters["cloud_region_data"])[cloud_region])["tenant-id"] |
| 347 | |
| 348 | service_invariant_uuid = service_dict["service_invariant_uuid"] |
| 349 | service_uuid = service_dict["service_uuid"] |
| 350 | service_instance_id = service_dict["service_instance_id"] |
| 351 | service_version = service_dict["service_version"] |
| 352 | |
| 353 | #Create vnf |
| 354 | vnf_create_out = (os.popen("oclip vnf-create -j {} -q {} -k {} -l {} -y {} -z {} -r {} -c {} -o {} -e {} -g {} -b {} -n {} -i {} -vn '{}'\ |
| 355 | -w {} -pn {} -lob {} -u {} -p {} -m {} |grep vf-id".format(service_invariant_uuid, parameters["service-model-name"], service_uuid, cloud_region, \ |
| 356 | service_instance_id, tenant-id, parameters["requestor-id"], vf_model_uuid, parameters["generic-vnf-name"], parameters["vf-name"], \ |
| 357 | vf_model_version, vf_model_invariant_uuid, service_version, vf_model_customization_name, parameters["service_name"], \ |
| 358 | parameters["Platform-Demonstration"], parameters["lob-name"], parameters["so_username"], parameters["so_password"], \ |
| 359 | parameters["so_url"]))).read() |
| 360 | |
| 361 | vnf_instance_id = (get_out_helper_2(vnf_create_out))[1] |
| 362 | |
| 363 | vf_model_dict["vnf_instance_id"] = vnf_instance_id |
| 364 | |
| 365 | return vf_model_dict |
| 366 | |
| 367 | def sdnc_preload(parameters, db_dict, service_dict): |
| 368 | |
| 369 | |
| 370 | preload_file = parameters["sdnc_preload_file"] |
| 371 | |
| 372 | #Replace values gotten from the service instance, vnf, vf in preload file, other values such as ip addresses |
| 373 | #should be directly changed in the preload file |
| 374 | #Items to search and replace in file |
| 375 | replace_dict = { |
| 376 | '"generic-vnf-name"' : ' "generic-vnf-name": "{}",\n'.format(parameters["generic-vnf-name"]), |
| 377 | '"generic-vnf-type"' : ' "generic-vnf-type": "{}",\n'.format(db_dict["vf_model_customization_name"]), |
| 378 | '"service-type"' : ' "service-type": "{}",\n'.format(service_dict["service_instance_id"]), |
| 379 | '"vnf-name"' : ' "vnf-name": "{}",\n'.format(parameters["vf-module-name"]), |
| 380 | '"vnf-type"' : ' "vnf-type": "{}"\n'.format(db_dict["vf_module_model_name"]), |
| 381 | '"vf_module_id"' : ' "vnf-parameter-value": "{}"\n'.format(db_dict["vf_module_model_name"]) |
| 382 | } |
| 383 | |
| 384 | with open(preload_file, 'r') as file: |
| 385 | preload_data = file.readlines() |
| 386 | |
| 387 | for key, val in replace_dict.iteritems(): |
| 388 | for line in range(len(preload_data)): |
| 389 | |
| 390 | if key in preload_data[line] and key == '"vf_module_id"': |
| 391 | preload_data[line + 1] = val |
| 392 | break |
| 393 | |
| 394 | elif key in preload_data[line] and key != '"vf_module_id"': |
| 395 | preload_data[line] = val |
| 396 | break |
| 397 | with open(preload_file, 'w') as file: |
| 398 | file.writelines(preload_data) |
| 399 | |
| 400 | os.system("oclip vf-preload -u {} -p {} -y {} -m {}".format(parameters["sdnc_user"], parameters["sdnc_password"], \ |
| 401 | preload_file, parameters["sdnc_url"])) |
| 402 | |
| 403 | |
| 404 | |
| 405 | def create_vf_module(parameters, service_dict, vnf_dict, db_dict): |
| 406 | |
| 407 | #vf module parameters |
| 408 | vf_module_model_name = db_dict["vf_module_model_name"] |
| 409 | vf_module_model_invariant_id = db_dict["vf_module_model_invariant_id"] |
| 410 | vf_module_model_version = db_dict["vf_module_model_version"] |
| 411 | vf_module_model_version_id = db_dict["vf_module_model_id"] |
| 412 | vf_module_customization_id = db_dict["vf_module_customization_id"] |
| 413 | |
| 414 | #service parameters |
| 415 | service_invariant_uuid = service_dict["service_invariant_uuid"] |
| 416 | service_uuid = service_dict["service_uuid"] |
| 417 | service_instance_id = service_dict["service_instance_id"] |
| 418 | service_version = service_dict["service_version"] |
| 419 | |
| 420 | #vnf parameters |
| 421 | vnf_instance_id = vnf_dict["vnf_instance_id"] |
| 422 | vf_model_id = vnf_dict["vf_id"] |
| 423 | vf_model_invariant_uuid = vnf_dict["vf_model_invariant_uuid"] |
| 424 | vf_model_version = vnf_dict["vf_model_version"] |
| 425 | vf_model_customization_name = db_dict["vf_model_customization_name"] |
| 426 | vf_model_customization_id = db_dict["vf_model_customization_id"] |
| 427 | |
| 428 | #Put in any cloud region, OOF will select the right one |
| 429 | cloud_region = next(iter(parameters["cloud_region_data"])) |
| 430 | tenant_id = ((parameters["cloud_region_data"])[cloud_region])["tenant-id"] |
| 431 | |
| 432 | |
| 433 | os.system("oclip vf-module-create -w {} -mn '{}' -x {} -l {} -sv {} -vc {} -vm {} -mv {} -i {} -vf {} -vi {} -r {} \ |
| 434 | -mc {} -api {} -mi {} -vid {} -y {} -R {} -si {} -up {} -sd {} -z {} -vn {} -vv {} -u {} -p {} -m {}".format(tenant-id, \ |
| 435 | vf_module_customization_name, service_instance_id, cloud_region, service_version, vf_module_customization_id, vf_module_model_version,\ |
| 436 | vf_model_version, parameters["vf-module-name"], parameters["vf-name"], vf_module_model_invariant_id, parameters["supress-rollback"], \ |
| 437 | vf_model_customization_id, parameters["test-api"], vf_model_invariant_uuid, vf_model_id, vnf_instance_id, parameters["requestor-id"], \ |
| 438 | service_uuid, parameters["use-preload"], service_invariant_uuid, parameters["service-model-name"], vf_module_model_name, \ |
| 439 | vf_module_model_version_id, parameters["so_username"], parameters["so_password"], parameters["so_url"])) |
| 440 | |
| 441 | |
| 442 | |
| 443 | |
| 444 | |
| 445 | |
| 446 | #Run Functions |
| 447 | |
| 448 | config_file_path = "/root/automation_stuff/hpa_automation_config.json" |
| 449 | config_file = open(config_file_path) |
| 450 | parameters = get_parameters(config_file) |
| 451 | set_open_cli_env(parameters) |
| 452 | create_complex(parameters) |
| 453 | register_all_clouds(parameters) |
| 454 | create_service_type(parameters) |
| 455 | create_customer(parameters) |
| 456 | add_customer_subscription(parameters) |
| 457 | output = create_vlm(parameters) |
| 458 | vsp_id = create_vsp(parameters, output) |
| 459 | vf_model_dict = create_vf_model(parameters, vsp_id) |
| 460 | vf_id = vf_model_dict["vf_id"] |
| 461 | vf_unique_id = vf_model_dict["vf_unique_id"] |
| 462 | sevice_model_list = create_service_model(parameters, vf_unique_id) |
| 463 | |
| 464 | add_policies(parameters) |
| 465 | service_dict = create_service_instance(parameters, service_model_list) |
| 466 | db_dict = query_db(parameters, vf_id) |
| 467 | vnf_dict = create_vnf(parameters, service_dict, db_dict, vf_model_dict) |
| 468 | sdnc_preload(parameters, db_dict, service_dict) |
| 469 | create_vf_module(parameters, service_dict, vnf_dict, db_dict) |