Bartek Grzybowski | fbbdbec | 2019-09-25 16:37:05 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
Yang Xu | 1b31a1d | 2019-06-26 01:50:15 -0400 | [diff] [blame] | 2 | |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 3 | import logging |
Bartek Grzybowski | fbbdbec | 2019-09-25 16:37:05 +0200 | [diff] [blame] | 4 | logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s %(name)s.%(funcName)s(): %(message)s') |
Yang Xu | 1b31a1d | 2019-06-26 01:50:15 -0400 | [diff] [blame] | 5 | |
| 6 | import sys |
Bartek Grzybowski | be1067b | 2020-03-04 14:01:02 +0100 | [diff] [blame] | 7 | from vcpecommon import * # pylint: disable=W0614 |
Yang Xu | c52ed6e | 2019-04-29 00:20:52 -0400 | [diff] [blame] | 8 | import sdcutils |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 9 | import soutils |
| 10 | from datetime import datetime |
| 11 | import preload |
| 12 | import vcpe_custom_service |
| 13 | import csar_parser |
| 14 | import config_sdnc_so |
Kang Xi | 6c76239 | 2018-05-30 09:27:34 -0400 | [diff] [blame] | 15 | import json |
Bartek Grzybowski | decd6fb6 | 2019-10-31 12:49:46 +0100 | [diff] [blame] | 16 | import urllib3 |
Bartek Grzybowski | 22e2060 | 2019-12-16 13:43:43 +0100 | [diff] [blame] | 17 | import argparse |
| 18 | from collections import OrderedDict |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 19 | |
Bartek Grzybowski | decd6fb6 | 2019-10-31 12:49:46 +0100 | [diff] [blame] | 20 | # disable InsecureRequestWarning warning in requests < 2.16.0 |
| 21 | urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) |
| 22 | # disable InsecureRequestWarning warning in requests >= 2.16.0 |
| 23 | from requests.packages.urllib3.exceptions import InsecureRequestWarning |
| 24 | requests.packages.urllib3.disable_warnings(InsecureRequestWarning) |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 25 | |
| 26 | def config_sniro(vcpecommon, vgmux_svc_instance_uuid, vbrg_svc_instance_uuid): |
| 27 | logger = logging.getLogger(__name__) |
| 28 | |
| 29 | logger.info('\n----------------------------------------------------------------------------------') |
| 30 | logger.info('Start to config SNIRO homing emulator') |
| 31 | |
| 32 | preloader = preload.Preload(vcpecommon) |
| 33 | template_sniro_data = vcpecommon.find_file('sniro_data', 'json', 'preload_templates') |
| 34 | template_sniro_request = vcpecommon.find_file('sniro_request', 'json', 'preload_templates') |
| 35 | |
| 36 | vcperescust_csar = vcpecommon.find_file('rescust', 'csar', 'csar') |
| 37 | parser = csar_parser.CsarParser() |
| 38 | parser.parse_csar(vcperescust_csar) |
| 39 | tunnelxconn_ar_name = None |
| 40 | brg_ar_name = None |
| 41 | vgw_name = None |
| 42 | for model in parser.vnf_models: |
Yang Xu | 86c0e4a | 2018-12-02 13:10:41 -0500 | [diff] [blame] | 43 | logger.info('modelCustomizationName = %s', model['modelCustomizationName']) |
Yang Xu | 27e1624 | 2018-12-28 01:00:50 -0500 | [diff] [blame] | 44 | if 'tunnel' in model['modelCustomizationName'].lower(): |
Yang Xu | 86c0e4a | 2018-12-02 13:10:41 -0500 | [diff] [blame] | 45 | logger.info('tunnel is in %s', model['modelCustomizationName']) |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 46 | tunnelxconn_ar_name = model['modelCustomizationName'] |
Yang Xu | 27e1624 | 2018-12-28 01:00:50 -0500 | [diff] [blame] | 47 | elif 'brg' in model['modelCustomizationName'].lower(): |
Yang Xu | 86c0e4a | 2018-12-02 13:10:41 -0500 | [diff] [blame] | 48 | logger.info('brg is in %s', model['modelCustomizationName']) |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 49 | brg_ar_name = model['modelCustomizationName'] |
Yang Xu | 86c0e4a | 2018-12-02 13:10:41 -0500 | [diff] [blame] | 50 | #elif 'vgw' in model['modelCustomizationName']: |
| 51 | else: |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 52 | vgw_name = model['modelCustomizationName'] |
| 53 | |
| 54 | if not (tunnelxconn_ar_name and brg_ar_name and vgw_name): |
| 55 | logger.error('Cannot find all names from %s.', vcperescust_csar) |
Bartek Grzybowski | 68d93c2 | 2019-10-30 10:55:55 +0100 | [diff] [blame] | 56 | sys.exit(1) |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 57 | |
| 58 | preloader.preload_sniro(template_sniro_data, template_sniro_request, tunnelxconn_ar_name, vgw_name, brg_ar_name, |
| 59 | vgmux_svc_instance_uuid, vbrg_svc_instance_uuid) |
| 60 | |
| 61 | |
| 62 | def create_one_service(vcpecommon, csar_file, vnf_template_file, preload_dict, suffix, heatbridge=False): |
| 63 | """ |
| 64 | :return: service instance UUID |
| 65 | """ |
| 66 | so = soutils.SoUtils(vcpecommon, 'v4') |
| 67 | return so.create_entire_service(csar_file, vnf_template_file, preload_dict, suffix, heatbridge) |
| 68 | |
Kang Xi | 6c76239 | 2018-05-30 09:27:34 -0400 | [diff] [blame] | 69 | |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 70 | def deploy_brg_only(): |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 71 | logger = logging.getLogger(__name__) |
| 72 | |
Bartek Grzybowski | c08278a | 2019-12-17 13:16:43 +0100 | [diff] [blame] | 73 | vcpecommon = VcpeCommon(cfg_file=args.config) |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 74 | preload_dict = vcpecommon.load_preload_data() |
Kang Xi | 6c76239 | 2018-05-30 09:27:34 -0400 | [diff] [blame] | 75 | # name_suffix = preload_dict['${brg_bng_net}'].split('_')[-1] |
| 76 | name_suffix = datetime.now().strftime('%Y%m%d%H%M') |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 77 | |
| 78 | # create multiple services based on the pre-determined order |
| 79 | svc_instance_uuid = vcpecommon.load_object(vcpecommon.svc_instance_uuid_file) |
Bartek Grzybowski | dc3a1e8 | 2019-11-20 15:43:26 +0100 | [diff] [blame] | 80 | for keyword in ['brgemu']: |
| 81 | keyword_vnf=keyword + "_" |
| 82 | keyword_gra=keyword + "gra_" |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 83 | heatbridge = 'gmux' == keyword |
| 84 | csar_file = vcpecommon.find_file(keyword, 'csar', 'csar') |
Bartek Grzybowski | dc3a1e8 | 2019-11-20 15:43:26 +0100 | [diff] [blame] | 85 | vnf_template_file = vcpecommon.find_file(keyword_vnf, 'json', 'preload_templates') |
| 86 | gra_template_file = vcpecommon.find_file(keyword_gra, 'json', 'preload_templates') |
| 87 | if vcpecommon.gra_api_flag: |
| 88 | vcpecommon.increase_ip_address_or_vni_in_template(gra_template_file, ['vbrgemu_private_ip_0']) |
| 89 | svc_instance_uuid[keyword] = create_one_service(vcpecommon, csar_file, gra_template_file, preload_dict, |
| 90 | name_suffix, heatbridge) |
| 91 | else: |
| 92 | vcpecommon.increase_ip_address_or_vni_in_template(vnf_template_file, ['vbrgemu_private_ip_0']) |
| 93 | svc_instance_uuid[keyword] = create_one_service(vcpecommon, csar_file, vnf_template_file, preload_dict, |
| 94 | name_suffix, heatbridge) |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 95 | if not svc_instance_uuid[keyword]: |
Bartek Grzybowski | 68d93c2 | 2019-10-30 10:55:55 +0100 | [diff] [blame] | 96 | sys.exit(1) |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 97 | |
| 98 | # Setting up SNIRO |
Brian Freeman | 9b3d6ca | 2019-11-06 13:22:53 -0500 | [diff] [blame] | 99 | config_sniro(vcpecommon, svc_instance_uuid['gmux'], svc_instance_uuid['brgemu']) |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 100 | |
Kang Xi | 6c76239 | 2018-05-30 09:27:34 -0400 | [diff] [blame] | 101 | |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 102 | def deploy_infra(): |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 103 | logger = logging.getLogger(__name__) |
| 104 | |
Bartek Grzybowski | c08278a | 2019-12-17 13:16:43 +0100 | [diff] [blame] | 105 | vcpecommon = VcpeCommon(cfg_file=args.config) |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 106 | |
Brian Freeman | 9b3d6ca | 2019-11-06 13:22:53 -0500 | [diff] [blame] | 107 | # preload all VNF-API networks |
| 108 | network_template = vcpecommon.find_file('network.', 'json', 'preload_templates') |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 109 | name_suffix = datetime.now().strftime('%Y%m%d%H%M') |
| 110 | preloader = preload.Preload(vcpecommon) |
| 111 | preload_dict = preloader.preload_all_networks(network_template, name_suffix) |
| 112 | logger.debug('Initial preload dictionary:') |
| 113 | logger.debug(json.dumps(preload_dict, indent=4, sort_keys=True)) |
| 114 | if not preload_dict: |
| 115 | logger.error("Failed to preload networks.") |
Bartek Grzybowski | 68d93c2 | 2019-10-30 10:55:55 +0100 | [diff] [blame] | 116 | sys.exit(1) |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 117 | vcpecommon.save_preload_data(preload_dict) |
| 118 | |
Brian Freeman | 9b3d6ca | 2019-11-06 13:22:53 -0500 | [diff] [blame] | 119 | # preload all GRA-API networks |
| 120 | network_template_gra = vcpecommon.find_file('networkgra.', 'json', 'preload_templates') |
| 121 | preloader = preload.Preload(vcpecommon) |
| 122 | preload_dict_gra = preloader.preload_all_networks(network_template_gra, name_suffix) |
| 123 | logger.debug('Initial preload dictionary:') |
| 124 | logger.debug(json.dumps(preload_dict, indent=4, sort_keys=True)) |
| 125 | if not preload_dict_gra: |
| 126 | logger.error("Failed to preload networks.") |
| 127 | sys.exit(1) |
| 128 | vcpecommon.save_preload_data(preload_dict_gra) |
| 129 | |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 130 | # create multiple services based on the pre-determined order |
| 131 | svc_instance_uuid = {} |
Brian Freeman | 9b3d6ca | 2019-11-06 13:22:53 -0500 | [diff] [blame] | 132 | for keyword in ['infra', 'bng', 'gmux', 'brgemu']: |
| 133 | keyword_vnf=keyword + "_" |
| 134 | keyword_gra=keyword + "gra_" |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 135 | heatbridge = 'gmux' == keyword |
| 136 | csar_file = vcpecommon.find_file(keyword, 'csar', 'csar') |
Brian Freeman | 9b3d6ca | 2019-11-06 13:22:53 -0500 | [diff] [blame] | 137 | vnf_template_file = vcpecommon.find_file(keyword_vnf, 'json', 'preload_templates') |
| 138 | gra_template_file = vcpecommon.find_file(keyword_gra, 'json', 'preload_templates') |
| 139 | if vcpecommon.gra_api_flag: |
| 140 | svc_instance_uuid[keyword] = create_one_service(vcpecommon, csar_file, gra_template_file, preload_dict, |
| 141 | name_suffix, heatbridge) |
| 142 | else: |
| 143 | svc_instance_uuid[keyword] = create_one_service(vcpecommon, csar_file, vnf_template_file, preload_dict, |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 144 | name_suffix, heatbridge) |
| 145 | if not svc_instance_uuid[keyword]: |
Bartek Grzybowski | 68d93c2 | 2019-10-30 10:55:55 +0100 | [diff] [blame] | 146 | sys.exit(1) |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 147 | |
| 148 | vcpecommon.save_object(svc_instance_uuid, vcpecommon.svc_instance_uuid_file) |
Brian Freeman | 9b3d6ca | 2019-11-06 13:22:53 -0500 | [diff] [blame] | 149 | |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 150 | # Setting up SNIRO |
Brian Freeman | 9b3d6ca | 2019-11-06 13:22:53 -0500 | [diff] [blame] | 151 | config_sniro(vcpecommon, svc_instance_uuid['gmux'], svc_instance_uuid['brgemu']) |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 152 | |
| 153 | print('----------------------------------------------------------------------------------------------------') |
| 154 | print('Congratulations! The following have been completed correctly:') |
| 155 | print(' - Infrastructure Service Instantiation: ') |
| 156 | print(' * 4 VMs: DHCP, AAA, DNS, Web Server') |
| 157 | print(' * 2 Networks: CPE_PUBLIC, CPE_SIGNAL') |
| 158 | print(' - vBNG Service Instantiation: ') |
| 159 | print(' * 1 VM: vBNG') |
| 160 | print(' * 2 Networks: BRG_BNG, BNG_MUX') |
| 161 | print(' - vGMUX Service Instantiation: ') |
| 162 | print(' * 1 VM: vGMUX') |
| 163 | print(' * 1 Network: MUX_GW') |
| 164 | print(' - vBRG Service Instantiation: ') |
| 165 | print(' * 1 VM: vBRG') |
| 166 | print(' - Adding vGMUX vServer information to AAI.') |
| 167 | print(' - SNIRO Homing Emulator configuration.') |
| 168 | |
| 169 | |
| 170 | def deploy_custom_service(): |
| 171 | nodes = ['brg', 'mux'] |
Bartek Grzybowski | c08278a | 2019-12-17 13:16:43 +0100 | [diff] [blame] | 172 | vcpecommon = VcpeCommon(nodes, cfg_file=args.config) |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 173 | custom_service = vcpe_custom_service.CustomService(vcpecommon) |
| 174 | |
| 175 | # clean up |
Kang Xi | 0e0a1d6 | 2018-07-23 16:53:54 -0400 | [diff] [blame] | 176 | host_dic = {k: vcpecommon.hosts[k] for k in nodes} |
| 177 | if False: |
| 178 | if not vcpecommon.delete_vxlan_interfaces(host_dic): |
Bartek Grzybowski | 68d93c2 | 2019-10-30 10:55:55 +0100 | [diff] [blame] | 179 | sys.exit(1) |
Kang Xi | 0e0a1d6 | 2018-07-23 16:53:54 -0400 | [diff] [blame] | 180 | custom_service.del_all_vgw_stacks(vcpecommon.vgw_name_keyword) |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 181 | |
Kang Xi | 6c76239 | 2018-05-30 09:27:34 -0400 | [diff] [blame] | 182 | #custom_service.clean_up_sdnc() |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 183 | |
| 184 | # create new service |
| 185 | csar_file = vcpecommon.find_file('rescust', 'csar', 'csar') |
| 186 | vgw_template_file = vcpecommon.find_file('vgw', 'json', 'preload_templates') |
Brian Freeman | 81f6e9e | 2018-11-11 22:36:20 -0500 | [diff] [blame] | 187 | vgw_gra_template_file = vcpecommon.find_file('gwgra', 'json', 'preload_templates') |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 188 | preload_dict = vcpecommon.load_preload_data() |
Brian Freeman | 81f6e9e | 2018-11-11 22:36:20 -0500 | [diff] [blame] | 189 | custom_service.create_custom_service(csar_file, vgw_template_file, vgw_gra_template_file, preload_dict) |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 190 | |
| 191 | |
| 192 | def closed_loop(lossrate=0): |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 193 | nodes = ['brg', 'mux'] |
| 194 | logger = logging.getLogger('__name__') |
Bartek Grzybowski | c08278a | 2019-12-17 13:16:43 +0100 | [diff] [blame] | 195 | vcpecommon = VcpeCommon(nodes, cfg_file=args.config) |
Bartek Grzybowski | dbb3ba1 | 2019-09-25 11:21:42 +0200 | [diff] [blame] | 196 | |
| 197 | logger.info('Setting up closed loop policy') |
| 198 | policy_template_file = vcpecommon.find_file('operational.vcpe', 'json', 'preload_templates') |
| 199 | vcpecommon.set_closed_loop_policy(policy_template_file) |
| 200 | |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 201 | logger.info('Cleaning up vGMUX data reporting settings') |
| 202 | vcpecommon.del_vgmux_ves_mode() |
| 203 | time.sleep(2) |
| 204 | vcpecommon.del_vgmux_ves_collector() |
| 205 | |
Yang Xu | 9f935b2 | 2018-11-22 10:56:52 -0500 | [diff] [blame] | 206 | logger.info('Starting vGMUX data reporting to DCAE') |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 207 | time.sleep(2) |
| 208 | vcpecommon.set_vgmux_ves_collector() |
| 209 | |
| 210 | logger.info('Setting vGMUX to report packet loss rate: %s', lossrate) |
| 211 | time.sleep(2) |
| 212 | vcpecommon.set_vgmux_packet_loss_rate(lossrate, vcpecommon.load_vgmux_vnf_name()) |
| 213 | if lossrate > 0: |
Yang Xu | 1b31a1d | 2019-06-26 01:50:15 -0400 | [diff] [blame] | 214 | print('Now please observe vGMUX being restarted') |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 215 | |
| 216 | |
| 217 | def init_so_sdnc(): |
| 218 | logger = logging.getLogger('__name__') |
Bartek Grzybowski | c08278a | 2019-12-17 13:16:43 +0100 | [diff] [blame] | 219 | vcpecommon = VcpeCommon(cfg_file=args.config) |
Bartek Grzybowski | ba8a72f | 2019-11-22 15:02:21 +0100 | [diff] [blame] | 220 | config_sdnc_so.insert_sdnc_ip_pool(vcpecommon) |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 221 | config_sdnc_so.insert_customer_service_to_so(vcpecommon) |
Yang Xu | 63a0afd | 2018-11-20 16:01:01 -0500 | [diff] [blame] | 222 | #config_sdnc_so.insert_customer_service_to_sdnc(vcpecommon) |
Brian Freeman | 8076a87 | 2018-11-13 11:34:48 -0500 | [diff] [blame] | 223 | vgw_vfmod_name_index= 0 |
| 224 | vcpecommon.save_object(vgw_vfmod_name_index, vcpecommon.vgw_vfmod_name_index_file) |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 225 | |
Yang Xu | 0e319ef | 2019-04-30 14:28:07 -0400 | [diff] [blame] | 226 | |
| 227 | def init(): |
Bartek Grzybowski | c08278a | 2019-12-17 13:16:43 +0100 | [diff] [blame] | 228 | vcpecommon = VcpeCommon(cfg_file=args.config) |
Yang Xu | 0e319ef | 2019-04-30 14:28:07 -0400 | [diff] [blame] | 229 | init_sdc(vcpecommon) |
| 230 | download_vcpe_service_templates(vcpecommon) |
Bartek Grzybowski | 6358aa3 | 2019-10-30 13:46:43 +0100 | [diff] [blame] | 231 | preloader = preload.Preload(vcpecommon) |
| 232 | template_aai_region_data = vcpecommon.find_file('aai_region_data', 'json', 'preload_templates') |
| 233 | preloader.preload_aai_data(template_aai_region_data) |
Yang Xu | 0e319ef | 2019-04-30 14:28:07 -0400 | [diff] [blame] | 234 | |
| 235 | |
| 236 | def init_sdc(vcpecommon): |
Yang Xu | c52ed6e | 2019-04-29 00:20:52 -0400 | [diff] [blame] | 237 | sdc = sdcutils.SdcUtils(vcpecommon) |
Brian Freeman | e8aa3f0 | 2019-09-20 08:29:22 -0500 | [diff] [blame] | 238 | # default SDC creates BRG - remove this in frankfurt |
| 239 | #sdc.create_allotted_resource_subcategory('BRG') |
Yang Xu | 0e319ef | 2019-04-30 14:28:07 -0400 | [diff] [blame] | 240 | |
| 241 | |
| 242 | def download_vcpe_service_templates(vcpecommon): |
| 243 | sdc = sdcutils.SdcUtils(vcpecommon) |
| 244 | sdc.download_vcpe_service_template() |
| 245 | |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 246 | |
Kang Xi | 6c76239 | 2018-05-30 09:27:34 -0400 | [diff] [blame] | 247 | def tmp_sniro(): |
| 248 | logger = logging.getLogger(__name__) |
| 249 | |
Bartek Grzybowski | c08278a | 2019-12-17 13:16:43 +0100 | [diff] [blame] | 250 | vcpecommon = VcpeCommon(cfg_file=args.config) |
Kang Xi | 6c76239 | 2018-05-30 09:27:34 -0400 | [diff] [blame] | 251 | |
| 252 | svc_instance_uuid = vcpecommon.load_object(vcpecommon.svc_instance_uuid_file) |
| 253 | # Setting up SNIRO |
Brian Freeman | 9b3d6ca | 2019-11-06 13:22:53 -0500 | [diff] [blame] | 254 | config_sniro(vcpecommon, svc_instance_uuid['gmux'], svc_instance_uuid['brgemu']) |
Kang Xi | 6c76239 | 2018-05-30 09:27:34 -0400 | [diff] [blame] | 255 | |
Yang Xu | 0e319ef | 2019-04-30 14:28:07 -0400 | [diff] [blame] | 256 | |
Bartek Grzybowski | d8affb3 | 2020-03-04 15:45:08 +0100 | [diff] [blame^] | 257 | def test(): |
Bartek Grzybowski | c08278a | 2019-12-17 13:16:43 +0100 | [diff] [blame] | 258 | vcpecommon = VcpeCommon(cfg_file=args.config) |
Yang Xu | 65b84a4 | 2018-12-31 17:48:02 +0000 | [diff] [blame] | 259 | print("oom-k8s-04 public ip: %s" % (vcpecommon.get_vm_public_ip_by_nova('oom-k8s-04'))) |
Yang Xu | 64339a8 | 2018-12-30 05:32:21 +0000 | [diff] [blame] | 260 | |
Yang Xu | 0e319ef | 2019-04-30 14:28:07 -0400 | [diff] [blame] | 261 | |
Bartek Grzybowski | 22e2060 | 2019-12-16 13:43:43 +0100 | [diff] [blame] | 262 | def get_arg_parser(modes): |
| 263 | """ |
| 264 | Parse cmd line options and return ArgumentParser object |
| 265 | :param modes: map of supported script modes |
| 266 | :return: ArgumentParser object |
| 267 | """ |
| 268 | # Build usage synopsis string |
| 269 | usage = "\n"*2 |
| 270 | for k,v in modes.items(): |
| 271 | usage += 'vcpe.py {0:12} {1}\n'.format(k + ':',v) |
| 272 | |
| 273 | parser = argparse.ArgumentParser(usage=usage, formatter_class= |
| 274 | argparse.ArgumentDefaultsHelpFormatter) |
| 275 | parser.add_argument('mode',metavar='MODE', |
| 276 | help='Script mode: {0}'.format('|'.join(modes.keys())), |
| 277 | choices=modes.keys()) |
Bartek Grzybowski | c08278a | 2019-12-17 13:16:43 +0100 | [diff] [blame] | 278 | parser.add_argument('--config',help='Configuration file path',default=None) |
Bartek Grzybowski | 22e2060 | 2019-12-16 13:43:43 +0100 | [diff] [blame] | 279 | |
| 280 | return parser |
| 281 | |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 282 | if __name__ == '__main__': |
Bartek Grzybowski | 22e2060 | 2019-12-16 13:43:43 +0100 | [diff] [blame] | 283 | # Supported modes matrix |
| 284 | # OrderedDict object has to be used to preserve desired modes |
| 285 | # order in synopsis text |
| 286 | modes = OrderedDict() |
| 287 | # modes["sdc"] = "Onboard VNFs, design and distribute vCPE services (under development)" |
| 288 | modes["init"] = "Add customer service data to SDNC and SO DBs" |
| 289 | modes["infra"] = "Deploy infrastructure, including DHCP, AAA, DNS, Web Server, vBNG, vGMUX, vBRG" |
| 290 | modes["brg"] = "Deploy brg only (for testing after infra succeeds)" |
| 291 | modes["customer"] = "Deploy customer service, including vGW and VxLANs" |
| 292 | modes["loop"] = "Test closed loop control (packet loss set to 22)" |
| 293 | modes["noloss"] = "Set vGMUX packet loss to 0" |
| 294 | modes["test"] = "" |
| 295 | modes["sniro"] = "Config SNIRO homing emulator" |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 296 | |
Bartek Grzybowski | 22e2060 | 2019-12-16 13:43:43 +0100 | [diff] [blame] | 297 | parser = get_arg_parser(modes) |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 298 | |
Bartek Grzybowski | 22e2060 | 2019-12-16 13:43:43 +0100 | [diff] [blame] | 299 | try: |
| 300 | assert len(sys.argv) != 1 |
| 301 | except AssertionError: |
| 302 | # No cmd line opts given, print help |
| 303 | parser.print_help() |
| 304 | sys.exit(1) |
| 305 | else: |
| 306 | args = parser.parse_args() |
| 307 | |
| 308 | if args.mode == 'init': |
| 309 | init() |
| 310 | init_so_sdnc() |
| 311 | elif args.mode == 'infra': |
Brian Freeman | 9b3d6ca | 2019-11-06 13:22:53 -0500 | [diff] [blame] | 312 | #if 'y' == raw_input('Ready to deploy infrastructure? y/n: ').lower(): |
Bartek Grzybowski | 22e2060 | 2019-12-16 13:43:43 +0100 | [diff] [blame] | 313 | deploy_infra() |
| 314 | elif args.mode == 'customer': |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 315 | if 'y' == raw_input('Ready to deploy customer service? y/n: ').lower(): |
| 316 | deploy_custom_service() |
Bartek Grzybowski | 22e2060 | 2019-12-16 13:43:43 +0100 | [diff] [blame] | 317 | elif args.mode == 'loop': |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 318 | closed_loop(22) |
Bartek Grzybowski | 22e2060 | 2019-12-16 13:43:43 +0100 | [diff] [blame] | 319 | elif args.mode == 'noloss': |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 320 | closed_loop(0) |
Bartek Grzybowski | 22e2060 | 2019-12-16 13:43:43 +0100 | [diff] [blame] | 321 | elif args.mode == 'brg': |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 322 | deploy_brg_only() |
Bartek Grzybowski | 22e2060 | 2019-12-16 13:43:43 +0100 | [diff] [blame] | 323 | elif args.mode == 'sniro': |
Yang Xu | 86c0e4a | 2018-12-02 13:10:41 -0500 | [diff] [blame] | 324 | tmp_sniro() |
Bartek Grzybowski | 22e2060 | 2019-12-16 13:43:43 +0100 | [diff] [blame] | 325 | elif args.mode == 'test': |
Yang Xu | 64339a8 | 2018-12-30 05:32:21 +0000 | [diff] [blame] | 326 | test() |