Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 1 | #! /usr/bin/python |
| 2 | import sys |
| 3 | import logging |
| 4 | from vcpecommon import * |
| 5 | import soutils |
| 6 | from datetime import datetime |
| 7 | import preload |
| 8 | import vcpe_custom_service |
| 9 | import csar_parser |
| 10 | import config_sdnc_so |
Kang Xi | 6c76239 | 2018-05-30 09:27:34 -0400 | [diff] [blame] | 11 | import json |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 12 | |
| 13 | |
| 14 | def config_sniro(vcpecommon, vgmux_svc_instance_uuid, vbrg_svc_instance_uuid): |
| 15 | logger = logging.getLogger(__name__) |
| 16 | |
| 17 | logger.info('\n----------------------------------------------------------------------------------') |
| 18 | logger.info('Start to config SNIRO homing emulator') |
| 19 | |
| 20 | preloader = preload.Preload(vcpecommon) |
| 21 | template_sniro_data = vcpecommon.find_file('sniro_data', 'json', 'preload_templates') |
| 22 | template_sniro_request = vcpecommon.find_file('sniro_request', 'json', 'preload_templates') |
| 23 | |
| 24 | vcperescust_csar = vcpecommon.find_file('rescust', 'csar', 'csar') |
| 25 | parser = csar_parser.CsarParser() |
| 26 | parser.parse_csar(vcperescust_csar) |
| 27 | tunnelxconn_ar_name = None |
| 28 | brg_ar_name = None |
| 29 | vgw_name = None |
| 30 | for model in parser.vnf_models: |
| 31 | if 'tunnel' in model['modelCustomizationName']: |
| 32 | tunnelxconn_ar_name = model['modelCustomizationName'] |
| 33 | elif 'brg' in model['modelCustomizationName']: |
| 34 | brg_ar_name = model['modelCustomizationName'] |
| 35 | elif 'vgw' in model['modelCustomizationName']: |
| 36 | vgw_name = model['modelCustomizationName'] |
| 37 | |
| 38 | if not (tunnelxconn_ar_name and brg_ar_name and vgw_name): |
| 39 | logger.error('Cannot find all names from %s.', vcperescust_csar) |
| 40 | sys.exit() |
| 41 | |
| 42 | preloader.preload_sniro(template_sniro_data, template_sniro_request, tunnelxconn_ar_name, vgw_name, brg_ar_name, |
| 43 | vgmux_svc_instance_uuid, vbrg_svc_instance_uuid) |
| 44 | |
| 45 | |
| 46 | def create_one_service(vcpecommon, csar_file, vnf_template_file, preload_dict, suffix, heatbridge=False): |
| 47 | """ |
| 48 | :return: service instance UUID |
| 49 | """ |
| 50 | so = soutils.SoUtils(vcpecommon, 'v4') |
| 51 | return so.create_entire_service(csar_file, vnf_template_file, preload_dict, suffix, heatbridge) |
| 52 | |
Kang Xi | 6c76239 | 2018-05-30 09:27:34 -0400 | [diff] [blame] | 53 | |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 54 | def deploy_brg_only(): |
| 55 | logging.basicConfig(level=logging.INFO, format='%(message)s') |
| 56 | logger = logging.getLogger(__name__) |
| 57 | |
| 58 | vcpecommon = VcpeCommon() |
| 59 | preload_dict = vcpecommon.load_preload_data() |
Kang Xi | 6c76239 | 2018-05-30 09:27:34 -0400 | [diff] [blame] | 60 | # name_suffix = preload_dict['${brg_bng_net}'].split('_')[-1] |
| 61 | name_suffix = datetime.now().strftime('%Y%m%d%H%M') |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 62 | |
| 63 | # create multiple services based on the pre-determined order |
| 64 | svc_instance_uuid = vcpecommon.load_object(vcpecommon.svc_instance_uuid_file) |
| 65 | for keyword in ['brg']: |
| 66 | heatbridge = 'gmux' == keyword |
| 67 | csar_file = vcpecommon.find_file(keyword, 'csar', 'csar') |
| 68 | vnf_template_file = vcpecommon.find_file(keyword, 'json', 'preload_templates') |
Kang Xi | 6c76239 | 2018-05-30 09:27:34 -0400 | [diff] [blame] | 69 | vcpecommon.increase_ip_address_or_vni_in_template(vnf_template_file, ['vbrgemu_private_ip_0']) |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 70 | svc_instance_uuid[keyword] = create_one_service(vcpecommon, csar_file, vnf_template_file, preload_dict, |
| 71 | name_suffix, heatbridge) |
| 72 | if not svc_instance_uuid[keyword]: |
| 73 | sys.exit() |
| 74 | |
| 75 | # Setting up SNIRO |
| 76 | config_sniro(vcpecommon, svc_instance_uuid['gmux'], svc_instance_uuid['brg']) |
| 77 | |
Kang Xi | 6c76239 | 2018-05-30 09:27:34 -0400 | [diff] [blame] | 78 | |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 79 | def deploy_infra(): |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 80 | logger = logging.getLogger(__name__) |
| 81 | |
| 82 | vcpecommon = VcpeCommon() |
| 83 | |
| 84 | # preload all networks |
| 85 | network_template = vcpecommon.find_file('network', 'json', 'preload_templates') |
| 86 | name_suffix = datetime.now().strftime('%Y%m%d%H%M') |
| 87 | preloader = preload.Preload(vcpecommon) |
| 88 | preload_dict = preloader.preload_all_networks(network_template, name_suffix) |
| 89 | logger.debug('Initial preload dictionary:') |
| 90 | logger.debug(json.dumps(preload_dict, indent=4, sort_keys=True)) |
| 91 | if not preload_dict: |
| 92 | logger.error("Failed to preload networks.") |
| 93 | sys.exit() |
| 94 | vcpecommon.save_preload_data(preload_dict) |
| 95 | |
| 96 | # create multiple services based on the pre-determined order |
| 97 | svc_instance_uuid = {} |
| 98 | for keyword in ['infra', 'bng', 'gmux', 'brg']: |
| 99 | heatbridge = 'gmux' == keyword |
| 100 | csar_file = vcpecommon.find_file(keyword, 'csar', 'csar') |
| 101 | vnf_template_file = vcpecommon.find_file(keyword, 'json', 'preload_templates') |
| 102 | svc_instance_uuid[keyword] = create_one_service(vcpecommon, csar_file, vnf_template_file, preload_dict, |
| 103 | name_suffix, heatbridge) |
| 104 | if not svc_instance_uuid[keyword]: |
| 105 | sys.exit() |
| 106 | |
| 107 | vcpecommon.save_object(svc_instance_uuid, vcpecommon.svc_instance_uuid_file) |
| 108 | # Setting up SNIRO |
| 109 | config_sniro(vcpecommon, svc_instance_uuid['gmux'], svc_instance_uuid['brg']) |
| 110 | |
| 111 | print('----------------------------------------------------------------------------------------------------') |
| 112 | print('Congratulations! The following have been completed correctly:') |
| 113 | print(' - Infrastructure Service Instantiation: ') |
| 114 | print(' * 4 VMs: DHCP, AAA, DNS, Web Server') |
| 115 | print(' * 2 Networks: CPE_PUBLIC, CPE_SIGNAL') |
| 116 | print(' - vBNG Service Instantiation: ') |
| 117 | print(' * 1 VM: vBNG') |
| 118 | print(' * 2 Networks: BRG_BNG, BNG_MUX') |
| 119 | print(' - vGMUX Service Instantiation: ') |
| 120 | print(' * 1 VM: vGMUX') |
| 121 | print(' * 1 Network: MUX_GW') |
| 122 | print(' - vBRG Service Instantiation: ') |
| 123 | print(' * 1 VM: vBRG') |
| 124 | print(' - Adding vGMUX vServer information to AAI.') |
| 125 | print(' - SNIRO Homing Emulator configuration.') |
| 126 | |
| 127 | |
| 128 | def deploy_custom_service(): |
| 129 | nodes = ['brg', 'mux'] |
| 130 | vcpecommon = VcpeCommon(nodes) |
| 131 | custom_service = vcpe_custom_service.CustomService(vcpecommon) |
| 132 | |
| 133 | # clean up |
Kang Xi | 0e0a1d6 | 2018-07-23 16:53:54 -0400 | [diff] [blame] | 134 | host_dic = {k: vcpecommon.hosts[k] for k in nodes} |
| 135 | if False: |
| 136 | if not vcpecommon.delete_vxlan_interfaces(host_dic): |
| 137 | sys.exit() |
| 138 | custom_service.del_all_vgw_stacks(vcpecommon.vgw_name_keyword) |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 139 | |
Kang Xi | 6c76239 | 2018-05-30 09:27:34 -0400 | [diff] [blame] | 140 | #custom_service.clean_up_sdnc() |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 141 | |
| 142 | # create new service |
| 143 | csar_file = vcpecommon.find_file('rescust', 'csar', 'csar') |
| 144 | vgw_template_file = vcpecommon.find_file('vgw', 'json', 'preload_templates') |
Brian Freeman | 81f6e9e | 2018-11-11 22:36:20 -0500 | [diff] [blame] | 145 | vgw_gra_template_file = vcpecommon.find_file('gwgra', 'json', 'preload_templates') |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 146 | preload_dict = vcpecommon.load_preload_data() |
Brian Freeman | 81f6e9e | 2018-11-11 22:36:20 -0500 | [diff] [blame] | 147 | 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] | 148 | |
| 149 | |
| 150 | def closed_loop(lossrate=0): |
| 151 | if lossrate > 0: |
| 152 | while 'y' != raw_input('Please enter docker container "drools" in Policy VM and type "policy stop". Then enter y here: ').lower(): |
| 153 | continue |
| 154 | nodes = ['brg', 'mux'] |
| 155 | logger = logging.getLogger('__name__') |
| 156 | vcpecommon = VcpeCommon(nodes) |
| 157 | logger.info('Cleaning up vGMUX data reporting settings') |
| 158 | vcpecommon.del_vgmux_ves_mode() |
| 159 | time.sleep(2) |
| 160 | vcpecommon.del_vgmux_ves_collector() |
| 161 | |
| 162 | logger.info('Staring vGMUX data reporting to DCAE') |
| 163 | time.sleep(2) |
| 164 | vcpecommon.set_vgmux_ves_collector() |
| 165 | |
| 166 | logger.info('Setting vGMUX to report packet loss rate: %s', lossrate) |
| 167 | time.sleep(2) |
| 168 | vcpecommon.set_vgmux_packet_loss_rate(lossrate, vcpecommon.load_vgmux_vnf_name()) |
| 169 | if lossrate > 0: |
| 170 | print('Please enter docker container "drools" in Policy VM and type "policy start". Then observe vGMUX being restarted.') |
| 171 | |
| 172 | |
| 173 | def init_so_sdnc(): |
| 174 | logger = logging.getLogger('__name__') |
| 175 | vcpecommon = VcpeCommon() |
| 176 | config_sdnc_so.insert_customer_service_to_so(vcpecommon) |
| 177 | config_sdnc_so.insert_customer_service_to_sdnc(vcpecommon) |
Brian Freeman | 8076a87 | 2018-11-13 11:34:48 -0500 | [diff] [blame^] | 178 | vgw_vfmod_name_index= 0 |
| 179 | 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] | 180 | |
| 181 | |
Kang Xi | 6c76239 | 2018-05-30 09:27:34 -0400 | [diff] [blame] | 182 | def tmp_sniro(): |
| 183 | logger = logging.getLogger(__name__) |
| 184 | |
| 185 | vcpecommon = VcpeCommon() |
| 186 | |
| 187 | svc_instance_uuid = vcpecommon.load_object(vcpecommon.svc_instance_uuid_file) |
| 188 | # Setting up SNIRO |
| 189 | config_sniro(vcpecommon, svc_instance_uuid['gmux'], svc_instance_uuid['brg']) |
| 190 | |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 191 | if __name__ == '__main__': |
Brian Freeman | a605bc7 | 2018-11-12 10:50:30 -0500 | [diff] [blame] | 192 | logging.basicConfig(level=logging.DEBUG, format='%(message)s') |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 193 | |
| 194 | print('----------------------------------------------------------------------------------------------------') |
| 195 | print(' vcpe.py: Brief info about this program') |
| 196 | # print(' vcpe.py sdc: Onboard VNFs, design and distribute vCPE services (under development)') |
| 197 | print(' vcpe.py init: Add customer service data to SDNC and SO DBs.') |
| 198 | print(' vcpe.py infra: Deploy infrastructure, including DHCP, AAA, DNS, Web Server, vBNG, vGMUX, vBRG.') |
Brian Freeman | ec9fe0e | 2018-11-12 12:37:12 -0500 | [diff] [blame] | 199 | print(' vcpe.py brg: Deploy brg only (for testing after infra succeeds).') |
Kang Xi | 11d278c | 2018-04-06 16:56:04 -0400 | [diff] [blame] | 200 | print(' vcpe.py customer: Deploy customer service, including vGW and VxLANs') |
| 201 | print(' vcpe.py loop: Test closed loop control') |
| 202 | print('----------------------------------------------------------------------------------------------------') |
| 203 | |
| 204 | if len(sys.argv) != 2: |
| 205 | sys.exit() |
| 206 | |
| 207 | if sys.argv[1] == 'sdc': |
| 208 | print('Under development') |
| 209 | elif sys.argv[1] == 'init': |
| 210 | if 'y' == raw_input('Ready to add customer service data to SDNC and SO DBs? This is needed only once.' |
| 211 | 'y/n: ').lower(): |
| 212 | init_so_sdnc() |
| 213 | elif sys.argv[1] == 'infra': |
| 214 | if 'y' == raw_input('Ready to deploy infrastructure? y/n: ').lower(): |
| 215 | deploy_infra() |
| 216 | elif sys.argv[1] == 'customer': |
| 217 | if 'y' == raw_input('Ready to deploy customer service? y/n: ').lower(): |
| 218 | deploy_custom_service() |
| 219 | elif sys.argv[1] == 'loop': |
| 220 | closed_loop(22) |
| 221 | elif sys.argv[1] == 'noloss': |
| 222 | closed_loop(0) |
| 223 | elif sys.argv[1] == 'brg': |
| 224 | deploy_brg_only() |
| 225 | |