blob: bf6fcafbca715444783d661d2d7556ae806dbfa4 [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
Kang Xi11d278c2018-04-06 16:56:04 -04007from vcpecommon import *
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
Kang Xi11d278c2018-04-06 16:56:04 -040017
Bartek Grzybowskidecd6fb62019-10-31 12:49:46 +010018# disable InsecureRequestWarning warning in requests < 2.16.0
19urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
20# disable InsecureRequestWarning warning in requests >= 2.16.0
21from requests.packages.urllib3.exceptions import InsecureRequestWarning
22requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
Kang Xi11d278c2018-04-06 16:56:04 -040023
24def config_sniro(vcpecommon, vgmux_svc_instance_uuid, vbrg_svc_instance_uuid):
25 logger = logging.getLogger(__name__)
26
27 logger.info('\n----------------------------------------------------------------------------------')
28 logger.info('Start to config SNIRO homing emulator')
29
30 preloader = preload.Preload(vcpecommon)
31 template_sniro_data = vcpecommon.find_file('sniro_data', 'json', 'preload_templates')
32 template_sniro_request = vcpecommon.find_file('sniro_request', 'json', 'preload_templates')
33
34 vcperescust_csar = vcpecommon.find_file('rescust', 'csar', 'csar')
35 parser = csar_parser.CsarParser()
36 parser.parse_csar(vcperescust_csar)
37 tunnelxconn_ar_name = None
38 brg_ar_name = None
39 vgw_name = None
40 for model in parser.vnf_models:
Yang Xu86c0e4a2018-12-02 13:10:41 -050041 logger.info('modelCustomizationName = %s', model['modelCustomizationName'])
Yang Xu27e16242018-12-28 01:00:50 -050042 if 'tunnel' in model['modelCustomizationName'].lower():
Yang Xu86c0e4a2018-12-02 13:10:41 -050043 logger.info('tunnel is in %s', model['modelCustomizationName'])
Kang Xi11d278c2018-04-06 16:56:04 -040044 tunnelxconn_ar_name = model['modelCustomizationName']
Yang Xu27e16242018-12-28 01:00:50 -050045 elif 'brg' in model['modelCustomizationName'].lower():
Yang Xu86c0e4a2018-12-02 13:10:41 -050046 logger.info('brg is in %s', model['modelCustomizationName'])
Kang Xi11d278c2018-04-06 16:56:04 -040047 brg_ar_name = model['modelCustomizationName']
Yang Xu86c0e4a2018-12-02 13:10:41 -050048 #elif 'vgw' in model['modelCustomizationName']:
49 else:
Kang Xi11d278c2018-04-06 16:56:04 -040050 vgw_name = model['modelCustomizationName']
51
52 if not (tunnelxconn_ar_name and brg_ar_name and vgw_name):
53 logger.error('Cannot find all names from %s.', vcperescust_csar)
Bartek Grzybowski68d93c22019-10-30 10:55:55 +010054 sys.exit(1)
Kang Xi11d278c2018-04-06 16:56:04 -040055
56 preloader.preload_sniro(template_sniro_data, template_sniro_request, tunnelxconn_ar_name, vgw_name, brg_ar_name,
57 vgmux_svc_instance_uuid, vbrg_svc_instance_uuid)
58
59
60def create_one_service(vcpecommon, csar_file, vnf_template_file, preload_dict, suffix, heatbridge=False):
61 """
62 :return: service instance UUID
63 """
64 so = soutils.SoUtils(vcpecommon, 'v4')
65 return so.create_entire_service(csar_file, vnf_template_file, preload_dict, suffix, heatbridge)
66
Kang Xi6c762392018-05-30 09:27:34 -040067
Kang Xi11d278c2018-04-06 16:56:04 -040068def deploy_brg_only():
Kang Xi11d278c2018-04-06 16:56:04 -040069 logger = logging.getLogger(__name__)
70
71 vcpecommon = VcpeCommon()
72 preload_dict = vcpecommon.load_preload_data()
Kang Xi6c762392018-05-30 09:27:34 -040073# name_suffix = preload_dict['${brg_bng_net}'].split('_')[-1]
74 name_suffix = datetime.now().strftime('%Y%m%d%H%M')
Kang Xi11d278c2018-04-06 16:56:04 -040075
76 # create multiple services based on the pre-determined order
77 svc_instance_uuid = vcpecommon.load_object(vcpecommon.svc_instance_uuid_file)
78 for keyword in ['brg']:
79 heatbridge = 'gmux' == keyword
80 csar_file = vcpecommon.find_file(keyword, 'csar', 'csar')
81 vnf_template_file = vcpecommon.find_file(keyword, 'json', 'preload_templates')
Kang Xi6c762392018-05-30 09:27:34 -040082 vcpecommon.increase_ip_address_or_vni_in_template(vnf_template_file, ['vbrgemu_private_ip_0'])
Kang Xi11d278c2018-04-06 16:56:04 -040083 svc_instance_uuid[keyword] = create_one_service(vcpecommon, csar_file, vnf_template_file, preload_dict,
84 name_suffix, heatbridge)
85 if not svc_instance_uuid[keyword]:
Bartek Grzybowski68d93c22019-10-30 10:55:55 +010086 sys.exit(1)
Kang Xi11d278c2018-04-06 16:56:04 -040087
88 # Setting up SNIRO
Brian Freeman9b3d6ca2019-11-06 13:22:53 -050089 config_sniro(vcpecommon, svc_instance_uuid['gmux'], svc_instance_uuid['brgemu'])
Kang Xi11d278c2018-04-06 16:56:04 -040090
Kang Xi6c762392018-05-30 09:27:34 -040091
Kang Xi11d278c2018-04-06 16:56:04 -040092def deploy_infra():
Kang Xi11d278c2018-04-06 16:56:04 -040093 logger = logging.getLogger(__name__)
94
95 vcpecommon = VcpeCommon()
96
Brian Freeman9b3d6ca2019-11-06 13:22:53 -050097 # preload all VNF-API networks
98 network_template = vcpecommon.find_file('network.', 'json', 'preload_templates')
Kang Xi11d278c2018-04-06 16:56:04 -040099 name_suffix = datetime.now().strftime('%Y%m%d%H%M')
100 preloader = preload.Preload(vcpecommon)
101 preload_dict = preloader.preload_all_networks(network_template, name_suffix)
102 logger.debug('Initial preload dictionary:')
103 logger.debug(json.dumps(preload_dict, indent=4, sort_keys=True))
104 if not preload_dict:
105 logger.error("Failed to preload networks.")
Bartek Grzybowski68d93c22019-10-30 10:55:55 +0100106 sys.exit(1)
Kang Xi11d278c2018-04-06 16:56:04 -0400107 vcpecommon.save_preload_data(preload_dict)
108
Brian Freeman9b3d6ca2019-11-06 13:22:53 -0500109 # preload all GRA-API networks
110 network_template_gra = vcpecommon.find_file('networkgra.', 'json', 'preload_templates')
111 preloader = preload.Preload(vcpecommon)
112 preload_dict_gra = preloader.preload_all_networks(network_template_gra, name_suffix)
113 logger.debug('Initial preload dictionary:')
114 logger.debug(json.dumps(preload_dict, indent=4, sort_keys=True))
115 if not preload_dict_gra:
116 logger.error("Failed to preload networks.")
117 sys.exit(1)
118 vcpecommon.save_preload_data(preload_dict_gra)
119
Kang Xi11d278c2018-04-06 16:56:04 -0400120 # create multiple services based on the pre-determined order
121 svc_instance_uuid = {}
Brian Freeman9b3d6ca2019-11-06 13:22:53 -0500122 for keyword in ['infra', 'bng', 'gmux', 'brgemu']:
123 keyword_vnf=keyword + "_"
124 keyword_gra=keyword + "gra_"
Kang Xi11d278c2018-04-06 16:56:04 -0400125 heatbridge = 'gmux' == keyword
126 csar_file = vcpecommon.find_file(keyword, 'csar', 'csar')
Brian Freeman9b3d6ca2019-11-06 13:22:53 -0500127 vnf_template_file = vcpecommon.find_file(keyword_vnf, 'json', 'preload_templates')
128 gra_template_file = vcpecommon.find_file(keyword_gra, 'json', 'preload_templates')
129 if vcpecommon.gra_api_flag:
130 svc_instance_uuid[keyword] = create_one_service(vcpecommon, csar_file, gra_template_file, preload_dict,
131 name_suffix, heatbridge)
132 else:
133 svc_instance_uuid[keyword] = create_one_service(vcpecommon, csar_file, vnf_template_file, preload_dict,
Kang Xi11d278c2018-04-06 16:56:04 -0400134 name_suffix, heatbridge)
135 if not svc_instance_uuid[keyword]:
Bartek Grzybowski68d93c22019-10-30 10:55:55 +0100136 sys.exit(1)
Kang Xi11d278c2018-04-06 16:56:04 -0400137
138 vcpecommon.save_object(svc_instance_uuid, vcpecommon.svc_instance_uuid_file)
Brian Freeman9b3d6ca2019-11-06 13:22:53 -0500139
Kang Xi11d278c2018-04-06 16:56:04 -0400140 # Setting up SNIRO
Brian Freeman9b3d6ca2019-11-06 13:22:53 -0500141 config_sniro(vcpecommon, svc_instance_uuid['gmux'], svc_instance_uuid['brgemu'])
Kang Xi11d278c2018-04-06 16:56:04 -0400142
143 print('----------------------------------------------------------------------------------------------------')
144 print('Congratulations! The following have been completed correctly:')
145 print(' - Infrastructure Service Instantiation: ')
146 print(' * 4 VMs: DHCP, AAA, DNS, Web Server')
147 print(' * 2 Networks: CPE_PUBLIC, CPE_SIGNAL')
148 print(' - vBNG Service Instantiation: ')
149 print(' * 1 VM: vBNG')
150 print(' * 2 Networks: BRG_BNG, BNG_MUX')
151 print(' - vGMUX Service Instantiation: ')
152 print(' * 1 VM: vGMUX')
153 print(' * 1 Network: MUX_GW')
154 print(' - vBRG Service Instantiation: ')
155 print(' * 1 VM: vBRG')
156 print(' - Adding vGMUX vServer information to AAI.')
157 print(' - SNIRO Homing Emulator configuration.')
158
159
160def deploy_custom_service():
161 nodes = ['brg', 'mux']
162 vcpecommon = VcpeCommon(nodes)
163 custom_service = vcpe_custom_service.CustomService(vcpecommon)
164
165 # clean up
Kang Xi0e0a1d62018-07-23 16:53:54 -0400166 host_dic = {k: vcpecommon.hosts[k] for k in nodes}
167 if False:
168 if not vcpecommon.delete_vxlan_interfaces(host_dic):
Bartek Grzybowski68d93c22019-10-30 10:55:55 +0100169 sys.exit(1)
Kang Xi0e0a1d62018-07-23 16:53:54 -0400170 custom_service.del_all_vgw_stacks(vcpecommon.vgw_name_keyword)
Kang Xi11d278c2018-04-06 16:56:04 -0400171
Kang Xi6c762392018-05-30 09:27:34 -0400172 #custom_service.clean_up_sdnc()
Kang Xi11d278c2018-04-06 16:56:04 -0400173
174 # create new service
175 csar_file = vcpecommon.find_file('rescust', 'csar', 'csar')
176 vgw_template_file = vcpecommon.find_file('vgw', 'json', 'preload_templates')
Brian Freeman81f6e9e2018-11-11 22:36:20 -0500177 vgw_gra_template_file = vcpecommon.find_file('gwgra', 'json', 'preload_templates')
Kang Xi11d278c2018-04-06 16:56:04 -0400178 preload_dict = vcpecommon.load_preload_data()
Brian Freeman81f6e9e2018-11-11 22:36:20 -0500179 custom_service.create_custom_service(csar_file, vgw_template_file, vgw_gra_template_file, preload_dict)
Kang Xi11d278c2018-04-06 16:56:04 -0400180
181
182def closed_loop(lossrate=0):
Kang Xi11d278c2018-04-06 16:56:04 -0400183 nodes = ['brg', 'mux']
184 logger = logging.getLogger('__name__')
185 vcpecommon = VcpeCommon(nodes)
Bartek Grzybowskidbb3ba12019-09-25 11:21:42 +0200186
187 logger.info('Setting up closed loop policy')
188 policy_template_file = vcpecommon.find_file('operational.vcpe', 'json', 'preload_templates')
189 vcpecommon.set_closed_loop_policy(policy_template_file)
190
Kang Xi11d278c2018-04-06 16:56:04 -0400191 logger.info('Cleaning up vGMUX data reporting settings')
192 vcpecommon.del_vgmux_ves_mode()
193 time.sleep(2)
194 vcpecommon.del_vgmux_ves_collector()
195
Yang Xu9f935b22018-11-22 10:56:52 -0500196 logger.info('Starting vGMUX data reporting to DCAE')
Kang Xi11d278c2018-04-06 16:56:04 -0400197 time.sleep(2)
198 vcpecommon.set_vgmux_ves_collector()
199
200 logger.info('Setting vGMUX to report packet loss rate: %s', lossrate)
201 time.sleep(2)
202 vcpecommon.set_vgmux_packet_loss_rate(lossrate, vcpecommon.load_vgmux_vnf_name())
203 if lossrate > 0:
Yang Xu1b31a1d2019-06-26 01:50:15 -0400204 print('Now please observe vGMUX being restarted')
Kang Xi11d278c2018-04-06 16:56:04 -0400205
206
207def init_so_sdnc():
208 logger = logging.getLogger('__name__')
209 vcpecommon = VcpeCommon()
Brian Freeman9b3d6ca2019-11-06 13:22:53 -0500210 #config_sdnc_so.insert_sdnc_ip_pool(vcpecommon)
Kang Xi11d278c2018-04-06 16:56:04 -0400211 config_sdnc_so.insert_customer_service_to_so(vcpecommon)
Yang Xu63a0afd2018-11-20 16:01:01 -0500212 #config_sdnc_so.insert_customer_service_to_sdnc(vcpecommon)
Brian Freeman8076a872018-11-13 11:34:48 -0500213 vgw_vfmod_name_index= 0
214 vcpecommon.save_object(vgw_vfmod_name_index, vcpecommon.vgw_vfmod_name_index_file)
Kang Xi11d278c2018-04-06 16:56:04 -0400215
Yang Xu0e319ef2019-04-30 14:28:07 -0400216
217def init():
Yang Xuc52ed6e2019-04-29 00:20:52 -0400218 vcpecommon = VcpeCommon()
Yang Xu0e319ef2019-04-30 14:28:07 -0400219 init_sdc(vcpecommon)
220 download_vcpe_service_templates(vcpecommon)
221
222
223def init_sdc(vcpecommon):
Yang Xuc52ed6e2019-04-29 00:20:52 -0400224 sdc = sdcutils.SdcUtils(vcpecommon)
Brian Freemane8aa3f02019-09-20 08:29:22 -0500225 # default SDC creates BRG - remove this in frankfurt
226 #sdc.create_allotted_resource_subcategory('BRG')
Yang Xu0e319ef2019-04-30 14:28:07 -0400227
228
229def download_vcpe_service_templates(vcpecommon):
230 sdc = sdcutils.SdcUtils(vcpecommon)
231 sdc.download_vcpe_service_template()
232
Kang Xi11d278c2018-04-06 16:56:04 -0400233
Kang Xi6c762392018-05-30 09:27:34 -0400234def tmp_sniro():
235 logger = logging.getLogger(__name__)
236
237 vcpecommon = VcpeCommon()
238
239 svc_instance_uuid = vcpecommon.load_object(vcpecommon.svc_instance_uuid_file)
240 # Setting up SNIRO
Brian Freeman9b3d6ca2019-11-06 13:22:53 -0500241 config_sniro(vcpecommon, svc_instance_uuid['gmux'], svc_instance_uuid['brgemu'])
Kang Xi6c762392018-05-30 09:27:34 -0400242
Yang Xu0e319ef2019-04-30 14:28:07 -0400243
Yang Xu64339a82018-12-30 05:32:21 +0000244def test():
245 vcpecommon = VcpeCommon()
Yang Xu65b84a42018-12-31 17:48:02 +0000246 print("oom-k8s-04 public ip: %s" % (vcpecommon.get_vm_public_ip_by_nova('oom-k8s-04')))
Yang Xu64339a82018-12-30 05:32:21 +0000247
Yang Xu0e319ef2019-04-30 14:28:07 -0400248
Kang Xi11d278c2018-04-06 16:56:04 -0400249if __name__ == '__main__':
Kang Xi11d278c2018-04-06 16:56:04 -0400250 print('----------------------------------------------------------------------------------------------------')
251 print(' vcpe.py: Brief info about this program')
252# print(' vcpe.py sdc: Onboard VNFs, design and distribute vCPE services (under development)')
253 print(' vcpe.py init: Add customer service data to SDNC and SO DBs.')
254 print(' vcpe.py infra: Deploy infrastructure, including DHCP, AAA, DNS, Web Server, vBNG, vGMUX, vBRG.')
Brian Freemanec9fe0e2018-11-12 12:37:12 -0500255 print(' vcpe.py brg: Deploy brg only (for testing after infra succeeds).')
Kang Xi11d278c2018-04-06 16:56:04 -0400256 print(' vcpe.py customer: Deploy customer service, including vGW and VxLANs')
Bartek Grzybowski304628b2019-10-17 10:44:39 +0200257 print(' vcpe.py loop: Test closed loop control (packet loss set to 22)')
258 print(' vcpe.py noloss: Set vGMUX packet loss to 0')
Kang Xi11d278c2018-04-06 16:56:04 -0400259 print('----------------------------------------------------------------------------------------------------')
260
261 if len(sys.argv) != 2:
262 sys.exit()
263
264 if sys.argv[1] == 'sdc':
265 print('Under development')
266 elif sys.argv[1] == 'init':
Yang Xu0e319ef2019-04-30 14:28:07 -0400267 init()
Kang Xi11d278c2018-04-06 16:56:04 -0400268 init_so_sdnc()
269 elif sys.argv[1] == 'infra':
Brian Freeman9b3d6ca2019-11-06 13:22:53 -0500270 #if 'y' == raw_input('Ready to deploy infrastructure? y/n: ').lower():
Kang Xi11d278c2018-04-06 16:56:04 -0400271 deploy_infra()
272 elif sys.argv[1] == 'customer':
273 if 'y' == raw_input('Ready to deploy customer service? y/n: ').lower():
274 deploy_custom_service()
275 elif sys.argv[1] == 'loop':
276 closed_loop(22)
277 elif sys.argv[1] == 'noloss':
278 closed_loop(0)
279 elif sys.argv[1] == 'brg':
280 deploy_brg_only()
Yang Xu86c0e4a2018-12-02 13:10:41 -0500281 elif sys.argv[1] == 'sniro':
282 tmp_sniro()
Yang Xu64339a82018-12-30 05:32:21 +0000283 elif sys.argv[1] == 'test':
284 test()
Kang Xi11d278c2018-04-06 16:56:04 -0400285