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 | 9d72e13 | 2019-05-22 16:20:08 +0800 | [diff] [blame] | 21 | import mysql.connector |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 22 | |
| 23 | def get_parameters(file): |
| 24 | parameters = json.load(file) |
| 25 | return parameters |
| 26 | |
| 27 | def get_out_helper(in_string): |
| 28 | out_list = (((in_string.replace('-','')).replace('|', '')).replace('+', '')).split() |
| 29 | return out_list |
| 30 | |
| 31 | def get_out_helper_2(in_string): |
| 32 | out_list = ((in_string.replace('|', '')).replace('+', '')).split() |
| 33 | return out_list |
| 34 | |
| 35 | def set_open_cli_env(parameters): |
| 36 | os.environ["OPEN_CLI_PRODUCT_IN_USE"] = parameters["open_cli_product"] |
| 37 | os.environ["OPEN_CLI_HOME"] = parameters["open_cli_home"] |
| 38 | |
| 39 | def create_complex(parameters): |
| 40 | complex_create_string = "oclip complex-create -j {} -r {} -x {} -y {} -lt {} -l {} -i {} -lo {} \ |
| 41 | -S {} -la {} -g {} -w {} -z {} -k {} -o {} -q {} -m {} -u {} -p {}".format(parameters["street2"], \ |
| 42 | parameters["physical_location"], parameters["complex_name"], \ |
| 43 | parameters["data_center_code"], parameters["latitude"], parameters["region"], \ |
| 44 | parameters["street1"], parameters["longitude"], parameters["state"], \ |
| 45 | parameters["lata"], parameters["city"], parameters["postal-code"], \ |
| 46 | parameters["complex_name"], parameters["country"], parameters["elevation"], \ |
| 47 | parameters["identity_url"], parameters["aai_url"], parameters["aai_username"], \ |
| 48 | parameters["aai_password"]) |
| 49 | |
| 50 | os.system(complex_create_string) |
| 51 | |
Haibin Huang | 169a51b | 2019-05-22 14:39:08 +0800 | [diff] [blame] | 52 | def create_vlm(parameters): |
| 53 | vlm_create_string = "oclip vlm-create -x {} -u {} -p {} -m {}".format(parameters["vendor-name"], \ |
| 54 | parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_onboarding_url"]) |
| 55 | command_out = (os.popen(vlm_create_string)).read() |
| 56 | out_list = get_out_helper(command_out) |
| 57 | vlm_id = out_list[3] |
| 58 | vlm_version = out_list[5] |
| 59 | |
| 60 | entitlement_string = "oclip vlm-entitlement-pool-create -x {} -y {} -e {} -z {} -k {} -g {} -l {} -u {} -p {} -m {}".format( \ |
| 61 | parameters["entitlement-pool-name"], vlm_id, vlm_version, parameters["entitlement-description"], parameters["vendor-name"], \ |
| 62 | parameters["expiry-date"], parameters["start-date"], parameters["sdc_creator"], parameters["sdc_password"], \ |
| 63 | parameters["sdc_onboarding_url"]) |
| 64 | command_out = (os.popen(entitlement_string)).read() |
| 65 | entitlement_id = (get_out_helper(command_out))[3] |
| 66 | |
| 67 | |
| 68 | key_group_string = "oclip vlm-key-group-create -c {} -e {} -x {} -y {} -u {} -p {} -m {}".format(vlm_id, vlm_version, \ |
| 69 | parameters["key-group-name"], parameters["key-group-type"], parameters["sdc_creator"], parameters["sdc_password"], \ |
| 70 | parameters["sdc_onboarding_url"]) |
| 71 | command_out = (os.popen(key_group_string)).read() |
| 72 | key_group_id = (get_out_helper(command_out))[3] |
| 73 | |
| 74 | feature_group_string = "oclip vlm-feature-group-create -x {} -y {} -e {} -z {} -g {} -b {} -c {} -u {} -p {} -m {}".format( |
| 75 | parameters["feature-grp-name"], vlm_id, vlm_version, parameters["feature-grp-desc"], key_group_id, entitlement_id, \ |
| 76 | parameters["part-no"], parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_onboarding_url"]) |
| 77 | command_out = (os.popen(feature_group_string)).read() |
| 78 | feature_group_id = (get_out_helper(command_out))[3] |
| 79 | |
| 80 | agreement_string = "oclip vlm-aggreement-create -x {} -y {} -e {} -z {} -g {} -u {} -p {} -m {}".format(parameters["agreement-name"], \ |
| 81 | vlm_id, vlm_version, parameters["agreement-desc"], feature_group_id, parameters["sdc_creator"], parameters["sdc_password"], \ |
| 82 | parameters["sdc_onboarding_url"]) |
| 83 | command_out = (os.popen(agreement_string)).read() |
| 84 | agreement_id = (get_out_helper(command_out))[3] |
| 85 | |
| 86 | submit_string = "oclip vlm-submit -x {} -y {} -u {} -p {} -m {}".format(vlm_id, vlm_version, parameters["sdc_creator"], \ |
| 87 | parameters["sdc_password"], parameters["sdc_onboarding_url"]) |
| 88 | os.system(submit_string) |
| 89 | |
| 90 | output = [feature_group_id, agreement_id, vlm_version, vlm_id ] |
| 91 | return output |
| 92 | |
| 93 | def create_vsp(parameters, in_list): |
| 94 | vnfs = parameters["vnf"] |
| 95 | vsp_dict = {} |
| 96 | for name, value in vnfs.iteritems(): |
| 97 | create_string = "oclip vsp-create -j {} -o {} -e {} -x {} -y {} -i {} -c {} -g {} -u {} -p {} -m {}".format( in_list[0], \ |
| 98 | parameters["onboarding-method"], parameters["vendor-name" ], value.get("vsp-name"), value.get("vsp-desc"), in_list[1], \ |
| 99 | in_list[2], in_list[3], parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_onboarding_url"] ) |
| 100 | command_out = (os.popen(create_string)).read() |
| 101 | out_list = get_out_helper(command_out) |
| 102 | vsp_id = out_list[3] |
| 103 | vsp_version = out_list[5] |
| 104 | |
| 105 | os.system("oclip vsp-add-artifact -x {} -y {} -z {} -u {} -p {} -m {}".format(vsp_id, vsp_version, value.get("path"), \ |
| 106 | parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_onboarding_url"])) |
| 107 | |
| 108 | os.system("oclip vsp-validate -x {} -y {} -u {} -p {} -m {}".format(vsp_id, vsp_version, parameters["sdc_creator"], \ |
| 109 | parameters["sdc_password"], parameters["sdc_onboarding_url"])) |
| 110 | |
| 111 | os.system("oclip vsp-submit -x {} -y {} -u {} -p {} -m {}".format(vsp_id, vsp_version, parameters["sdc_creator"], \ |
| 112 | parameters["sdc_password"], parameters["sdc_onboarding_url"])) |
| 113 | |
| 114 | os.system("oclip vsp-package -x {} -y {} -u {} -p {} -m {}".format(vsp_id, vsp_version, parameters["sdc_creator"], \ |
| 115 | parameters["sdc_password"], parameters["sdc_onboarding_url"])) |
| 116 | |
| 117 | vsp_ids[name] = vsp_id |
| 118 | return vsp_ids |
| 119 | |
| 120 | def create_vf_model(parameters, vsp_dict): |
| 121 | vnfs = parameters["vnfs"] |
| 122 | vf_dict = {} |
| 123 | for name, value in vnfs.iteritems(): |
| 124 | create_string = "oclip vf-model-create -y {} -g {} -x {} -z {} -b {} -u {} -p {} -m {}".format(value.get("vf-description"), \ |
| 125 | value.get("vsp-version"), value.get("vf-name"), parameters["vendor-name"], vsp_dict[name], \ |
| 126 | parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"]) |
| 127 | os.system(create_string) |
| 128 | |
| 129 | output = (os.popen("oclip vf-model-list -m {} -u {} -p {} | grep {}".format(parameters["sdc_catalog_url"], \ |
| 130 | parameters["sdc_creator"], parameters["sdc_password"], value.get("vf-name")))).read() |
| 131 | output = (get_out_helper_2(output)) |
| 132 | |
| 133 | vf_unique_id = output[1] |
| 134 | |
| 135 | os.system("oclip vf-model-certify -b {} -r {} -u {} -p {} -m {}".format(vf_unique_id, value.get("vf-remarks"), \ |
| 136 | parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"])) |
| 137 | |
| 138 | #Check for new parameters after certification |
| 139 | output = (os.popen("oclip vf-model-list -m {} -u {} -p {} | grep {}".format(parameters["sdc_catalog_url"], \ |
| 140 | parameters["sdc_creator"], parameters["sdc_password"], value.get("vf-name")))).read() |
| 141 | output = (get_out_helper_2(output)) |
| 142 | |
| 143 | vf_dict[name] = output[1] |
| 144 | |
| 145 | return vf_dict |
| 146 | |
| 147 | |
| 148 | def create_service_model(parameters, vf_dict): |
| 149 | vnfs = parameters["vnfs"] |
| 150 | |
| 151 | create_string = "oclip service-model-create -z {} -y {} -e {} -x {} -c {} -b {} -u {} -p {} -m {} |grep ID".format(parameters["project-code"], \ |
| 152 | parameters["service-model-desc"], parameters["icon-id"], parameters["service-model-name"], parameters["category-display"], \ |
| 153 | parameters["category"],parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"]) |
| 154 | |
| 155 | service_model_id = (get_out_helper_2((os.popen(create_string)).read()))[1] |
| 156 | |
| 157 | for name, value in vnfs.iteritems(): |
| 158 | os.system("oclip service-model-add-vf -x {} -b {} -y {} -z {} -u {} -p {} -m {}".format(service_model_id, \ |
| 159 | parameters["vf-version"], vf_dict[name], value.get("vf-name"), parameters["sdc_creator"], \ |
| 160 | parameters["sdc_password"], parameters["sdc_catalog_url"] )) |
| 161 | |
| 162 | os.system("oclip service-model-test-request -b {} -r {} -u {} -p {} -m {}".format(service_model_id, parameters["service-test-remarks"], \ |
| 163 | parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"])) |
| 164 | |
| 165 | os.system("oclip service-model-test-start -b {} -u {} -p {} -m {}".format(service_model_id, parameters["sdc_tester"], \ |
| 166 | parameters["sdc_password"], parameters["sdc_catalog_url"])) |
| 167 | |
| 168 | os.system("oclip service-model-test-accept -b {} -r {} -u {} -p {} -m {}".format(service_model_id, parameters["service-accept-remarks"], \ |
| 169 | parameters["sdc_tester"], parameters["sdc_password"], parameters["sdc_catalog_url"])) |
| 170 | |
| 171 | #Get uniqueId for the service model |
| 172 | service_model_values = (os.popen("oclip service-model-list -u {} -p {} -m {} |grep {}".format(parameters["sdc_creator"], \ |
| 173 | parameters["sdc_password"], parameters["sdc_catalog_url"], parameters["service-model-name"]))).read() |
| 174 | service_model_values = get_out_helper_2(service_model_values) |
| 175 | service_model_uniqueId = (service_model_values)[1] |
| 176 | |
| 177 | os.system("oclip service-model-approve -b {} -r {} -u {} -p {} -m {}".format(service_model_uniqueId, parameters["service-approve-remarks"], \ |
| 178 | parameters["sdc_governor"], parameters["sdc_password"], parameters["sdc_catalog_url"])) |
| 179 | |
| 180 | os.system("oclip service-model-distribute -b {} -u {} -p {} -m {}".format(service_model_uniqueId, parameters["sdc_operator"], \ |
| 181 | parameters["sdc_password"], parameters["sdc_catalog_url"])) |
| 182 | |
| 183 | return service_model_values |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 184 | |
| 185 | def register_cloud_helper(cloud_region, values, parameters): |
| 186 | #Create Cloud |
| 187 | cloud_create_string = 'oclip cloud-create -e {} -b {} -I {{\\\\\\"openstack-region-id\\\\\\":\\\\\\"{}\\\\\\"}} \ |
| 188 | -x {} -y {} -j {} -w {} -l {} -url {} -n {} -q {} -r {} -Q {} -i {} -g {} -z {} -k {} -c {} -m {} -u {} -p {}'.format( |
| 189 | values.get("esr-system-info-id"), values.get("user-name"), cloud_region, parameters["cloud-owner"], \ |
| 190 | cloud_region, values.get("password"), values.get("cloud-region-version"), values.get("default-tenant"), \ |
| 191 | values.get("service-url"), parameters["complex_name"], values.get("cloud-type"), parameters["owner-defined-type"], \ |
| 192 | values.get("system-type"), values.get("identity-url"), parameters["cloud-zone"], values.get("ssl-insecure"), \ |
| 193 | values.get("system-status"), values.get("cloud-domain"), parameters["aai_url"], parameters["aai_username"], \ |
| 194 | parameters["aai_password"]) |
| 195 | |
| 196 | |
| 197 | os.system(cloud_create_string) |
| 198 | |
| 199 | #Associate Cloud with complex |
| 200 | complex_associate_string = "oclip complex-associate -x {} -y {} -z {} -m {} -u {} -p {}".format(parameters["complex_name"], \ |
| 201 | cloud_region, parameters["cloud-owner"], parameters["aai_url"], parameters["aai_username"], parameters["aai_password"]) |
| 202 | os.system(complex_associate_string) |
| 203 | |
| 204 | #Register Cloud with Multicloud |
| 205 | multicloud_register_string = "oclip multicloud-register-cloud -y {} -x {} -m {}".format(parameters["cloud-owner"], \ |
| 206 | cloud_region, parameters["multicloud_url"]) |
| 207 | os.system(multicloud_register_string) |
| 208 | |
| 209 | def register_all_clouds(parameters): |
| 210 | cloud_dictionary = parameters["cloud_region_data"] |
| 211 | for cloud_region, cloud_region_values in cloud_dictionary.iteritems(): |
| 212 | register_cloud_helper(cloud_region, cloud_region_values, parameters) |
| 213 | |
Haibin Huang | 48dc681 | 2019-05-16 11:51:20 +0000 | [diff] [blame] | 214 | def register_vnfm_helper(vnfm_key, values, parameters): |
| 215 | #Create vnfm |
| 216 | vnfm_create_string = 'oclip vnfm-create -b {} -c {} -e {} -v {} -g {} -x {} -i {} -j {} -q {} \ |
| 217 | -m {} -u {} -p {}'.format(vnfm_key, values.get("type"), values.get("vendor"), \ |
| 218 | values.get("version"), values.get("url"), values.get("vim-id"), \ |
| 219 | values.get("user-name"), values.get("user-password"), values.get("vnfm-version"), \ |
| 220 | parameters["aai_url"], parameters["aai_username"], parameters["aai_password"]) |
| 221 | |
| 222 | os.system(vnfm_create_string) |
| 223 | |
| 224 | def register_vnfm(parameters): |
| 225 | vnfm_params = parameters["vnfm_params"] |
| 226 | for vnfm_key, vnfm_values in vnfm_params.iteritems(): |
| 227 | register_vnfm_helper(vnfm_key, vnfm_values, parameters) |
| 228 | |
Haibin Huang | 9d72e13 | 2019-05-22 16:20:08 +0800 | [diff] [blame] | 229 | def add_policy_models(parameters): |
| 230 | mydb = mysql.connector.connect( |
| 231 | host="policydb", |
| 232 | user="policy_user", |
| 233 | passwd="policy_user", |
| 234 | database="onap_sdk", |
| 235 | ) |
Haibin Huang | 48dc681 | 2019-05-16 11:51:20 +0000 | [diff] [blame] | 236 | |
Haibin Huang | 9d72e13 | 2019-05-22 16:20:08 +0800 | [diff] [blame] | 237 | mycursor = mydb.cursor() |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 238 | |
Haibin Huang | 9d72e13 | 2019-05-22 16:20:08 +0800 | [diff] [blame] | 239 | sql = "INSERT INTO optimizationmodels (modelname, description, dependency, imported_by, \ |
| 240 | attributes, ref_attributes, sub_attributes, version, annotation, enumValues, \ |
| 241 | dataOrderInfo) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" |
| 242 | val = [ |
| 243 | ('hpaPolicy', 'HPA Tests Model', '[]', 'demo', 'identity=string:defaultValue-null:required-true:MANY-false:description-null', \ |
| 244 | 'policyScope=MANY-true,policyType=POLICYTYPE:MANY-false,resources=MANY-true,flavorFeatures=flavorFeatures_properties:MANY-true:description-null', \ |
| 245 | '{"directives_properties":{"attributes":"directives_attributes_properties:required-false:MANY-true:description-null",\ |
| 246 | "type":"string:defaultValue-null:required-false:MANY-false:description-null"},\ |
| 247 | "directives_attributes_properties":{"attribute_name":"string:defaultValue-null:required-false:MANY-false:description-null",\ |
| 248 | "attribute_value":"string:defaultValue-null:required-false:MANY-false:description-null"},\ |
| 249 | "flavorProperties_properties":{"score":"string:defaultValue-null:required-false:MANY-false:description-null",\ |
| 250 | "hpa-feature-attributes":"hpa-feature-attributes_properties:required-true:MANY-true:description-null",\ |
| 251 | "directives":"directives_properties:required-true:MANY-true:description-null",\ |
| 252 | "hpa-version":"string:defaultValue-null:required-true:MANY-false:description-null",\ |
| 253 | "hpa-feature":"string:defaultValue-null:required-true:MANY-false:description-null",\ |
| 254 | "mandatory":"string:defaultValue-null:required-true:MANY-false:description-null",\ |
| 255 | "architecture":"string:defaultValue-null:required-true:MANY-false:description-null"},\ |
| 256 | "flavorFeatures_properties":{"directives":"directives_properties:required-true:MANY-true:description-null",\ |
| 257 | "flavorProperties":"flavorProperties_properties:required-true:MANY-true:description-null",\ |
| 258 | "id":"string:defaultValue-null:required-true:MANY-false:description-null",\ |
| 259 | "type":"string:defaultValue-null:required-true:MANY-false:description-null"},\ |
| 260 | "hpa-feature-attributes_properties":{"unit":"string:defaultValue-null:required-false:MANY-false:description-null",\ |
| 261 | "hpa-attribute-value":"string:defaultValue-null:required-true:MANY-false:description-null",\ |
| 262 | "hpa-attribute-key":"string:defaultValue-null:required-true:MANY-false:description-null",\ |
| 263 | "operator":"OPERATOR:defaultValue-null:required-false:MANY-false:description-null"}}', \ |
| 264 | 'test1', 'policyScope=matching-true, policyType=matching-true', \ |
| 265 | 'OPERATOR=[<,<equal-sign,>,>equal-sign,equal-sign,!equal-sign,any,all,subset,], POLICYTYPE=[hpa,]', '""'), |
| 266 | ('distancePolicy', 'distancePolicy', '[]', 'demo', 'identity=string:defaultValue-null:required-true:MANY-false:description-null', \ |
| 267 | 'policyScope=MANY-true,distanceProperties=distanceProperties_properties:MANY-false:description-null,policyType=POLICYTYPE:MANY-false,\ |
| 268 | resources=MANY-true,applicableResources=APPLICABLERESOURCES:MANY-false', \ |
| 269 | '{"distanceProperties_properties":{"locationInfo":"string:defaultValue-null:required-true:MANY-false:description-null",\ |
| 270 | "distance":"distance_properties:required-true:MANY-false:description-null"},\ |
| 271 | "distance_properties":{"unit":"UNIT:defaultValue-null:required-true:MANY-false:description-null",\ |
| 272 | "value":"string:defaultValue-null:required-true:MANY-false:description-null","operator":"OPERATOR:defaultValue-null:required-true:MANY-false:description-null"}}', \ |
| 273 | 'test1', 'policyScope=matching-true, policyType=matching-true', \ |
| 274 | 'OPERATOR=[<,<equal-sign,>,>equal-sign,equal-sign,], APPLICABLERESOURCES=[any,all,], POLICYTYPE=[distance_to_location,] ', '""'), |
| 275 | ('optimizationPolicy', 'Optimization policy model', '[]', 'demo', 'identity=string:defaultValue-null:required-true:MANY-false:description-null', \ |
| 276 | 'objectiveParameter=objectiveParameter_properties:MANY-false:description-null,policyScope=MANY-true,policyType=POLICYTYPE:MANY-false,\ |
| 277 | objective=objectiveParameter_properties:MANY-false:description-null', \ |
| 278 | '{"parameterAttributes_properties":{"customerLocationInfo":"string:defaultValue-null:required-true:MANY-false:description-null",\ |
| 279 | "parameter":"string:defaultValue-null:required-true:MANY-false:description-null",\ |
| 280 | "resources":"string:defaultValue-null:required-true:MANY-false:description-null",\ |
| 281 | "weight":"string:defaultValue-null:required-true:MANY-false:description-null",\ |
| 282 | "operator":"OPERATOR:defaultValue-null:required-true:MANY-false:description-null"},\ |
| 283 | "objectiveParameter_properties":{"parameterAttributes":"parameterAttributes_properties:required-true:MANY-true:description-null",\ |
| 284 | "operator":"OPERATOR:defaultValue-null:required-true:MANY-false:description-null"}}', \ |
| 285 | 'test1', 'policyScope=matching-true, policyType=matching-true', 'OPERATOR=[*,+,-,/,%,], POLICYTYPE=[placement_optimization,]', '""'), |
| 286 | ('queryPolicy', 'Query policy model', '[]', 'demo', 'identity=string:defaultValue-null:required-true:MANY-false:description-null', \ |
| 287 | 'policyScope=MANY-true,policyType=POLICYTYPE:MANY-false,queryProperties=queryProperties_properties:MANY-true:description-null', \ |
| 288 | '{"queryProperties_properties":{"attribute_location":"string:defaultValue-null:required-true:MANY-false:description-null",\ |
| 289 | "attribute":"string:defaultValue-null:required-true:MANY-false:description-null","value":"string:defaultValue-null:required-true:MANY-false:description-null"}}', \ |
| 290 | 'test1', 'policyScope=matching-true, policyType=matching-true', 'POLICYTYPE=[request_param_query,]', '""'), |
| 291 | ('vnfPolicy', 'VnfPolicy model', '[]', 'demo', 'identity=string:defaultValue-null:required-true:MANY-false:description-null', \ |
| 292 | 'policyScope=MANY-true,policyType=POLICYTYPE:MANY-false,resources=MANY-true,\ |
| 293 | vnfProperties=vnfProperties_properties:MANY-true:description-null,applicableResources=APPLICABLERESOURCES:MANY-false', \ |
| 294 | '{"vnfProperties_properties":{"serviceType":"string:defaultValue-null:required-true:MANY-false:description-null",\ |
| 295 | "inventoryProvider":"string:defaultValue-null:required-true:MANY-false:description-null",\ |
| 296 | "inventoryType":"INVENTORYTYPE:defaultValue-null:required-true:MANY-false:description-null",\ |
| 297 | "customerId":"string:defaultValue-null:required-true:MANY-false:description-null"}}', \ |
| 298 | 'test1', 'policyScope=matching-true, policyType=matching-true', \ |
| 299 | 'INVENTORYTYPE=[serviceInstanceId,vnfName,cloudRegionId,vimId,], APPLICABLERESOURCES=[any,all,], POLICYTYPE=[vnfPolicy,]', '""'), |
| 300 | ('vim_fit', 'Capacity policy model', '[]', 'demo', 'identity=string:defaultValue-null:required-true:MANY-false:description-null', \ |
| 301 | 'policyScope=MANY-true,policyType=POLICYTYPE:MANY-false,capacityProperties=capacityProperties_properties:MANY-false:description-null,\ |
| 302 | resources=MANY-true,applicableResources=APPLICABLERESOURCES:MANY-false', \ |
| 303 | '{"capacityProperties_properties":{"request":"string:defaultValue-null:required-true:MANY-false:description-null",\ |
| 304 | "controller":"string:defaultValue-null:required-true:MANY-false:description-null"}}', \ |
| 305 | 'test1', 'policyScope=matching-true, policyType=matching-true ', ' APPLICABLERESOURCES=[any,all,], POLICYTYPE=[vim_fit,]', '""'), |
| 306 | ('affinityPolicy', 'Affinity policy model', '[]', 'demo', 'identity=string:defaultValue-null:required-true:MANY-false:description-null', \ |
| 307 | 'policyScope=MANY-true,policyType=POLICYTYPE:MANY-false,affinityProperties=affinityProperties_properties:MANY-false:description-null,\ |
| 308 | resources=MANY-true,applicableResources=APPLICABLERESOURCES:MANY-false', \ |
| 309 | '{"affinityProperties_properties":{"qualifier":"QUALIFIER:defaultValue-null:required-true:MANY-false:description-null",\ |
| 310 | "category":"string:defaultValue-null:required-true:MANY-false:description-null"}}', \ |
| 311 | 'test1', 'policyScope=matching-true, policyType=matching-true ', ' APPLICABLERESOURCES=[any,all,], POLICYTYPE=[zone,], QUALIFIER=[same,different,]', '""'), |
| 312 | ('pciPolicy', 'Pci policy model', '[]', 'demo', 'identity=string:defaultValue-null:required-true:MANY-false:description-null', \ |
| 313 | 'policyScope=MANY-true,policyType=POLICYTYPE:MANY-false,resources=MANY-true,pciProperties=pciProperties_properties:MANY-true:description-null', \ |
| 314 | '{"pciProperties_properties":{"pciOptimizationTimeConstraint":"string:defaultValue-null:required-false:MANY-false:description-null",\ |
| 315 | "pciOptimizationNwConstraint":"string:defaultValue-null:required-false:MANY-false:description-null",\ |
| 316 | "algoCategory":"string:defaultValue-null:required-false:MANY-false:description-null",\ |
| 317 | "pciOptmizationAlgoName":"string:defaultValue-null:required-false:MANY-false:description-null",\ |
| 318 | "pciOptimizationPriority":"string:defaultValue-null:required-false:MANY-false:description-null"}}', \ |
| 319 | 'test1', 'olicyScope=matching-true, policyType=matching-true ', ' POLICYTYPE=[pciPolicy,]', '""'), |
| 320 | ('subscriberPolicy', 'Subscriber Policy Model', '[]', 'demo', 'identity=string:defaultValue-null:required-true:MANY-false:description-null', \ |
| 321 | 'policyScope=MANY-true,policyType=POLICYTYPE:MANY-false,properties=properties_properties:MANY-false:description-type of a policy', \ |
| 322 | '{"properties_properties":{"provStatus":"PROVSTATUS:defaultValue-null:required-true:MANY-false:description-null",\ |
| 323 | "subscriberName":"SUBSCRIBERNAME:defaultValue-null:required-true:MANY-false:description-null",\ |
| 324 | "subscriberRole":"SUBSCRIBERROLE:defaultValue-null:required-true:MANY-false:description-null"}}', \ |
| 325 | 'test1', 'policyScope=matching-true, policyType=matching-true, properties=matching-true ', \ |
| 326 | ' SUBSCRIBERNAME=[], SUBSCRIBERROLE=[], POLICYTYPE=[subscriberPolicy,], PROVSTATUS=[]', '""') |
| 327 | ] |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 328 | |
Haibin Huang | 9d72e13 | 2019-05-22 16:20:08 +0800 | [diff] [blame] | 329 | mycursor.executemany(sql, val) |
| 330 | mydb.commit() |
| 331 | print(mycursor.rowcount, "was inserted.") |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 332 | |
| 333 | def onboard_vnf(parameters): |
Haibin Huang | ee3b43d | 2019-05-21 10:53:59 +0800 | [diff] [blame] | 334 | vnfs = parameters["vnfs"] |
| 335 | vnf_onboard_outputs = {} |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 336 | |
Haibin Huang | ee3b43d | 2019-05-21 10:53:59 +0800 | [diff] [blame] | 337 | for key, value in vnfs.items(): |
| 338 | vnf_onboard_string = 'oclip vfc-catalog-onboard-vnf -c {}'.format(value.get("csar-id")) |
| 339 | vnf_onboard_outs[key] = (os.popen(ns_onboard_string)).read() |
| 340 | return vnf_onboard_outputs |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 341 | |
| 342 | def onboard_ns(parameters): |
| 343 | ns_onboard_string = 'oclip vfc-catalog-onboard-ns -c {}'.format(parameters["ns-csar-id"]) |
| 344 | ns_onboard_out = (os.popen(ns_onboard_string)).read() |
| 345 | return ns_onboard_out |
| 346 | |
Haibin Huang | ee3b43d | 2019-05-21 10:53:59 +0800 | [diff] [blame] | 347 | def create_ns(parameters, csar_id): |
| 348 | ns = parameters["ns"] |
| 349 | ns_create_string = 'oclip vfc-nslcm-create -m {} -c {} -n {}'.format(parameters["vfc-url"], \ |
| 350 | csar_id, ns.get("name")) |
| 351 | print ns_create_string |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 352 | ns_create_out = (os.popen(ns_create_string)).read() |
Haibin Huang | ee3b43d | 2019-05-21 10:53:59 +0800 | [diff] [blame] | 353 | print ns_create_out |
| 354 | ns_instance_id = (get_out_helper_2(ns_create_out))[3] |
| 355 | return ns_instance_id |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 356 | |
Haibin Huang | ee3b43d | 2019-05-21 10:53:59 +0800 | [diff] [blame] | 357 | def instantiate_ns(parameters, ns_instance_id): |
| 358 | ns_instantiate_string = 'oclip vfc-nslcm-instantiate -m {} -i {} -c {} -n {}'.format(parameters["vfc-url"], \ |
| 359 | ns_instance_id, parameters["location"], parameters["sdc-controller-id"]) |
| 360 | print ns_instantiate_string |
| 361 | |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 362 | ns_instantiate_out = (os.popen(ns_instantiate_string)).read() |
| 363 | return ns_instantiate_out |
| 364 | |
Haibin Huang | ee3b43d | 2019-05-21 10:53:59 +0800 | [diff] [blame] | 365 | def create_ns_package(parameters): |
| 366 | ns = parameters["ns"] |
| 367 | create_ns_string = 'oclip vfc-catalog-create-ns -m {} -c {} -e {}'.format(parameters["vfc-url"], \ |
| 368 | ns.get("key"), ns.get("value")) |
| 369 | cmd_out = (os.popen(create_ns_string)).read() |
| 370 | out_list = get_out_helper_2(cmd_out) |
| 371 | return out_list[4] |
| 372 | |
| 373 | def create_vnf_package(parameters): |
| 374 | vnfs = parameters["vnfs"] |
| 375 | outputs = {} |
| 376 | |
| 377 | for vnf_key, vnf_values in vnfs.iteritems(): |
| 378 | create_vnf_string = 'oclip vfc-catalog-create-vnf -m {} -c {} -e {}'.format(parameters["vfc-url"], \ |
| 379 | vnf_values.get("key"), vnf_values.get("value")) |
| 380 | cmd_out = (os.popen(create_vnf_string)).read() |
| 381 | out_list = get_out_helper_2(cmd_out) |
| 382 | outputs[vnf_key] = out_list[4] |
| 383 | |
| 384 | return outputs |
| 385 | |
| 386 | def upload_ns_package(parameters, ns_package_output): |
| 387 | ns = parameters["ns"] |
| 388 | ns_upload_string = '{}/api/nsd/v1/ns_descriptors/{}/nsd_content'.format(parameters["vfc-url"], ns_package_output) |
| 389 | print ns_upload_string |
| 390 | print ns.get("path") |
| 391 | resp = requests.put(ns_upload_string, files={'file': open(ns.get("path"), 'rb')}) |
| 392 | return resp |
| 393 | |
| 394 | def upload_vnf_package(parameters, vnf_package_output): |
| 395 | vnfs = parameters["vnfs"] |
| 396 | for vnf_key, vnf_values in vnfs.iteritems(): |
| 397 | vnf_upload_str = '{}/api/vnfpkgm/v1/vnf_packages/{}/package_content'.format(parameters["vfc-url"], \ |
| 398 | vnf_package_output[vnf_key], vnf_package_output[vnf_key]) |
| 399 | resp = requests.put(vnf_upload_str, files={'file': open(vnf_values.get("path"), 'rb')}) |
| 400 | return resp |
| 401 | |
| 402 | |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 403 | #Run Functions |
| 404 | parser = argparse.ArgumentParser() |
| 405 | 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] | 406 | 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] | 407 | |
| 408 | parser.add_argument('--version', action='version', version='%(prog)s 1.0') |
| 409 | |
| 410 | results = parser.parse_args() |
| 411 | |
| 412 | config_file_path = results.config_file_path |
Haibin Huang | 169a51b | 2019-05-22 14:39:08 +0800 | [diff] [blame] | 413 | model = results.model |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 414 | if config_file_path is None: |
| 415 | sys.exit(1) |
| 416 | config_file = open(config_file_path) |
| 417 | parameters = get_parameters(config_file) |
| 418 | |
| 419 | # 1.Set cli command envionment |
| 420 | set_open_cli_env(parameters) |
| 421 | |
| 422 | # 2.Create cloud complex |
| 423 | create_complex(parameters) |
| 424 | |
Haibin Huang | 48dc681 | 2019-05-16 11:51:20 +0000 | [diff] [blame] | 425 | # 3.Register all clouds |
| 426 | register_all_clouds(parameters) |
| 427 | |
| 428 | # 4.Register vnfm |
| 429 | register_vnfm(parameters) |
| 430 | |
Haibin Huang | ee3b43d | 2019-05-21 10:53:59 +0800 | [diff] [blame] | 431 | # 5.create csar file |
| 432 | # 5.1 upload csar file to catalog |
| 433 | # 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] | 434 | # SDC output data model is not align with VFC, we use an workaround method |
| 435 | # We just do run time automation |
Haibin Huang | ee3b43d | 2019-05-21 10:53:59 +0800 | [diff] [blame] | 436 | ns_package_output = "" |
| 437 | |
Haibin Huang | 169a51b | 2019-05-22 14:39:08 +0800 | [diff] [blame] | 438 | if model == "sdc": |
Haibin Huang | ee3b43d | 2019-05-21 10:53:59 +0800 | [diff] [blame] | 439 | print "use csar file is distributed by sdc" |
Haibin Huang | 169a51b | 2019-05-22 14:39:08 +0800 | [diff] [blame] | 440 | output = create_vlm(parameters) |
| 441 | vsp_dict = create_vsp(parameters, output) |
| 442 | vf_dict = create_vf_model(parameters, vsp_dict) |
| 443 | service_model_list = create_service_model(parameters, vf_dict) |
| 444 | # |
| 445 | vnf_onboard_output = onboard_vnf(parameters) |
| 446 | print vnf_onboard_output |
| 447 | ns_onboard_out = onboard_ns(parameters) |
| 448 | print ns_onboard_out |
Haibin Huang | ee3b43d | 2019-05-21 10:53:59 +0800 | [diff] [blame] | 449 | else: |
| 450 | print "use csar file is uploaded by local" |
| 451 | vnf_package_output = create_vnf_package(parameters) |
| 452 | print vnf_package_output |
| 453 | ns_package_output = create_ns_package(parameters) |
| 454 | print ns_package_output |
| 455 | upload_vnf_out = upload_vnf_package(parameters, vnf_package_output) |
| 456 | print upload_vnf_out |
| 457 | upload_ns_out = upload_ns_package(parameters, ns_package_output) |
| 458 | print upload_ns_out |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 459 | |
Haibin Huang | 48dc681 | 2019-05-16 11:51:20 +0000 | [diff] [blame] | 460 | # 6.add_policies function not currently working, using curl commands |
Haibin Huang | 9d72e13 | 2019-05-22 16:20:08 +0800 | [diff] [blame] | 461 | add_policy_models(parameters) |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 462 | |
Haibin Huang | 48dc681 | 2019-05-16 11:51:20 +0000 | [diff] [blame] | 463 | # 7. VFC part |
Haibin Huang | ee3b43d | 2019-05-21 10:53:59 +0800 | [diff] [blame] | 464 | ns_instance_id = create_ns(parameters, ns_package_output) |
Haibin Huang | 169a51b | 2019-05-22 14:39:08 +0800 | [diff] [blame] | 465 | ns_instance_id = "d0ecc83f-339f-4621-b565-07eb9090a379" |
Haibin Huang | ee3b43d | 2019-05-21 10:53:59 +0800 | [diff] [blame] | 466 | print ns_instance_id |
| 467 | instantiate_ns_output = instantiate_ns(parameters, ns_instance_id) |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 468 | print instantiate_ns_output |