blob: c768aa84dd27b5b06cfb9ff56960ab19128a1feb [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
Kang Xi11d278c2018-04-06 16:56:04 -040016
17
18def config_sniro(vcpecommon, vgmux_svc_instance_uuid, vbrg_svc_instance_uuid):
19 logger = logging.getLogger(__name__)
20
21 logger.info('\n----------------------------------------------------------------------------------')
22 logger.info('Start to config SNIRO homing emulator')
23
24 preloader = preload.Preload(vcpecommon)
25 template_sniro_data = vcpecommon.find_file('sniro_data', 'json', 'preload_templates')
26 template_sniro_request = vcpecommon.find_file('sniro_request', 'json', 'preload_templates')
27
28 vcperescust_csar = vcpecommon.find_file('rescust', 'csar', 'csar')
29 parser = csar_parser.CsarParser()
30 parser.parse_csar(vcperescust_csar)
31 tunnelxconn_ar_name = None
32 brg_ar_name = None
33 vgw_name = None
34 for model in parser.vnf_models:
Yang Xu86c0e4a2018-12-02 13:10:41 -050035 logger.info('modelCustomizationName = %s', model['modelCustomizationName'])
Yang Xu27e16242018-12-28 01:00:50 -050036 if 'tunnel' in model['modelCustomizationName'].lower():
Yang Xu86c0e4a2018-12-02 13:10:41 -050037 logger.info('tunnel is in %s', model['modelCustomizationName'])
Kang Xi11d278c2018-04-06 16:56:04 -040038 tunnelxconn_ar_name = model['modelCustomizationName']
Yang Xu27e16242018-12-28 01:00:50 -050039 elif 'brg' in model['modelCustomizationName'].lower():
Yang Xu86c0e4a2018-12-02 13:10:41 -050040 logger.info('brg is in %s', model['modelCustomizationName'])
Kang Xi11d278c2018-04-06 16:56:04 -040041 brg_ar_name = model['modelCustomizationName']
Yang Xu86c0e4a2018-12-02 13:10:41 -050042 #elif 'vgw' in model['modelCustomizationName']:
43 else:
Kang Xi11d278c2018-04-06 16:56:04 -040044 vgw_name = model['modelCustomizationName']
45
46 if not (tunnelxconn_ar_name and brg_ar_name and vgw_name):
47 logger.error('Cannot find all names from %s.', vcperescust_csar)
Bartek Grzybowski68d93c22019-10-30 10:55:55 +010048 sys.exit(1)
Kang Xi11d278c2018-04-06 16:56:04 -040049
50 preloader.preload_sniro(template_sniro_data, template_sniro_request, tunnelxconn_ar_name, vgw_name, brg_ar_name,
51 vgmux_svc_instance_uuid, vbrg_svc_instance_uuid)
52
53
54def create_one_service(vcpecommon, csar_file, vnf_template_file, preload_dict, suffix, heatbridge=False):
55 """
56 :return: service instance UUID
57 """
58 so = soutils.SoUtils(vcpecommon, 'v4')
59 return so.create_entire_service(csar_file, vnf_template_file, preload_dict, suffix, heatbridge)
60
Kang Xi6c762392018-05-30 09:27:34 -040061
Kang Xi11d278c2018-04-06 16:56:04 -040062def deploy_brg_only():
Kang Xi11d278c2018-04-06 16:56:04 -040063 logger = logging.getLogger(__name__)
64
65 vcpecommon = VcpeCommon()
66 preload_dict = vcpecommon.load_preload_data()
Kang Xi6c762392018-05-30 09:27:34 -040067# name_suffix = preload_dict['${brg_bng_net}'].split('_')[-1]
68 name_suffix = datetime.now().strftime('%Y%m%d%H%M')
Kang Xi11d278c2018-04-06 16:56:04 -040069
70 # create multiple services based on the pre-determined order
71 svc_instance_uuid = vcpecommon.load_object(vcpecommon.svc_instance_uuid_file)
72 for keyword in ['brg']:
73 heatbridge = 'gmux' == keyword
74 csar_file = vcpecommon.find_file(keyword, 'csar', 'csar')
75 vnf_template_file = vcpecommon.find_file(keyword, 'json', 'preload_templates')
Kang Xi6c762392018-05-30 09:27:34 -040076 vcpecommon.increase_ip_address_or_vni_in_template(vnf_template_file, ['vbrgemu_private_ip_0'])
Kang Xi11d278c2018-04-06 16:56:04 -040077 svc_instance_uuid[keyword] = create_one_service(vcpecommon, csar_file, vnf_template_file, preload_dict,
78 name_suffix, heatbridge)
79 if not svc_instance_uuid[keyword]:
Bartek Grzybowski68d93c22019-10-30 10:55:55 +010080 sys.exit(1)
Kang Xi11d278c2018-04-06 16:56:04 -040081
82 # Setting up SNIRO
Brian Freeman9b3d6ca2019-11-06 13:22:53 -050083 config_sniro(vcpecommon, svc_instance_uuid['gmux'], svc_instance_uuid['brgemu'])
Kang Xi11d278c2018-04-06 16:56:04 -040084
Kang Xi6c762392018-05-30 09:27:34 -040085
Kang Xi11d278c2018-04-06 16:56:04 -040086def deploy_infra():
Kang Xi11d278c2018-04-06 16:56:04 -040087 logger = logging.getLogger(__name__)
88
89 vcpecommon = VcpeCommon()
90
Brian Freeman9b3d6ca2019-11-06 13:22:53 -050091 # preload all VNF-API networks
92 network_template = vcpecommon.find_file('network.', 'json', 'preload_templates')
Kang Xi11d278c2018-04-06 16:56:04 -040093 name_suffix = datetime.now().strftime('%Y%m%d%H%M')
94 preloader = preload.Preload(vcpecommon)
95 preload_dict = preloader.preload_all_networks(network_template, name_suffix)
96 logger.debug('Initial preload dictionary:')
97 logger.debug(json.dumps(preload_dict, indent=4, sort_keys=True))
98 if not preload_dict:
99 logger.error("Failed to preload networks.")
Bartek Grzybowski68d93c22019-10-30 10:55:55 +0100100 sys.exit(1)
Kang Xi11d278c2018-04-06 16:56:04 -0400101 vcpecommon.save_preload_data(preload_dict)
102
Brian Freeman9b3d6ca2019-11-06 13:22:53 -0500103 # preload all GRA-API networks
104 network_template_gra = vcpecommon.find_file('networkgra.', 'json', 'preload_templates')
105 preloader = preload.Preload(vcpecommon)
106 preload_dict_gra = preloader.preload_all_networks(network_template_gra, name_suffix)
107 logger.debug('Initial preload dictionary:')
108 logger.debug(json.dumps(preload_dict, indent=4, sort_keys=True))
109 if not preload_dict_gra:
110 logger.error("Failed to preload networks.")
111 sys.exit(1)
112 vcpecommon.save_preload_data(preload_dict_gra)
113
Kang Xi11d278c2018-04-06 16:56:04 -0400114 # create multiple services based on the pre-determined order
115 svc_instance_uuid = {}
Brian Freeman9b3d6ca2019-11-06 13:22:53 -0500116 for keyword in ['infra', 'bng', 'gmux', 'brgemu']:
117 keyword_vnf=keyword + "_"
118 keyword_gra=keyword + "gra_"
Kang Xi11d278c2018-04-06 16:56:04 -0400119 heatbridge = 'gmux' == keyword
120 csar_file = vcpecommon.find_file(keyword, 'csar', 'csar')
Brian Freeman9b3d6ca2019-11-06 13:22:53 -0500121 vnf_template_file = vcpecommon.find_file(keyword_vnf, 'json', 'preload_templates')
122 gra_template_file = vcpecommon.find_file(keyword_gra, 'json', 'preload_templates')
123 if vcpecommon.gra_api_flag:
124 svc_instance_uuid[keyword] = create_one_service(vcpecommon, csar_file, gra_template_file, preload_dict,
125 name_suffix, heatbridge)
126 else:
127 svc_instance_uuid[keyword] = create_one_service(vcpecommon, csar_file, vnf_template_file, preload_dict,
Kang Xi11d278c2018-04-06 16:56:04 -0400128 name_suffix, heatbridge)
129 if not svc_instance_uuid[keyword]:
Bartek Grzybowski68d93c22019-10-30 10:55:55 +0100130 sys.exit(1)
Kang Xi11d278c2018-04-06 16:56:04 -0400131
132 vcpecommon.save_object(svc_instance_uuid, vcpecommon.svc_instance_uuid_file)
Brian Freeman9b3d6ca2019-11-06 13:22:53 -0500133
Kang Xi11d278c2018-04-06 16:56:04 -0400134 # Setting up SNIRO
Brian Freeman9b3d6ca2019-11-06 13:22:53 -0500135 config_sniro(vcpecommon, svc_instance_uuid['gmux'], svc_instance_uuid['brgemu'])
Kang Xi11d278c2018-04-06 16:56:04 -0400136
137 print('----------------------------------------------------------------------------------------------------')
138 print('Congratulations! The following have been completed correctly:')
139 print(' - Infrastructure Service Instantiation: ')
140 print(' * 4 VMs: DHCP, AAA, DNS, Web Server')
141 print(' * 2 Networks: CPE_PUBLIC, CPE_SIGNAL')
142 print(' - vBNG Service Instantiation: ')
143 print(' * 1 VM: vBNG')
144 print(' * 2 Networks: BRG_BNG, BNG_MUX')
145 print(' - vGMUX Service Instantiation: ')
146 print(' * 1 VM: vGMUX')
147 print(' * 1 Network: MUX_GW')
148 print(' - vBRG Service Instantiation: ')
149 print(' * 1 VM: vBRG')
150 print(' - Adding vGMUX vServer information to AAI.')
151 print(' - SNIRO Homing Emulator configuration.')
152
153
154def deploy_custom_service():
155 nodes = ['brg', 'mux']
156 vcpecommon = VcpeCommon(nodes)
157 custom_service = vcpe_custom_service.CustomService(vcpecommon)
158
159 # clean up
Kang Xi0e0a1d62018-07-23 16:53:54 -0400160 host_dic = {k: vcpecommon.hosts[k] for k in nodes}
161 if False:
162 if not vcpecommon.delete_vxlan_interfaces(host_dic):
Bartek Grzybowski68d93c22019-10-30 10:55:55 +0100163 sys.exit(1)
Kang Xi0e0a1d62018-07-23 16:53:54 -0400164 custom_service.del_all_vgw_stacks(vcpecommon.vgw_name_keyword)
Kang Xi11d278c2018-04-06 16:56:04 -0400165
Kang Xi6c762392018-05-30 09:27:34 -0400166 #custom_service.clean_up_sdnc()
Kang Xi11d278c2018-04-06 16:56:04 -0400167
168 # create new service
169 csar_file = vcpecommon.find_file('rescust', 'csar', 'csar')
170 vgw_template_file = vcpecommon.find_file('vgw', 'json', 'preload_templates')
Brian Freeman81f6e9e2018-11-11 22:36:20 -0500171 vgw_gra_template_file = vcpecommon.find_file('gwgra', 'json', 'preload_templates')
Kang Xi11d278c2018-04-06 16:56:04 -0400172 preload_dict = vcpecommon.load_preload_data()
Brian Freeman81f6e9e2018-11-11 22:36:20 -0500173 custom_service.create_custom_service(csar_file, vgw_template_file, vgw_gra_template_file, preload_dict)
Kang Xi11d278c2018-04-06 16:56:04 -0400174
175
176def closed_loop(lossrate=0):
Kang Xi11d278c2018-04-06 16:56:04 -0400177 nodes = ['brg', 'mux']
178 logger = logging.getLogger('__name__')
179 vcpecommon = VcpeCommon(nodes)
Bartek Grzybowskidbb3ba12019-09-25 11:21:42 +0200180
181 logger.info('Setting up closed loop policy')
182 policy_template_file = vcpecommon.find_file('operational.vcpe', 'json', 'preload_templates')
183 vcpecommon.set_closed_loop_policy(policy_template_file)
184
Kang Xi11d278c2018-04-06 16:56:04 -0400185 logger.info('Cleaning up vGMUX data reporting settings')
186 vcpecommon.del_vgmux_ves_mode()
187 time.sleep(2)
188 vcpecommon.del_vgmux_ves_collector()
189
Yang Xu9f935b22018-11-22 10:56:52 -0500190 logger.info('Starting vGMUX data reporting to DCAE')
Kang Xi11d278c2018-04-06 16:56:04 -0400191 time.sleep(2)
192 vcpecommon.set_vgmux_ves_collector()
193
194 logger.info('Setting vGMUX to report packet loss rate: %s', lossrate)
195 time.sleep(2)
196 vcpecommon.set_vgmux_packet_loss_rate(lossrate, vcpecommon.load_vgmux_vnf_name())
197 if lossrate > 0:
Yang Xu1b31a1d2019-06-26 01:50:15 -0400198 print('Now please observe vGMUX being restarted')
Kang Xi11d278c2018-04-06 16:56:04 -0400199
200
201def init_so_sdnc():
202 logger = logging.getLogger('__name__')
203 vcpecommon = VcpeCommon()
Brian Freeman9b3d6ca2019-11-06 13:22:53 -0500204 #config_sdnc_so.insert_sdnc_ip_pool(vcpecommon)
Kang Xi11d278c2018-04-06 16:56:04 -0400205 config_sdnc_so.insert_customer_service_to_so(vcpecommon)
Yang Xu63a0afd2018-11-20 16:01:01 -0500206 #config_sdnc_so.insert_customer_service_to_sdnc(vcpecommon)
Brian Freeman8076a872018-11-13 11:34:48 -0500207 vgw_vfmod_name_index= 0
208 vcpecommon.save_object(vgw_vfmod_name_index, vcpecommon.vgw_vfmod_name_index_file)
Kang Xi11d278c2018-04-06 16:56:04 -0400209
Yang Xu0e319ef2019-04-30 14:28:07 -0400210
211def init():
Yang Xuc52ed6e2019-04-29 00:20:52 -0400212 vcpecommon = VcpeCommon()
Yang Xu0e319ef2019-04-30 14:28:07 -0400213 init_sdc(vcpecommon)
214 download_vcpe_service_templates(vcpecommon)
215
216
217def init_sdc(vcpecommon):
Yang Xuc52ed6e2019-04-29 00:20:52 -0400218 sdc = sdcutils.SdcUtils(vcpecommon)
Brian Freemane8aa3f02019-09-20 08:29:22 -0500219 # default SDC creates BRG - remove this in frankfurt
220 #sdc.create_allotted_resource_subcategory('BRG')
Yang Xu0e319ef2019-04-30 14:28:07 -0400221
222
223def download_vcpe_service_templates(vcpecommon):
224 sdc = sdcutils.SdcUtils(vcpecommon)
225 sdc.download_vcpe_service_template()
226
Kang Xi11d278c2018-04-06 16:56:04 -0400227
Kang Xi6c762392018-05-30 09:27:34 -0400228def tmp_sniro():
229 logger = logging.getLogger(__name__)
230
231 vcpecommon = VcpeCommon()
232
233 svc_instance_uuid = vcpecommon.load_object(vcpecommon.svc_instance_uuid_file)
234 # Setting up SNIRO
Brian Freeman9b3d6ca2019-11-06 13:22:53 -0500235 config_sniro(vcpecommon, svc_instance_uuid['gmux'], svc_instance_uuid['brgemu'])
Kang Xi6c762392018-05-30 09:27:34 -0400236
Yang Xu0e319ef2019-04-30 14:28:07 -0400237
Yang Xu64339a82018-12-30 05:32:21 +0000238def test():
239 vcpecommon = VcpeCommon()
Yang Xu65b84a42018-12-31 17:48:02 +0000240 print("oom-k8s-04 public ip: %s" % (vcpecommon.get_vm_public_ip_by_nova('oom-k8s-04')))
Yang Xu64339a82018-12-30 05:32:21 +0000241
Yang Xu0e319ef2019-04-30 14:28:07 -0400242
Kang Xi11d278c2018-04-06 16:56:04 -0400243if __name__ == '__main__':
Kang Xi11d278c2018-04-06 16:56:04 -0400244 print('----------------------------------------------------------------------------------------------------')
245 print(' vcpe.py: Brief info about this program')
246# print(' vcpe.py sdc: Onboard VNFs, design and distribute vCPE services (under development)')
247 print(' vcpe.py init: Add customer service data to SDNC and SO DBs.')
248 print(' vcpe.py infra: Deploy infrastructure, including DHCP, AAA, DNS, Web Server, vBNG, vGMUX, vBRG.')
Brian Freemanec9fe0e2018-11-12 12:37:12 -0500249 print(' vcpe.py brg: Deploy brg only (for testing after infra succeeds).')
Kang Xi11d278c2018-04-06 16:56:04 -0400250 print(' vcpe.py customer: Deploy customer service, including vGW and VxLANs')
Bartek Grzybowski304628b2019-10-17 10:44:39 +0200251 print(' vcpe.py loop: Test closed loop control (packet loss set to 22)')
252 print(' vcpe.py noloss: Set vGMUX packet loss to 0')
Kang Xi11d278c2018-04-06 16:56:04 -0400253 print('----------------------------------------------------------------------------------------------------')
254
255 if len(sys.argv) != 2:
256 sys.exit()
257
258 if sys.argv[1] == 'sdc':
259 print('Under development')
260 elif sys.argv[1] == 'init':
Yang Xu0e319ef2019-04-30 14:28:07 -0400261 init()
Kang Xi11d278c2018-04-06 16:56:04 -0400262 init_so_sdnc()
263 elif sys.argv[1] == 'infra':
Brian Freeman9b3d6ca2019-11-06 13:22:53 -0500264 #if 'y' == raw_input('Ready to deploy infrastructure? y/n: ').lower():
Kang Xi11d278c2018-04-06 16:56:04 -0400265 deploy_infra()
266 elif sys.argv[1] == 'customer':
267 if 'y' == raw_input('Ready to deploy customer service? y/n: ').lower():
268 deploy_custom_service()
269 elif sys.argv[1] == 'loop':
270 closed_loop(22)
271 elif sys.argv[1] == 'noloss':
272 closed_loop(0)
273 elif sys.argv[1] == 'brg':
274 deploy_brg_only()
Yang Xu86c0e4a2018-12-02 13:10:41 -0500275 elif sys.argv[1] == 'sniro':
276 tmp_sniro()
Yang Xu64339a82018-12-30 05:32:21 +0000277 elif sys.argv[1] == 'test':
278 test()
Kang Xi11d278c2018-04-06 16:56:04 -0400279