blob: 3221d482afe731055cc55905e98eaa7a259716eb [file] [log] [blame]
Kang Xi11d278c2018-04-06 16:56:04 -04001#! /usr/bin/python
Yang Xu1b31a1d2019-06-26 01:50:15 -04002
Kang Xi11d278c2018-04-06 16:56:04 -04003import logging
Yang Xu1b31a1d2019-06-26 01:50:15 -04004logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s %(name)s.%(funcName)s(): %(message)s')
5
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)
48 sys.exit()
49
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]:
80 sys.exit()
81
82 # Setting up SNIRO
83 config_sniro(vcpecommon, svc_instance_uuid['gmux'], svc_instance_uuid['brg'])
84
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
91 # preload all networks
92 network_template = vcpecommon.find_file('network', 'json', 'preload_templates')
93 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.")
100 sys.exit()
101 vcpecommon.save_preload_data(preload_dict)
102
103 # create multiple services based on the pre-determined order
104 svc_instance_uuid = {}
105 for keyword in ['infra', 'bng', 'gmux', 'brg']:
106 heatbridge = 'gmux' == keyword
107 csar_file = vcpecommon.find_file(keyword, 'csar', 'csar')
108 vnf_template_file = vcpecommon.find_file(keyword, 'json', 'preload_templates')
109 svc_instance_uuid[keyword] = create_one_service(vcpecommon, csar_file, vnf_template_file, preload_dict,
110 name_suffix, heatbridge)
111 if not svc_instance_uuid[keyword]:
112 sys.exit()
113
114 vcpecommon.save_object(svc_instance_uuid, vcpecommon.svc_instance_uuid_file)
115 # Setting up SNIRO
116 config_sniro(vcpecommon, svc_instance_uuid['gmux'], svc_instance_uuid['brg'])
117
118 print('----------------------------------------------------------------------------------------------------')
119 print('Congratulations! The following have been completed correctly:')
120 print(' - Infrastructure Service Instantiation: ')
121 print(' * 4 VMs: DHCP, AAA, DNS, Web Server')
122 print(' * 2 Networks: CPE_PUBLIC, CPE_SIGNAL')
123 print(' - vBNG Service Instantiation: ')
124 print(' * 1 VM: vBNG')
125 print(' * 2 Networks: BRG_BNG, BNG_MUX')
126 print(' - vGMUX Service Instantiation: ')
127 print(' * 1 VM: vGMUX')
128 print(' * 1 Network: MUX_GW')
129 print(' - vBRG Service Instantiation: ')
130 print(' * 1 VM: vBRG')
131 print(' - Adding vGMUX vServer information to AAI.')
132 print(' - SNIRO Homing Emulator configuration.')
133
134
135def deploy_custom_service():
136 nodes = ['brg', 'mux']
137 vcpecommon = VcpeCommon(nodes)
138 custom_service = vcpe_custom_service.CustomService(vcpecommon)
139
140 # clean up
Kang Xi0e0a1d62018-07-23 16:53:54 -0400141 host_dic = {k: vcpecommon.hosts[k] for k in nodes}
142 if False:
143 if not vcpecommon.delete_vxlan_interfaces(host_dic):
144 sys.exit()
145 custom_service.del_all_vgw_stacks(vcpecommon.vgw_name_keyword)
Kang Xi11d278c2018-04-06 16:56:04 -0400146
Kang Xi6c762392018-05-30 09:27:34 -0400147 #custom_service.clean_up_sdnc()
Kang Xi11d278c2018-04-06 16:56:04 -0400148
149 # create new service
150 csar_file = vcpecommon.find_file('rescust', 'csar', 'csar')
151 vgw_template_file = vcpecommon.find_file('vgw', 'json', 'preload_templates')
Brian Freeman81f6e9e2018-11-11 22:36:20 -0500152 vgw_gra_template_file = vcpecommon.find_file('gwgra', 'json', 'preload_templates')
Kang Xi11d278c2018-04-06 16:56:04 -0400153 preload_dict = vcpecommon.load_preload_data()
Brian Freeman81f6e9e2018-11-11 22:36:20 -0500154 custom_service.create_custom_service(csar_file, vgw_template_file, vgw_gra_template_file, preload_dict)
Kang Xi11d278c2018-04-06 16:56:04 -0400155
156
157def closed_loop(lossrate=0):
Kang Xi11d278c2018-04-06 16:56:04 -0400158 nodes = ['brg', 'mux']
159 logger = logging.getLogger('__name__')
160 vcpecommon = VcpeCommon(nodes)
161 logger.info('Cleaning up vGMUX data reporting settings')
162 vcpecommon.del_vgmux_ves_mode()
163 time.sleep(2)
164 vcpecommon.del_vgmux_ves_collector()
165
Yang Xu9f935b22018-11-22 10:56:52 -0500166 logger.info('Starting vGMUX data reporting to DCAE')
Kang Xi11d278c2018-04-06 16:56:04 -0400167 time.sleep(2)
168 vcpecommon.set_vgmux_ves_collector()
169
170 logger.info('Setting vGMUX to report packet loss rate: %s', lossrate)
171 time.sleep(2)
172 vcpecommon.set_vgmux_packet_loss_rate(lossrate, vcpecommon.load_vgmux_vnf_name())
173 if lossrate > 0:
Yang Xu1b31a1d2019-06-26 01:50:15 -0400174 print('Now please observe vGMUX being restarted')
Kang Xi11d278c2018-04-06 16:56:04 -0400175
176
177def init_so_sdnc():
178 logger = logging.getLogger('__name__')
179 vcpecommon = VcpeCommon()
180 config_sdnc_so.insert_customer_service_to_so(vcpecommon)
Yang Xu63a0afd2018-11-20 16:01:01 -0500181 #config_sdnc_so.insert_customer_service_to_sdnc(vcpecommon)
Brian Freeman8076a872018-11-13 11:34:48 -0500182 vgw_vfmod_name_index= 0
183 vcpecommon.save_object(vgw_vfmod_name_index, vcpecommon.vgw_vfmod_name_index_file)
Kang Xi11d278c2018-04-06 16:56:04 -0400184
Yang Xu0e319ef2019-04-30 14:28:07 -0400185
186def init():
Yang Xuc52ed6e2019-04-29 00:20:52 -0400187 vcpecommon = VcpeCommon()
Yang Xu0e319ef2019-04-30 14:28:07 -0400188 init_sdc(vcpecommon)
189 download_vcpe_service_templates(vcpecommon)
190
191
192def init_sdc(vcpecommon):
Yang Xuc52ed6e2019-04-29 00:20:52 -0400193 sdc = sdcutils.SdcUtils(vcpecommon)
Yang Xu0e319ef2019-04-30 14:28:07 -0400194 sdc.create_allotted_resource_subcategory('BRG')
195
196
197def download_vcpe_service_templates(vcpecommon):
198 sdc = sdcutils.SdcUtils(vcpecommon)
199 sdc.download_vcpe_service_template()
200
Kang Xi11d278c2018-04-06 16:56:04 -0400201
Kang Xi6c762392018-05-30 09:27:34 -0400202def tmp_sniro():
203 logger = logging.getLogger(__name__)
204
205 vcpecommon = VcpeCommon()
206
207 svc_instance_uuid = vcpecommon.load_object(vcpecommon.svc_instance_uuid_file)
208 # Setting up SNIRO
209 config_sniro(vcpecommon, svc_instance_uuid['gmux'], svc_instance_uuid['brg'])
210
Yang Xu0e319ef2019-04-30 14:28:07 -0400211
Yang Xu64339a82018-12-30 05:32:21 +0000212def test():
213 vcpecommon = VcpeCommon()
Yang Xu65b84a42018-12-31 17:48:02 +0000214 print("oom-k8s-04 public ip: %s" % (vcpecommon.get_vm_public_ip_by_nova('oom-k8s-04')))
Yang Xu64339a82018-12-30 05:32:21 +0000215
Yang Xu0e319ef2019-04-30 14:28:07 -0400216
Kang Xi11d278c2018-04-06 16:56:04 -0400217if __name__ == '__main__':
Kang Xi11d278c2018-04-06 16:56:04 -0400218 print('----------------------------------------------------------------------------------------------------')
219 print(' vcpe.py: Brief info about this program')
220# print(' vcpe.py sdc: Onboard VNFs, design and distribute vCPE services (under development)')
221 print(' vcpe.py init: Add customer service data to SDNC and SO DBs.')
222 print(' vcpe.py infra: Deploy infrastructure, including DHCP, AAA, DNS, Web Server, vBNG, vGMUX, vBRG.')
Brian Freemanec9fe0e2018-11-12 12:37:12 -0500223 print(' vcpe.py brg: Deploy brg only (for testing after infra succeeds).')
Kang Xi11d278c2018-04-06 16:56:04 -0400224 print(' vcpe.py customer: Deploy customer service, including vGW and VxLANs')
225 print(' vcpe.py loop: Test closed loop control')
226 print('----------------------------------------------------------------------------------------------------')
227
228 if len(sys.argv) != 2:
229 sys.exit()
230
231 if sys.argv[1] == 'sdc':
232 print('Under development')
233 elif sys.argv[1] == 'init':
Yang Xu0e319ef2019-04-30 14:28:07 -0400234 init()
Kang Xi11d278c2018-04-06 16:56:04 -0400235 init_so_sdnc()
236 elif sys.argv[1] == 'infra':
237 if 'y' == raw_input('Ready to deploy infrastructure? y/n: ').lower():
238 deploy_infra()
239 elif sys.argv[1] == 'customer':
240 if 'y' == raw_input('Ready to deploy customer service? y/n: ').lower():
241 deploy_custom_service()
242 elif sys.argv[1] == 'loop':
243 closed_loop(22)
244 elif sys.argv[1] == 'noloss':
245 closed_loop(0)
246 elif sys.argv[1] == 'brg':
247 deploy_brg_only()
Yang Xu86c0e4a2018-12-02 13:10:41 -0500248 elif sys.argv[1] == 'sniro':
249 tmp_sniro()
Yang Xu64339a82018-12-30 05:32:21 +0000250 elif sys.argv[1] == 'test':
251 test()
Kang Xi11d278c2018-04-06 16:56:04 -0400252