Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [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 time |
| 18 | import argparse |
| 19 | import sys |
Haibin Huang | ee3b43d | 2019-05-21 10:53:59 +0800 | [diff] [blame] | 20 | import requests |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 21 | |
| 22 | def get_parameters(file): |
| 23 | parameters = json.load(file) |
| 24 | return parameters |
| 25 | |
| 26 | def get_out_helper(in_string): |
| 27 | out_list = (((in_string.replace('-','')).replace('|', '')).replace('+', '')).split() |
| 28 | return out_list |
| 29 | |
| 30 | def get_out_helper_2(in_string): |
| 31 | out_list = ((in_string.replace('|', '')).replace('+', '')).split() |
| 32 | return out_list |
| 33 | |
| 34 | def set_open_cli_env(parameters): |
| 35 | os.environ["OPEN_CLI_PRODUCT_IN_USE"] = parameters["open_cli_product"] |
| 36 | os.environ["OPEN_CLI_HOME"] = parameters["open_cli_home"] |
| 37 | |
| 38 | def create_complex(parameters): |
| 39 | complex_create_string = "oclip complex-create -j {} -r {} -x {} -y {} -lt {} -l {} -i {} -lo {} \ |
| 40 | -S {} -la {} -g {} -w {} -z {} -k {} -o {} -q {} -m {} -u {} -p {}".format(parameters["street2"], \ |
| 41 | parameters["physical_location"], parameters["complex_name"], \ |
| 42 | parameters["data_center_code"], parameters["latitude"], parameters["region"], \ |
| 43 | parameters["street1"], parameters["longitude"], parameters["state"], \ |
| 44 | parameters["lata"], parameters["city"], parameters["postal-code"], \ |
| 45 | parameters["complex_name"], parameters["country"], parameters["elevation"], \ |
| 46 | parameters["identity_url"], parameters["aai_url"], parameters["aai_username"], \ |
| 47 | parameters["aai_password"]) |
| 48 | |
| 49 | os.system(complex_create_string) |
| 50 | |
Haibin Huang | 169a51b | 2019-05-22 14:39:08 +0800 | [diff] [blame^] | 51 | def create_vlm(parameters): |
| 52 | vlm_create_string = "oclip vlm-create -x {} -u {} -p {} -m {}".format(parameters["vendor-name"], \ |
| 53 | parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_onboarding_url"]) |
| 54 | command_out = (os.popen(vlm_create_string)).read() |
| 55 | out_list = get_out_helper(command_out) |
| 56 | vlm_id = out_list[3] |
| 57 | vlm_version = out_list[5] |
| 58 | |
| 59 | entitlement_string = "oclip vlm-entitlement-pool-create -x {} -y {} -e {} -z {} -k {} -g {} -l {} -u {} -p {} -m {}".format( \ |
| 60 | parameters["entitlement-pool-name"], vlm_id, vlm_version, parameters["entitlement-description"], parameters["vendor-name"], \ |
| 61 | parameters["expiry-date"], parameters["start-date"], parameters["sdc_creator"], parameters["sdc_password"], \ |
| 62 | parameters["sdc_onboarding_url"]) |
| 63 | command_out = (os.popen(entitlement_string)).read() |
| 64 | entitlement_id = (get_out_helper(command_out))[3] |
| 65 | |
| 66 | |
| 67 | key_group_string = "oclip vlm-key-group-create -c {} -e {} -x {} -y {} -u {} -p {} -m {}".format(vlm_id, vlm_version, \ |
| 68 | parameters["key-group-name"], parameters["key-group-type"], parameters["sdc_creator"], parameters["sdc_password"], \ |
| 69 | parameters["sdc_onboarding_url"]) |
| 70 | command_out = (os.popen(key_group_string)).read() |
| 71 | key_group_id = (get_out_helper(command_out))[3] |
| 72 | |
| 73 | feature_group_string = "oclip vlm-feature-group-create -x {} -y {} -e {} -z {} -g {} -b {} -c {} -u {} -p {} -m {}".format( |
| 74 | parameters["feature-grp-name"], vlm_id, vlm_version, parameters["feature-grp-desc"], key_group_id, entitlement_id, \ |
| 75 | parameters["part-no"], parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_onboarding_url"]) |
| 76 | command_out = (os.popen(feature_group_string)).read() |
| 77 | feature_group_id = (get_out_helper(command_out))[3] |
| 78 | |
| 79 | agreement_string = "oclip vlm-aggreement-create -x {} -y {} -e {} -z {} -g {} -u {} -p {} -m {}".format(parameters["agreement-name"], \ |
| 80 | vlm_id, vlm_version, parameters["agreement-desc"], feature_group_id, parameters["sdc_creator"], parameters["sdc_password"], \ |
| 81 | parameters["sdc_onboarding_url"]) |
| 82 | command_out = (os.popen(agreement_string)).read() |
| 83 | agreement_id = (get_out_helper(command_out))[3] |
| 84 | |
| 85 | submit_string = "oclip vlm-submit -x {} -y {} -u {} -p {} -m {}".format(vlm_id, vlm_version, parameters["sdc_creator"], \ |
| 86 | parameters["sdc_password"], parameters["sdc_onboarding_url"]) |
| 87 | os.system(submit_string) |
| 88 | |
| 89 | output = [feature_group_id, agreement_id, vlm_version, vlm_id ] |
| 90 | return output |
| 91 | |
| 92 | def create_vsp(parameters, in_list): |
| 93 | vnfs = parameters["vnf"] |
| 94 | vsp_dict = {} |
| 95 | for name, value in vnfs.iteritems(): |
| 96 | create_string = "oclip vsp-create -j {} -o {} -e {} -x {} -y {} -i {} -c {} -g {} -u {} -p {} -m {}".format( in_list[0], \ |
| 97 | parameters["onboarding-method"], parameters["vendor-name" ], value.get("vsp-name"), value.get("vsp-desc"), in_list[1], \ |
| 98 | in_list[2], in_list[3], parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_onboarding_url"] ) |
| 99 | command_out = (os.popen(create_string)).read() |
| 100 | out_list = get_out_helper(command_out) |
| 101 | vsp_id = out_list[3] |
| 102 | vsp_version = out_list[5] |
| 103 | |
| 104 | os.system("oclip vsp-add-artifact -x {} -y {} -z {} -u {} -p {} -m {}".format(vsp_id, vsp_version, value.get("path"), \ |
| 105 | parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_onboarding_url"])) |
| 106 | |
| 107 | os.system("oclip vsp-validate -x {} -y {} -u {} -p {} -m {}".format(vsp_id, vsp_version, parameters["sdc_creator"], \ |
| 108 | parameters["sdc_password"], parameters["sdc_onboarding_url"])) |
| 109 | |
| 110 | os.system("oclip vsp-submit -x {} -y {} -u {} -p {} -m {}".format(vsp_id, vsp_version, parameters["sdc_creator"], \ |
| 111 | parameters["sdc_password"], parameters["sdc_onboarding_url"])) |
| 112 | |
| 113 | os.system("oclip vsp-package -x {} -y {} -u {} -p {} -m {}".format(vsp_id, vsp_version, parameters["sdc_creator"], \ |
| 114 | parameters["sdc_password"], parameters["sdc_onboarding_url"])) |
| 115 | |
| 116 | vsp_ids[name] = vsp_id |
| 117 | return vsp_ids |
| 118 | |
| 119 | def create_vf_model(parameters, vsp_dict): |
| 120 | vnfs = parameters["vnfs"] |
| 121 | vf_dict = {} |
| 122 | for name, value in vnfs.iteritems(): |
| 123 | create_string = "oclip vf-model-create -y {} -g {} -x {} -z {} -b {} -u {} -p {} -m {}".format(value.get("vf-description"), \ |
| 124 | value.get("vsp-version"), value.get("vf-name"), parameters["vendor-name"], vsp_dict[name], \ |
| 125 | parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"]) |
| 126 | os.system(create_string) |
| 127 | |
| 128 | output = (os.popen("oclip vf-model-list -m {} -u {} -p {} | grep {}".format(parameters["sdc_catalog_url"], \ |
| 129 | parameters["sdc_creator"], parameters["sdc_password"], value.get("vf-name")))).read() |
| 130 | output = (get_out_helper_2(output)) |
| 131 | |
| 132 | vf_unique_id = output[1] |
| 133 | |
| 134 | os.system("oclip vf-model-certify -b {} -r {} -u {} -p {} -m {}".format(vf_unique_id, value.get("vf-remarks"), \ |
| 135 | parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"])) |
| 136 | |
| 137 | #Check for new parameters after certification |
| 138 | output = (os.popen("oclip vf-model-list -m {} -u {} -p {} | grep {}".format(parameters["sdc_catalog_url"], \ |
| 139 | parameters["sdc_creator"], parameters["sdc_password"], value.get("vf-name")))).read() |
| 140 | output = (get_out_helper_2(output)) |
| 141 | |
| 142 | vf_dict[name] = output[1] |
| 143 | |
| 144 | return vf_dict |
| 145 | |
| 146 | |
| 147 | def create_service_model(parameters, vf_dict): |
| 148 | vnfs = parameters["vnfs"] |
| 149 | |
| 150 | create_string = "oclip service-model-create -z {} -y {} -e {} -x {} -c {} -b {} -u {} -p {} -m {} |grep ID".format(parameters["project-code"], \ |
| 151 | parameters["service-model-desc"], parameters["icon-id"], parameters["service-model-name"], parameters["category-display"], \ |
| 152 | parameters["category"],parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"]) |
| 153 | |
| 154 | service_model_id = (get_out_helper_2((os.popen(create_string)).read()))[1] |
| 155 | |
| 156 | for name, value in vnfs.iteritems(): |
| 157 | os.system("oclip service-model-add-vf -x {} -b {} -y {} -z {} -u {} -p {} -m {}".format(service_model_id, \ |
| 158 | parameters["vf-version"], vf_dict[name], value.get("vf-name"), parameters["sdc_creator"], \ |
| 159 | parameters["sdc_password"], parameters["sdc_catalog_url"] )) |
| 160 | |
| 161 | os.system("oclip service-model-test-request -b {} -r {} -u {} -p {} -m {}".format(service_model_id, parameters["service-test-remarks"], \ |
| 162 | parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"])) |
| 163 | |
| 164 | os.system("oclip service-model-test-start -b {} -u {} -p {} -m {}".format(service_model_id, parameters["sdc_tester"], \ |
| 165 | parameters["sdc_password"], parameters["sdc_catalog_url"])) |
| 166 | |
| 167 | os.system("oclip service-model-test-accept -b {} -r {} -u {} -p {} -m {}".format(service_model_id, parameters["service-accept-remarks"], \ |
| 168 | parameters["sdc_tester"], parameters["sdc_password"], parameters["sdc_catalog_url"])) |
| 169 | |
| 170 | #Get uniqueId for the service model |
| 171 | service_model_values = (os.popen("oclip service-model-list -u {} -p {} -m {} |grep {}".format(parameters["sdc_creator"], \ |
| 172 | parameters["sdc_password"], parameters["sdc_catalog_url"], parameters["service-model-name"]))).read() |
| 173 | service_model_values = get_out_helper_2(service_model_values) |
| 174 | service_model_uniqueId = (service_model_values)[1] |
| 175 | |
| 176 | os.system("oclip service-model-approve -b {} -r {} -u {} -p {} -m {}".format(service_model_uniqueId, parameters["service-approve-remarks"], \ |
| 177 | parameters["sdc_governor"], parameters["sdc_password"], parameters["sdc_catalog_url"])) |
| 178 | |
| 179 | os.system("oclip service-model-distribute -b {} -u {} -p {} -m {}".format(service_model_uniqueId, parameters["sdc_operator"], \ |
| 180 | parameters["sdc_password"], parameters["sdc_catalog_url"])) |
| 181 | |
| 182 | return service_model_values |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 183 | |
| 184 | def register_cloud_helper(cloud_region, values, parameters): |
| 185 | #Create Cloud |
| 186 | cloud_create_string = 'oclip cloud-create -e {} -b {} -I {{\\\\\\"openstack-region-id\\\\\\":\\\\\\"{}\\\\\\"}} \ |
| 187 | -x {} -y {} -j {} -w {} -l {} -url {} -n {} -q {} -r {} -Q {} -i {} -g {} -z {} -k {} -c {} -m {} -u {} -p {}'.format( |
| 188 | values.get("esr-system-info-id"), values.get("user-name"), cloud_region, parameters["cloud-owner"], \ |
| 189 | cloud_region, values.get("password"), values.get("cloud-region-version"), values.get("default-tenant"), \ |
| 190 | values.get("service-url"), parameters["complex_name"], values.get("cloud-type"), parameters["owner-defined-type"], \ |
| 191 | values.get("system-type"), values.get("identity-url"), parameters["cloud-zone"], values.get("ssl-insecure"), \ |
| 192 | values.get("system-status"), values.get("cloud-domain"), parameters["aai_url"], parameters["aai_username"], \ |
| 193 | parameters["aai_password"]) |
| 194 | |
| 195 | |
| 196 | os.system(cloud_create_string) |
| 197 | |
| 198 | #Associate Cloud with complex |
| 199 | complex_associate_string = "oclip complex-associate -x {} -y {} -z {} -m {} -u {} -p {}".format(parameters["complex_name"], \ |
| 200 | cloud_region, parameters["cloud-owner"], parameters["aai_url"], parameters["aai_username"], parameters["aai_password"]) |
| 201 | os.system(complex_associate_string) |
| 202 | |
| 203 | #Register Cloud with Multicloud |
| 204 | multicloud_register_string = "oclip multicloud-register-cloud -y {} -x {} -m {}".format(parameters["cloud-owner"], \ |
| 205 | cloud_region, parameters["multicloud_url"]) |
| 206 | os.system(multicloud_register_string) |
| 207 | |
| 208 | def register_all_clouds(parameters): |
| 209 | cloud_dictionary = parameters["cloud_region_data"] |
| 210 | for cloud_region, cloud_region_values in cloud_dictionary.iteritems(): |
| 211 | register_cloud_helper(cloud_region, cloud_region_values, parameters) |
| 212 | |
Haibin Huang | 48dc681 | 2019-05-16 11:51:20 +0000 | [diff] [blame] | 213 | def register_vnfm_helper(vnfm_key, values, parameters): |
| 214 | #Create vnfm |
| 215 | vnfm_create_string = 'oclip vnfm-create -b {} -c {} -e {} -v {} -g {} -x {} -i {} -j {} -q {} \ |
| 216 | -m {} -u {} -p {}'.format(vnfm_key, values.get("type"), values.get("vendor"), \ |
| 217 | values.get("version"), values.get("url"), values.get("vim-id"), \ |
| 218 | values.get("user-name"), values.get("user-password"), values.get("vnfm-version"), \ |
| 219 | parameters["aai_url"], parameters["aai_username"], parameters["aai_password"]) |
| 220 | |
| 221 | os.system(vnfm_create_string) |
| 222 | |
| 223 | def register_vnfm(parameters): |
| 224 | vnfm_params = parameters["vnfm_params"] |
| 225 | for vnfm_key, vnfm_values in vnfm_params.iteritems(): |
| 226 | register_vnfm_helper(vnfm_key, vnfm_values, parameters) |
| 227 | |
| 228 | |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 229 | #VNF Deployment Section |
| 230 | def add_policies(parameters): |
| 231 | resource_string = (os.popen("oclip get-resource-module-name -u {} -p {} -m {} |grep {}".format(\ |
| 232 | parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"], \ |
| 233 | parameters["service-model-name"] ))).read() |
| 234 | resource_module_name = (get_out_helper_2(resource_string))[1] |
| 235 | |
| 236 | #Put in the right resource module name in all policies located in parameters["policy_directory"] |
| 237 | os.system("find {}/ -type f -exec sed -i 's/{}/{}/g' {{}} \;".format( |
| 238 | parameters["policy_directory"], parameters["temp_resource_module_name"], resource_module_name)) |
| 239 | |
| 240 | #Upload policy models |
| 241 | for model in os.listdir(parameters["policy_models_directory"]): |
| 242 | os.system("oclip policy-type-create -x {} -u {} -p {} -m {}".format(model, parameters["policy_username"], \ |
| 243 | parameters["policy_password"], parameters["policy_url"])) |
| 244 | time.sleep(0.5) |
| 245 | |
| 246 | #print("Put in the resourceModuleName {} in your policy files in {}. ".format(resource_module_name, \ |
| 247 | #(parameters["policy_directory"]))) |
| 248 | #raw_input("Press Enter to continue...") |
| 249 | |
| 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 | policy_file = (os.path.join(parameters["policy_directory"], policy)) |
| 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"], parameters["policy_password"], policy_name, parameters["policy_scope"], \ |
| 258 | parameters["policy_config_type"], parameters["policy_onapName"], policy_file)) |
| 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 | def onboard_vnf(parameters): |
Haibin Huang | ee3b43d | 2019-05-21 10:53:59 +0800 | [diff] [blame] | 266 | vnfs = parameters["vnfs"] |
| 267 | vnf_onboard_outputs = {} |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 268 | |
Haibin Huang | ee3b43d | 2019-05-21 10:53:59 +0800 | [diff] [blame] | 269 | for key, value in vnfs.items(): |
| 270 | vnf_onboard_string = 'oclip vfc-catalog-onboard-vnf -c {}'.format(value.get("csar-id")) |
| 271 | vnf_onboard_outs[key] = (os.popen(ns_onboard_string)).read() |
| 272 | return vnf_onboard_outputs |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 273 | |
| 274 | def onboard_ns(parameters): |
| 275 | ns_onboard_string = 'oclip vfc-catalog-onboard-ns -c {}'.format(parameters["ns-csar-id"]) |
| 276 | ns_onboard_out = (os.popen(ns_onboard_string)).read() |
| 277 | return ns_onboard_out |
| 278 | |
Haibin Huang | ee3b43d | 2019-05-21 10:53:59 +0800 | [diff] [blame] | 279 | def create_ns(parameters, csar_id): |
| 280 | ns = parameters["ns"] |
| 281 | ns_create_string = 'oclip vfc-nslcm-create -m {} -c {} -n {}'.format(parameters["vfc-url"], \ |
| 282 | csar_id, ns.get("name")) |
| 283 | print ns_create_string |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 284 | ns_create_out = (os.popen(ns_create_string)).read() |
Haibin Huang | ee3b43d | 2019-05-21 10:53:59 +0800 | [diff] [blame] | 285 | print ns_create_out |
| 286 | ns_instance_id = (get_out_helper_2(ns_create_out))[3] |
| 287 | return ns_instance_id |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 288 | |
Haibin Huang | ee3b43d | 2019-05-21 10:53:59 +0800 | [diff] [blame] | 289 | def instantiate_ns(parameters, ns_instance_id): |
| 290 | ns_instantiate_string = 'oclip vfc-nslcm-instantiate -m {} -i {} -c {} -n {}'.format(parameters["vfc-url"], \ |
| 291 | ns_instance_id, parameters["location"], parameters["sdc-controller-id"]) |
| 292 | print ns_instantiate_string |
| 293 | |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 294 | ns_instantiate_out = (os.popen(ns_instantiate_string)).read() |
| 295 | return ns_instantiate_out |
| 296 | |
Haibin Huang | ee3b43d | 2019-05-21 10:53:59 +0800 | [diff] [blame] | 297 | def create_ns_package(parameters): |
| 298 | ns = parameters["ns"] |
| 299 | create_ns_string = 'oclip vfc-catalog-create-ns -m {} -c {} -e {}'.format(parameters["vfc-url"], \ |
| 300 | ns.get("key"), ns.get("value")) |
| 301 | cmd_out = (os.popen(create_ns_string)).read() |
| 302 | out_list = get_out_helper_2(cmd_out) |
| 303 | return out_list[4] |
| 304 | |
| 305 | def create_vnf_package(parameters): |
| 306 | vnfs = parameters["vnfs"] |
| 307 | outputs = {} |
| 308 | |
| 309 | for vnf_key, vnf_values in vnfs.iteritems(): |
| 310 | create_vnf_string = 'oclip vfc-catalog-create-vnf -m {} -c {} -e {}'.format(parameters["vfc-url"], \ |
| 311 | vnf_values.get("key"), vnf_values.get("value")) |
| 312 | cmd_out = (os.popen(create_vnf_string)).read() |
| 313 | out_list = get_out_helper_2(cmd_out) |
| 314 | outputs[vnf_key] = out_list[4] |
| 315 | |
| 316 | return outputs |
| 317 | |
| 318 | def upload_ns_package(parameters, ns_package_output): |
| 319 | ns = parameters["ns"] |
| 320 | ns_upload_string = '{}/api/nsd/v1/ns_descriptors/{}/nsd_content'.format(parameters["vfc-url"], ns_package_output) |
| 321 | print ns_upload_string |
| 322 | print ns.get("path") |
| 323 | resp = requests.put(ns_upload_string, files={'file': open(ns.get("path"), 'rb')}) |
| 324 | return resp |
| 325 | |
| 326 | def upload_vnf_package(parameters, vnf_package_output): |
| 327 | vnfs = parameters["vnfs"] |
| 328 | for vnf_key, vnf_values in vnfs.iteritems(): |
| 329 | vnf_upload_str = '{}/api/vnfpkgm/v1/vnf_packages/{}/package_content'.format(parameters["vfc-url"], \ |
| 330 | vnf_package_output[vnf_key], vnf_package_output[vnf_key]) |
| 331 | resp = requests.put(vnf_upload_str, files={'file': open(vnf_values.get("path"), 'rb')}) |
| 332 | return resp |
| 333 | |
| 334 | |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 335 | #Run Functions |
| 336 | parser = argparse.ArgumentParser() |
| 337 | parser.add_argument('-f', action='store', dest='config_file_path', help='Store config file path') |
Haibin Huang | 169a51b | 2019-05-22 14:39:08 +0800 | [diff] [blame^] | 338 | parser.add_argument('-t', action='store', dest='model', help='Store config file path') |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 339 | |
| 340 | parser.add_argument('--version', action='version', version='%(prog)s 1.0') |
| 341 | |
| 342 | results = parser.parse_args() |
| 343 | |
| 344 | config_file_path = results.config_file_path |
Haibin Huang | 169a51b | 2019-05-22 14:39:08 +0800 | [diff] [blame^] | 345 | model = results.model |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 346 | if config_file_path is None: |
| 347 | sys.exit(1) |
| 348 | config_file = open(config_file_path) |
| 349 | parameters = get_parameters(config_file) |
| 350 | |
| 351 | # 1.Set cli command envionment |
| 352 | set_open_cli_env(parameters) |
| 353 | |
| 354 | # 2.Create cloud complex |
| 355 | create_complex(parameters) |
| 356 | |
Haibin Huang | 48dc681 | 2019-05-16 11:51:20 +0000 | [diff] [blame] | 357 | # 3.Register all clouds |
| 358 | register_all_clouds(parameters) |
| 359 | |
| 360 | # 4.Register vnfm |
| 361 | register_vnfm(parameters) |
| 362 | |
Haibin Huang | ee3b43d | 2019-05-21 10:53:59 +0800 | [diff] [blame] | 363 | # 5.create csar file |
| 364 | # 5.1 upload csar file to catalog |
| 365 | # 5.2 FIXME:Because SDC internal API will change without notice, so I will maually design VNF and Service. |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 366 | # SDC output data model is not align with VFC, we use an workaround method |
| 367 | # We just do run time automation |
Haibin Huang | ee3b43d | 2019-05-21 10:53:59 +0800 | [diff] [blame] | 368 | ns_package_output = "" |
| 369 | |
Haibin Huang | 169a51b | 2019-05-22 14:39:08 +0800 | [diff] [blame^] | 370 | if model == "sdc": |
Haibin Huang | ee3b43d | 2019-05-21 10:53:59 +0800 | [diff] [blame] | 371 | print "use csar file is distributed by sdc" |
Haibin Huang | 169a51b | 2019-05-22 14:39:08 +0800 | [diff] [blame^] | 372 | output = create_vlm(parameters) |
| 373 | vsp_dict = create_vsp(parameters, output) |
| 374 | vf_dict = create_vf_model(parameters, vsp_dict) |
| 375 | service_model_list = create_service_model(parameters, vf_dict) |
| 376 | # |
| 377 | vnf_onboard_output = onboard_vnf(parameters) |
| 378 | print vnf_onboard_output |
| 379 | ns_onboard_out = onboard_ns(parameters) |
| 380 | print ns_onboard_out |
Haibin Huang | ee3b43d | 2019-05-21 10:53:59 +0800 | [diff] [blame] | 381 | else: |
| 382 | print "use csar file is uploaded by local" |
| 383 | vnf_package_output = create_vnf_package(parameters) |
| 384 | print vnf_package_output |
| 385 | ns_package_output = create_ns_package(parameters) |
| 386 | print ns_package_output |
| 387 | upload_vnf_out = upload_vnf_package(parameters, vnf_package_output) |
| 388 | print upload_vnf_out |
| 389 | upload_ns_out = upload_ns_package(parameters, ns_package_output) |
| 390 | print upload_ns_out |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 391 | |
Haibin Huang | 48dc681 | 2019-05-16 11:51:20 +0000 | [diff] [blame] | 392 | # 6.add_policies function not currently working, using curl commands |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 393 | # add_policies(parameters) |
| 394 | |
Haibin Huang | 48dc681 | 2019-05-16 11:51:20 +0000 | [diff] [blame] | 395 | # 7. VFC part |
Haibin Huang | ee3b43d | 2019-05-21 10:53:59 +0800 | [diff] [blame] | 396 | ns_instance_id = create_ns(parameters, ns_package_output) |
Haibin Huang | 169a51b | 2019-05-22 14:39:08 +0800 | [diff] [blame^] | 397 | ns_instance_id = "d0ecc83f-339f-4621-b565-07eb9090a379" |
Haibin Huang | ee3b43d | 2019-05-21 10:53:59 +0800 | [diff] [blame] | 398 | print ns_instance_id |
| 399 | instantiate_ns_output = instantiate_ns(parameters, ns_instance_id) |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 400 | print instantiate_ns_output |