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