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