blob: d8e1d37f7ffaa7bb7ffcb1d219bb14a775ce1020 [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)
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
15import json
16import os
17import time
18import argparse
19import sys
Haibin Huangee3b43d2019-05-21 10:53:59 +080020import requests
Haibin Huang9d72e132019-05-22 16:20:08 +080021import mysql.connector
Haibin Huang9b514232019-05-09 14:36:05 +080022
23def get_parameters(file):
24 parameters = json.load(file)
25 return parameters
26
27def get_out_helper(in_string):
28 out_list = (((in_string.replace('-','')).replace('|', '')).replace('+', '')).split()
29 return out_list
30
31def get_out_helper_2(in_string):
32 out_list = ((in_string.replace('|', '')).replace('+', '')).split()
33 return out_list
34
35def 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
39def 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 Huang169a51b2019-05-22 14:39:08 +080052def 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
93def 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
120def 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
148def 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 Huang9b514232019-05-09 14:36:05 +0800184
185def 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
209def 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 Huang48dc6812019-05-16 11:51:20 +0000214def 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
224def 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 Huang9d72e132019-05-22 16:20:08 +0800229def 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 Huang48dc6812019-05-16 11:51:20 +0000236
Haibin Huang9d72e132019-05-22 16:20:08 +0800237 mycursor = mydb.cursor()
Haibin Huang9b514232019-05-09 14:36:05 +0800238
Haibin Huang9d72e132019-05-22 16:20:08 +0800239 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 Huang9b514232019-05-09 14:36:05 +0800328
Haibin Huang9d72e132019-05-22 16:20:08 +0800329 mycursor.executemany(sql, val)
330 mydb.commit()
331 print(mycursor.rowcount, "was inserted.")
Haibin Huang9b514232019-05-09 14:36:05 +0800332
333def onboard_vnf(parameters):
Haibin Huangee3b43d2019-05-21 10:53:59 +0800334 vnfs = parameters["vnfs"]
335 vnf_onboard_outputs = {}
Haibin Huang9b514232019-05-09 14:36:05 +0800336
Haibin Huangee3b43d2019-05-21 10:53:59 +0800337 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 Huang9b514232019-05-09 14:36:05 +0800341
342def 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 Huangee3b43d2019-05-21 10:53:59 +0800347def 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 Huang9b514232019-05-09 14:36:05 +0800352 ns_create_out = (os.popen(ns_create_string)).read()
Haibin Huangee3b43d2019-05-21 10:53:59 +0800353 print ns_create_out
354 ns_instance_id = (get_out_helper_2(ns_create_out))[3]
355 return ns_instance_id
Haibin Huang9b514232019-05-09 14:36:05 +0800356
Haibin Huangee3b43d2019-05-21 10:53:59 +0800357def 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 Huang9b514232019-05-09 14:36:05 +0800362 ns_instantiate_out = (os.popen(ns_instantiate_string)).read()
363 return ns_instantiate_out
364
Haibin Huangee3b43d2019-05-21 10:53:59 +0800365def 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
373def 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
386def 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
394def 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 Huang9b514232019-05-09 14:36:05 +0800403#Run Functions
404parser = argparse.ArgumentParser()
405parser.add_argument('-f', action='store', dest='config_file_path', help='Store config file path')
Haibin Huang169a51b2019-05-22 14:39:08 +0800406parser.add_argument('-t', action='store', dest='model', help='Store config file path')
Haibin Huang9b514232019-05-09 14:36:05 +0800407
408parser.add_argument('--version', action='version', version='%(prog)s 1.0')
409
410results = parser.parse_args()
411
412config_file_path = results.config_file_path
Haibin Huang169a51b2019-05-22 14:39:08 +0800413model = results.model
Haibin Huang9b514232019-05-09 14:36:05 +0800414if config_file_path is None:
415 sys.exit(1)
416config_file = open(config_file_path)
417parameters = get_parameters(config_file)
418
419# 1.Set cli command envionment
420set_open_cli_env(parameters)
421
422# 2.Create cloud complex
423create_complex(parameters)
424
Haibin Huang48dc6812019-05-16 11:51:20 +0000425# 3.Register all clouds
426register_all_clouds(parameters)
427
428# 4.Register vnfm
429register_vnfm(parameters)
430
Haibin Huangee3b43d2019-05-21 10:53:59 +0800431# 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 Huang9b514232019-05-09 14:36:05 +0800434# SDC output data model is not align with VFC, we use an workaround method
435# We just do run time automation
Haibin Huangee3b43d2019-05-21 10:53:59 +0800436ns_package_output = ""
437
Haibin Huang169a51b2019-05-22 14:39:08 +0800438if model == "sdc":
Haibin Huangee3b43d2019-05-21 10:53:59 +0800439 print "use csar file is distributed by sdc"
Haibin Huang169a51b2019-05-22 14:39:08 +0800440 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 Huangee3b43d2019-05-21 10:53:59 +0800449else:
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 Huang9b514232019-05-09 14:36:05 +0800459
Haibin Huang48dc6812019-05-16 11:51:20 +0000460# 6.add_policies function not currently working, using curl commands
Haibin Huang9d72e132019-05-22 16:20:08 +0800461add_policy_models(parameters)
Haibin Huang9b514232019-05-09 14:36:05 +0800462
Haibin Huang48dc6812019-05-16 11:51:20 +0000463# 7. VFC part
Haibin Huangee3b43d2019-05-21 10:53:59 +0800464ns_instance_id = create_ns(parameters, ns_package_output)
Haibin Huang169a51b2019-05-22 14:39:08 +0800465ns_instance_id = "d0ecc83f-339f-4621-b565-07eb9090a379"
Haibin Huangee3b43d2019-05-21 10:53:59 +0800466print ns_instance_id
467instantiate_ns_output = instantiate_ns(parameters, ns_instance_id)
Haibin Huang9b514232019-05-09 14:36:05 +0800468print instantiate_ns_output