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 |
Ruoyu Ying | f8229d0 | 2019-09-29 19:55:47 +0800 | [diff] [blame] | 36 | cloud_create_string = 'oclip cloud-create -e {} -b {} -x {} -y {} -j {} -w {} -l {} -url {} -n {} -q {} \ |
| 37 | -r {} -Q {} -i {} -g {} -z {} -k {} -c {} -m {} -u {} -p {}'.format( values.get("esr-system-info-id"), \ |
| 38 | values.get("user-name"), parameters["cloud-owner"], cloud_region, values.get("password"), \ |
| 39 | values.get("cloud-region-version"), values.get("default-tenant"), values.get("service-url"), \ |
| 40 | parameters["complex_name"], values.get("cloud-type"), parameters["owner-defined-type"], values.get("system-type"),\ |
| 41 | values.get("identity-url"), parameters["cloud-zone"], values.get("ssl-insecure"), values.get("system-status"), \ |
| 42 | values.get("cloud-domain"), parameters["aai_url"], parameters["aai_username"], parameters["aai_password"]) |
root@rancher | 6c68bee | 2019-05-01 16:39:12 -0700 | [diff] [blame] | 43 | |
| 44 | |
| 45 | os.system(cloud_create_string) |
| 46 | |
| 47 | #Associate Cloud with complex |
| 48 | complex_associate_string = "oclip complex-associate -x {} -y {} -z {} -m {} -u {} -p {}".format(parameters["complex_name"], \ |
| 49 | cloud_region, parameters["cloud-owner"], parameters["aai_url"], parameters["aai_username"], parameters["aai_password"]) |
| 50 | os.system(complex_associate_string) |
| 51 | |
| 52 | #Register Cloud with Multicloud |
| 53 | multicloud_register_string = "oclip multicloud-register-cloud -y {} -x {} -m {}".format(parameters["cloud-owner"], \ |
| 54 | cloud_region, parameters["multicloud_url"]) |
| 55 | os.system(multicloud_register_string) |
Itohan | 1f3c8d6 | 2019-05-24 23:52:26 +0000 | [diff] [blame] | 56 | time.sleep(2) |
root@rancher | 6c68bee | 2019-05-01 16:39:12 -0700 | [diff] [blame] | 57 | |
| 58 | def register_all_clouds(parameters): |
| 59 | cloud_dictionary = parameters["cloud_region_data"] |
| 60 | for cloud_region, cloud_region_values in cloud_dictionary.iteritems(): |
| 61 | register_cloud_helper(cloud_region, cloud_region_values, parameters) |
| 62 | |
| 63 | def create_service_type(parameters): |
| 64 | create_string = "oclip service-type-create -x {} -m {} -u {} -p {}".format( parameters["service_name"], \ |
| 65 | parameters["aai_url"], parameters["aai_username"], parameters["aai_password"]) |
| 66 | os.system(create_string) |
| 67 | |
| 68 | def create_customer(parameters): |
| 69 | create_string = "oclip customer-create -x {} -y {} -m {} -u {} -p {}".format( parameters["customer_name"], \ |
| 70 | parameters["subscriber_name"], parameters["aai_url"], parameters["aai_username"], parameters["aai_password"]) |
| 71 | os.system(create_string) |
| 72 | |
| 73 | def add_customer_subscription(parameters): |
| 74 | subscription_check = 0 |
| 75 | for cloud_region, cloud_region_values in (parameters["cloud_region_data"]).iteritems(): |
| 76 | if subscription_check == 0 : |
| 77 | subscription_string = "oclip subscription-create -x {} -c {} -z {} -e {} -y {} -r {} -m {} -u {} -p {}".format(\ |
| 78 | parameters["customer_name"], cloud_region_values.get("tenant-id"), parameters["cloud-owner"], parameters["service_name"],\ |
| 79 | cloud_region_values.get("default-tenant"), cloud_region, parameters["aai_url"], parameters["aai_username"], parameters["aai_password"] ) |
| 80 | else: |
| 81 | subscription_string = "oclip subscription-cloud-add -x {} -c {} -z {} -e {} -y {} -r {} -m {} -u {} -p {}".format(\ |
| 82 | parameters["customer_name"], cloud_region_values.get("tenant-id"), parameters["cloud-owner"], parameters["service_name"],\ |
| 83 | cloud_region_values.get("default-tenant"), cloud_region, parameters["aai_url"], parameters["aai_username"], parameters["aai_password"] ) |
| 84 | os.system(subscription_string) |
| 85 | subscription_check+=1 |
| 86 | |
| 87 | def get_out_helper(in_string): |
| 88 | out_list = (((in_string.replace('-','')).replace('|', '')).replace('+', '')).split() |
| 89 | return out_list |
| 90 | |
| 91 | def get_out_helper_2(in_string): |
| 92 | out_list = ((in_string.replace('|', '')).replace('+', '')).split() |
| 93 | return out_list |
| 94 | |
| 95 | #ONBOARDING SECTION |
| 96 | def create_vlm(parameters): |
| 97 | vlm_create_string = "oclip vlm-create -x {} -u {} -p {} -m {}".format(parameters["vendor-name"], \ |
| 98 | parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_onboarding_url"]) |
| 99 | command_out = (os.popen(vlm_create_string)).read() |
| 100 | out_list = get_out_helper(command_out) |
| 101 | vlm_id = out_list[3] |
| 102 | vlm_version = out_list[5] |
| 103 | |
Ruoyu Ying | f8229d0 | 2019-09-29 19:55:47 +0800 | [diff] [blame] | 104 | |
| 105 | entitlement_string = "oclip vlm-entitlement-pool-create -x {} -y {} -e {} -k {} -g {} -l {} -u {} -p {} -m {}".format( \ |
| 106 | parameters["entitlement-pool-name"], vlm_id, vlm_version, parameters["vendor-name"], parameters["expiry-date"], \ |
| 107 | parameters["start-date"], parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_onboarding_url"]) |
root@rancher | 6c68bee | 2019-05-01 16:39:12 -0700 | [diff] [blame] | 108 | command_out = (os.popen(entitlement_string)).read() |
| 109 | entitlement_id = (get_out_helper(command_out))[3] |
| 110 | |
root@rancher | 6c68bee | 2019-05-01 16:39:12 -0700 | [diff] [blame] | 111 | key_group_string = "oclip vlm-key-group-create -c {} -e {} -x {} -y {} -u {} -p {} -m {}".format(vlm_id, vlm_version, \ |
| 112 | parameters["key-group-name"], parameters["key-group-type"], parameters["sdc_creator"], parameters["sdc_password"], \ |
| 113 | parameters["sdc_onboarding_url"]) |
| 114 | command_out = (os.popen(key_group_string)).read() |
| 115 | key_group_id = (get_out_helper(command_out))[3] |
| 116 | |
Ruoyu Ying | f8229d0 | 2019-09-29 19:55:47 +0800 | [diff] [blame] | 117 | feature_group_string = "oclip vlm-feature-group-create -x {} -y {} -e {} -g {} -b {} -c {} -u {} -p {} -m {}".format( |
| 118 | parameters["feature-grp-name"], vlm_id, vlm_version, key_group_id, entitlement_id, \ |
root@rancher | 6c68bee | 2019-05-01 16:39:12 -0700 | [diff] [blame] | 119 | parameters["part-no"], parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_onboarding_url"]) |
| 120 | command_out = (os.popen(feature_group_string)).read() |
| 121 | feature_group_id = (get_out_helper(command_out))[3] |
| 122 | |
Ruoyu Ying | f8229d0 | 2019-09-29 19:55:47 +0800 | [diff] [blame] | 123 | agreement_string = "oclip vlm-aggreement-create -x {} -y {} -e {} -g {} -u {} -p {} -m {}".format(parameters["agreement-name"], \ |
| 124 | vlm_id, vlm_version, feature_group_id, parameters["sdc_creator"], parameters["sdc_password"], \ |
root@rancher | 6c68bee | 2019-05-01 16:39:12 -0700 | [diff] [blame] | 125 | parameters["sdc_onboarding_url"]) |
| 126 | command_out = (os.popen(agreement_string)).read() |
| 127 | agreement_id = (get_out_helper(command_out))[3] |
| 128 | |
Ruoyu Ying | f8229d0 | 2019-09-29 19:55:47 +0800 | [diff] [blame] | 129 | |
root@rancher | 6c68bee | 2019-05-01 16:39:12 -0700 | [diff] [blame] | 130 | submit_string = "oclip vlm-submit -x {} -y {} -u {} -p {} -m {}".format(vlm_id, vlm_version, parameters["sdc_creator"], \ |
| 131 | parameters["sdc_password"], parameters["sdc_onboarding_url"]) |
| 132 | os.system(submit_string) |
| 133 | |
| 134 | output = [feature_group_id, agreement_id, vlm_version, vlm_id ] |
Ruoyu Ying | f8229d0 | 2019-09-29 19:55:47 +0800 | [diff] [blame] | 135 | |
root@rancher | 6c68bee | 2019-05-01 16:39:12 -0700 | [diff] [blame] | 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] |
Ruoyu Ying | f8229d0 | 2019-09-29 19:55:47 +0800 | [diff] [blame] | 145 | vsp_version = out_list[7] |
root@rancher | 6c68bee | 2019-05-01 16:39:12 -0700 | [diff] [blame] | 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 | |
Ruoyu Ying | f8229d0 | 2019-09-29 19:55:47 +0800 | [diff] [blame] | 159 | |
root@rancher | 6c68bee | 2019-05-01 16:39:12 -0700 | [diff] [blame] | 160 | return vsp_id |
| 161 | |
| 162 | |
| 163 | def create_vf_model(parameters, vsp_id): |
| 164 | create_string = "oclip vf-model-create -y {} -g {} -x {} -z {} -b {} -u {} -p {} -m {}".format(parameters["vf-description"], \ |
| 165 | parameters["vsp-version"], parameters["vf-name"], parameters["vendor-name"], vsp_id, parameters["sdc_creator"], \ |
| 166 | parameters["sdc_password"], parameters["sdc_catalog_url"]) |
| 167 | os.system(create_string) |
| 168 | |
| 169 | output = (os.popen("oclip vf-model-list -m {} -u {} -p {} | grep {}".format(parameters["sdc_catalog_url"], \ |
| 170 | parameters["sdc_creator"], parameters["sdc_password"], parameters["vf-name"]))).read() |
| 171 | output = (get_out_helper_2(output)) |
| 172 | |
Itohan | 454b279 | 2019-05-06 23:18:34 +0000 | [diff] [blame] | 173 | vf_unique_id = output[1] |
| 174 | |
| 175 | os.system("oclip vf-model-certify -b {} -r {} -u {} -p {} -m {}".format(vf_unique_id, parameters["vf-remarks"], \ |
| 176 | parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"])) |
| 177 | |
| 178 | #Check for new parameters after certification |
| 179 | output = (os.popen("oclip vf-model-list -m {} -u {} -p {} | grep {}".format(parameters["sdc_catalog_url"], \ |
| 180 | parameters["sdc_creator"], parameters["sdc_password"], parameters["vf-name"]))).read() |
| 181 | output = (get_out_helper_2(output)) |
| 182 | |
root@rancher | 6c68bee | 2019-05-01 16:39:12 -0700 | [diff] [blame] | 183 | vf_id = output[0] |
| 184 | vf_unique_id = output[1] |
| 185 | vf_model_invariant_uuid = output[2] |
| 186 | vf_model_version = output[4] |
| 187 | |
root@rancher | 6c68bee | 2019-05-01 16:39:12 -0700 | [diff] [blame] | 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): |
Ruoyu Ying | f8229d0 | 2019-09-29 19:55:47 +0800 | [diff] [blame] | 198 | create_string = "oclip service-model-create -z {} -y {} -e {} -x {} -c {} -b {} -u {} -p {} -m {} |grep -i ID".format(parameters["project-code"], \ |
Itohan | 8ec5f1f | 2019-05-04 00:21:47 +0000 | [diff] [blame] | 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"]) |
root@rancher | 6c68bee | 2019-05-01 16:39:12 -0700 | [diff] [blame] | 201 | |
| 202 | service_model_id = (get_out_helper_2((os.popen(create_string)).read()))[1] |
| 203 | |
Itohan | 8ec5f1f | 2019-05-04 00:21:47 +0000 | [diff] [blame] | 204 | 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@rancher | 6c68bee | 2019-05-01 16:39:12 -0700 | [diff] [blame] | 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 | |
Itohan | 8ec5f1f | 2019-05-04 00:21:47 +0000 | [diff] [blame] | 216 | #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@rancher | 6c68bee | 2019-05-01 16:39:12 -0700 | [diff] [blame] | 218 | parameters["sdc_password"], parameters["sdc_catalog_url"], parameters["service-model-name"]))).read() |
Itohan | 8ec5f1f | 2019-05-04 00:21:47 +0000 | [diff] [blame] | 219 | service_model_values = get_out_helper_2(service_model_values) |
| 220 | service_model_uniqueId = (service_model_values)[1] |
root@rancher | 6c68bee | 2019-05-01 16:39:12 -0700 | [diff] [blame] | 221 | |
Itohan | 8ec5f1f | 2019-05-04 00:21:47 +0000 | [diff] [blame] | 222 | 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] | 223 | parameters["sdc_governor"], parameters["sdc_password"], parameters["sdc_catalog_url"])) |
| 224 | |
Itohan | 8ec5f1f | 2019-05-04 00:21:47 +0000 | [diff] [blame] | 225 | 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] | 226 | parameters["sdc_password"], parameters["sdc_catalog_url"])) |
| 227 | |
Itohan | 8ec5f1f | 2019-05-04 00:21:47 +0000 | [diff] [blame] | 228 | return service_model_values |
root@rancher | 6c68bee | 2019-05-01 16:39:12 -0700 | [diff] [blame] | 229 | |
| 230 | |
| 231 | #VNF Deployment Section |
Itohan | e2f489f | 2019-06-03 23:53:15 +0000 | [diff] [blame] | 232 | def upload_policy_models(parameters): |
Itohan Ukponmwan | 63929cf | 2019-09-13 00:08:39 +0000 | [diff] [blame] | 233 | os.system("python insert_policy_models_heat.py {} {} {}".format(parameters["policy_db_ip"], \ |
Itohan | e2f489f | 2019-06-03 23:53:15 +0000 | [diff] [blame] | 234 | parameters["policy_db_user"], parameters["policy_db_password"])) |
root@rancher | 6c68bee | 2019-05-01 16:39:12 -0700 | [diff] [blame] | 235 | |
root@rancher | 6c68bee | 2019-05-01 16:39:12 -0700 | [diff] [blame] | 236 | def add_policies(parameters): |
| 237 | resource_string = (os.popen("oclip get-resource-module-name -u {} -p {} -m {} |grep {}".format(\ |
| 238 | parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"], \ |
Itohan | 1f3c8d6 | 2019-05-24 23:52:26 +0000 | [diff] [blame] | 239 | parameters["vf-name"] ))).read() |
root@rancher | 6c68bee | 2019-05-01 16:39:12 -0700 | [diff] [blame] | 240 | resource_module_name = (get_out_helper_2(resource_string))[1] |
| 241 | |
Itohan | 454b279 | 2019-05-06 23:18:34 +0000 | [diff] [blame] | 242 | #Put in the right resource module name in all policies located in parameters["policy_directory"] |
| 243 | os.system("find {}/ -type f -exec sed -i 's/{}/{}/g' {{}} \;".format( |
| 244 | parameters["policy_directory"], parameters["temp_resource_module_name"], resource_module_name)) |
| 245 | |
root@rancher | 6c68bee | 2019-05-01 16:39:12 -0700 | [diff] [blame] | 246 | #Loop through policy, put in resource_model_name and create policies |
| 247 | for policy in os.listdir(parameters["policy_directory"]): |
Itohan | ecd1ebd | 2019-06-05 20:18:48 +0000 | [diff] [blame] | 248 | |
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 | |
Itohan | ecd1ebd | 2019-06-05 20:18:48 +0000 | [diff] [blame] | 251 | #Get policy name from policy file |
| 252 | policy_contents = open(policy_file, 'r').read() |
| 253 | start_string = '"policyName\\":\\"' |
| 254 | end_string = '\\",\\"ver' |
| 255 | policy_name = policy_contents[policy_contents.find(start_string)+len(start_string):policy_contents.rfind(end_string)] |
| 256 | |
| 257 | |
Itohan | 1f3c8d6 | 2019-05-24 23:52:26 +0000 | [diff] [blame] | 258 | #Create policy |
Itohan | 8ec5f1f | 2019-05-04 00:21:47 +0000 | [diff] [blame] | 259 | os.system("oclip policy-create-outdated -m {} -u {} -p {} -x {} -S {} -T {} -o {} -b $(cat {})".format(parameters["policy_url"],\ |
| 260 | parameters["policy_username"], parameters["policy_password"], policy_name, parameters["policy_scope"], \ |
| 261 | parameters["policy_config_type"], parameters["policy_onapName"], policy_file)) |
root@rancher | 6c68bee | 2019-05-01 16:39:12 -0700 | [diff] [blame] | 262 | |
| 263 | #Push policy |
| 264 | os.system("oclip policy-push-outdated -m {} -u {} -p {} -x {} -b {} -c {}".format(parameters["policy_url"], \ |
| 265 | parameters["policy_username"], parameters["policy_password"], policy_name, parameters["policy_config_type"],\ |
| 266 | parameters["policy_pdp_group"])) |
| 267 | |
| 268 | |
| 269 | def create_service_instance(parameters, sevice_model_list): |
| 270 | #Get Required parameters |
| 271 | service_uuid = service_model_list[0] |
Itohan | 8ec5f1f | 2019-05-04 00:21:47 +0000 | [diff] [blame] | 272 | service_invariant_uuid = service_model_list[2] |
| 273 | service_version = service_model_list[4] |
root@rancher | 6c68bee | 2019-05-01 16:39:12 -0700 | [diff] [blame] | 274 | |
| 275 | owning_entity_values = (os.popen("oclip owning-entity-list -u {} -p {} -m {} |grep {}".format(parameters["aai_username"], \ |
| 276 | parameters["aai_password"], parameters["aai_url"], parameters["owning-entity-name"]))).read() |
| 277 | owning_entity_id = (get_out_helper_2(owning_entity_values))[1] |
| 278 | |
| 279 | #Create service instance |
| 280 | instance_output = (os.popen("oclip service-create -w {} -la {} -lo {} -o {} -A {} -i {} -y {} -x {} -q {} -O {} -k {}-{} -P {} \ |
| 281 | -H {} -n {} -e {} -j {} -S {} -g {} -z {} -c {} -u {} -p {} -m {} |grep service-id".format(parameters["service_name"], \ |
| 282 | parameters["customer-latitude"], parameters["customer-longitude"], parameters["orchestrator"], parameters["a-la-carte"], \ |
| 283 | parameters["service-model-name"], parameters["company-name"], parameters["projectName"], parameters["requestor-id"], \ |
Itohan | 8ec5f1f | 2019-05-04 00:21:47 +0000 | [diff] [blame] | 284 | 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] | 285 | service_uuid, service_invariant_uuid, service_version, parameters["subscriber_name"], service_uuid, owning_entity_id, \ |
| 286 | parameters["customer_name"], parameters["so_username"], parameters["so_password"], parameters["so_url"] ))).read() |
| 287 | |
| 288 | service_instance_id = (get_out_helper_2(instance_output))[1] |
| 289 | output_dict = {} |
| 290 | |
| 291 | output_dict["service_instance_id"] = service_instance_id |
| 292 | output_dict["service_uuid"] = service_uuid |
| 293 | output_dict["service_invariant_uuid"] = service_invariant_uuid |
| 294 | output_dict["service_version"] = service_version |
| 295 | |
| 296 | |
| 297 | return output_dict |
| 298 | |
Itohan | 8ec5f1f | 2019-05-04 00:21:47 +0000 | [diff] [blame] | 299 | def query_db(parameters, service_model_uuid, vf_model_uuid): |
root@rancher | 6c68bee | 2019-05-01 16:39:12 -0700 | [diff] [blame] | 300 | |
| 301 | out_dictionary = {} |
| 302 | #Query DB Certain parameters required |
Ruoyu Ying | f8229d0 | 2019-09-29 19:55:47 +0800 | [diff] [blame] | 303 | mariadb_connection = mariadb.connect(user='{}'.format(parameters["so_mariadb_user"]), host='{}'.format(parameters["mariadb_host"]), |
root@rancher | 6c68bee | 2019-05-01 16:39:12 -0700 | [diff] [blame] | 304 | password='{}'.format(parameters["so_mariadb_password"]), database='{}'.format(parameters["so_mariadb_db"])) |
| 305 | values = mariadb_connection.cursor() |
| 306 | |
| 307 | #Get vf model customization values |
| 308 | 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] | 309 | SERVICE_MODEL_UUID = "{}"'.format(service_model_uuid)) |
root@rancher | 6c68bee | 2019-05-01 16:39:12 -0700 | [diff] [blame] | 310 | vf_customization_values = values.fetchall() |
| 311 | |
| 312 | out_dictionary["vf_model_customization_name"] = vf_customization_values[0][0] |
| 313 | out_dictionary["vf_model_customization_id"] = vf_customization_values[0][1] |
| 314 | |
| 315 | values.execute('SELECT MODEL_INVARIANT_UUID, MODEL_UUID, MODEL_NAME, MODEL_VERSION FROM vf_module WHERE \ |
| 316 | VNF_RESOURCE_MODEL_UUID = "{}"'.format(vf_model_uuid)) |
| 317 | |
| 318 | vf_module_values = values.fetchall() |
| 319 | out_dictionary["vf_module_model_invariant_id"] = vf_module_values[0][0] |
| 320 | out_dictionary["vf_module_model_id"] = vf_module_values[0][1] |
| 321 | out_dictionary["vf_module_model_name"] = vf_module_values[0][2] |
| 322 | out_dictionary["vf_module_model_version"] = vf_module_values[0][3] |
| 323 | |
| 324 | values.execute('SELECT MODEL_CUSTOMIZATION_UUID FROM vf_module_customization WHERE \ |
Itohan | 8ec5f1f | 2019-05-04 00:21:47 +0000 | [diff] [blame] | 325 | VF_MODULE_MODEL_UUID = "{}"'.format(out_dictionary["vf_module_model_id"])) |
root@rancher | 6c68bee | 2019-05-01 16:39:12 -0700 | [diff] [blame] | 326 | vf_module_customization = values.fetchall() |
| 327 | |
| 328 | out_dictionary["vf_module_customization_id"] = vf_module_customization[0][0] |
| 329 | values.close() |
| 330 | mariadb_connection.close() |
| 331 | |
| 332 | return out_dictionary |
| 333 | |
| 334 | |
| 335 | |
| 336 | def create_vnf(parameters, service_dict, db_dict, vf_model_dict): |
| 337 | |
| 338 | vf_model_uuid = vf_model_dict["vf_id"] |
| 339 | vf_model_invariant_uuid = vf_model_dict["vf_model_invariant_uuid"] |
| 340 | vf_model_version = vf_model_dict["vf_model_version"] |
| 341 | |
root@rancher | 6c68bee | 2019-05-01 16:39:12 -0700 | [diff] [blame] | 342 | vf_model_customization_name = db_dict["vf_model_customization_name"] |
| 343 | vf_model_customization_id = db_dict["vf_model_customization_id"] |
| 344 | |
| 345 | #Put in any cloud region, OOF will select the right one |
| 346 | cloud_region = next(iter(parameters["cloud_region_data"])) |
| 347 | tenant_id = ((parameters["cloud_region_data"])[cloud_region])["tenant-id"] |
| 348 | |
| 349 | service_invariant_uuid = service_dict["service_invariant_uuid"] |
| 350 | service_uuid = service_dict["service_uuid"] |
| 351 | service_instance_id = service_dict["service_instance_id"] |
| 352 | service_version = service_dict["service_version"] |
| 353 | |
| 354 | #Create vnf |
| 355 | 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] | 356 | -w {} -pn {} -lob {} -u {} -p {} -m {} |grep vf-id".format(service_invariant_uuid, parameters["service-model-name"], \ |
| 357 | service_uuid, cloud_region, service_instance_id, tenant_id, parameters["requestor-id"], vf_model_uuid, \ |
| 358 | parameters["generic-vnf-name"], parameters["vf-name"], vf_model_version, vf_model_invariant_uuid, service_version, \ |
| 359 | vf_model_customization_id, vf_model_customization_name, parameters["service_name"], parameters["platform-name"], \ |
| 360 | 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] | 361 | |
| 362 | vnf_instance_id = (get_out_helper_2(vnf_create_out))[1] |
| 363 | |
| 364 | vf_model_dict["vnf_instance_id"] = vnf_instance_id |
| 365 | |
| 366 | return vf_model_dict |
| 367 | |
| 368 | def sdnc_preload(parameters, db_dict, service_dict): |
| 369 | |
| 370 | |
| 371 | preload_file = parameters["sdnc_preload_file"] |
| 372 | |
| 373 | #Replace values gotten from the service instance, vnf, vf in preload file, other values such as ip addresses |
| 374 | #should be directly changed in the preload file |
| 375 | #Items to search and replace in file |
| 376 | replace_dict = { |
| 377 | '"generic-vnf-name"' : ' "generic-vnf-name": "{}",\n'.format(parameters["generic-vnf-name"]), |
| 378 | '"generic-vnf-type"' : ' "generic-vnf-type": "{}",\n'.format(db_dict["vf_model_customization_name"]), |
| 379 | '"service-type"' : ' "service-type": "{}",\n'.format(service_dict["service_instance_id"]), |
| 380 | '"vnf-name"' : ' "vnf-name": "{}",\n'.format(parameters["vf-module-name"]), |
| 381 | '"vnf-type"' : ' "vnf-type": "{}"\n'.format(db_dict["vf_module_model_name"]), |
| 382 | '"vf_module_id"' : ' "vnf-parameter-value": "{}"\n'.format(db_dict["vf_module_model_name"]) |
| 383 | } |
| 384 | |
| 385 | with open(preload_file, 'r') as file: |
| 386 | preload_data = file.readlines() |
| 387 | |
| 388 | for key, val in replace_dict.iteritems(): |
| 389 | for line in range(len(preload_data)): |
| 390 | |
| 391 | if key in preload_data[line] and key == '"vf_module_id"': |
| 392 | preload_data[line + 1] = val |
| 393 | break |
| 394 | |
| 395 | elif key in preload_data[line] and key != '"vf_module_id"': |
| 396 | preload_data[line] = val |
| 397 | break |
| 398 | with open(preload_file, 'w') as file: |
| 399 | file.writelines(preload_data) |
| 400 | |
| 401 | os.system("oclip vf-preload -u {} -p {} -y {} -m {}".format(parameters["sdnc_user"], parameters["sdnc_password"], \ |
| 402 | preload_file, parameters["sdnc_url"])) |
| 403 | |
| 404 | |
| 405 | |
| 406 | def create_vf_module(parameters, service_dict, vnf_dict, db_dict): |
| 407 | |
| 408 | #vf module parameters |
| 409 | vf_module_model_name = db_dict["vf_module_model_name"] |
| 410 | vf_module_model_invariant_id = db_dict["vf_module_model_invariant_id"] |
| 411 | vf_module_model_version = db_dict["vf_module_model_version"] |
| 412 | vf_module_model_version_id = db_dict["vf_module_model_id"] |
| 413 | vf_module_customization_id = db_dict["vf_module_customization_id"] |
| 414 | |
| 415 | #service parameters |
| 416 | service_invariant_uuid = service_dict["service_invariant_uuid"] |
| 417 | service_uuid = service_dict["service_uuid"] |
| 418 | service_instance_id = service_dict["service_instance_id"] |
| 419 | service_version = service_dict["service_version"] |
| 420 | |
| 421 | #vnf parameters |
| 422 | vnf_instance_id = vnf_dict["vnf_instance_id"] |
| 423 | vf_model_id = vnf_dict["vf_id"] |
| 424 | vf_model_invariant_uuid = vnf_dict["vf_model_invariant_uuid"] |
| 425 | vf_model_version = vnf_dict["vf_model_version"] |
| 426 | vf_model_customization_name = db_dict["vf_model_customization_name"] |
| 427 | vf_model_customization_id = db_dict["vf_model_customization_id"] |
| 428 | |
| 429 | #Put in any cloud region, OOF will select the right one |
| 430 | cloud_region = next(iter(parameters["cloud_region_data"])) |
| 431 | tenant_id = ((parameters["cloud_region_data"])[cloud_region])["tenant-id"] |
| 432 | |
| 433 | |
| 434 | 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] | 435 | -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] | 436 | 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] | 437 | vf_model_version, parameters["vf-module-name"], parameters["vf-name"], vf_module_model_invariant_id, parameters["supress-rollback"], \ |
| 438 | vf_model_customization_id, parameters["test-api"], vf_model_invariant_uuid, vf_model_id, vnf_instance_id, parameters["requestor-id"], \ |
| 439 | 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] | 440 | 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] | 441 | |
| 442 | |
| 443 | |
| 444 | |
| 445 | |
| 446 | |
| 447 | #Run Functions |
| 448 | |
Ruoyu Ying | f8229d0 | 2019-09-29 19:55:47 +0800 | [diff] [blame] | 449 | config_file_path = "/root/integration/test/hpa_automation/heat/hpa_automation_config.json" |
root@rancher | 6c68bee | 2019-05-01 16:39:12 -0700 | [diff] [blame] | 450 | config_file = open(config_file_path) |
Itohan | e2f489f | 2019-06-03 23:53:15 +0000 | [diff] [blame] | 451 | |
| 452 | #Get required parameters from hpa config file |
root@rancher | 6c68bee | 2019-05-01 16:39:12 -0700 | [diff] [blame] | 453 | parameters = get_parameters(config_file) |
Itohan | e2f489f | 2019-06-03 23:53:15 +0000 | [diff] [blame] | 454 | |
| 455 | #Set CLI env variables |
root@rancher | 6c68bee | 2019-05-01 16:39:12 -0700 | [diff] [blame] | 456 | set_open_cli_env(parameters) |
| 457 | create_complex(parameters) |
| 458 | register_all_clouds(parameters) |
Itohan | ecd1ebd | 2019-06-05 20:18:48 +0000 | [diff] [blame] | 459 | |
root@rancher | 6c68bee | 2019-05-01 16:39:12 -0700 | [diff] [blame] | 460 | create_service_type(parameters) |
Itohan | ecd1ebd | 2019-06-05 20:18:48 +0000 | [diff] [blame] | 461 | |
root@rancher | 6c68bee | 2019-05-01 16:39:12 -0700 | [diff] [blame] | 462 | create_customer(parameters) |
| 463 | add_customer_subscription(parameters) |
Itohan | e2f489f | 2019-06-03 23:53:15 +0000 | [diff] [blame] | 464 | |
| 465 | vlm_output = create_vlm(parameters) |
| 466 | print "vlm parameters={}".format(vlm_output) |
| 467 | |
| 468 | vsp_id = create_vsp(parameters, vlm_output) |
| 469 | print "vsp id={}".format(vsp_id) |
| 470 | |
root@rancher | 6c68bee | 2019-05-01 16:39:12 -0700 | [diff] [blame] | 471 | vf_model_dict = create_vf_model(parameters, vsp_id) |
Itohan | e2f489f | 2019-06-03 23:53:15 +0000 | [diff] [blame] | 472 | print "vf model parameters={}".format(vf_model_dict) |
root@rancher | 6c68bee | 2019-05-01 16:39:12 -0700 | [diff] [blame] | 473 | vf_id = vf_model_dict["vf_id"] |
| 474 | vf_unique_id = vf_model_dict["vf_unique_id"] |
Itohan | e2f489f | 2019-06-03 23:53:15 +0000 | [diff] [blame] | 475 | |
Itohan | 8ec5f1f | 2019-05-04 00:21:47 +0000 | [diff] [blame] | 476 | service_model_list = create_service_model(parameters, vf_unique_id) |
Itohan | e2f489f | 2019-06-03 23:53:15 +0000 | [diff] [blame] | 477 | print "service model parameters={}".format(service_model_list) |
| 478 | |
| 479 | upload_policy_models(parameters) |
Itohan | 1f3c8d6 | 2019-05-24 23:52:26 +0000 | [diff] [blame] | 480 | add_policies(parameters) |
Itohan | e2f489f | 2019-06-03 23:53:15 +0000 | [diff] [blame] | 481 | |
Itohan | ecd1ebd | 2019-06-05 20:18:48 +0000 | [diff] [blame] | 482 | #Create Service Instance |
root@rancher | 6c68bee | 2019-05-01 16:39:12 -0700 | [diff] [blame] | 483 | service_dict = create_service_instance(parameters, service_model_list) |
Itohan | e2f489f | 2019-06-03 23:53:15 +0000 | [diff] [blame] | 484 | print "service instance parameters={}".format(service_dict) |
Itohan | 8ec5f1f | 2019-05-04 00:21:47 +0000 | [diff] [blame] | 485 | service_model_uuid = service_dict["service_uuid"] |
Itohan | 76ea974 | 2019-10-07 21:21:19 +0000 | [diff] [blame] | 486 | time.sleep(2) |
Itohan | 8ec5f1f | 2019-05-04 00:21:47 +0000 | [diff] [blame] | 487 | db_dict = query_db(parameters, service_model_uuid, vf_id) |
Itohan | e2f489f | 2019-06-03 23:53:15 +0000 | [diff] [blame] | 488 | |
| 489 | #Wait for Service instance to be created then create VNF Instance |
| 490 | while True: |
| 491 | #Check if service instance has been created" |
Itohan Ukponmwan | 63929cf | 2019-09-13 00:08:39 +0000 | [diff] [blame] | 492 | check_service_instance = os.popen("oclip service-instance-list -u {} -p {} -m {} |grep {}-{}".format(parameters["aai_username"], \ |
| 493 | parameters["aai_password"], parameters["aai_url"], parameters["instance-name"], parameters["service_name"])).read() |
Itohan | e2f489f | 2019-06-03 23:53:15 +0000 | [diff] [blame] | 494 | if check_service_instance: |
| 495 | print "service instance created successfully" |
| 496 | #Create VNF Instance |
| 497 | vnf_dict = create_vnf(parameters, service_dict, db_dict, vf_model_dict) |
| 498 | time.sleep(10) |
| 499 | print "vnf instance parameters={}".format(vnf_dict) |
| 500 | break |
| 501 | print "service instance create in progress" |
| 502 | time.sleep(30) |
| 503 | |
| 504 | #Preload VF module and create VF module |
root@rancher | 6c68bee | 2019-05-01 16:39:12 -0700 | [diff] [blame] | 505 | sdnc_preload(parameters, db_dict, service_dict) |
| 506 | create_vf_module(parameters, service_dict, vnf_dict, db_dict) |
Itohan | ecd1ebd | 2019-06-05 20:18:48 +0000 | [diff] [blame] | 507 | print "Deployment complete!!!, check cloud to confirm that vf module has been created" |