blob: 04cf818375cde442de00d6aeb7c29ac15bfea75b [file] [log] [blame]
Brian Freeman9a56c902019-04-16 11:27:00 -05001import time
DR695Hf2b75da2019-08-28 10:52:51 -04002import os
3import json
4from vcpeutils.csar_parser import CsarParser
Brian Freeman9a56c902019-04-16 11:27:00 -05005from robot.api import logger
DR695H205db3c2019-07-01 13:58:49 -04006from datetime import datetime
DR695H205db3c2019-07-01 13:58:49 -04007import sys
DR695H3a8c9452019-07-08 17:34:52 -04008from ONAPLibrary.PreloadSDNCKeywords import PreloadSDNCKeywords
DR695H843119f2019-07-09 18:10:15 -04009from ONAPLibrary.RequestSOKeywords import RequestSOKeywords
DR695Hbec8e3f2019-07-19 17:58:45 -040010from ONAPLibrary.BaseAAIKeywords import BaseAAIKeywords
11from ONAPLibrary.UUIDKeywords import UUIDKeywords
Brian Freeman9a56c902019-04-16 11:27:00 -050012
13
14class SoUtils:
15
16 def __init__(self):
DR695H96707b22019-07-01 11:26:06 -040017 # SO urls, note: do NOT add a '/' at the end of the url
18 self.so_nbi_port = '8080'
19 self.so_host = 'so.onap'
20 self.so_si_path = '/onap/so/infra/serviceInstantiation/v7/serviceInstances'
21 self.so_orch_path = '/onap/so/infra/orchestrationRequests/v6'
DR695H843119f2019-07-09 18:10:15 -040022 self.service_req_api_url = 'http://' + self.so_host + ':' + self.so_nbi_port
23 self.so_check_progress_api_url = 'http://' + self.so_host + ':' + self.so_nbi_port + self.so_orch_path + '/'
DR695H96707b22019-07-01 11:26:06 -040024 self.so_userpass = 'InfraPortalClient', 'password1$'
25 self.so_headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}
DR695Hdea87652019-05-24 16:33:23 -040026
DR695H3a8c9452019-07-08 17:34:52 -040027 # mr utls
28 self.mr_ip_addr = 'mr.onap'
29 self.mr_ip_port = '3904'
30
31 # sdnc urls
32 self.sdnc_ip_addr = 'sdnc.onap'
33 self.sdnc_preloading_port = '8282'
34 self.sdnc_endpoint = 'http://' + self.sdnc_ip_addr + ':' + self.sdnc_preloading_port
35 self.sdnc_preload_vnf_url = '/restconf/operations/VNF-API:preload-vnf-topology-operation'
DR695H205db3c2019-07-01 13:58:49 -040036 # properties
37 self.homing_solution = 'sniro' # value is either 'sniro' or 'oof'
38 self.customer_location_used_by_oof = {
39 "customerLatitude": "32.897480",
40 "customerLongitude": "-97.040443",
41 "customerName": "some_company"
42 }
43 self.product_family_id = 'f9457e8c-4afd-45da-9389-46acd9bf5116'
44 self.custom_product_family_id = 'a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb'
45 self.instance_name_prefix = {
46 'service': 'svc',
47 'network': 'net',
48 'vnf': 'vnf',
49 'vfmodule': 'vf'
50 }
51
DR695H3a8c9452019-07-08 17:34:52 -040052 # set the openstack cloud access credentials here
53 self.cloud = {
54 '--os-auth-url': 'http://10.12.25.2:5000',
55 '--os-username': 'kxi',
56 '--os-user-domain-id': 'default',
57 '--os-project-domain-id': 'default',
58 '--os-tenant-id': '09d8566ea45e43aa974cf447ed591d77',
59 '--os-region-name': 'RegionOne',
60 '--os-password': 'n3JhGMGuDzD8',
61 '--os-project-domain-name': 'Integration-SB-03',
62 '--os-identity-api-version': '3'
63 }
64
65 self.template_path = 'robot/assets/templates'
DR695H3a8c9452019-07-08 17:34:52 -040066 self.owning_entity_name = 'OE-Demonstration1'
67 self.project_name = 'Project-Demonstration'
68 self.owning_entity_id = '520cc603-a3c4-4ec2-9ef4-ca70facd79c0'
69 self.global_subscriber_id = 'Demonstration'
70 self.vgw_VfModuleModelInvariantUuid = '26d6a718-17b2-4ba8-8691-c44343b2ecd2'
DR695H843119f2019-07-09 18:10:15 -040071 self.so = RequestSOKeywords()
DR695Hbec8e3f2019-07-19 17:58:45 -040072 self.aai = BaseAAIKeywords()
73 self.uuid = UUIDKeywords()
Brian Freeman9a56c902019-04-16 11:27:00 -050074
DR695H158df8f2019-05-04 15:51:36 -040075 @staticmethod
76 def add_req_info(req_details, instance_name, product_family_id=None):
Brian Freeman9a56c902019-04-16 11:27:00 -050077 req_details['requestInfo'] = {
78 'instanceName': instance_name,
79 'source': 'VID',
80 'suppressRollback': 'true',
81 'requestorId': 'vCPE-Robot'
82 }
83 if product_family_id:
84 req_details['requestInfo']['productFamilyId'] = product_family_id
85
DR695H158df8f2019-05-04 15:51:36 -040086 @staticmethod
87 def add_related_instance(req_details, instance_id, instance_model):
Brian Freeman9a56c902019-04-16 11:27:00 -050088 instance = {"instanceId": instance_id, "modelInfo": instance_model}
89 if 'relatedInstanceList' not in req_details:
90 req_details['relatedInstanceList'] = [{"relatedInstance": instance}]
91 else:
92 req_details['relatedInstanceList'].append({"relatedInstance": instance})
93
DR695H843119f2019-07-09 18:10:15 -040094 def generate_vnf_or_network_request(self, instance_name, vnf_or_network_model, service_instance_id, service_model,
95 tenant_id, region_name):
Brian Freeman9a56c902019-04-16 11:27:00 -050096 req_details = {
97 'modelInfo': vnf_or_network_model,
DR695H843119f2019-07-09 18:10:15 -040098 'cloudConfiguration': {"lcpCloudRegionId": region_name,
99 "tenantId": tenant_id},
Brian Freeman9a56c902019-04-16 11:27:00 -0500100 'requestParameters': {"userParams": []},
101 'platform': {"platformName": "Platform-Demonstration"}
102 }
DR695H205db3c2019-07-01 13:58:49 -0400103 self.add_req_info(req_details, instance_name, self.product_family_id)
Brian Freeman9a56c902019-04-16 11:27:00 -0500104 self.add_related_instance(req_details, service_instance_id, service_model)
105 return {'requestDetails': req_details}
106
107 def generate_vfmodule_request(self, instance_name, vfmodule_model, service_instance_id,
DR695H843119f2019-07-09 18:10:15 -0400108 service_model, vnf_instance_id, vnf_model, tenant_id, region_name):
Brian Freeman9a56c902019-04-16 11:27:00 -0500109 req_details = {
110 'modelInfo': vfmodule_model,
DR695H843119f2019-07-09 18:10:15 -0400111 'cloudConfiguration': {"lcpCloudRegionId": region_name,
112 "tenantId": tenant_id},
Brian Freeman9a56c902019-04-16 11:27:00 -0500113 'requestParameters': {"usePreload": 'true'}
114 }
DR695H205db3c2019-07-01 13:58:49 -0400115 self.add_req_info(req_details, instance_name, self.product_family_id)
Brian Freeman9a56c902019-04-16 11:27:00 -0500116 self.add_related_instance(req_details, service_instance_id, service_model)
117 self.add_related_instance(req_details, vnf_instance_id, vnf_model)
118 return {'requestDetails': req_details}
119
120 def generate_service_request(self, instance_name, model):
121 req_details = {
122 'modelInfo': model,
DR695H3a8c9452019-07-08 17:34:52 -0400123 'subscriberInfo': {'globalSubscriberId': self.global_subscriber_id},
Brian Freeman9a56c902019-04-16 11:27:00 -0500124 'requestParameters': {
125 "userParams": [],
126 "subscriptionServiceType": "vCPE",
127 "aLaCarte": 'true'
128 }
129 }
130 self.add_req_info(req_details, instance_name)
131 self.add_project_info(req_details)
132 self.add_owning_entity(req_details)
133 return {'requestDetails': req_details}
134
135 def add_project_info(self, req_details):
DR695H3a8c9452019-07-08 17:34:52 -0400136 req_details['project'] = {'projectName': self.project_name}
Brian Freeman9a56c902019-04-16 11:27:00 -0500137
138 def add_owning_entity(self, req_details):
DR695H3a8c9452019-07-08 17:34:52 -0400139 req_details['owningEntity'] = {'owningEntityId': self.owning_entity_id,
140 'owningEntityName': self.owning_entity_name}
Brian Freeman9a56c902019-04-16 11:27:00 -0500141
DR695H843119f2019-07-09 18:10:15 -0400142 def generate_custom_service_request(self, instance_name, model, brg_mac, tenant_id, region_name):
Brian Freeman9a56c902019-04-16 11:27:00 -0500143 brg_mac_enc = brg_mac.replace(':', '-')
144 req_details = {
145 'modelInfo': model,
146 'subscriberInfo': {'subscriberName': 'Kaneohe',
DR695H3a8c9452019-07-08 17:34:52 -0400147 'globalSubscriberId': self.global_subscriber_id},
DR695H843119f2019-07-09 18:10:15 -0400148 'cloudConfiguration': {"lcpCloudRegionId": region_name,
149 "tenantId": tenant_id},
Brian Freeman9a56c902019-04-16 11:27:00 -0500150 'requestParameters': {
151 "userParams": [
152 {
153 'name': 'BRG_WAN_MAC_Address',
154 'value': brg_mac
155 },
156 {
157 'name': 'VfModuleNames',
158 'value': [
159 {
DR695H3a8c9452019-07-08 17:34:52 -0400160 'VfModuleModelInvariantUuid': self.vgw_VfModuleModelInvariantUuid,
Brian Freeman9a56c902019-04-16 11:27:00 -0500161 'VfModuleName': 'VGW2BRG-{0}'.format(brg_mac_enc)
162 }
163 ]
164 },
165 {
166 "name": "Customer_Location",
DR695H205db3c2019-07-01 13:58:49 -0400167 "value": self.customer_location_used_by_oof
Brian Freeman9a56c902019-04-16 11:27:00 -0500168 },
169 {
170 "name": "Homing_Solution",
DR695H205db3c2019-07-01 13:58:49 -0400171 "value": self.homing_solution
Brian Freeman9a56c902019-04-16 11:27:00 -0500172 }
173 ],
174 "subscriptionServiceType": "vCPE",
175 'aLaCarte': 'false'
176 }
177 }
DR695H205db3c2019-07-01 13:58:49 -0400178 self.add_req_info(req_details, instance_name, self.custom_product_family_id)
Brian Freeman9a56c902019-04-16 11:27:00 -0500179 self.add_project_info(req_details)
180 self.add_owning_entity(req_details)
181 return {'requestDetails': req_details}
182
DR695H843119f2019-07-09 18:10:15 -0400183 def create_custom_service(self, csar_file, brg_mac, tenant_id, region_name, name_suffix=None):
DR695Hae6fedd2019-05-01 18:52:33 -0400184 parser = CsarParser()
Brian Freeman9a56c902019-04-16 11:27:00 -0500185 if not parser.parse_csar(csar_file):
186 return False
187
188 # yyyymmdd_hhmm
189 if not name_suffix:
190 name_suffix = '_' + datetime.now().strftime('%Y%m%d%H%M')
191
192 # create service
DR695H205db3c2019-07-01 13:58:49 -0400193 instance_name = '_'.join([self.instance_name_prefix['service'],
Brian Freeman9a56c902019-04-16 11:27:00 -0500194 parser.svc_model['modelName'][0:10], name_suffix])
195 instance_name = instance_name.lower()
DR695H843119f2019-07-09 18:10:15 -0400196 req = self.generate_custom_service_request(instance_name, parser.svc_model, brg_mac, tenant_id, region_name)
197 logger.info(json.dumps(req, indent=2, sort_keys=True))
198 logger.info('Creating custom service {0}.'.format(instance_name))
199 req_id, svc_instance_id = self.so.run_create_request(self.service_req_api_url, self.so_si_path,
200 json.dumps(req), auth=self.so_userpass)
201 done, resp = self.so.run_polling_get_request(self.so_check_progress_api_url, req_id, tries=50, interval=5,
202 auth=self.so_userpass)
203 return done
Brian Freeman9a56c902019-04-16 11:27:00 -0500204
DR695Hbec8e3f2019-07-19 17:58:45 -0400205 def create_entire_service(self, csar_file, vnf_template_file, preload_dict, region_name, tenant_id, ssh_key):
Brian Freeman9a56c902019-04-16 11:27:00 -0500206 """
207 :param csar_file:
208 :param vnf_template_file:
209 :param preload_dict:
DR695H158df8f2019-05-04 15:51:36 -0400210 :param region_name:
211 :param tenant_id
DR695H843119f2019-07-09 18:10:15 -0400212 :param ssh_key
Brian Freeman9a56c902019-04-16 11:27:00 -0500213 :return: service instance UUID
214 """
DR695Hbec8e3f2019-07-19 17:58:45 -0400215
216 name_suffix = str(self.uuid.generate_timestamp())
217
DR695H843119f2019-07-09 18:10:15 -0400218 logger.info('\n----------------------------------------------------------------------------------')
219 logger.info('Start to create entire service defined in csar: {0}'.format(csar_file))
DR695Hae6fedd2019-05-01 18:52:33 -0400220 parser = CsarParser()
DR695H843119f2019-07-09 18:10:15 -0400221 logger.info('Parsing csar ...')
Brian Freeman9a56c902019-04-16 11:27:00 -0500222 if not parser.parse_csar(csar_file):
DR695H843119f2019-07-09 18:10:15 -0400223 logger.error('Cannot parse csar: {0}'.format(csar_file))
Brian Freeman9a56c902019-04-16 11:27:00 -0500224 return None
225
226 # Set Global timestamp for instancenames
227 global_timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
228 # create service
DR695H205db3c2019-07-01 13:58:49 -0400229 instance_name = '_'.join([self.instance_name_prefix['service'],
Brian Freeman9a56c902019-04-16 11:27:00 -0500230 parser.svc_model['modelName'], global_timestamp, name_suffix])
231 instance_name = instance_name.lower()
DR695H158df8f2019-05-04 15:51:36 -0400232 instance_name = instance_name.replace(' ', '')
233 instance_name = instance_name.replace(':', '')
DR695H843119f2019-07-09 18:10:15 -0400234 logger.info('Creating service instance: {0}.'.format(instance_name))
Brian Freeman9a56c902019-04-16 11:27:00 -0500235 req = self.generate_service_request(instance_name, parser.svc_model)
DR695H843119f2019-07-09 18:10:15 -0400236 logger.debug(json.dumps(req, indent=2, sort_keys=True))
237 req_id, svc_instance_id = self.so.run_create_request(self.service_req_api_url, self.so_si_path,
238 json.dumps(req), auth=self.so_userpass)
239 done, resp = self.so.run_polling_get_request(self.so_check_progress_api_url, req_id, tries=50, interval=5,
240 auth=self.so_userpass)
241 if not done:
Brian Freeman9a56c902019-04-16 11:27:00 -0500242 return None
243
244 # wait for AAI to complete traversal
DR695H3db57152019-07-31 17:42:10 -0400245 self.aai.wait_for_node_to_exist('service-instance', 'service-instance-id', svc_instance_id)
Brian Freeman9a56c902019-04-16 11:27:00 -0500246
247 # create networks
248 for model in parser.net_models:
249 base_name = model['modelCustomizationName'].lower().replace('mux_vg', 'mux_gw')
DR695H205db3c2019-07-01 13:58:49 -0400250 network_name = '_'.join([self.instance_name_prefix['network'], base_name, name_suffix])
Brian Freeman9a56c902019-04-16 11:27:00 -0500251 network_name = network_name.lower()
DR695H843119f2019-07-09 18:10:15 -0400252 logger.info('Creating network: ' + network_name)
253 req = self.generate_vnf_or_network_request(network_name, model, svc_instance_id, parser.svc_model,
254 tenant_id, region_name)
255 logger.debug(json.dumps(req, indent=2, sort_keys=True))
256
257 url = '/'.join([self.so_si_path, svc_instance_id, 'networks'])
258 req_id, net_instance_id = self.so.run_create_request(self.service_req_api_url, url, json.dumps(req),
259 auth=self.so_userpass)
260
261 done, resp = self.so.run_polling_get_request(self.so_check_progress_api_url, req_id, tries=50, interval=5,
262 auth=self.so_userpass)
263 if not done:
Brian Freeman9a56c902019-04-16 11:27:00 -0500264 return None
265
DR695H843119f2019-07-09 18:10:15 -0400266 logger.info('Changing subnet name to ' + self.network_name_to_subnet_name(network_name))
DR695H3a8c9452019-07-08 17:34:52 -0400267 self.set_network_name(network_name)
Brian Freeman9a56c902019-04-16 11:27:00 -0500268 subnet_name_changed = False
269 for i in range(20):
270 time.sleep(3)
DR695H3a8c9452019-07-08 17:34:52 -0400271 if self.set_subnet_name(network_name):
Brian Freeman9a56c902019-04-16 11:27:00 -0500272 subnet_name_changed = True
273 break
274
275 if not subnet_name_changed:
DR695H843119f2019-07-09 18:10:15 -0400276 logger.error('Failed to change subnet name for ' + network_name)
Brian Freeman9a56c902019-04-16 11:27:00 -0500277 return None
278
Brian Freeman9a56c902019-04-16 11:27:00 -0500279 vnf_model = None
280 vnf_instance_id = None
281 # create VNF
282 if len(parser.vnf_models) == 1:
283 vnf_model = parser.vnf_models[0]
DR695H205db3c2019-07-01 13:58:49 -0400284 vnf_instance_name = '_'.join([self.instance_name_prefix['vnf'],
Brian Freeman9a56c902019-04-16 11:27:00 -0500285 vnf_model['modelCustomizationName'].split(' ')[0], name_suffix])
286 vnf_instance_name = vnf_instance_name.lower()
DR695H158df8f2019-05-04 15:51:36 -0400287 vnf_instance_name = vnf_instance_name.replace(' ', '')
288 vnf_instance_name = vnf_instance_name.replace(':', '')
DR695H843119f2019-07-09 18:10:15 -0400289 logger.info('Creating VNF: ' + vnf_instance_name)
290 req = self.generate_vnf_or_network_request(vnf_instance_name, vnf_model, svc_instance_id, parser.svc_model,
291 tenant_id, region_name)
292 logger.debug(json.dumps(req, indent=2, sort_keys=True))
293
294 url = '/'.join([self.so_si_path, svc_instance_id, 'vnfs'])
295 req_id, vnf_instance_id = self.so.run_create_request(self.service_req_api_url, url, json.dumps(req),
296 auth=self.so_userpass)
297 done, resp = self.so.run_polling_get_request(self.so_check_progress_api_url, req_id, tries=50, interval=5,
298 auth=self.so_userpass)
299 if not done:
300 logger.error('Failed to create VNF {0}.'.format(vnf_instance_name))
Brian Freeman9a56c902019-04-16 11:27:00 -0500301 return False
302
303 # wait for AAI to complete traversal
304 if not vnf_instance_id:
DR695H843119f2019-07-09 18:10:15 -0400305 logger.error('No VNF instance ID returned!')
Brian Freeman9a56c902019-04-16 11:27:00 -0500306 sys.exit()
DR695H3db57152019-07-31 17:42:10 -0400307 self.aai.wait_for_node_to_exist('generic-vnf', 'vnf-id', vnf_instance_id)
Brian Freeman9a56c902019-04-16 11:27:00 -0500308
DR695Hf2b75da2019-08-28 10:52:51 -0400309 # SDNC Preload
DR695H3a8c9452019-07-08 17:34:52 -0400310 preloader = PreloadSDNCKeywords()
311 vfmodule_name = '_'.join(['vf',
312 parser.vfmodule_models[0]['modelCustomizationName'].split('..')[0].lower(),
313 name_suffix])
Brian Freeman9a56c902019-04-16 11:27:00 -0500314
DR695H3a8c9452019-07-08 17:34:52 -0400315 extra_preload = {
DR695H843119f2019-07-09 18:10:15 -0400316 'pub_key': ssh_key,
DR695H3a8c9452019-07-08 17:34:52 -0400317 'vnf_type': parser.vfmodule_models[0]['modelCustomizationName'],
318 'generic_vnf_type': parser.vfmodule_models[0]['modelCustomizationName'],
319 'service_type': svc_instance_id,
320 'generic_vnf_name': vnf_model['modelCustomizationName'],
321 'vnf_name': vfmodule_name,
322 'mr_ip_addr': self.mr_ip_addr,
323 'mr_ip_port': self.mr_ip_port,
324 'sdnc_oam_ip': self.sdnc_ip_addr,
325 'suffix': name_suffix,
326 'oam_onap_net': 'oam_network_2No2',
327 'oam_onap_subnet': 'oam_network_2No2',
328 'public_net': 'external',
329 'public_net_id': '971040b2-7059-49dc-b220-4fab50cb2ad4'
330 }
331
332 preload_dict.update(extra_preload)
333 preloader.preload_vfmodule(self.sdnc_endpoint, self.sdnc_preload_vnf_url, self.template_path, vnf_template_file,
334 preload_dict)
Brian Freeman9a56c902019-04-16 11:27:00 -0500335
336 # create VF Module
337 if len(parser.vfmodule_models) == 1:
338 if not vnf_instance_id or not vnf_model:
DR695H843119f2019-07-09 18:10:15 -0400339 logger.error('Invalid VNF instance ID or VNF model!')
Brian Freeman9a56c902019-04-16 11:27:00 -0500340 sys.exit()
341
342 model = parser.vfmodule_models[0]
DR695H205db3c2019-07-01 13:58:49 -0400343 vfmodule_instance_name = '_'.join([self.instance_name_prefix['vfmodule'],
Brian Freeman9a56c902019-04-16 11:27:00 -0500344 model['modelCustomizationName'].split('..')[0], name_suffix])
345 vfmodule_instance_name = vfmodule_instance_name.lower()
DR695H158df8f2019-05-04 15:51:36 -0400346 vfmodule_instance_name = vfmodule_instance_name.replace(' ', '')
347 vfmodule_instance_name = vfmodule_instance_name.replace(':', '')
DR695H843119f2019-07-09 18:10:15 -0400348 logger.info('Creating VF Module: ' + vfmodule_instance_name)
Brian Freeman9a56c902019-04-16 11:27:00 -0500349 req = self.generate_vfmodule_request(vfmodule_instance_name, model, svc_instance_id, parser.svc_model,
DR695H843119f2019-07-09 18:10:15 -0400350 vnf_instance_id, vnf_model, tenant_id, region_name)
351 logger.debug(json.dumps(req, indent=2, sort_keys=True))
352
353 url = '/'.join([self.so_si_path, svc_instance_id, 'vnfs', vnf_instance_id, 'vfModules'])
354 req_id, vfmodule_instance_id = self.so.run_create_request(self.service_req_api_url, url, json.dumps(req),
355 auth=self.so_userpass)
356
357 done, resp = self.so.run_polling_get_request(self.so_check_progress_api_url, req_id, tries=50, interval=50,
358 auth=self.so_userpass)
359 if not done:
360 logger.error('Failed to create VF Module {0}.'.format(vfmodule_instance_name))
Brian Freeman9a56c902019-04-16 11:27:00 -0500361 return None
362
DR695H96707b22019-07-01 11:26:06 -0400363 return svc_instance_id
DR695H205db3c2019-07-01 13:58:49 -0400364
DR695H3a8c9452019-07-08 17:34:52 -0400365 @staticmethod
366 def network_name_to_subnet_name(network_name):
367 """
368 :param network_name: example: vcpe_net_cpe_signal_201711281221
369 :return: vcpe_net_cpe_signal_subnet_201711281221
370 """
371 fields = network_name.split('_')
372 fields.insert(-1, 'subnet')
373 return '_'.join(fields)
374
375 def set_network_name(self, network_name):
376 param = ' '.join([k + ' ' + v for k, v in list(self.cloud.items())])
377 openstackcmd = 'openstack ' + param
378 cmd = ' '.join([openstackcmd, 'network set --name', network_name, 'ONAP-NW1'])
379 os.popen(cmd)
380
381 def set_subnet_name(self, network_name):
382 """
383 Example: network_name = vcpe_net_cpe_signal_201711281221
384 set subnet name to vcpe_net_cpe_signal_subnet_201711281221
385 :return:
386 """
387 param = ' '.join([k + ' ' + v for k, v in list(self.cloud.items())])
388 openstackcmd = 'openstack ' + param
389
390 # expected results: | subnets | subnet_id |
391 subnet_info = os.popen(openstackcmd + ' network show ' + network_name + ' |grep subnets').read().split('|')
392 if len(subnet_info) > 2 and subnet_info[1].strip() == 'subnets':
393 subnet_id = subnet_info[2].strip()
394 subnet_name = self.network_name_to_subnet_name(network_name)
395 cmd = ' '.join([openstackcmd, 'subnet set --name', subnet_name, subnet_id])
396 os.popen(cmd)
DR695H843119f2019-07-09 18:10:15 -0400397 logger.info("Subnet name set to: " + subnet_name)
DR695H3a8c9452019-07-08 17:34:52 -0400398 return True
399 else:
DR695H843119f2019-07-09 18:10:15 -0400400 logger.error("Can't get subnet info from network name: " + network_name)
DR695H3a8c9452019-07-08 17:34:52 -0400401 return False