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 | 13433a8 | 2019-06-04 16:14:59 +0800 | [diff] [blame] | 214 | def create_service_type(parameters): |
| 215 | create_string = "oclip service-type-create -x {} -m {} -u {} -p {}".format( parameters["service_name"], \ |
| 216 | parameters["aai_url"], parameters["aai_username"], parameters["aai_password"]) |
| 217 | os.system(create_string) |
| 218 | |
| 219 | def create_customer(parameters): |
| 220 | create_string = "oclip customer-create -x {} -y {} -m {} -u {} -p {}".format( parameters["customer_name"], \ |
| 221 | parameters["subscriber_name"], parameters["aai_url"], parameters["aai_username"], parameters["aai_password"]) |
| 222 | os.system(create_string) |
| 223 | |
| 224 | def add_customer_subscription(parameters): |
| 225 | subscription_check = 0 |
| 226 | for cloud_region, cloud_region_values in (parameters["cloud_region_data"]).iteritems(): |
| 227 | if subscription_check == 0 : |
| 228 | subscription_string = "oclip subscription-create -x {} -c {} -z {} -e {} -y {} -r {} -m {} -u {} -p {}".format(\ |
| 229 | parameters["customer_name"], cloud_region_values.get("tenant-id"), parameters["cloud-owner"], parameters["service_name"],\ |
| 230 | cloud_region_values.get("default-tenant"), cloud_region, parameters["aai_url"], parameters["aai_username"], parameters["aai_password"] ) |
| 231 | else: |
| 232 | subscription_string = "oclip subscription-cloud-add -x {} -c {} -z {} -e {} -y {} -r {} -m {} -u {} -p {}".format(\ |
| 233 | parameters["customer_name"], cloud_region_values.get("tenant-id"), parameters["cloud-owner"], parameters["service_name"],\ |
| 234 | cloud_region_values.get("default-tenant"), cloud_region, parameters["aai_url"], parameters["aai_username"], parameters["aai_password"] ) |
| 235 | os.system(subscription_string) |
| 236 | subscription_check+=1 |
| 237 | |
Haibin Huang | 48dc681 | 2019-05-16 11:51:20 +0000 | [diff] [blame] | 238 | def register_vnfm_helper(vnfm_key, values, parameters): |
| 239 | #Create vnfm |
| 240 | vnfm_create_string = 'oclip vnfm-create -b {} -c {} -e {} -v {} -g {} -x {} -i {} -j {} -q {} \ |
| 241 | -m {} -u {} -p {}'.format(vnfm_key, values.get("type"), values.get("vendor"), \ |
| 242 | values.get("version"), values.get("url"), values.get("vim-id"), \ |
| 243 | values.get("user-name"), values.get("user-password"), values.get("vnfm-version"), \ |
| 244 | parameters["aai_url"], parameters["aai_username"], parameters["aai_password"]) |
| 245 | |
| 246 | os.system(vnfm_create_string) |
| 247 | |
| 248 | def register_vnfm(parameters): |
| 249 | vnfm_params = parameters["vnfm_params"] |
| 250 | for vnfm_key, vnfm_values in vnfm_params.iteritems(): |
| 251 | register_vnfm_helper(vnfm_key, vnfm_values, parameters) |
| 252 | |
Haibin Huang | 9d72e13 | 2019-05-22 16:20:08 +0800 | [diff] [blame] | 253 | def add_policy_models(parameters): |
| 254 | mydb = mysql.connector.connect( |
| 255 | host="policydb", |
| 256 | user="policy_user", |
| 257 | passwd="policy_user", |
| 258 | database="onap_sdk", |
| 259 | ) |
Haibin Huang | 48dc681 | 2019-05-16 11:51:20 +0000 | [diff] [blame] | 260 | |
Haibin Huang | 9d72e13 | 2019-05-22 16:20:08 +0800 | [diff] [blame] | 261 | mycursor = mydb.cursor() |
Haibin Huang | d8d2be9 | 2019-05-23 17:06:06 +0800 | [diff] [blame] | 262 | hpa_sql = "INSERT INTO optimizationmodels (modelname, description, dependency, imported_by, \ |
| 263 | attributes, ref_attributes, sub_attributes, version, annotation, enumValues, \ |
| 264 | dataOrderInfo) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" |
| 265 | hpa_val = ('hpaPolicy', 'HPA Tests Model', '[]', 'demo', 'identity=string:defaultValue-null:required-true:MANY-false:description-null', \ |
Haibin Huang | 9d72e13 | 2019-05-22 16:20:08 +0800 | [diff] [blame] | 266 | 'policyScope=MANY-true,policyType=POLICYTYPE:MANY-false,resources=MANY-true,flavorFeatures=flavorFeatures_properties:MANY-true:description-null', \ |
| 267 | '{"directives_properties":{"attributes":"directives_attributes_properties:required-false:MANY-true:description-null",\ |
| 268 | "type":"string:defaultValue-null:required-false:MANY-false:description-null"},\ |
| 269 | "directives_attributes_properties":{"attribute_name":"string:defaultValue-null:required-false:MANY-false:description-null",\ |
| 270 | "attribute_value":"string:defaultValue-null:required-false:MANY-false:description-null"},\ |
| 271 | "flavorProperties_properties":{"score":"string:defaultValue-null:required-false:MANY-false:description-null",\ |
| 272 | "hpa-feature-attributes":"hpa-feature-attributes_properties:required-true:MANY-true:description-null",\ |
| 273 | "directives":"directives_properties:required-true:MANY-true:description-null",\ |
| 274 | "hpa-version":"string:defaultValue-null:required-true:MANY-false:description-null",\ |
| 275 | "hpa-feature":"string:defaultValue-null:required-true:MANY-false:description-null",\ |
| 276 | "mandatory":"string:defaultValue-null:required-true:MANY-false:description-null",\ |
| 277 | "architecture":"string:defaultValue-null:required-true:MANY-false:description-null"},\ |
| 278 | "flavorFeatures_properties":{"directives":"directives_properties:required-true:MANY-true:description-null",\ |
| 279 | "flavorProperties":"flavorProperties_properties:required-true:MANY-true:description-null",\ |
| 280 | "id":"string:defaultValue-null:required-true:MANY-false:description-null",\ |
| 281 | "type":"string:defaultValue-null:required-true:MANY-false:description-null"},\ |
| 282 | "hpa-feature-attributes_properties":{"unit":"string:defaultValue-null:required-false:MANY-false:description-null",\ |
| 283 | "hpa-attribute-value":"string:defaultValue-null:required-true:MANY-false:description-null",\ |
| 284 | "hpa-attribute-key":"string:defaultValue-null:required-true:MANY-false:description-null",\ |
| 285 | "operator":"OPERATOR:defaultValue-null:required-false:MANY-false:description-null"}}', \ |
| 286 | 'test1', 'policyScope=matching-true, policyType=matching-true', \ |
Haibin Huang | d8d2be9 | 2019-05-23 17:06:06 +0800 | [diff] [blame] | 287 | 'OPERATOR=[<,<equal-sign,>,>equal-sign,equal-sign,!equal-sign,any,all,subset,], POLICYTYPE=[hpa,]', '""') |
| 288 | |
| 289 | mycursor.execute(hpa_sql, hpa_val) |
| 290 | |
| 291 | sql = "INSERT INTO microservicemodels (modelname, description, dependency, imported_by, \ |
| 292 | attributes, ref_attributes, sub_attributes, version, annotation, enumValues, \ |
| 293 | dataOrderInfo) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" |
| 294 | val = [ |
Haibin Huang | 9d72e13 | 2019-05-22 16:20:08 +0800 | [diff] [blame] | 295 | ('distancePolicy', 'distancePolicy', '[]', 'demo', 'identity=string:defaultValue-null:required-true:MANY-false:description-null', \ |
| 296 | 'policyScope=MANY-true,distanceProperties=distanceProperties_properties:MANY-false:description-null,policyType=POLICYTYPE:MANY-false,\ |
| 297 | resources=MANY-true,applicableResources=APPLICABLERESOURCES:MANY-false', \ |
| 298 | '{"distanceProperties_properties":{"locationInfo":"string:defaultValue-null:required-true:MANY-false:description-null",\ |
| 299 | "distance":"distance_properties:required-true:MANY-false:description-null"},\ |
| 300 | "distance_properties":{"unit":"UNIT:defaultValue-null:required-true:MANY-false:description-null",\ |
| 301 | "value":"string:defaultValue-null:required-true:MANY-false:description-null","operator":"OPERATOR:defaultValue-null:required-true:MANY-false:description-null"}}', \ |
| 302 | 'test1', 'policyScope=matching-true, policyType=matching-true', \ |
| 303 | 'OPERATOR=[<,<equal-sign,>,>equal-sign,equal-sign,], APPLICABLERESOURCES=[any,all,], POLICYTYPE=[distance_to_location,] ', '""'), |
| 304 | ('optimizationPolicy', 'Optimization policy model', '[]', 'demo', 'identity=string:defaultValue-null:required-true:MANY-false:description-null', \ |
| 305 | 'objectiveParameter=objectiveParameter_properties:MANY-false:description-null,policyScope=MANY-true,policyType=POLICYTYPE:MANY-false,\ |
| 306 | objective=objectiveParameter_properties:MANY-false:description-null', \ |
| 307 | '{"parameterAttributes_properties":{"customerLocationInfo":"string:defaultValue-null:required-true:MANY-false:description-null",\ |
| 308 | "parameter":"string:defaultValue-null:required-true:MANY-false:description-null",\ |
| 309 | "resources":"string:defaultValue-null:required-true:MANY-false:description-null",\ |
| 310 | "weight":"string:defaultValue-null:required-true:MANY-false:description-null",\ |
| 311 | "operator":"OPERATOR:defaultValue-null:required-true:MANY-false:description-null"},\ |
| 312 | "objectiveParameter_properties":{"parameterAttributes":"parameterAttributes_properties:required-true:MANY-true:description-null",\ |
| 313 | "operator":"OPERATOR:defaultValue-null:required-true:MANY-false:description-null"}}', \ |
| 314 | 'test1', 'policyScope=matching-true, policyType=matching-true', 'OPERATOR=[*,+,-,/,%,], POLICYTYPE=[placement_optimization,]', '""'), |
| 315 | ('queryPolicy', 'Query policy model', '[]', 'demo', 'identity=string:defaultValue-null:required-true:MANY-false:description-null', \ |
| 316 | 'policyScope=MANY-true,policyType=POLICYTYPE:MANY-false,queryProperties=queryProperties_properties:MANY-true:description-null', \ |
| 317 | '{"queryProperties_properties":{"attribute_location":"string:defaultValue-null:required-true:MANY-false:description-null",\ |
| 318 | "attribute":"string:defaultValue-null:required-true:MANY-false:description-null","value":"string:defaultValue-null:required-true:MANY-false:description-null"}}', \ |
| 319 | 'test1', 'policyScope=matching-true, policyType=matching-true', 'POLICYTYPE=[request_param_query,]', '""'), |
| 320 | ('vnfPolicy', 'VnfPolicy model', '[]', 'demo', 'identity=string:defaultValue-null:required-true:MANY-false:description-null', \ |
| 321 | 'policyScope=MANY-true,policyType=POLICYTYPE:MANY-false,resources=MANY-true,\ |
| 322 | vnfProperties=vnfProperties_properties:MANY-true:description-null,applicableResources=APPLICABLERESOURCES:MANY-false', \ |
| 323 | '{"vnfProperties_properties":{"serviceType":"string:defaultValue-null:required-true:MANY-false:description-null",\ |
| 324 | "inventoryProvider":"string:defaultValue-null:required-true:MANY-false:description-null",\ |
| 325 | "inventoryType":"INVENTORYTYPE:defaultValue-null:required-true:MANY-false:description-null",\ |
| 326 | "customerId":"string:defaultValue-null:required-true:MANY-false:description-null"}}', \ |
| 327 | 'test1', 'policyScope=matching-true, policyType=matching-true', \ |
| 328 | 'INVENTORYTYPE=[serviceInstanceId,vnfName,cloudRegionId,vimId,], APPLICABLERESOURCES=[any,all,], POLICYTYPE=[vnfPolicy,]', '""'), |
| 329 | ('vim_fit', 'Capacity policy model', '[]', 'demo', 'identity=string:defaultValue-null:required-true:MANY-false:description-null', \ |
| 330 | 'policyScope=MANY-true,policyType=POLICYTYPE:MANY-false,capacityProperties=capacityProperties_properties:MANY-false:description-null,\ |
| 331 | resources=MANY-true,applicableResources=APPLICABLERESOURCES:MANY-false', \ |
| 332 | '{"capacityProperties_properties":{"request":"string:defaultValue-null:required-true:MANY-false:description-null",\ |
| 333 | "controller":"string:defaultValue-null:required-true:MANY-false:description-null"}}', \ |
| 334 | 'test1', 'policyScope=matching-true, policyType=matching-true ', ' APPLICABLERESOURCES=[any,all,], POLICYTYPE=[vim_fit,]', '""'), |
| 335 | ('affinityPolicy', 'Affinity policy model', '[]', 'demo', 'identity=string:defaultValue-null:required-true:MANY-false:description-null', \ |
| 336 | 'policyScope=MANY-true,policyType=POLICYTYPE:MANY-false,affinityProperties=affinityProperties_properties:MANY-false:description-null,\ |
| 337 | resources=MANY-true,applicableResources=APPLICABLERESOURCES:MANY-false', \ |
| 338 | '{"affinityProperties_properties":{"qualifier":"QUALIFIER:defaultValue-null:required-true:MANY-false:description-null",\ |
| 339 | "category":"string:defaultValue-null:required-true:MANY-false:description-null"}}', \ |
| 340 | 'test1', 'policyScope=matching-true, policyType=matching-true ', ' APPLICABLERESOURCES=[any,all,], POLICYTYPE=[zone,], QUALIFIER=[same,different,]', '""'), |
| 341 | ('pciPolicy', 'Pci policy model', '[]', 'demo', 'identity=string:defaultValue-null:required-true:MANY-false:description-null', \ |
| 342 | 'policyScope=MANY-true,policyType=POLICYTYPE:MANY-false,resources=MANY-true,pciProperties=pciProperties_properties:MANY-true:description-null', \ |
| 343 | '{"pciProperties_properties":{"pciOptimizationTimeConstraint":"string:defaultValue-null:required-false:MANY-false:description-null",\ |
| 344 | "pciOptimizationNwConstraint":"string:defaultValue-null:required-false:MANY-false:description-null",\ |
| 345 | "algoCategory":"string:defaultValue-null:required-false:MANY-false:description-null",\ |
| 346 | "pciOptmizationAlgoName":"string:defaultValue-null:required-false:MANY-false:description-null",\ |
| 347 | "pciOptimizationPriority":"string:defaultValue-null:required-false:MANY-false:description-null"}}', \ |
| 348 | 'test1', 'olicyScope=matching-true, policyType=matching-true ', ' POLICYTYPE=[pciPolicy,]', '""'), |
| 349 | ('subscriberPolicy', 'Subscriber Policy Model', '[]', 'demo', 'identity=string:defaultValue-null:required-true:MANY-false:description-null', \ |
| 350 | 'policyScope=MANY-true,policyType=POLICYTYPE:MANY-false,properties=properties_properties:MANY-false:description-type of a policy', \ |
| 351 | '{"properties_properties":{"provStatus":"PROVSTATUS:defaultValue-null:required-true:MANY-false:description-null",\ |
| 352 | "subscriberName":"SUBSCRIBERNAME:defaultValue-null:required-true:MANY-false:description-null",\ |
| 353 | "subscriberRole":"SUBSCRIBERROLE:defaultValue-null:required-true:MANY-false:description-null"}}', \ |
| 354 | 'test1', 'policyScope=matching-true, policyType=matching-true, properties=matching-true ', \ |
| 355 | ' SUBSCRIBERNAME=[], SUBSCRIBERROLE=[], POLICYTYPE=[subscriberPolicy,], PROVSTATUS=[]', '""') |
| 356 | ] |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 357 | |
Haibin Huang | 9d72e13 | 2019-05-22 16:20:08 +0800 | [diff] [blame] | 358 | mycursor.executemany(sql, val) |
| 359 | mydb.commit() |
| 360 | print(mycursor.rowcount, "was inserted.") |
Haibin Huang | d8d2be9 | 2019-05-23 17:06:06 +0800 | [diff] [blame] | 361 | |
| 362 | def add_policies(parameters): |
| 363 | #Loop through policy, put in resource_model_name and create policies |
| 364 | for policy in os.listdir(parameters["policy_directory"]): |
| 365 | policy_name = "{}.{}".format(parameters["policy_scope"], os.path.splitext(policy)[0]) |
| 366 | policy_file = (os.path.join(parameters["policy_directory"], policy)) |
| 367 | #Create policy |
| 368 | os.system("oclip policy-create-outdated -m {} -u {} -p {} -x {} -S {} -T {} -o {} -b $(cat {})".format(parameters["policy_url"],\ |
| 369 | parameters["policy_username"], parameters["policy_password"], policy_name, parameters["policy_scope"], \ |
| 370 | parameters["policy_config_type"], parameters["policy_onapName"], policy_file)) |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 371 | |
Haibin Huang | d8d2be9 | 2019-05-23 17:06:06 +0800 | [diff] [blame] | 372 | #Push policy |
| 373 | os.system("oclip policy-push-outdated -m {} -u {} -p {} -x {} -b {} -c {}".format(parameters["policy_url"], \ |
| 374 | parameters["policy_username"], parameters["policy_password"], policy_name, parameters["policy_config_type"],\ |
| 375 | parameters["policy_pdp_group"])) |
| 376 | |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 377 | def onboard_vnf(parameters): |
Haibin Huang | ee3b43d | 2019-05-21 10:53:59 +0800 | [diff] [blame] | 378 | vnfs = parameters["vnfs"] |
| 379 | vnf_onboard_outputs = {} |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 380 | |
Haibin Huang | ee3b43d | 2019-05-21 10:53:59 +0800 | [diff] [blame] | 381 | for key, value in vnfs.items(): |
| 382 | vnf_onboard_string = 'oclip vfc-catalog-onboard-vnf -c {}'.format(value.get("csar-id")) |
| 383 | vnf_onboard_outs[key] = (os.popen(ns_onboard_string)).read() |
| 384 | return vnf_onboard_outputs |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 385 | |
| 386 | def onboard_ns(parameters): |
| 387 | ns_onboard_string = 'oclip vfc-catalog-onboard-ns -c {}'.format(parameters["ns-csar-id"]) |
| 388 | ns_onboard_out = (os.popen(ns_onboard_string)).read() |
| 389 | return ns_onboard_out |
| 390 | |
Haibin Huang | ee3b43d | 2019-05-21 10:53:59 +0800 | [diff] [blame] | 391 | def create_ns(parameters, csar_id): |
| 392 | ns = parameters["ns"] |
Haibin Huang | 13433a8 | 2019-06-04 16:14:59 +0800 | [diff] [blame] | 393 | ns_create_string = 'oclip vfc-nslcm-create -m {} -c {} -n {} -q {} -S {}'.format(parameters["vfc-url"], \ |
| 394 | csar_id, ns.get("name"), parameters["customer_name"], parameters["service_name"]) |
Haibin Huang | ee3b43d | 2019-05-21 10:53:59 +0800 | [diff] [blame] | 395 | print ns_create_string |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 396 | ns_create_out = (os.popen(ns_create_string)).read() |
Haibin Huang | ee3b43d | 2019-05-21 10:53:59 +0800 | [diff] [blame] | 397 | print ns_create_out |
| 398 | ns_instance_id = (get_out_helper_2(ns_create_out))[3] |
| 399 | return ns_instance_id |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 400 | |
Haibin Huang | ee3b43d | 2019-05-21 10:53:59 +0800 | [diff] [blame] | 401 | def instantiate_ns(parameters, ns_instance_id): |
| 402 | ns_instantiate_string = 'oclip vfc-nslcm-instantiate -m {} -i {} -c {} -n {}'.format(parameters["vfc-url"], \ |
| 403 | ns_instance_id, parameters["location"], parameters["sdc-controller-id"]) |
| 404 | print ns_instantiate_string |
| 405 | |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 406 | ns_instantiate_out = (os.popen(ns_instantiate_string)).read() |
| 407 | return ns_instantiate_out |
| 408 | |
Haibin Huang | ee3b43d | 2019-05-21 10:53:59 +0800 | [diff] [blame] | 409 | def create_ns_package(parameters): |
| 410 | ns = parameters["ns"] |
| 411 | create_ns_string = 'oclip vfc-catalog-create-ns -m {} -c {} -e {}'.format(parameters["vfc-url"], \ |
| 412 | ns.get("key"), ns.get("value")) |
| 413 | cmd_out = (os.popen(create_ns_string)).read() |
| 414 | out_list = get_out_helper_2(cmd_out) |
| 415 | return out_list[4] |
| 416 | |
| 417 | def create_vnf_package(parameters): |
| 418 | vnfs = parameters["vnfs"] |
| 419 | outputs = {} |
| 420 | |
| 421 | for vnf_key, vnf_values in vnfs.iteritems(): |
| 422 | create_vnf_string = 'oclip vfc-catalog-create-vnf -m {} -c {} -e {}'.format(parameters["vfc-url"], \ |
| 423 | vnf_values.get("key"), vnf_values.get("value")) |
| 424 | cmd_out = (os.popen(create_vnf_string)).read() |
| 425 | out_list = get_out_helper_2(cmd_out) |
| 426 | outputs[vnf_key] = out_list[4] |
| 427 | |
| 428 | return outputs |
| 429 | |
| 430 | def upload_ns_package(parameters, ns_package_output): |
| 431 | ns = parameters["ns"] |
| 432 | ns_upload_string = '{}/api/nsd/v1/ns_descriptors/{}/nsd_content'.format(parameters["vfc-url"], ns_package_output) |
| 433 | print ns_upload_string |
| 434 | print ns.get("path") |
| 435 | resp = requests.put(ns_upload_string, files={'file': open(ns.get("path"), 'rb')}) |
| 436 | return resp |
| 437 | |
| 438 | def upload_vnf_package(parameters, vnf_package_output): |
| 439 | vnfs = parameters["vnfs"] |
| 440 | for vnf_key, vnf_values in vnfs.iteritems(): |
| 441 | vnf_upload_str = '{}/api/vnfpkgm/v1/vnf_packages/{}/package_content'.format(parameters["vfc-url"], \ |
| 442 | vnf_package_output[vnf_key], vnf_package_output[vnf_key]) |
| 443 | resp = requests.put(vnf_upload_str, files={'file': open(vnf_values.get("path"), 'rb')}) |
| 444 | return resp |
| 445 | |
| 446 | |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 447 | #Run Functions |
| 448 | parser = argparse.ArgumentParser() |
| 449 | 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] | 450 | 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] | 451 | |
| 452 | parser.add_argument('--version', action='version', version='%(prog)s 1.0') |
| 453 | |
| 454 | results = parser.parse_args() |
| 455 | |
| 456 | config_file_path = results.config_file_path |
Haibin Huang | 169a51b | 2019-05-22 14:39:08 +0800 | [diff] [blame] | 457 | model = results.model |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 458 | if config_file_path is None: |
| 459 | sys.exit(1) |
| 460 | config_file = open(config_file_path) |
| 461 | parameters = get_parameters(config_file) |
| 462 | |
| 463 | # 1.Set cli command envionment |
| 464 | set_open_cli_env(parameters) |
| 465 | |
| 466 | # 2.Create cloud complex |
| 467 | create_complex(parameters) |
| 468 | |
Haibin Huang | 13433a8 | 2019-06-04 16:14:59 +0800 | [diff] [blame] | 469 | # 3.1 Register all clouds |
Haibin Huang | 48dc681 | 2019-05-16 11:51:20 +0000 | [diff] [blame] | 470 | register_all_clouds(parameters) |
| 471 | |
Haibin Huang | 13433a8 | 2019-06-04 16:14:59 +0800 | [diff] [blame] | 472 | # 3.2 create service and customer |
| 473 | create_service_type(parameters) |
| 474 | create_customer(parameters) |
| 475 | add_customer_subscription(parameters) |
| 476 | |
Haibin Huang | 48dc681 | 2019-05-16 11:51:20 +0000 | [diff] [blame] | 477 | # 4.Register vnfm |
| 478 | register_vnfm(parameters) |
| 479 | |
Haibin Huang | ee3b43d | 2019-05-21 10:53:59 +0800 | [diff] [blame] | 480 | # 5.create csar file |
| 481 | # 5.1 upload csar file to catalog |
| 482 | # 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] | 483 | # SDC output data model is not align with VFC, we use an workaround method |
| 484 | # We just do run time automation |
Haibin Huang | ee3b43d | 2019-05-21 10:53:59 +0800 | [diff] [blame] | 485 | ns_package_output = "" |
| 486 | |
Haibin Huang | 169a51b | 2019-05-22 14:39:08 +0800 | [diff] [blame] | 487 | if model == "sdc": |
Haibin Huang | ee3b43d | 2019-05-21 10:53:59 +0800 | [diff] [blame] | 488 | print "use csar file is distributed by sdc" |
Haibin Huang | 13433a8 | 2019-06-04 16:14:59 +0800 | [diff] [blame] | 489 | # output = create_vlm(parameters) |
| 490 | # vsp_dict = create_vsp(parameters, output) |
| 491 | # vf_dict = create_vf_model(parameters, vsp_dict) |
| 492 | # service_model_list = create_service_model(parameters, vf_dict) |
| 493 | |
Haibin Huang | 169a51b | 2019-05-22 14:39:08 +0800 | [diff] [blame] | 494 | vnf_onboard_output = onboard_vnf(parameters) |
| 495 | print vnf_onboard_output |
| 496 | ns_onboard_out = onboard_ns(parameters) |
| 497 | print ns_onboard_out |
Haibin Huang | ee3b43d | 2019-05-21 10:53:59 +0800 | [diff] [blame] | 498 | else: |
| 499 | print "use csar file is uploaded by local" |
| 500 | vnf_package_output = create_vnf_package(parameters) |
| 501 | print vnf_package_output |
| 502 | ns_package_output = create_ns_package(parameters) |
| 503 | print ns_package_output |
| 504 | upload_vnf_out = upload_vnf_package(parameters, vnf_package_output) |
| 505 | print upload_vnf_out |
| 506 | upload_ns_out = upload_ns_package(parameters, ns_package_output) |
| 507 | print upload_ns_out |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 508 | |
Haibin Huang | 48dc681 | 2019-05-16 11:51:20 +0000 | [diff] [blame] | 509 | # 6.add_policies function not currently working, using curl commands |
Haibin Huang | 9d72e13 | 2019-05-22 16:20:08 +0800 | [diff] [blame] | 510 | add_policy_models(parameters) |
Haibin Huang | d8d2be9 | 2019-05-23 17:06:06 +0800 | [diff] [blame] | 511 | add_policies(parameters) |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 512 | |
Haibin Huang | 48dc681 | 2019-05-16 11:51:20 +0000 | [diff] [blame] | 513 | # 7. VFC part |
Haibin Huang | ee3b43d | 2019-05-21 10:53:59 +0800 | [diff] [blame] | 514 | ns_instance_id = create_ns(parameters, ns_package_output) |
| 515 | print ns_instance_id |
| 516 | instantiate_ns_output = instantiate_ns(parameters, ns_instance_id) |
Haibin Huang | 9b51423 | 2019-05-09 14:36:05 +0800 | [diff] [blame] | 517 | print instantiate_ns_output |