blob: ac6a161d24b5fe3e31d30b35babe3d16cb057e5e [file] [log] [blame]
Haibin Huang9b514232019-05-09 14:36:05 +08001#!/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)
Pratik Rajafe83ec2020-06-06 21:59:32 +05306#Install python mysql.connector (pip install --no-cache-dir mysql-connector-python)
Haibin Huang9b514232019-05-09 14:36:05 +08007#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
15import json
16import os
Haibin Huang9b514232019-05-09 14:36:05 +080017import argparse
18import sys
Haibin Huangee3b43d2019-05-21 10:53:59 +080019import requests
Haibin Huang9d72e132019-05-22 16:20:08 +080020import mysql.connector
Haibin Huang9b514232019-05-09 14:36:05 +080021
22def get_parameters(file):
23 parameters = json.load(file)
24 return parameters
25
26def get_out_helper(in_string):
27 out_list = (((in_string.replace('-','')).replace('|', '')).replace('+', '')).split()
28 return out_list
29
30def get_out_helper_2(in_string):
31 out_list = ((in_string.replace('|', '')).replace('+', '')).split()
32 return out_list
33
34def 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
38def 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 Huang169a51b2019-05-22 14:39:08 +080051def 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
92def create_vsp(parameters, in_list):
93 vnfs = parameters["vnf"]
yangyan50fce382019-09-20 15:47:40 +080094 vsp_ids = {}
Haibin Huang169a51b2019-05-22 14:39:08 +080095 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], \
yangyan50fce382019-09-20 15:47:40 +080097 parameters["onboarding-method"], parameters["vendor-name"], value.get("vsp-name"), value.get("vsp-desc"), in_list[1], \
Haibin Huang169a51b2019-05-22 14:39:08 +080098 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
119def 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
147def 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 Huang9b514232019-05-09 14:36:05 +0800183
184def 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
208def 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 Huang13433a82019-06-04 16:14:59 +0800213def create_service_type(parameters):
214 create_string = "oclip service-type-create -x {} -m {} -u {} -p {}".format( parameters["service_name"], \
215 parameters["aai_url"], parameters["aai_username"], parameters["aai_password"])
216 os.system(create_string)
217
218def create_customer(parameters):
219 create_string = "oclip customer-create -x {} -y {} -m {} -u {} -p {}".format( parameters["customer_name"], \
220 parameters["subscriber_name"], parameters["aai_url"], parameters["aai_username"], parameters["aai_password"])
221 os.system(create_string)
222
223def add_customer_subscription(parameters):
224 subscription_check = 0
225 for cloud_region, cloud_region_values in (parameters["cloud_region_data"]).iteritems():
Pratik Rajafe83ec2020-06-06 21:59:32 +0530226 if subscription_check == 0 :
227 subscription_string = "oclip subscription-create -x {} -c {} -z {} -e {} -y {} -r {} -m {} -u {} -p {}".format(\
228 parameters["customer_name"], cloud_region_values.get("tenant-id"), parameters["cloud-owner"], parameters["service_name"],\
229 cloud_region_values.get("default-tenant"), cloud_region, parameters["aai_url"], parameters["aai_username"], parameters["aai_password"] )
230 else:
231 subscription_string = "oclip subscription-cloud-add -x {} -c {} -z {} -e {} -y {} -r {} -m {} -u {} -p {}".format(\
232 parameters["customer_name"], cloud_region_values.get("tenant-id"), parameters["cloud-owner"], parameters["service_name"],\
233 cloud_region_values.get("default-tenant"), cloud_region, parameters["aai_url"], parameters["aai_username"], parameters["aai_password"] )
234 os.system(subscription_string)
235 subscription_check+=1
Haibin Huang13433a82019-06-04 16:14:59 +0800236
Haibin Huang48dc6812019-05-16 11:51:20 +0000237def register_vnfm_helper(vnfm_key, values, parameters):
238 #Create vnfm
239 vnfm_create_string = 'oclip vnfm-create -b {} -c {} -e {} -v {} -g {} -x {} -i {} -j {} -q {} \
240 -m {} -u {} -p {}'.format(vnfm_key, values.get("type"), values.get("vendor"), \
241 values.get("version"), values.get("url"), values.get("vim-id"), \
242 values.get("user-name"), values.get("user-password"), values.get("vnfm-version"), \
243 parameters["aai_url"], parameters["aai_username"], parameters["aai_password"])
244
245 os.system(vnfm_create_string)
246
247def register_vnfm(parameters):
248 vnfm_params = parameters["vnfm_params"]
249 for vnfm_key, vnfm_values in vnfm_params.iteritems():
250 register_vnfm_helper(vnfm_key, vnfm_values, parameters)
251
Pratik Rajafe83ec2020-06-06 21:59:32 +0530252def add_policy_models():
Haibin Huang9d72e132019-05-22 16:20:08 +0800253 mydb = mysql.connector.connect(
254 host="policydb",
255 user="policy_user",
256 passwd="policy_user",
257 database="onap_sdk",
258 )
Haibin Huang48dc6812019-05-16 11:51:20 +0000259
Haibin Huang9d72e132019-05-22 16:20:08 +0800260 mycursor = mydb.cursor()
Haibin Huangd8d2be92019-05-23 17:06:06 +0800261 hpa_sql = "INSERT INTO optimizationmodels (modelname, description, dependency, imported_by, \
262 attributes, ref_attributes, sub_attributes, version, annotation, enumValues, \
263 dataOrderInfo) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
264 hpa_val = ('hpaPolicy', 'HPA Tests Model', '[]', 'demo', 'identity=string:defaultValue-null:required-true:MANY-false:description-null', \
Haibin Huang9d72e132019-05-22 16:20:08 +0800265 'policyScope=MANY-true,policyType=POLICYTYPE:MANY-false,resources=MANY-true,flavorFeatures=flavorFeatures_properties:MANY-true:description-null', \
266 '{"directives_properties":{"attributes":"directives_attributes_properties:required-false:MANY-true:description-null",\
267 "type":"string:defaultValue-null:required-false:MANY-false:description-null"},\
268 "directives_attributes_properties":{"attribute_name":"string:defaultValue-null:required-false:MANY-false:description-null",\
269 "attribute_value":"string:defaultValue-null:required-false:MANY-false:description-null"},\
270 "flavorProperties_properties":{"score":"string:defaultValue-null:required-false:MANY-false:description-null",\
271 "hpa-feature-attributes":"hpa-feature-attributes_properties:required-true:MANY-true:description-null",\
272 "directives":"directives_properties:required-true:MANY-true:description-null",\
273 "hpa-version":"string:defaultValue-null:required-true:MANY-false:description-null",\
274 "hpa-feature":"string:defaultValue-null:required-true:MANY-false:description-null",\
275 "mandatory":"string:defaultValue-null:required-true:MANY-false:description-null",\
276 "architecture":"string:defaultValue-null:required-true:MANY-false:description-null"},\
277 "flavorFeatures_properties":{"directives":"directives_properties:required-true:MANY-true:description-null",\
278 "flavorProperties":"flavorProperties_properties:required-true:MANY-true:description-null",\
279 "id":"string:defaultValue-null:required-true:MANY-false:description-null",\
280 "type":"string:defaultValue-null:required-true:MANY-false:description-null"},\
281 "hpa-feature-attributes_properties":{"unit":"string:defaultValue-null:required-false:MANY-false:description-null",\
282 "hpa-attribute-value":"string:defaultValue-null:required-true:MANY-false:description-null",\
283 "hpa-attribute-key":"string:defaultValue-null:required-true:MANY-false:description-null",\
284 "operator":"OPERATOR:defaultValue-null:required-false:MANY-false:description-null"}}', \
285 'test1', 'policyScope=matching-true, policyType=matching-true', \
Haibin Huangd8d2be92019-05-23 17:06:06 +0800286 'OPERATOR=[<,<equal-sign,>,>equal-sign,equal-sign,!equal-sign,any,all,subset,], POLICYTYPE=[hpa,]', '""')
287
288 mycursor.execute(hpa_sql, hpa_val)
Bartek Grzybowski2ee028b2020-03-05 14:35:29 +0100289
Haibin Huangd8d2be92019-05-23 17:06:06 +0800290 sql = "INSERT INTO microservicemodels (modelname, description, dependency, imported_by, \
291 attributes, ref_attributes, sub_attributes, version, annotation, enumValues, \
292 dataOrderInfo) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
293 val = [
Haibin Huang9d72e132019-05-22 16:20:08 +0800294 ('distancePolicy', 'distancePolicy', '[]', 'demo', 'identity=string:defaultValue-null:required-true:MANY-false:description-null', \
295 'policyScope=MANY-true,distanceProperties=distanceProperties_properties:MANY-false:description-null,policyType=POLICYTYPE:MANY-false,\
296 resources=MANY-true,applicableResources=APPLICABLERESOURCES:MANY-false', \
297 '{"distanceProperties_properties":{"locationInfo":"string:defaultValue-null:required-true:MANY-false:description-null",\
298 "distance":"distance_properties:required-true:MANY-false:description-null"},\
299 "distance_properties":{"unit":"UNIT:defaultValue-null:required-true:MANY-false:description-null",\
300 "value":"string:defaultValue-null:required-true:MANY-false:description-null","operator":"OPERATOR:defaultValue-null:required-true:MANY-false:description-null"}}', \
301 'test1', 'policyScope=matching-true, policyType=matching-true', \
302 'OPERATOR=[<,<equal-sign,>,>equal-sign,equal-sign,], APPLICABLERESOURCES=[any,all,], POLICYTYPE=[distance_to_location,] ', '""'),
303 ('optimizationPolicy', 'Optimization policy model', '[]', 'demo', 'identity=string:defaultValue-null:required-true:MANY-false:description-null', \
304 'objectiveParameter=objectiveParameter_properties:MANY-false:description-null,policyScope=MANY-true,policyType=POLICYTYPE:MANY-false,\
305 objective=objectiveParameter_properties:MANY-false:description-null', \
306 '{"parameterAttributes_properties":{"customerLocationInfo":"string:defaultValue-null:required-true:MANY-false:description-null",\
307 "parameter":"string:defaultValue-null:required-true:MANY-false:description-null",\
308 "resources":"string:defaultValue-null:required-true:MANY-false:description-null",\
309 "weight":"string:defaultValue-null:required-true:MANY-false:description-null",\
310 "operator":"OPERATOR:defaultValue-null:required-true:MANY-false:description-null"},\
311 "objectiveParameter_properties":{"parameterAttributes":"parameterAttributes_properties:required-true:MANY-true:description-null",\
312 "operator":"OPERATOR:defaultValue-null:required-true:MANY-false:description-null"}}', \
313 'test1', 'policyScope=matching-true, policyType=matching-true', 'OPERATOR=[*,+,-,/,%,], POLICYTYPE=[placement_optimization,]', '""'),
314 ('queryPolicy', 'Query policy model', '[]', 'demo', 'identity=string:defaultValue-null:required-true:MANY-false:description-null', \
315 'policyScope=MANY-true,policyType=POLICYTYPE:MANY-false,queryProperties=queryProperties_properties:MANY-true:description-null', \
316 '{"queryProperties_properties":{"attribute_location":"string:defaultValue-null:required-true:MANY-false:description-null",\
317 "attribute":"string:defaultValue-null:required-true:MANY-false:description-null","value":"string:defaultValue-null:required-true:MANY-false:description-null"}}', \
318 'test1', 'policyScope=matching-true, policyType=matching-true', 'POLICYTYPE=[request_param_query,]', '""'),
319 ('vnfPolicy', 'VnfPolicy model', '[]', 'demo', 'identity=string:defaultValue-null:required-true:MANY-false:description-null', \
320 'policyScope=MANY-true,policyType=POLICYTYPE:MANY-false,resources=MANY-true,\
321 vnfProperties=vnfProperties_properties:MANY-true:description-null,applicableResources=APPLICABLERESOURCES:MANY-false', \
322 '{"vnfProperties_properties":{"serviceType":"string:defaultValue-null:required-true:MANY-false:description-null",\
323 "inventoryProvider":"string:defaultValue-null:required-true:MANY-false:description-null",\
324 "inventoryType":"INVENTORYTYPE:defaultValue-null:required-true:MANY-false:description-null",\
325 "customerId":"string:defaultValue-null:required-true:MANY-false:description-null"}}', \
326 'test1', 'policyScope=matching-true, policyType=matching-true', \
327 'INVENTORYTYPE=[serviceInstanceId,vnfName,cloudRegionId,vimId,], APPLICABLERESOURCES=[any,all,], POLICYTYPE=[vnfPolicy,]', '""'),
328 ('vim_fit', 'Capacity policy model', '[]', 'demo', 'identity=string:defaultValue-null:required-true:MANY-false:description-null', \
329 'policyScope=MANY-true,policyType=POLICYTYPE:MANY-false,capacityProperties=capacityProperties_properties:MANY-false:description-null,\
330 resources=MANY-true,applicableResources=APPLICABLERESOURCES:MANY-false', \
331 '{"capacityProperties_properties":{"request":"string:defaultValue-null:required-true:MANY-false:description-null",\
332 "controller":"string:defaultValue-null:required-true:MANY-false:description-null"}}', \
333 'test1', 'policyScope=matching-true, policyType=matching-true ', ' APPLICABLERESOURCES=[any,all,], POLICYTYPE=[vim_fit,]', '""'),
334 ('affinityPolicy', 'Affinity policy model', '[]', 'demo', 'identity=string:defaultValue-null:required-true:MANY-false:description-null', \
335 'policyScope=MANY-true,policyType=POLICYTYPE:MANY-false,affinityProperties=affinityProperties_properties:MANY-false:description-null,\
336 resources=MANY-true,applicableResources=APPLICABLERESOURCES:MANY-false', \
337 '{"affinityProperties_properties":{"qualifier":"QUALIFIER:defaultValue-null:required-true:MANY-false:description-null",\
338 "category":"string:defaultValue-null:required-true:MANY-false:description-null"}}', \
339 'test1', 'policyScope=matching-true, policyType=matching-true ', ' APPLICABLERESOURCES=[any,all,], POLICYTYPE=[zone,], QUALIFIER=[same,different,]', '""'),
340 ('pciPolicy', 'Pci policy model', '[]', 'demo', 'identity=string:defaultValue-null:required-true:MANY-false:description-null', \
341 'policyScope=MANY-true,policyType=POLICYTYPE:MANY-false,resources=MANY-true,pciProperties=pciProperties_properties:MANY-true:description-null', \
342 '{"pciProperties_properties":{"pciOptimizationTimeConstraint":"string:defaultValue-null:required-false:MANY-false:description-null",\
343 "pciOptimizationNwConstraint":"string:defaultValue-null:required-false:MANY-false:description-null",\
344 "algoCategory":"string:defaultValue-null:required-false:MANY-false:description-null",\
345 "pciOptmizationAlgoName":"string:defaultValue-null:required-false:MANY-false:description-null",\
346 "pciOptimizationPriority":"string:defaultValue-null:required-false:MANY-false:description-null"}}', \
347 'test1', 'olicyScope=matching-true, policyType=matching-true ', ' POLICYTYPE=[pciPolicy,]', '""'),
348 ('subscriberPolicy', 'Subscriber Policy Model', '[]', 'demo', 'identity=string:defaultValue-null:required-true:MANY-false:description-null', \
349 'policyScope=MANY-true,policyType=POLICYTYPE:MANY-false,properties=properties_properties:MANY-false:description-type of a policy', \
350 '{"properties_properties":{"provStatus":"PROVSTATUS:defaultValue-null:required-true:MANY-false:description-null",\
351 "subscriberName":"SUBSCRIBERNAME:defaultValue-null:required-true:MANY-false:description-null",\
352 "subscriberRole":"SUBSCRIBERROLE:defaultValue-null:required-true:MANY-false:description-null"}}', \
353 'test1', 'policyScope=matching-true, policyType=matching-true, properties=matching-true ', \
354 ' SUBSCRIBERNAME=[], SUBSCRIBERROLE=[], POLICYTYPE=[subscriberPolicy,], PROVSTATUS=[]', '""')
355 ]
Haibin Huang9b514232019-05-09 14:36:05 +0800356
Haibin Huang9d72e132019-05-22 16:20:08 +0800357 mycursor.executemany(sql, val)
358 mydb.commit()
359 print(mycursor.rowcount, "was inserted.")
Bartek Grzybowski2ee028b2020-03-05 14:35:29 +0100360
Haibin Huangd8d2be92019-05-23 17:06:06 +0800361def add_policies(parameters):
362 #Loop through policy, put in resource_model_name and create policies
363 for policy in os.listdir(parameters["policy_directory"]):
Pratik Rajafe83ec2020-06-06 21:59:32 +0530364 policy_name = "{}.{}".format(parameters["policy_scope"], os.path.splitext(policy)[0])
365 policy_file = (os.path.join(parameters["policy_directory"], policy))
366 # Create policy
367 os.system("oclip policy-create-outdated -m {} -u {} -p {} -x {} -S {} -T {} -o {} -b $(cat {})".format(parameters["policy_url"],\
368 parameters["policy_username"], parameters["policy_password"], policy_name, parameters["policy_scope"], \
369 parameters["policy_config_type"], parameters["policy_onapName"], policy_file))
Haibin Huang9b514232019-05-09 14:36:05 +0800370
Pratik Rajafe83ec2020-06-06 21:59:32 +0530371 # Push policy
372 os.system("oclip policy-push-outdated -m {} -u {} -p {} -x {} -b {} -c {}".format(parameters["policy_url"], \
Haibin Huangd8d2be92019-05-23 17:06:06 +0800373 parameters["policy_username"], parameters["policy_password"], policy_name, parameters["policy_config_type"],\
374 parameters["policy_pdp_group"]))
yangyan85c07282019-09-09 15:27:31 +0800375
Haibin Huang9b514232019-05-09 14:36:05 +0800376def onboard_vnf(parameters):
Haibin Huangee3b43d2019-05-21 10:53:59 +0800377 vnfs = parameters["vnfs"]
378 vnf_onboard_outputs = {}
Haibin Huang9b514232019-05-09 14:36:05 +0800379
Haibin Huangee3b43d2019-05-21 10:53:59 +0800380 for key, value in vnfs.items():
yangyan85c07282019-09-09 15:27:31 +0800381 vnf_onboard_string = 'oclip vfc-catalog-onboard-vnf -m {} -c {}'\
382 .format(value.get("url"), value.get("csar-id"))
yangyanf1d460a2019-09-09 10:00:23 +0800383 vnf_onboard_outputs[key] = (os.popen(vnf_onboard_string)).read()
Haibin Huangee3b43d2019-05-21 10:53:59 +0800384 return vnf_onboard_outputs
Haibin Huang9b514232019-05-09 14:36:05 +0800385
386def onboard_ns(parameters):
yangyan6a5ec682019-09-09 15:32:43 +0800387 ns_onboard_string = 'oclip vfc-catalog-onboard-ns -m {} -c {}'.format(parameters["ns"]["url"],
388 parameters["ns"]["csar-id"])
Haibin Huang9b514232019-05-09 14:36:05 +0800389 ns_onboard_out = (os.popen(ns_onboard_string)).read()
390 return ns_onboard_out
391
Haibin Huangee3b43d2019-05-21 10:53:59 +0800392def create_ns(parameters, csar_id):
393 ns = parameters["ns"]
Haibin Huang13433a82019-06-04 16:14:59 +0800394 ns_create_string = 'oclip vfc-nslcm-create -m {} -c {} -n {} -q {} -S {}'.format(parameters["vfc-url"], \
395 csar_id, ns.get("name"), parameters["customer_name"], parameters["service_name"])
Bartek Grzybowski2ee028b2020-03-05 14:35:29 +0100396 print(ns_create_string)
Haibin Huang9b514232019-05-09 14:36:05 +0800397 ns_create_out = (os.popen(ns_create_string)).read()
Bartek Grzybowski2ee028b2020-03-05 14:35:29 +0100398 print(ns_create_out)
yangyandd95f022019-09-10 12:11:10 +0800399 ns_instance_id = (get_out_helper_2(ns_create_out))[4]
Haibin Huangee3b43d2019-05-21 10:53:59 +0800400 return ns_instance_id
Haibin Huang9b514232019-05-09 14:36:05 +0800401
Haibin Huangee3b43d2019-05-21 10:53:59 +0800402def instantiate_ns(parameters, ns_instance_id):
403 ns_instantiate_string = 'oclip vfc-nslcm-instantiate -m {} -i {} -c {} -n {}'.format(parameters["vfc-url"], \
404 ns_instance_id, parameters["location"], parameters["sdc-controller-id"])
Bartek Grzybowski2ee028b2020-03-05 14:35:29 +0100405 print(ns_instantiate_string)
Haibin Huangee3b43d2019-05-21 10:53:59 +0800406
Haibin Huang9b514232019-05-09 14:36:05 +0800407 ns_instantiate_out = (os.popen(ns_instantiate_string)).read()
408 return ns_instantiate_out
409
yangyan43fdf7b2019-09-24 10:51:44 +0800410def terminate_ns(parameters, ns_instance_id):
411 ns_terminate_string = 'oclip vfc-nslcm-terminate -m {} -i {}'.format(parameters["vfc-url"], ns_instance_id)
Bartek Grzybowski2ee028b2020-03-05 14:35:29 +0100412 print(ns_terminate_string)
yangyan43fdf7b2019-09-24 10:51:44 +0800413 ns_terminate_out = (os.popen(ns_terminate_string)).read()
Bartek Grzybowski2ee028b2020-03-05 14:35:29 +0100414 print(ns_terminate_out)
yangyan43fdf7b2019-09-24 10:51:44 +0800415 return ns_terminate_out
416
417def delete_ns(parameters, ns_instance_id):
418 ns_delete_string = 'oclip vfc-nslcm-delete -m {} -c {}'.format(parameters["vfc-url"], ns_instance_id)
Bartek Grzybowski2ee028b2020-03-05 14:35:29 +0100419 print(ns_delete_string)
yangyan43fdf7b2019-09-24 10:51:44 +0800420 ns_delete_out = (os.popen(ns_delete_string)).read()
421 return ns_delete_out
422
Haibin Huangee3b43d2019-05-21 10:53:59 +0800423def create_ns_package(parameters):
424 ns = parameters["ns"]
425 create_ns_string = 'oclip vfc-catalog-create-ns -m {} -c {} -e {}'.format(parameters["vfc-url"], \
426 ns.get("key"), ns.get("value"))
427 cmd_out = (os.popen(create_ns_string)).read()
Bartek Grzybowski2ee028b2020-03-05 14:35:29 +0100428 out_list = get_out_helper_2(cmd_out)
Haibin Huangee3b43d2019-05-21 10:53:59 +0800429 return out_list[4]
430
431def create_vnf_package(parameters):
432 vnfs = parameters["vnfs"]
433 outputs = {}
434
435 for vnf_key, vnf_values in vnfs.iteritems():
436 create_vnf_string = 'oclip vfc-catalog-create-vnf -m {} -c {} -e {}'.format(parameters["vfc-url"], \
437 vnf_values.get("key"), vnf_values.get("value"))
438 cmd_out = (os.popen(create_vnf_string)).read()
Bartek Grzybowski2ee028b2020-03-05 14:35:29 +0100439 out_list = get_out_helper_2(cmd_out)
Haibin Huangee3b43d2019-05-21 10:53:59 +0800440 outputs[vnf_key] = out_list[4]
441
442 return outputs
443
444def upload_ns_package(parameters, ns_package_output):
445 ns = parameters["ns"]
446 ns_upload_string = '{}/api/nsd/v1/ns_descriptors/{}/nsd_content'.format(parameters["vfc-url"], ns_package_output)
Bartek Grzybowski2ee028b2020-03-05 14:35:29 +0100447 print(ns_upload_string)
448 print(ns.get("path"))
Haibin Huangee3b43d2019-05-21 10:53:59 +0800449 resp = requests.put(ns_upload_string, files={'file': open(ns.get("path"), 'rb')})
450 return resp
451
452def upload_vnf_package(parameters, vnf_package_output):
453 vnfs = parameters["vnfs"]
454 for vnf_key, vnf_values in vnfs.iteritems():
455 vnf_upload_str = '{}/api/vnfpkgm/v1/vnf_packages/{}/package_content'.format(parameters["vfc-url"], \
456 vnf_package_output[vnf_key], vnf_package_output[vnf_key])
457 resp = requests.put(vnf_upload_str, files={'file': open(vnf_values.get("path"), 'rb')})
458 return resp
459
460
Haibin Huang9b514232019-05-09 14:36:05 +0800461#Run Functions
462parser = argparse.ArgumentParser()
463parser.add_argument('-f', action='store', dest='config_file_path', help='Store config file path')
Haibin Huang169a51b2019-05-22 14:39:08 +0800464parser.add_argument('-t', action='store', dest='model', help='Store config file path')
Haibin Huang9b514232019-05-09 14:36:05 +0800465
466parser.add_argument('--version', action='version', version='%(prog)s 1.0')
467
468results = parser.parse_args()
469
470config_file_path = results.config_file_path
Haibin Huang169a51b2019-05-22 14:39:08 +0800471model = results.model
Haibin Huang9b514232019-05-09 14:36:05 +0800472if config_file_path is None:
473 sys.exit(1)
474config_file = open(config_file_path)
475parameters = get_parameters(config_file)
476
477# 1.Set cli command envionment
478set_open_cli_env(parameters)
479
480# 2.Create cloud complex
481create_complex(parameters)
482
Haibin Huang13433a82019-06-04 16:14:59 +0800483# 3.1 Register all clouds
Haibin Huang48dc6812019-05-16 11:51:20 +0000484register_all_clouds(parameters)
485
Haibin Huang13433a82019-06-04 16:14:59 +0800486# 3.2 create service and customer
487create_service_type(parameters)
488create_customer(parameters)
489add_customer_subscription(parameters)
490
Haibin Huang48dc6812019-05-16 11:51:20 +0000491# 4.Register vnfm
492register_vnfm(parameters)
493
Haibin Huangee3b43d2019-05-21 10:53:59 +0800494# 5.create csar file
495# 5.1 upload csar file to catalog
496# 5.2 FIXME:Because SDC internal API will change without notice, so I will maually design VNF and Service.
Haibin Huang9b514232019-05-09 14:36:05 +0800497# SDC output data model is not align with VFC, we use an workaround method
Bartek Grzybowski2ee028b2020-03-05 14:35:29 +0100498# We just do run time automation
Haibin Huangee3b43d2019-05-21 10:53:59 +0800499ns_package_output = ""
500
Haibin Huang169a51b2019-05-22 14:39:08 +0800501if model == "sdc":
Bartek Grzybowski2ee028b2020-03-05 14:35:29 +0100502 print("use csar file is distributed by sdc")
Haibin Huang13433a82019-06-04 16:14:59 +0800503 # output = create_vlm(parameters)
504 # vsp_dict = create_vsp(parameters, output)
505 # vf_dict = create_vf_model(parameters, vsp_dict)
506 # service_model_list = create_service_model(parameters, vf_dict)
Bartek Grzybowski2ee028b2020-03-05 14:35:29 +0100507
Haibin Huang169a51b2019-05-22 14:39:08 +0800508 vnf_onboard_output = onboard_vnf(parameters)
Bartek Grzybowski2ee028b2020-03-05 14:35:29 +0100509 print(vnf_onboard_output)
yangyandd95f022019-09-10 12:11:10 +0800510 ns_out = onboard_ns(parameters)
Bartek Grzybowski2ee028b2020-03-05 14:35:29 +0100511 print(ns_out)
Haibin Huangee3b43d2019-05-21 10:53:59 +0800512else:
Bartek Grzybowski2ee028b2020-03-05 14:35:29 +0100513 print("use csar file is uploaded by local")
Haibin Huangee3b43d2019-05-21 10:53:59 +0800514 vnf_package_output = create_vnf_package(parameters)
Bartek Grzybowski2ee028b2020-03-05 14:35:29 +0100515 print(vnf_package_output)
Haibin Huangee3b43d2019-05-21 10:53:59 +0800516 ns_package_output = create_ns_package(parameters)
Bartek Grzybowski2ee028b2020-03-05 14:35:29 +0100517 print(ns_package_output)
Haibin Huangee3b43d2019-05-21 10:53:59 +0800518 upload_vnf_out = upload_vnf_package(parameters, vnf_package_output)
Bartek Grzybowski2ee028b2020-03-05 14:35:29 +0100519 print(upload_vnf_out)
yangyandd95f022019-09-10 12:11:10 +0800520 ns_out = upload_ns_package(parameters, ns_package_output)
Bartek Grzybowski2ee028b2020-03-05 14:35:29 +0100521 print(ns_out)
Haibin Huang9b514232019-05-09 14:36:05 +0800522
Haibin Huang48dc6812019-05-16 11:51:20 +0000523# 6.add_policies function not currently working, using curl commands
Pratik Rajafe83ec2020-06-06 21:59:32 +0530524add_policy_models()
Haibin Huangd8d2be92019-05-23 17:06:06 +0800525add_policies(parameters)
Haibin Huang9b514232019-05-09 14:36:05 +0800526
Haibin Huang48dc6812019-05-16 11:51:20 +0000527# 7. VFC part
yangyandd95f022019-09-10 12:11:10 +0800528ns_instance_id = create_ns(parameters, ns_out)
Bartek Grzybowski2ee028b2020-03-05 14:35:29 +0100529print(ns_instance_id)
Haibin Huangee3b43d2019-05-21 10:53:59 +0800530instantiate_ns_output = instantiate_ns(parameters, ns_instance_id)
Bartek Grzybowski2ee028b2020-03-05 14:35:29 +0100531print(instantiate_ns_output)
yangyan43fdf7b2019-09-24 10:51:44 +0800532
533#terminate and delete ns;
Bartek Grzybowski2ee028b2020-03-05 14:35:29 +0100534#option args add the end of json file
yangyan43fdf7b2019-09-24 10:51:44 +0800535
536if sys.argv[3] == "terminate":
537 terminate_ns_output = terminate_ns(parameters, ns_instance_id)
Bartek Grzybowski2ee028b2020-03-05 14:35:29 +0100538 print(terminate_ns_output)
yangyan43fdf7b2019-09-24 10:51:44 +0800539
540elif sys.argv[3] == "delete":
541 delete_ns_output = delete_ns(parameters, ns_instance_id)
Bartek Grzybowski2ee028b2020-03-05 14:35:29 +0100542 print(delete_ns_output)