blob: c4737296b9f1aad9b1be549fc7c54f20a509552e [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 Xi6c762392018-05-30 09:27:34 -0400134 #host_dic = {k: vcpecommon.hosts[k] for k in nodes}
135 #if not vcpecommon.delete_vxlan_interfaces(host_dic):
136 # sys.exit()
Kang Xi11d278c2018-04-06 16:56:04 -0400137
Kang Xi6c762392018-05-30 09:27:34 -0400138 #custom_service.clean_up_sdnc()
139 #custom_service.del_all_vgw_stacks(vcpecommon.vgw_name_keyword)
Kang Xi11d278c2018-04-06 16:56:04 -0400140
141 # create new service
142 csar_file = vcpecommon.find_file('rescust', 'csar', 'csar')
143 vgw_template_file = vcpecommon.find_file('vgw', 'json', 'preload_templates')
144 preload_dict = vcpecommon.load_preload_data()
145 custom_service.create_custom_service(csar_file, vgw_template_file, preload_dict)
146
147
148def closed_loop(lossrate=0):
149 if lossrate > 0:
150 while 'y' != raw_input('Please enter docker container "drools" in Policy VM and type "policy stop". Then enter y here: ').lower():
151 continue
152 nodes = ['brg', 'mux']
153 logger = logging.getLogger('__name__')
154 vcpecommon = VcpeCommon(nodes)
155 logger.info('Cleaning up vGMUX data reporting settings')
156 vcpecommon.del_vgmux_ves_mode()
157 time.sleep(2)
158 vcpecommon.del_vgmux_ves_collector()
159
160 logger.info('Staring vGMUX data reporting to DCAE')
161 time.sleep(2)
162 vcpecommon.set_vgmux_ves_collector()
163
164 logger.info('Setting vGMUX to report packet loss rate: %s', lossrate)
165 time.sleep(2)
166 vcpecommon.set_vgmux_packet_loss_rate(lossrate, vcpecommon.load_vgmux_vnf_name())
167 if lossrate > 0:
168 print('Please enter docker container "drools" in Policy VM and type "policy start". Then observe vGMUX being restarted.')
169
170
171def init_so_sdnc():
172 logger = logging.getLogger('__name__')
173 vcpecommon = VcpeCommon()
174 config_sdnc_so.insert_customer_service_to_so(vcpecommon)
175 config_sdnc_so.insert_customer_service_to_sdnc(vcpecommon)
176
177
Kang Xi6c762392018-05-30 09:27:34 -0400178def tmp_sniro():
179 logger = logging.getLogger(__name__)
180
181 vcpecommon = VcpeCommon()
182
183 svc_instance_uuid = vcpecommon.load_object(vcpecommon.svc_instance_uuid_file)
184 # Setting up SNIRO
185 config_sniro(vcpecommon, svc_instance_uuid['gmux'], svc_instance_uuid['brg'])
186
Kang Xi11d278c2018-04-06 16:56:04 -0400187if __name__ == '__main__':
188 logging.basicConfig(level=logging.INFO, format='%(message)s')
189
190 print('----------------------------------------------------------------------------------------------------')
191 print(' vcpe.py: Brief info about this program')
192# print(' vcpe.py sdc: Onboard VNFs, design and distribute vCPE services (under development)')
193 print(' vcpe.py init: Add customer service data to SDNC and SO DBs.')
194 print(' vcpe.py infra: Deploy infrastructure, including DHCP, AAA, DNS, Web Server, vBNG, vGMUX, vBRG.')
195 print(' vcpe.py customer: Deploy customer service, including vGW and VxLANs')
196 print(' vcpe.py loop: Test closed loop control')
197 print('----------------------------------------------------------------------------------------------------')
198
199 if len(sys.argv) != 2:
200 sys.exit()
201
202 if sys.argv[1] == 'sdc':
203 print('Under development')
204 elif sys.argv[1] == 'init':
205 if 'y' == raw_input('Ready to add customer service data to SDNC and SO DBs? This is needed only once.'
206 'y/n: ').lower():
207 init_so_sdnc()
208 elif sys.argv[1] == 'infra':
209 if 'y' == raw_input('Ready to deploy infrastructure? y/n: ').lower():
210 deploy_infra()
211 elif sys.argv[1] == 'customer':
212 if 'y' == raw_input('Ready to deploy customer service? y/n: ').lower():
213 deploy_custom_service()
214 elif sys.argv[1] == 'loop':
215 closed_loop(22)
216 elif sys.argv[1] == 'noloss':
217 closed_loop(0)
218 elif sys.argv[1] == 'brg':
219 deploy_brg_only()
220