blob: 9ecda81d22cdc0645b8278fe7c00985a9557b06a [file] [log] [blame]
Bartek Grzybowskifbbdbec2019-09-25 16:37:05 +02001#!/usr/bin/env python
Yang Xu1b31a1d2019-06-26 01:50:15 -04002
Kang Xi11d278c2018-04-06 16:56:04 -04003import logging
Bartek Grzybowskifbbdbec2019-09-25 16:37:05 +02004logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s %(name)s.%(funcName)s(): %(message)s')
Yang Xu1b31a1d2019-06-26 01:50:15 -04005
6import sys
Bartek Grzybowskibe1067b2020-03-04 14:01:02 +01007from vcpecommon import * # pylint: disable=W0614
Yang Xuc52ed6e2019-04-29 00:20:52 -04008import sdcutils
Kang Xi11d278c2018-04-06 16:56:04 -04009import soutils
10from datetime import datetime
11import preload
12import vcpe_custom_service
13import csar_parser
14import config_sdnc_so
Kang Xi6c762392018-05-30 09:27:34 -040015import json
Bartek Grzybowskidecd6fb62019-10-31 12:49:46 +010016import urllib3
Bartek Grzybowski22e20602019-12-16 13:43:43 +010017import argparse
18from collections import OrderedDict
Kang Xi11d278c2018-04-06 16:56:04 -040019
Bartek Grzybowskidecd6fb62019-10-31 12:49:46 +010020# disable InsecureRequestWarning warning in requests < 2.16.0
21urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
22# disable InsecureRequestWarning warning in requests >= 2.16.0
23from requests.packages.urllib3.exceptions import InsecureRequestWarning
24requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
Kang Xi11d278c2018-04-06 16:56:04 -040025
26def 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 Xu86c0e4a2018-12-02 13:10:41 -050043 logger.info('modelCustomizationName = %s', model['modelCustomizationName'])
Yang Xu27e16242018-12-28 01:00:50 -050044 if 'tunnel' in model['modelCustomizationName'].lower():
Yang Xu86c0e4a2018-12-02 13:10:41 -050045 logger.info('tunnel is in %s', model['modelCustomizationName'])
Kang Xi11d278c2018-04-06 16:56:04 -040046 tunnelxconn_ar_name = model['modelCustomizationName']
Yang Xu27e16242018-12-28 01:00:50 -050047 elif 'brg' in model['modelCustomizationName'].lower():
Yang Xu86c0e4a2018-12-02 13:10:41 -050048 logger.info('brg is in %s', model['modelCustomizationName'])
Kang Xi11d278c2018-04-06 16:56:04 -040049 brg_ar_name = model['modelCustomizationName']
Yang Xu86c0e4a2018-12-02 13:10:41 -050050 #elif 'vgw' in model['modelCustomizationName']:
51 else:
Kang Xi11d278c2018-04-06 16:56:04 -040052 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 Grzybowski68d93c22019-10-30 10:55:55 +010056 sys.exit(1)
Kang Xi11d278c2018-04-06 16:56:04 -040057
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
62def 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 Xi6c762392018-05-30 09:27:34 -040069
Kang Xi11d278c2018-04-06 16:56:04 -040070def deploy_brg_only():
Kang Xi11d278c2018-04-06 16:56:04 -040071 logger = logging.getLogger(__name__)
72
Bartek Grzybowskic08278a2019-12-17 13:16:43 +010073 vcpecommon = VcpeCommon(cfg_file=args.config)
Kang Xi11d278c2018-04-06 16:56:04 -040074 preload_dict = vcpecommon.load_preload_data()
Kang Xi6c762392018-05-30 09:27:34 -040075# name_suffix = preload_dict['${brg_bng_net}'].split('_')[-1]
76 name_suffix = datetime.now().strftime('%Y%m%d%H%M')
Kang Xi11d278c2018-04-06 16:56:04 -040077
78 # create multiple services based on the pre-determined order
79 svc_instance_uuid = vcpecommon.load_object(vcpecommon.svc_instance_uuid_file)
Bartek Grzybowskidc3a1e82019-11-20 15:43:26 +010080 for keyword in ['brgemu']:
81 keyword_vnf=keyword + "_"
82 keyword_gra=keyword + "gra_"
Kang Xi11d278c2018-04-06 16:56:04 -040083 heatbridge = 'gmux' == keyword
84 csar_file = vcpecommon.find_file(keyword, 'csar', 'csar')
Bartek Grzybowskidc3a1e82019-11-20 15:43:26 +010085 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 Xi11d278c2018-04-06 16:56:04 -040095 if not svc_instance_uuid[keyword]:
Bartek Grzybowski68d93c22019-10-30 10:55:55 +010096 sys.exit(1)
Kang Xi11d278c2018-04-06 16:56:04 -040097
98 # Setting up SNIRO
Brian Freeman9b3d6ca2019-11-06 13:22:53 -050099 config_sniro(vcpecommon, svc_instance_uuid['gmux'], svc_instance_uuid['brgemu'])
Kang Xi11d278c2018-04-06 16:56:04 -0400100
Kang Xi6c762392018-05-30 09:27:34 -0400101
Kang Xi11d278c2018-04-06 16:56:04 -0400102def deploy_infra():
Kang Xi11d278c2018-04-06 16:56:04 -0400103 logger = logging.getLogger(__name__)
104
Bartek Grzybowskic08278a2019-12-17 13:16:43 +0100105 vcpecommon = VcpeCommon(cfg_file=args.config)
Kang Xi11d278c2018-04-06 16:56:04 -0400106
Brian Freeman9b3d6ca2019-11-06 13:22:53 -0500107 # preload all VNF-API networks
108 network_template = vcpecommon.find_file('network.', 'json', 'preload_templates')
Kang Xi11d278c2018-04-06 16:56:04 -0400109 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 Grzybowski68d93c22019-10-30 10:55:55 +0100116 sys.exit(1)
Kang Xi11d278c2018-04-06 16:56:04 -0400117 vcpecommon.save_preload_data(preload_dict)
118
Brian Freeman9b3d6ca2019-11-06 13:22:53 -0500119 # 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 Xi11d278c2018-04-06 16:56:04 -0400130 # create multiple services based on the pre-determined order
131 svc_instance_uuid = {}
Brian Freeman9b3d6ca2019-11-06 13:22:53 -0500132 for keyword in ['infra', 'bng', 'gmux', 'brgemu']:
133 keyword_vnf=keyword + "_"
134 keyword_gra=keyword + "gra_"
Kang Xi11d278c2018-04-06 16:56:04 -0400135 heatbridge = 'gmux' == keyword
136 csar_file = vcpecommon.find_file(keyword, 'csar', 'csar')
Brian Freeman9b3d6ca2019-11-06 13:22:53 -0500137 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 Xi11d278c2018-04-06 16:56:04 -0400144 name_suffix, heatbridge)
145 if not svc_instance_uuid[keyword]:
Bartek Grzybowski68d93c22019-10-30 10:55:55 +0100146 sys.exit(1)
Kang Xi11d278c2018-04-06 16:56:04 -0400147
148 vcpecommon.save_object(svc_instance_uuid, vcpecommon.svc_instance_uuid_file)
Brian Freeman9b3d6ca2019-11-06 13:22:53 -0500149
Kang Xi11d278c2018-04-06 16:56:04 -0400150 # Setting up SNIRO
Brian Freeman9b3d6ca2019-11-06 13:22:53 -0500151 config_sniro(vcpecommon, svc_instance_uuid['gmux'], svc_instance_uuid['brgemu'])
Kang Xi11d278c2018-04-06 16:56:04 -0400152
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
170def deploy_custom_service():
171 nodes = ['brg', 'mux']
Bartek Grzybowskic08278a2019-12-17 13:16:43 +0100172 vcpecommon = VcpeCommon(nodes, cfg_file=args.config)
Kang Xi11d278c2018-04-06 16:56:04 -0400173 custom_service = vcpe_custom_service.CustomService(vcpecommon)
174
175 # clean up
Kang Xi0e0a1d62018-07-23 16:53:54 -0400176 host_dic = {k: vcpecommon.hosts[k] for k in nodes}
177 if False:
178 if not vcpecommon.delete_vxlan_interfaces(host_dic):
Bartek Grzybowski68d93c22019-10-30 10:55:55 +0100179 sys.exit(1)
Kang Xi0e0a1d62018-07-23 16:53:54 -0400180 custom_service.del_all_vgw_stacks(vcpecommon.vgw_name_keyword)
Kang Xi11d278c2018-04-06 16:56:04 -0400181
Kang Xi6c762392018-05-30 09:27:34 -0400182 #custom_service.clean_up_sdnc()
Kang Xi11d278c2018-04-06 16:56:04 -0400183
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 Freeman81f6e9e2018-11-11 22:36:20 -0500187 vgw_gra_template_file = vcpecommon.find_file('gwgra', 'json', 'preload_templates')
Kang Xi11d278c2018-04-06 16:56:04 -0400188 preload_dict = vcpecommon.load_preload_data()
Brian Freeman81f6e9e2018-11-11 22:36:20 -0500189 custom_service.create_custom_service(csar_file, vgw_template_file, vgw_gra_template_file, preload_dict)
Kang Xi11d278c2018-04-06 16:56:04 -0400190
191
192def closed_loop(lossrate=0):
Kang Xi11d278c2018-04-06 16:56:04 -0400193 nodes = ['brg', 'mux']
194 logger = logging.getLogger('__name__')
Bartek Grzybowskic08278a2019-12-17 13:16:43 +0100195 vcpecommon = VcpeCommon(nodes, cfg_file=args.config)
Bartek Grzybowskidbb3ba12019-09-25 11:21:42 +0200196
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 Xi11d278c2018-04-06 16:56:04 -0400201 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 Xu9f935b22018-11-22 10:56:52 -0500206 logger.info('Starting vGMUX data reporting to DCAE')
Kang Xi11d278c2018-04-06 16:56:04 -0400207 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 Xu1b31a1d2019-06-26 01:50:15 -0400214 print('Now please observe vGMUX being restarted')
Kang Xi11d278c2018-04-06 16:56:04 -0400215
216
217def init_so_sdnc():
218 logger = logging.getLogger('__name__')
Bartek Grzybowskic08278a2019-12-17 13:16:43 +0100219 vcpecommon = VcpeCommon(cfg_file=args.config)
Bartek Grzybowskiba8a72f2019-11-22 15:02:21 +0100220 config_sdnc_so.insert_sdnc_ip_pool(vcpecommon)
Kang Xi11d278c2018-04-06 16:56:04 -0400221 config_sdnc_so.insert_customer_service_to_so(vcpecommon)
Yang Xu63a0afd2018-11-20 16:01:01 -0500222 #config_sdnc_so.insert_customer_service_to_sdnc(vcpecommon)
Brian Freeman8076a872018-11-13 11:34:48 -0500223 vgw_vfmod_name_index= 0
224 vcpecommon.save_object(vgw_vfmod_name_index, vcpecommon.vgw_vfmod_name_index_file)
Kang Xi11d278c2018-04-06 16:56:04 -0400225
Yang Xu0e319ef2019-04-30 14:28:07 -0400226
227def init():
Bartek Grzybowskic08278a2019-12-17 13:16:43 +0100228 vcpecommon = VcpeCommon(cfg_file=args.config)
Yang Xu0e319ef2019-04-30 14:28:07 -0400229 init_sdc(vcpecommon)
230 download_vcpe_service_templates(vcpecommon)
Bartek Grzybowski6358aa32019-10-30 13:46:43 +0100231 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 Xu0e319ef2019-04-30 14:28:07 -0400234
235
236def init_sdc(vcpecommon):
Yang Xuc52ed6e2019-04-29 00:20:52 -0400237 sdc = sdcutils.SdcUtils(vcpecommon)
Brian Freemane8aa3f02019-09-20 08:29:22 -0500238 # default SDC creates BRG - remove this in frankfurt
239 #sdc.create_allotted_resource_subcategory('BRG')
Yang Xu0e319ef2019-04-30 14:28:07 -0400240
241
242def download_vcpe_service_templates(vcpecommon):
243 sdc = sdcutils.SdcUtils(vcpecommon)
244 sdc.download_vcpe_service_template()
245
Kang Xi11d278c2018-04-06 16:56:04 -0400246
Kang Xi6c762392018-05-30 09:27:34 -0400247def tmp_sniro():
248 logger = logging.getLogger(__name__)
249
Bartek Grzybowskic08278a2019-12-17 13:16:43 +0100250 vcpecommon = VcpeCommon(cfg_file=args.config)
Kang Xi6c762392018-05-30 09:27:34 -0400251
252 svc_instance_uuid = vcpecommon.load_object(vcpecommon.svc_instance_uuid_file)
253 # Setting up SNIRO
Brian Freeman9b3d6ca2019-11-06 13:22:53 -0500254 config_sniro(vcpecommon, svc_instance_uuid['gmux'], svc_instance_uuid['brgemu'])
Kang Xi6c762392018-05-30 09:27:34 -0400255
Yang Xu0e319ef2019-04-30 14:28:07 -0400256
Bartek Grzybowskid8affb32020-03-04 15:45:08 +0100257def test():
Bartek Grzybowskic08278a2019-12-17 13:16:43 +0100258 vcpecommon = VcpeCommon(cfg_file=args.config)
Yang Xu65b84a42018-12-31 17:48:02 +0000259 print("oom-k8s-04 public ip: %s" % (vcpecommon.get_vm_public_ip_by_nova('oom-k8s-04')))
Yang Xu64339a82018-12-30 05:32:21 +0000260
Yang Xu0e319ef2019-04-30 14:28:07 -0400261
Bartek Grzybowski22e20602019-12-16 13:43:43 +0100262def 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 Grzybowskic08278a2019-12-17 13:16:43 +0100278 parser.add_argument('--config',help='Configuration file path',default=None)
Bartek Grzybowski22e20602019-12-16 13:43:43 +0100279
280 return parser
281
Kang Xi11d278c2018-04-06 16:56:04 -0400282if __name__ == '__main__':
Bartek Grzybowski22e20602019-12-16 13:43:43 +0100283 # 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 Xi11d278c2018-04-06 16:56:04 -0400296
Bartek Grzybowski22e20602019-12-16 13:43:43 +0100297 parser = get_arg_parser(modes)
Kang Xi11d278c2018-04-06 16:56:04 -0400298
Bartek Grzybowski22e20602019-12-16 13:43:43 +0100299 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 Freeman9b3d6ca2019-11-06 13:22:53 -0500312 #if 'y' == raw_input('Ready to deploy infrastructure? y/n: ').lower():
Bartek Grzybowski22e20602019-12-16 13:43:43 +0100313 deploy_infra()
314 elif args.mode == 'customer':
Kang Xi11d278c2018-04-06 16:56:04 -0400315 if 'y' == raw_input('Ready to deploy customer service? y/n: ').lower():
316 deploy_custom_service()
Bartek Grzybowski22e20602019-12-16 13:43:43 +0100317 elif args.mode == 'loop':
Kang Xi11d278c2018-04-06 16:56:04 -0400318 closed_loop(22)
Bartek Grzybowski22e20602019-12-16 13:43:43 +0100319 elif args.mode == 'noloss':
Kang Xi11d278c2018-04-06 16:56:04 -0400320 closed_loop(0)
Bartek Grzybowski22e20602019-12-16 13:43:43 +0100321 elif args.mode == 'brg':
Kang Xi11d278c2018-04-06 16:56:04 -0400322 deploy_brg_only()
Bartek Grzybowski22e20602019-12-16 13:43:43 +0100323 elif args.mode == 'sniro':
Yang Xu86c0e4a2018-12-02 13:10:41 -0500324 tmp_sniro()
Bartek Grzybowski22e20602019-12-16 13:43:43 +0100325 elif args.mode == 'test':
Yang Xu64339a82018-12-30 05:32:21 +0000326 test()