blob: 26f27fb7a11e238fa87cbc24497c1b960c39a495 [file] [log] [blame]
Kang Xi11d278c2018-04-06 16:56:04 -04001#! /usr/bin/python
2import sys
3import logging
4from vcpecommon import *
5import soutils
6from datetime import datetime
7import preload
8import vcpe_custom_service
9import csar_parser
10import config_sdnc_so
Kang Xi6c762392018-05-30 09:27:34 -040011import json
Kang Xi11d278c2018-04-06 16:56:04 -040012
13
14def 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
46def 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 Xi6c762392018-05-30 09:27:34 -040053
Kang Xi11d278c2018-04-06 16:56:04 -040054def 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 Xi6c762392018-05-30 09:27:34 -040060# name_suffix = preload_dict['${brg_bng_net}'].split('_')[-1]
61 name_suffix = datetime.now().strftime('%Y%m%d%H%M')
Kang Xi11d278c2018-04-06 16:56:04 -040062
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 Xi6c762392018-05-30 09:27:34 -040069 vcpecommon.increase_ip_address_or_vni_in_template(vnf_template_file, ['vbrgemu_private_ip_0'])
Kang Xi11d278c2018-04-06 16:56:04 -040070 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 Xi6c762392018-05-30 09:27:34 -040078
Kang Xi11d278c2018-04-06 16:56:04 -040079def deploy_infra():
Kang Xi11d278c2018-04-06 16:56:04 -040080 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
128def deploy_custom_service():
129 nodes = ['brg', 'mux']
130 vcpecommon = VcpeCommon(nodes)
131 custom_service = vcpe_custom_service.CustomService(vcpecommon)
132
133 # clean up
Kang Xi0e0a1d62018-07-23 16:53:54 -0400134 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 Xi11d278c2018-04-06 16:56:04 -0400139
Kang Xi6c762392018-05-30 09:27:34 -0400140 #custom_service.clean_up_sdnc()
Kang Xi11d278c2018-04-06 16:56:04 -0400141
142 # create new service
143 csar_file = vcpecommon.find_file('rescust', 'csar', 'csar')
144 vgw_template_file = vcpecommon.find_file('vgw', 'json', 'preload_templates')
145 preload_dict = vcpecommon.load_preload_data()
146 custom_service.create_custom_service(csar_file, vgw_template_file, preload_dict)
147
148
149def closed_loop(lossrate=0):
150 if lossrate > 0:
151 while 'y' != raw_input('Please enter docker container "drools" in Policy VM and type "policy stop". Then enter y here: ').lower():
152 continue
153 nodes = ['brg', 'mux']
154 logger = logging.getLogger('__name__')
155 vcpecommon = VcpeCommon(nodes)
156 logger.info('Cleaning up vGMUX data reporting settings')
157 vcpecommon.del_vgmux_ves_mode()
158 time.sleep(2)
159 vcpecommon.del_vgmux_ves_collector()
160
161 logger.info('Staring vGMUX data reporting to DCAE')
162 time.sleep(2)
163 vcpecommon.set_vgmux_ves_collector()
164
165 logger.info('Setting vGMUX to report packet loss rate: %s', lossrate)
166 time.sleep(2)
167 vcpecommon.set_vgmux_packet_loss_rate(lossrate, vcpecommon.load_vgmux_vnf_name())
168 if lossrate > 0:
169 print('Please enter docker container "drools" in Policy VM and type "policy start". Then observe vGMUX being restarted.')
170
171
172def init_so_sdnc():
173 logger = logging.getLogger('__name__')
174 vcpecommon = VcpeCommon()
175 config_sdnc_so.insert_customer_service_to_so(vcpecommon)
176 config_sdnc_so.insert_customer_service_to_sdnc(vcpecommon)
177
178
Kang Xi6c762392018-05-30 09:27:34 -0400179def tmp_sniro():
180 logger = logging.getLogger(__name__)
181
182 vcpecommon = VcpeCommon()
183
184 svc_instance_uuid = vcpecommon.load_object(vcpecommon.svc_instance_uuid_file)
185 # Setting up SNIRO
186 config_sniro(vcpecommon, svc_instance_uuid['gmux'], svc_instance_uuid['brg'])
187
Kang Xi11d278c2018-04-06 16:56:04 -0400188if __name__ == '__main__':
189 logging.basicConfig(level=logging.INFO, format='%(message)s')
190
191 print('----------------------------------------------------------------------------------------------------')
192 print(' vcpe.py: Brief info about this program')
193# print(' vcpe.py sdc: Onboard VNFs, design and distribute vCPE services (under development)')
194 print(' vcpe.py init: Add customer service data to SDNC and SO DBs.')
195 print(' vcpe.py infra: Deploy infrastructure, including DHCP, AAA, DNS, Web Server, vBNG, vGMUX, vBRG.')
196 print(' vcpe.py customer: Deploy customer service, including vGW and VxLANs')
197 print(' vcpe.py loop: Test closed loop control')
198 print('----------------------------------------------------------------------------------------------------')
199
200 if len(sys.argv) != 2:
201 sys.exit()
202
203 if sys.argv[1] == 'sdc':
204 print('Under development')
205 elif sys.argv[1] == 'init':
206 if 'y' == raw_input('Ready to add customer service data to SDNC and SO DBs? This is needed only once.'
207 'y/n: ').lower():
208 init_so_sdnc()
209 elif sys.argv[1] == 'infra':
210 if 'y' == raw_input('Ready to deploy infrastructure? y/n: ').lower():
211 deploy_infra()
212 elif sys.argv[1] == 'customer':
213 if 'y' == raw_input('Ready to deploy customer service? y/n: ').lower():
214 deploy_custom_service()
215 elif sys.argv[1] == 'loop':
216 closed_loop(22)
217 elif sys.argv[1] == 'noloss':
218 closed_loop(0)
219 elif sys.argv[1] == 'brg':
220 deploy_brg_only()
221