Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 1 | import time |
DR695H | f2b75da | 2019-08-28 10:52:51 -0400 | [diff] [blame] | 2 | import os |
| 3 | import json |
| 4 | from vcpeutils.csar_parser import CsarParser |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 5 | from robot.api import logger |
DR695H | 205db3c | 2019-07-01 13:58:49 -0400 | [diff] [blame] | 6 | from datetime import datetime |
DR695H | 205db3c | 2019-07-01 13:58:49 -0400 | [diff] [blame] | 7 | import sys |
DR695H | 3a8c945 | 2019-07-08 17:34:52 -0400 | [diff] [blame] | 8 | from ONAPLibrary.PreloadSDNCKeywords import PreloadSDNCKeywords |
DR695H | 843119f | 2019-07-09 18:10:15 -0400 | [diff] [blame] | 9 | from ONAPLibrary.RequestSOKeywords import RequestSOKeywords |
DR695H | bec8e3f | 2019-07-19 17:58:45 -0400 | [diff] [blame] | 10 | from ONAPLibrary.BaseAAIKeywords import BaseAAIKeywords |
| 11 | from ONAPLibrary.UUIDKeywords import UUIDKeywords |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 12 | |
| 13 | |
| 14 | class SoUtils: |
| 15 | |
| 16 | def __init__(self): |
DR695H | 96707b2 | 2019-07-01 11:26:06 -0400 | [diff] [blame] | 17 | # 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' |
DR695H | 843119f | 2019-07-09 18:10:15 -0400 | [diff] [blame] | 22 | 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 + '/' |
DR695H | 96707b2 | 2019-07-01 11:26:06 -0400 | [diff] [blame] | 24 | self.so_userpass = 'InfraPortalClient', 'password1$' |
| 25 | self.so_headers = {'Content-Type': 'application/json', 'Accept': 'application/json'} |
DR695H | dea8765 | 2019-05-24 16:33:23 -0400 | [diff] [blame] | 26 | |
DR695H | 3a8c945 | 2019-07-08 17:34:52 -0400 | [diff] [blame] | 27 | # 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' |
DR695H | 205db3c | 2019-07-01 13:58:49 -0400 | [diff] [blame] | 36 | # 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 | |
DR695H | 3a8c945 | 2019-07-08 17:34:52 -0400 | [diff] [blame] | 52 | # 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' |
DR695H | 3a8c945 | 2019-07-08 17:34:52 -0400 | [diff] [blame] | 66 | 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' |
DR695H | 843119f | 2019-07-09 18:10:15 -0400 | [diff] [blame] | 71 | self.so = RequestSOKeywords() |
DR695H | bec8e3f | 2019-07-19 17:58:45 -0400 | [diff] [blame] | 72 | self.aai = BaseAAIKeywords() |
| 73 | self.uuid = UUIDKeywords() |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 74 | |
DR695H | 158df8f | 2019-05-04 15:51:36 -0400 | [diff] [blame] | 75 | @staticmethod |
| 76 | def add_req_info(req_details, instance_name, product_family_id=None): |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 77 | 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 | |
DR695H | 158df8f | 2019-05-04 15:51:36 -0400 | [diff] [blame] | 86 | @staticmethod |
| 87 | def add_related_instance(req_details, instance_id, instance_model): |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 88 | 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 | |
DR695H | 843119f | 2019-07-09 18:10:15 -0400 | [diff] [blame] | 94 | def generate_vnf_or_network_request(self, instance_name, vnf_or_network_model, service_instance_id, service_model, |
| 95 | tenant_id, region_name): |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 96 | req_details = { |
| 97 | 'modelInfo': vnf_or_network_model, |
DR695H | 843119f | 2019-07-09 18:10:15 -0400 | [diff] [blame] | 98 | 'cloudConfiguration': {"lcpCloudRegionId": region_name, |
| 99 | "tenantId": tenant_id}, |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 100 | 'requestParameters': {"userParams": []}, |
| 101 | 'platform': {"platformName": "Platform-Demonstration"} |
| 102 | } |
DR695H | 205db3c | 2019-07-01 13:58:49 -0400 | [diff] [blame] | 103 | self.add_req_info(req_details, instance_name, self.product_family_id) |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 104 | 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, |
DR695H | 843119f | 2019-07-09 18:10:15 -0400 | [diff] [blame] | 108 | service_model, vnf_instance_id, vnf_model, tenant_id, region_name): |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 109 | req_details = { |
| 110 | 'modelInfo': vfmodule_model, |
DR695H | 843119f | 2019-07-09 18:10:15 -0400 | [diff] [blame] | 111 | 'cloudConfiguration': {"lcpCloudRegionId": region_name, |
| 112 | "tenantId": tenant_id}, |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 113 | 'requestParameters': {"usePreload": 'true'} |
| 114 | } |
DR695H | 205db3c | 2019-07-01 13:58:49 -0400 | [diff] [blame] | 115 | self.add_req_info(req_details, instance_name, self.product_family_id) |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 116 | 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, |
DR695H | 3a8c945 | 2019-07-08 17:34:52 -0400 | [diff] [blame] | 123 | 'subscriberInfo': {'globalSubscriberId': self.global_subscriber_id}, |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 124 | '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): |
DR695H | 3a8c945 | 2019-07-08 17:34:52 -0400 | [diff] [blame] | 136 | req_details['project'] = {'projectName': self.project_name} |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 137 | |
| 138 | def add_owning_entity(self, req_details): |
DR695H | 3a8c945 | 2019-07-08 17:34:52 -0400 | [diff] [blame] | 139 | req_details['owningEntity'] = {'owningEntityId': self.owning_entity_id, |
| 140 | 'owningEntityName': self.owning_entity_name} |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 141 | |
DR695H | 843119f | 2019-07-09 18:10:15 -0400 | [diff] [blame] | 142 | def generate_custom_service_request(self, instance_name, model, brg_mac, tenant_id, region_name): |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 143 | brg_mac_enc = brg_mac.replace(':', '-') |
| 144 | req_details = { |
| 145 | 'modelInfo': model, |
| 146 | 'subscriberInfo': {'subscriberName': 'Kaneohe', |
DR695H | 3a8c945 | 2019-07-08 17:34:52 -0400 | [diff] [blame] | 147 | 'globalSubscriberId': self.global_subscriber_id}, |
DR695H | 843119f | 2019-07-09 18:10:15 -0400 | [diff] [blame] | 148 | 'cloudConfiguration': {"lcpCloudRegionId": region_name, |
| 149 | "tenantId": tenant_id}, |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 150 | 'requestParameters': { |
| 151 | "userParams": [ |
| 152 | { |
| 153 | 'name': 'BRG_WAN_MAC_Address', |
| 154 | 'value': brg_mac |
| 155 | }, |
| 156 | { |
| 157 | 'name': 'VfModuleNames', |
| 158 | 'value': [ |
| 159 | { |
DR695H | 3a8c945 | 2019-07-08 17:34:52 -0400 | [diff] [blame] | 160 | 'VfModuleModelInvariantUuid': self.vgw_VfModuleModelInvariantUuid, |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 161 | 'VfModuleName': 'VGW2BRG-{0}'.format(brg_mac_enc) |
| 162 | } |
| 163 | ] |
| 164 | }, |
| 165 | { |
| 166 | "name": "Customer_Location", |
DR695H | 205db3c | 2019-07-01 13:58:49 -0400 | [diff] [blame] | 167 | "value": self.customer_location_used_by_oof |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 168 | }, |
| 169 | { |
| 170 | "name": "Homing_Solution", |
DR695H | 205db3c | 2019-07-01 13:58:49 -0400 | [diff] [blame] | 171 | "value": self.homing_solution |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 172 | } |
| 173 | ], |
| 174 | "subscriptionServiceType": "vCPE", |
| 175 | 'aLaCarte': 'false' |
| 176 | } |
| 177 | } |
DR695H | 205db3c | 2019-07-01 13:58:49 -0400 | [diff] [blame] | 178 | self.add_req_info(req_details, instance_name, self.custom_product_family_id) |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 179 | self.add_project_info(req_details) |
| 180 | self.add_owning_entity(req_details) |
| 181 | return {'requestDetails': req_details} |
| 182 | |
DR695H | 843119f | 2019-07-09 18:10:15 -0400 | [diff] [blame] | 183 | def create_custom_service(self, csar_file, brg_mac, tenant_id, region_name, name_suffix=None): |
DR695H | ae6fedd | 2019-05-01 18:52:33 -0400 | [diff] [blame] | 184 | parser = CsarParser() |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 185 | 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 |
DR695H | 205db3c | 2019-07-01 13:58:49 -0400 | [diff] [blame] | 193 | instance_name = '_'.join([self.instance_name_prefix['service'], |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 194 | parser.svc_model['modelName'][0:10], name_suffix]) |
| 195 | instance_name = instance_name.lower() |
DR695H | 843119f | 2019-07-09 18:10:15 -0400 | [diff] [blame] | 196 | 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 Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 204 | |
DR695H | bec8e3f | 2019-07-19 17:58:45 -0400 | [diff] [blame] | 205 | def create_entire_service(self, csar_file, vnf_template_file, preload_dict, region_name, tenant_id, ssh_key): |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 206 | """ |
| 207 | :param csar_file: |
| 208 | :param vnf_template_file: |
| 209 | :param preload_dict: |
DR695H | 158df8f | 2019-05-04 15:51:36 -0400 | [diff] [blame] | 210 | :param region_name: |
| 211 | :param tenant_id |
DR695H | 843119f | 2019-07-09 18:10:15 -0400 | [diff] [blame] | 212 | :param ssh_key |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 213 | :return: service instance UUID |
| 214 | """ |
DR695H | bec8e3f | 2019-07-19 17:58:45 -0400 | [diff] [blame] | 215 | |
| 216 | name_suffix = str(self.uuid.generate_timestamp()) |
| 217 | |
DR695H | 843119f | 2019-07-09 18:10:15 -0400 | [diff] [blame] | 218 | logger.info('\n----------------------------------------------------------------------------------') |
| 219 | logger.info('Start to create entire service defined in csar: {0}'.format(csar_file)) |
DR695H | ae6fedd | 2019-05-01 18:52:33 -0400 | [diff] [blame] | 220 | parser = CsarParser() |
DR695H | 843119f | 2019-07-09 18:10:15 -0400 | [diff] [blame] | 221 | logger.info('Parsing csar ...') |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 222 | if not parser.parse_csar(csar_file): |
DR695H | 843119f | 2019-07-09 18:10:15 -0400 | [diff] [blame] | 223 | logger.error('Cannot parse csar: {0}'.format(csar_file)) |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 224 | return None |
| 225 | |
| 226 | # Set Global timestamp for instancenames |
| 227 | global_timestamp = datetime.now().strftime("%Y%m%d%H%M%S") |
| 228 | # create service |
DR695H | 205db3c | 2019-07-01 13:58:49 -0400 | [diff] [blame] | 229 | instance_name = '_'.join([self.instance_name_prefix['service'], |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 230 | parser.svc_model['modelName'], global_timestamp, name_suffix]) |
| 231 | instance_name = instance_name.lower() |
DR695H | 158df8f | 2019-05-04 15:51:36 -0400 | [diff] [blame] | 232 | instance_name = instance_name.replace(' ', '') |
| 233 | instance_name = instance_name.replace(':', '') |
DR695H | 843119f | 2019-07-09 18:10:15 -0400 | [diff] [blame] | 234 | logger.info('Creating service instance: {0}.'.format(instance_name)) |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 235 | req = self.generate_service_request(instance_name, parser.svc_model) |
DR695H | 843119f | 2019-07-09 18:10:15 -0400 | [diff] [blame] | 236 | 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 Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 242 | return None |
| 243 | |
| 244 | # wait for AAI to complete traversal |
DR695H | 3db5715 | 2019-07-31 17:42:10 -0400 | [diff] [blame] | 245 | self.aai.wait_for_node_to_exist('service-instance', 'service-instance-id', svc_instance_id) |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 246 | |
| 247 | # create networks |
| 248 | for model in parser.net_models: |
| 249 | base_name = model['modelCustomizationName'].lower().replace('mux_vg', 'mux_gw') |
DR695H | 205db3c | 2019-07-01 13:58:49 -0400 | [diff] [blame] | 250 | network_name = '_'.join([self.instance_name_prefix['network'], base_name, name_suffix]) |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 251 | network_name = network_name.lower() |
DR695H | 843119f | 2019-07-09 18:10:15 -0400 | [diff] [blame] | 252 | 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 Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 264 | return None |
| 265 | |
DR695H | 843119f | 2019-07-09 18:10:15 -0400 | [diff] [blame] | 266 | logger.info('Changing subnet name to ' + self.network_name_to_subnet_name(network_name)) |
DR695H | 3a8c945 | 2019-07-08 17:34:52 -0400 | [diff] [blame] | 267 | self.set_network_name(network_name) |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 268 | subnet_name_changed = False |
| 269 | for i in range(20): |
| 270 | time.sleep(3) |
DR695H | 3a8c945 | 2019-07-08 17:34:52 -0400 | [diff] [blame] | 271 | if self.set_subnet_name(network_name): |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 272 | subnet_name_changed = True |
| 273 | break |
| 274 | |
| 275 | if not subnet_name_changed: |
DR695H | 843119f | 2019-07-09 18:10:15 -0400 | [diff] [blame] | 276 | logger.error('Failed to change subnet name for ' + network_name) |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 277 | return None |
| 278 | |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 279 | 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] |
DR695H | 205db3c | 2019-07-01 13:58:49 -0400 | [diff] [blame] | 284 | vnf_instance_name = '_'.join([self.instance_name_prefix['vnf'], |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 285 | vnf_model['modelCustomizationName'].split(' ')[0], name_suffix]) |
| 286 | vnf_instance_name = vnf_instance_name.lower() |
DR695H | 158df8f | 2019-05-04 15:51:36 -0400 | [diff] [blame] | 287 | vnf_instance_name = vnf_instance_name.replace(' ', '') |
| 288 | vnf_instance_name = vnf_instance_name.replace(':', '') |
DR695H | 843119f | 2019-07-09 18:10:15 -0400 | [diff] [blame] | 289 | 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 Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 301 | return False |
| 302 | |
| 303 | # wait for AAI to complete traversal |
| 304 | if not vnf_instance_id: |
DR695H | 843119f | 2019-07-09 18:10:15 -0400 | [diff] [blame] | 305 | logger.error('No VNF instance ID returned!') |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 306 | sys.exit() |
DR695H | 3db5715 | 2019-07-31 17:42:10 -0400 | [diff] [blame] | 307 | self.aai.wait_for_node_to_exist('generic-vnf', 'vnf-id', vnf_instance_id) |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 308 | |
DR695H | f2b75da | 2019-08-28 10:52:51 -0400 | [diff] [blame] | 309 | # SDNC Preload |
DR695H | 3a8c945 | 2019-07-08 17:34:52 -0400 | [diff] [blame] | 310 | preloader = PreloadSDNCKeywords() |
| 311 | vfmodule_name = '_'.join(['vf', |
| 312 | parser.vfmodule_models[0]['modelCustomizationName'].split('..')[0].lower(), |
| 313 | name_suffix]) |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 314 | |
DR695H | 3a8c945 | 2019-07-08 17:34:52 -0400 | [diff] [blame] | 315 | extra_preload = { |
DR695H | 843119f | 2019-07-09 18:10:15 -0400 | [diff] [blame] | 316 | 'pub_key': ssh_key, |
DR695H | 3a8c945 | 2019-07-08 17:34:52 -0400 | [diff] [blame] | 317 | '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 Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 335 | |
| 336 | # create VF Module |
| 337 | if len(parser.vfmodule_models) == 1: |
| 338 | if not vnf_instance_id or not vnf_model: |
DR695H | 843119f | 2019-07-09 18:10:15 -0400 | [diff] [blame] | 339 | logger.error('Invalid VNF instance ID or VNF model!') |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 340 | sys.exit() |
| 341 | |
| 342 | model = parser.vfmodule_models[0] |
DR695H | 205db3c | 2019-07-01 13:58:49 -0400 | [diff] [blame] | 343 | vfmodule_instance_name = '_'.join([self.instance_name_prefix['vfmodule'], |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 344 | model['modelCustomizationName'].split('..')[0], name_suffix]) |
| 345 | vfmodule_instance_name = vfmodule_instance_name.lower() |
DR695H | 158df8f | 2019-05-04 15:51:36 -0400 | [diff] [blame] | 346 | vfmodule_instance_name = vfmodule_instance_name.replace(' ', '') |
| 347 | vfmodule_instance_name = vfmodule_instance_name.replace(':', '') |
DR695H | 843119f | 2019-07-09 18:10:15 -0400 | [diff] [blame] | 348 | logger.info('Creating VF Module: ' + vfmodule_instance_name) |
Brian Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 349 | req = self.generate_vfmodule_request(vfmodule_instance_name, model, svc_instance_id, parser.svc_model, |
DR695H | 843119f | 2019-07-09 18:10:15 -0400 | [diff] [blame] | 350 | 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 Freeman | 9a56c90 | 2019-04-16 11:27:00 -0500 | [diff] [blame] | 361 | return None |
| 362 | |
DR695H | 96707b2 | 2019-07-01 11:26:06 -0400 | [diff] [blame] | 363 | return svc_instance_id |
DR695H | 205db3c | 2019-07-01 13:58:49 -0400 | [diff] [blame] | 364 | |
DR695H | 3a8c945 | 2019-07-08 17:34:52 -0400 | [diff] [blame] | 365 | @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) |
DR695H | 843119f | 2019-07-09 18:10:15 -0400 | [diff] [blame] | 397 | logger.info("Subnet name set to: " + subnet_name) |
DR695H | 3a8c945 | 2019-07-08 17:34:52 -0400 | [diff] [blame] | 398 | return True |
| 399 | else: |
DR695H | 843119f | 2019-07-09 18:10:15 -0400 | [diff] [blame] | 400 | logger.error("Can't get subnet info from network name: " + network_name) |
DR695H | 3a8c945 | 2019-07-08 17:34:52 -0400 | [diff] [blame] | 401 | return False |