blob: b7b8eb7e393b8e37dc06de1933d4b7dff9100199 [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 Huangd8d2be92019-05-23 17:06:06 +0800238 hpa_sql = "INSERT INTO optimizationmodels (modelname, description, dependency, imported_by, \
239 attributes, ref_attributes, sub_attributes, version, annotation, enumValues, \
240 dataOrderInfo) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
241 hpa_val = ('hpaPolicy', 'HPA Tests Model', '[]', 'demo', 'identity=string:defaultValue-null:required-true:MANY-false:description-null', \
Haibin Huang9d72e132019-05-22 16:20:08 +0800242 'policyScope=MANY-true,policyType=POLICYTYPE:MANY-false,resources=MANY-true,flavorFeatures=flavorFeatures_properties:MANY-true:description-null', \
243 '{"directives_properties":{"attributes":"directives_attributes_properties:required-false:MANY-true:description-null",\
244 "type":"string:defaultValue-null:required-false:MANY-false:description-null"},\
245 "directives_attributes_properties":{"attribute_name":"string:defaultValue-null:required-false:MANY-false:description-null",\
246 "attribute_value":"string:defaultValue-null:required-false:MANY-false:description-null"},\
247 "flavorProperties_properties":{"score":"string:defaultValue-null:required-false:MANY-false:description-null",\
248 "hpa-feature-attributes":"hpa-feature-attributes_properties:required-true:MANY-true:description-null",\
249 "directives":"directives_properties:required-true:MANY-true:description-null",\
250 "hpa-version":"string:defaultValue-null:required-true:MANY-false:description-null",\
251 "hpa-feature":"string:defaultValue-null:required-true:MANY-false:description-null",\
252 "mandatory":"string:defaultValue-null:required-true:MANY-false:description-null",\
253 "architecture":"string:defaultValue-null:required-true:MANY-false:description-null"},\
254 "flavorFeatures_properties":{"directives":"directives_properties:required-true:MANY-true:description-null",\
255 "flavorProperties":"flavorProperties_properties:required-true:MANY-true:description-null",\
256 "id":"string:defaultValue-null:required-true:MANY-false:description-null",\
257 "type":"string:defaultValue-null:required-true:MANY-false:description-null"},\
258 "hpa-feature-attributes_properties":{"unit":"string:defaultValue-null:required-false:MANY-false:description-null",\
259 "hpa-attribute-value":"string:defaultValue-null:required-true:MANY-false:description-null",\
260 "hpa-attribute-key":"string:defaultValue-null:required-true:MANY-false:description-null",\
261 "operator":"OPERATOR:defaultValue-null:required-false:MANY-false:description-null"}}', \
262 'test1', 'policyScope=matching-true, policyType=matching-true', \
Haibin Huangd8d2be92019-05-23 17:06:06 +0800263 'OPERATOR=[<,<equal-sign,>,>equal-sign,equal-sign,!equal-sign,any,all,subset,], POLICYTYPE=[hpa,]', '""')
264
265 mycursor.execute(hpa_sql, hpa_val)
266
267 sql = "INSERT INTO microservicemodels (modelname, description, dependency, imported_by, \
268 attributes, ref_attributes, sub_attributes, version, annotation, enumValues, \
269 dataOrderInfo) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
270 val = [
Haibin Huang9d72e132019-05-22 16:20:08 +0800271 ('distancePolicy', 'distancePolicy', '[]', 'demo', 'identity=string:defaultValue-null:required-true:MANY-false:description-null', \
272 'policyScope=MANY-true,distanceProperties=distanceProperties_properties:MANY-false:description-null,policyType=POLICYTYPE:MANY-false,\
273 resources=MANY-true,applicableResources=APPLICABLERESOURCES:MANY-false', \
274 '{"distanceProperties_properties":{"locationInfo":"string:defaultValue-null:required-true:MANY-false:description-null",\
275 "distance":"distance_properties:required-true:MANY-false:description-null"},\
276 "distance_properties":{"unit":"UNIT:defaultValue-null:required-true:MANY-false:description-null",\
277 "value":"string:defaultValue-null:required-true:MANY-false:description-null","operator":"OPERATOR:defaultValue-null:required-true:MANY-false:description-null"}}', \
278 'test1', 'policyScope=matching-true, policyType=matching-true', \
279 'OPERATOR=[<,<equal-sign,>,>equal-sign,equal-sign,], APPLICABLERESOURCES=[any,all,], POLICYTYPE=[distance_to_location,] ', '""'),
280 ('optimizationPolicy', 'Optimization policy model', '[]', 'demo', 'identity=string:defaultValue-null:required-true:MANY-false:description-null', \
281 'objectiveParameter=objectiveParameter_properties:MANY-false:description-null,policyScope=MANY-true,policyType=POLICYTYPE:MANY-false,\
282 objective=objectiveParameter_properties:MANY-false:description-null', \
283 '{"parameterAttributes_properties":{"customerLocationInfo":"string:defaultValue-null:required-true:MANY-false:description-null",\
284 "parameter":"string:defaultValue-null:required-true:MANY-false:description-null",\
285 "resources":"string:defaultValue-null:required-true:MANY-false:description-null",\
286 "weight":"string:defaultValue-null:required-true:MANY-false:description-null",\
287 "operator":"OPERATOR:defaultValue-null:required-true:MANY-false:description-null"},\
288 "objectiveParameter_properties":{"parameterAttributes":"parameterAttributes_properties:required-true:MANY-true:description-null",\
289 "operator":"OPERATOR:defaultValue-null:required-true:MANY-false:description-null"}}', \
290 'test1', 'policyScope=matching-true, policyType=matching-true', 'OPERATOR=[*,+,-,/,%,], POLICYTYPE=[placement_optimization,]', '""'),
291 ('queryPolicy', 'Query policy model', '[]', 'demo', 'identity=string:defaultValue-null:required-true:MANY-false:description-null', \
292 'policyScope=MANY-true,policyType=POLICYTYPE:MANY-false,queryProperties=queryProperties_properties:MANY-true:description-null', \
293 '{"queryProperties_properties":{"attribute_location":"string:defaultValue-null:required-true:MANY-false:description-null",\
294 "attribute":"string:defaultValue-null:required-true:MANY-false:description-null","value":"string:defaultValue-null:required-true:MANY-false:description-null"}}', \
295 'test1', 'policyScope=matching-true, policyType=matching-true', 'POLICYTYPE=[request_param_query,]', '""'),
296 ('vnfPolicy', 'VnfPolicy model', '[]', 'demo', 'identity=string:defaultValue-null:required-true:MANY-false:description-null', \
297 'policyScope=MANY-true,policyType=POLICYTYPE:MANY-false,resources=MANY-true,\
298 vnfProperties=vnfProperties_properties:MANY-true:description-null,applicableResources=APPLICABLERESOURCES:MANY-false', \
299 '{"vnfProperties_properties":{"serviceType":"string:defaultValue-null:required-true:MANY-false:description-null",\
300 "inventoryProvider":"string:defaultValue-null:required-true:MANY-false:description-null",\
301 "inventoryType":"INVENTORYTYPE:defaultValue-null:required-true:MANY-false:description-null",\
302 "customerId":"string:defaultValue-null:required-true:MANY-false:description-null"}}', \
303 'test1', 'policyScope=matching-true, policyType=matching-true', \
304 'INVENTORYTYPE=[serviceInstanceId,vnfName,cloudRegionId,vimId,], APPLICABLERESOURCES=[any,all,], POLICYTYPE=[vnfPolicy,]', '""'),
305 ('vim_fit', 'Capacity policy model', '[]', 'demo', 'identity=string:defaultValue-null:required-true:MANY-false:description-null', \
306 'policyScope=MANY-true,policyType=POLICYTYPE:MANY-false,capacityProperties=capacityProperties_properties:MANY-false:description-null,\
307 resources=MANY-true,applicableResources=APPLICABLERESOURCES:MANY-false', \
308 '{"capacityProperties_properties":{"request":"string:defaultValue-null:required-true:MANY-false:description-null",\
309 "controller":"string:defaultValue-null:required-true:MANY-false:description-null"}}', \
310 'test1', 'policyScope=matching-true, policyType=matching-true ', ' APPLICABLERESOURCES=[any,all,], POLICYTYPE=[vim_fit,]', '""'),
311 ('affinityPolicy', 'Affinity policy model', '[]', 'demo', 'identity=string:defaultValue-null:required-true:MANY-false:description-null', \
312 'policyScope=MANY-true,policyType=POLICYTYPE:MANY-false,affinityProperties=affinityProperties_properties:MANY-false:description-null,\
313 resources=MANY-true,applicableResources=APPLICABLERESOURCES:MANY-false', \
314 '{"affinityProperties_properties":{"qualifier":"QUALIFIER:defaultValue-null:required-true:MANY-false:description-null",\
315 "category":"string:defaultValue-null:required-true:MANY-false:description-null"}}', \
316 'test1', 'policyScope=matching-true, policyType=matching-true ', ' APPLICABLERESOURCES=[any,all,], POLICYTYPE=[zone,], QUALIFIER=[same,different,]', '""'),
317 ('pciPolicy', 'Pci policy model', '[]', 'demo', 'identity=string:defaultValue-null:required-true:MANY-false:description-null', \
318 'policyScope=MANY-true,policyType=POLICYTYPE:MANY-false,resources=MANY-true,pciProperties=pciProperties_properties:MANY-true:description-null', \
319 '{"pciProperties_properties":{"pciOptimizationTimeConstraint":"string:defaultValue-null:required-false:MANY-false:description-null",\
320 "pciOptimizationNwConstraint":"string:defaultValue-null:required-false:MANY-false:description-null",\
321 "algoCategory":"string:defaultValue-null:required-false:MANY-false:description-null",\
322 "pciOptmizationAlgoName":"string:defaultValue-null:required-false:MANY-false:description-null",\
323 "pciOptimizationPriority":"string:defaultValue-null:required-false:MANY-false:description-null"}}', \
324 'test1', 'olicyScope=matching-true, policyType=matching-true ', ' POLICYTYPE=[pciPolicy,]', '""'),
325 ('subscriberPolicy', 'Subscriber Policy Model', '[]', 'demo', 'identity=string:defaultValue-null:required-true:MANY-false:description-null', \
326 'policyScope=MANY-true,policyType=POLICYTYPE:MANY-false,properties=properties_properties:MANY-false:description-type of a policy', \
327 '{"properties_properties":{"provStatus":"PROVSTATUS:defaultValue-null:required-true:MANY-false:description-null",\
328 "subscriberName":"SUBSCRIBERNAME:defaultValue-null:required-true:MANY-false:description-null",\
329 "subscriberRole":"SUBSCRIBERROLE:defaultValue-null:required-true:MANY-false:description-null"}}', \
330 'test1', 'policyScope=matching-true, policyType=matching-true, properties=matching-true ', \
331 ' SUBSCRIBERNAME=[], SUBSCRIBERROLE=[], POLICYTYPE=[subscriberPolicy,], PROVSTATUS=[]', '""')
332 ]
Haibin Huang9b514232019-05-09 14:36:05 +0800333
Haibin Huang9d72e132019-05-22 16:20:08 +0800334 mycursor.executemany(sql, val)
335 mydb.commit()
336 print(mycursor.rowcount, "was inserted.")
Haibin Huangd8d2be92019-05-23 17:06:06 +0800337
338def add_policies(parameters):
339 #Loop through policy, put in resource_model_name and create policies
340 for policy in os.listdir(parameters["policy_directory"]):
341 policy_name = "{}.{}".format(parameters["policy_scope"], os.path.splitext(policy)[0])
342 policy_file = (os.path.join(parameters["policy_directory"], policy))
343 #Create policy
344 os.system("oclip policy-create-outdated -m {} -u {} -p {} -x {} -S {} -T {} -o {} -b $(cat {})".format(parameters["policy_url"],\
345 parameters["policy_username"], parameters["policy_password"], policy_name, parameters["policy_scope"], \
346 parameters["policy_config_type"], parameters["policy_onapName"], policy_file))
Haibin Huang9b514232019-05-09 14:36:05 +0800347
Haibin Huangd8d2be92019-05-23 17:06:06 +0800348 #Push policy
349 os.system("oclip policy-push-outdated -m {} -u {} -p {} -x {} -b {} -c {}".format(parameters["policy_url"], \
350 parameters["policy_username"], parameters["policy_password"], policy_name, parameters["policy_config_type"],\
351 parameters["policy_pdp_group"]))
352
Haibin Huang9b514232019-05-09 14:36:05 +0800353def onboard_vnf(parameters):
Haibin Huangee3b43d2019-05-21 10:53:59 +0800354 vnfs = parameters["vnfs"]
355 vnf_onboard_outputs = {}
Haibin Huang9b514232019-05-09 14:36:05 +0800356
Haibin Huangee3b43d2019-05-21 10:53:59 +0800357 for key, value in vnfs.items():
358 vnf_onboard_string = 'oclip vfc-catalog-onboard-vnf -c {}'.format(value.get("csar-id"))
359 vnf_onboard_outs[key] = (os.popen(ns_onboard_string)).read()
360 return vnf_onboard_outputs
Haibin Huang9b514232019-05-09 14:36:05 +0800361
362def onboard_ns(parameters):
363 ns_onboard_string = 'oclip vfc-catalog-onboard-ns -c {}'.format(parameters["ns-csar-id"])
364 ns_onboard_out = (os.popen(ns_onboard_string)).read()
365 return ns_onboard_out
366
Haibin Huangee3b43d2019-05-21 10:53:59 +0800367def create_ns(parameters, csar_id):
368 ns = parameters["ns"]
369 ns_create_string = 'oclip vfc-nslcm-create -m {} -c {} -n {}'.format(parameters["vfc-url"], \
370 csar_id, ns.get("name"))
371 print ns_create_string
Haibin Huang9b514232019-05-09 14:36:05 +0800372 ns_create_out = (os.popen(ns_create_string)).read()
Haibin Huangee3b43d2019-05-21 10:53:59 +0800373 print ns_create_out
374 ns_instance_id = (get_out_helper_2(ns_create_out))[3]
375 return ns_instance_id
Haibin Huang9b514232019-05-09 14:36:05 +0800376
Haibin Huangee3b43d2019-05-21 10:53:59 +0800377def instantiate_ns(parameters, ns_instance_id):
378 ns_instantiate_string = 'oclip vfc-nslcm-instantiate -m {} -i {} -c {} -n {}'.format(parameters["vfc-url"], \
379 ns_instance_id, parameters["location"], parameters["sdc-controller-id"])
380 print ns_instantiate_string
381
Haibin Huang9b514232019-05-09 14:36:05 +0800382 ns_instantiate_out = (os.popen(ns_instantiate_string)).read()
383 return ns_instantiate_out
384
Haibin Huangee3b43d2019-05-21 10:53:59 +0800385def create_ns_package(parameters):
386 ns = parameters["ns"]
387 create_ns_string = 'oclip vfc-catalog-create-ns -m {} -c {} -e {}'.format(parameters["vfc-url"], \
388 ns.get("key"), ns.get("value"))
389 cmd_out = (os.popen(create_ns_string)).read()
390 out_list = get_out_helper_2(cmd_out)
391 return out_list[4]
392
393def create_vnf_package(parameters):
394 vnfs = parameters["vnfs"]
395 outputs = {}
396
397 for vnf_key, vnf_values in vnfs.iteritems():
398 create_vnf_string = 'oclip vfc-catalog-create-vnf -m {} -c {} -e {}'.format(parameters["vfc-url"], \
399 vnf_values.get("key"), vnf_values.get("value"))
400 cmd_out = (os.popen(create_vnf_string)).read()
401 out_list = get_out_helper_2(cmd_out)
402 outputs[vnf_key] = out_list[4]
403
404 return outputs
405
406def upload_ns_package(parameters, ns_package_output):
407 ns = parameters["ns"]
408 ns_upload_string = '{}/api/nsd/v1/ns_descriptors/{}/nsd_content'.format(parameters["vfc-url"], ns_package_output)
409 print ns_upload_string
410 print ns.get("path")
411 resp = requests.put(ns_upload_string, files={'file': open(ns.get("path"), 'rb')})
412 return resp
413
414def upload_vnf_package(parameters, vnf_package_output):
415 vnfs = parameters["vnfs"]
416 for vnf_key, vnf_values in vnfs.iteritems():
417 vnf_upload_str = '{}/api/vnfpkgm/v1/vnf_packages/{}/package_content'.format(parameters["vfc-url"], \
418 vnf_package_output[vnf_key], vnf_package_output[vnf_key])
419 resp = requests.put(vnf_upload_str, files={'file': open(vnf_values.get("path"), 'rb')})
420 return resp
421
422
Haibin Huang9b514232019-05-09 14:36:05 +0800423#Run Functions
424parser = argparse.ArgumentParser()
425parser.add_argument('-f', action='store', dest='config_file_path', help='Store config file path')
Haibin Huang169a51b2019-05-22 14:39:08 +0800426parser.add_argument('-t', action='store', dest='model', help='Store config file path')
Haibin Huang9b514232019-05-09 14:36:05 +0800427
428parser.add_argument('--version', action='version', version='%(prog)s 1.0')
429
430results = parser.parse_args()
431
432config_file_path = results.config_file_path
Haibin Huang169a51b2019-05-22 14:39:08 +0800433model = results.model
Haibin Huang9b514232019-05-09 14:36:05 +0800434if config_file_path is None:
435 sys.exit(1)
436config_file = open(config_file_path)
437parameters = get_parameters(config_file)
438
439# 1.Set cli command envionment
440set_open_cli_env(parameters)
441
442# 2.Create cloud complex
443create_complex(parameters)
444
Haibin Huang48dc6812019-05-16 11:51:20 +0000445# 3.Register all clouds
446register_all_clouds(parameters)
447
448# 4.Register vnfm
449register_vnfm(parameters)
450
Haibin Huangee3b43d2019-05-21 10:53:59 +0800451# 5.create csar file
452# 5.1 upload csar file to catalog
453# 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 +0800454# SDC output data model is not align with VFC, we use an workaround method
455# We just do run time automation
Haibin Huangee3b43d2019-05-21 10:53:59 +0800456ns_package_output = ""
457
Haibin Huang169a51b2019-05-22 14:39:08 +0800458if model == "sdc":
Haibin Huangee3b43d2019-05-21 10:53:59 +0800459 print "use csar file is distributed by sdc"
Haibin Huang169a51b2019-05-22 14:39:08 +0800460 output = create_vlm(parameters)
461 vsp_dict = create_vsp(parameters, output)
462 vf_dict = create_vf_model(parameters, vsp_dict)
463 service_model_list = create_service_model(parameters, vf_dict)
464 #
465 vnf_onboard_output = onboard_vnf(parameters)
466 print vnf_onboard_output
467 ns_onboard_out = onboard_ns(parameters)
468 print ns_onboard_out
Haibin Huangee3b43d2019-05-21 10:53:59 +0800469else:
470 print "use csar file is uploaded by local"
471 vnf_package_output = create_vnf_package(parameters)
472 print vnf_package_output
473 ns_package_output = create_ns_package(parameters)
474 print ns_package_output
475 upload_vnf_out = upload_vnf_package(parameters, vnf_package_output)
476 print upload_vnf_out
477 upload_ns_out = upload_ns_package(parameters, ns_package_output)
478 print upload_ns_out
Haibin Huang9b514232019-05-09 14:36:05 +0800479
Haibin Huang48dc6812019-05-16 11:51:20 +0000480# 6.add_policies function not currently working, using curl commands
Haibin Huang9d72e132019-05-22 16:20:08 +0800481add_policy_models(parameters)
Haibin Huangd8d2be92019-05-23 17:06:06 +0800482add_policies(parameters)
Haibin Huang9b514232019-05-09 14:36:05 +0800483
Haibin Huang48dc6812019-05-16 11:51:20 +0000484# 7. VFC part
Haibin Huangee3b43d2019-05-21 10:53:59 +0800485ns_instance_id = create_ns(parameters, ns_package_output)
Haibin Huang169a51b2019-05-22 14:39:08 +0800486ns_instance_id = "d0ecc83f-339f-4621-b565-07eb9090a379"
Haibin Huangee3b43d2019-05-21 10:53:59 +0800487print ns_instance_id
488instantiate_ns_output = instantiate_ns(parameters, ns_instance_id)
Haibin Huang9b514232019-05-09 14:36:05 +0800489print instantiate_ns_output