4 logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)s %(name)s.%(funcName)s(): %(message)s')
5 #logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s %(name)s.%(funcName)s(): %(message)s')
8 from vcpecommon import *
11 from datetime import datetime
13 import vcpe_custom_service
19 def config_sniro(vcpecommon, vgmux_svc_instance_uuid, vbrg_svc_instance_uuid):
20 logger = logging.getLogger(__name__)
22 logger.info('\n----------------------------------------------------------------------------------')
23 logger.info('Start to config SNIRO homing emulator')
25 preloader = preload.Preload(vcpecommon)
26 template_sniro_data = vcpecommon.find_file('sniro_data', 'json', 'preload_templates')
27 template_sniro_request = vcpecommon.find_file('sniro_request', 'json', 'preload_templates')
29 vcperescust_csar = vcpecommon.find_file('rescust', 'csar', 'csar')
30 parser = csar_parser.CsarParser()
31 parser.parse_csar(vcperescust_csar)
32 tunnelxconn_ar_name = None
35 for model in parser.vnf_models:
36 logger.info('modelCustomizationName = %s', model['modelCustomizationName'])
37 if 'tunnel' in model['modelCustomizationName'].lower():
38 logger.info('tunnel is in %s', model['modelCustomizationName'])
39 tunnelxconn_ar_name = model['modelCustomizationName']
40 elif 'brg' in model['modelCustomizationName'].lower():
41 logger.info('brg is in %s', model['modelCustomizationName'])
42 brg_ar_name = model['modelCustomizationName']
43 #elif 'vgw' in model['modelCustomizationName']:
45 vgw_name = model['modelCustomizationName']
47 if not (tunnelxconn_ar_name and brg_ar_name and vgw_name):
48 logger.error('Cannot find all names from %s.', vcperescust_csar)
51 preloader.preload_sniro(template_sniro_data, template_sniro_request, tunnelxconn_ar_name, vgw_name, brg_ar_name,
52 vgmux_svc_instance_uuid, vbrg_svc_instance_uuid)
55 def create_one_service(vcpecommon, csar_file, vnf_template_file, preload_dict, suffix, heatbridge=False):
57 :return: service instance UUID
59 so = soutils.SoUtils(vcpecommon, 'v4')
60 return so.create_entire_service(csar_file, vnf_template_file, preload_dict, suffix, heatbridge)
63 def deploy_brg_only():
64 logger = logging.getLogger(__name__)
66 vcpecommon = VcpeCommon()
67 preload_dict = vcpecommon.load_preload_data()
68 # name_suffix = preload_dict['${brg_bng_net}'].split('_')[-1]
69 name_suffix = datetime.now().strftime('%Y%m%d%H%M')
71 # create multiple services based on the pre-determined order
72 svc_instance_uuid = vcpecommon.load_object(vcpecommon.svc_instance_uuid_file)
73 for keyword in ['brg']:
74 heatbridge = 'gmux' == keyword
75 csar_file = vcpecommon.find_file(keyword, 'csar', 'csar')
76 vnf_template_file = vcpecommon.find_file(keyword, 'json', 'preload_templates')
77 vcpecommon.increase_ip_address_or_vni_in_template(vnf_template_file, ['vbrgemu_private_ip_0'])
78 svc_instance_uuid[keyword] = create_one_service(vcpecommon, csar_file, vnf_template_file, preload_dict,
79 name_suffix, heatbridge)
80 if not svc_instance_uuid[keyword]:
84 config_sniro(vcpecommon, svc_instance_uuid['gmux'], svc_instance_uuid['brg'])
88 logger = logging.getLogger(__name__)
90 vcpecommon = VcpeCommon()
92 # preload all networks
93 network_template = vcpecommon.find_file('network', 'json', 'preload_templates')
94 name_suffix = datetime.now().strftime('%Y%m%d%H%M')
95 preloader = preload.Preload(vcpecommon)
96 preload_dict = preloader.preload_all_networks(network_template, name_suffix)
97 logger.debug('Initial preload dictionary:')
98 logger.debug(json.dumps(preload_dict, indent=4, sort_keys=True))
100 logger.error("Failed to preload networks.")
102 vcpecommon.save_preload_data(preload_dict)
104 # create multiple services based on the pre-determined order
105 svc_instance_uuid = {}
106 for keyword in ['infra', 'bng', 'gmux', 'brg']:
107 heatbridge = 'gmux' == keyword
108 csar_file = vcpecommon.find_file(keyword, 'csar', 'csar')
109 vnf_template_file = vcpecommon.find_file(keyword, 'json', 'preload_templates')
110 svc_instance_uuid[keyword] = create_one_service(vcpecommon, csar_file, vnf_template_file, preload_dict,
111 name_suffix, heatbridge)
112 if not svc_instance_uuid[keyword]:
115 vcpecommon.save_object(svc_instance_uuid, vcpecommon.svc_instance_uuid_file)
117 config_sniro(vcpecommon, svc_instance_uuid['gmux'], svc_instance_uuid['brg'])
119 print('----------------------------------------------------------------------------------------------------')
120 print('Congratulations! The following have been completed correctly:')
121 print(' - Infrastructure Service Instantiation: ')
122 print(' * 4 VMs: DHCP, AAA, DNS, Web Server')
123 print(' * 2 Networks: CPE_PUBLIC, CPE_SIGNAL')
124 print(' - vBNG Service Instantiation: ')
125 print(' * 1 VM: vBNG')
126 print(' * 2 Networks: BRG_BNG, BNG_MUX')
127 print(' - vGMUX Service Instantiation: ')
128 print(' * 1 VM: vGMUX')
129 print(' * 1 Network: MUX_GW')
130 print(' - vBRG Service Instantiation: ')
131 print(' * 1 VM: vBRG')
132 print(' - Adding vGMUX vServer information to AAI.')
133 print(' - SNIRO Homing Emulator configuration.')
136 def deploy_custom_service():
137 nodes = ['brg', 'mux']
138 vcpecommon = VcpeCommon(nodes)
139 custom_service = vcpe_custom_service.CustomService(vcpecommon)
142 host_dic = {k: vcpecommon.hosts[k] for k in nodes}
144 if not vcpecommon.delete_vxlan_interfaces(host_dic):
146 custom_service.del_all_vgw_stacks(vcpecommon.vgw_name_keyword)
148 #custom_service.clean_up_sdnc()
151 csar_file = vcpecommon.find_file('rescust', 'csar', 'csar')
152 vgw_template_file = vcpecommon.find_file('vgw', 'json', 'preload_templates')
153 vgw_gra_template_file = vcpecommon.find_file('gwgra', 'json', 'preload_templates')
154 preload_dict = vcpecommon.load_preload_data()
155 custom_service.create_custom_service(csar_file, vgw_template_file, vgw_gra_template_file, preload_dict)
158 def closed_loop(lossrate=0):
159 nodes = ['brg', 'mux']
160 logger = logging.getLogger('__name__')
161 vcpecommon = VcpeCommon(nodes)
162 logger.info('Cleaning up vGMUX data reporting settings')
163 vcpecommon.del_vgmux_ves_mode()
165 vcpecommon.del_vgmux_ves_collector()
167 logger.info('Starting vGMUX data reporting to DCAE')
169 vcpecommon.set_vgmux_ves_collector()
171 logger.info('Setting vGMUX to report packet loss rate: %s', lossrate)
173 vcpecommon.set_vgmux_packet_loss_rate(lossrate, vcpecommon.load_vgmux_vnf_name())
175 print('Now please observe vGMUX being restarted')
179 logger = logging.getLogger('__name__')
180 vcpecommon = VcpeCommon()
181 config_sdnc_so.insert_customer_service_to_so(vcpecommon)
182 #config_sdnc_so.insert_customer_service_to_sdnc(vcpecommon)
183 vgw_vfmod_name_index= 0
184 vcpecommon.save_object(vgw_vfmod_name_index, vcpecommon.vgw_vfmod_name_index_file)
188 vcpecommon = VcpeCommon()
190 download_vcpe_service_templates(vcpecommon)
193 def init_sdc(vcpecommon):
194 sdc = sdcutils.SdcUtils(vcpecommon)
195 # default SDC creates BRG - remove this in frankfurt
196 #sdc.create_allotted_resource_subcategory('BRG')
199 def download_vcpe_service_templates(vcpecommon):
200 sdc = sdcutils.SdcUtils(vcpecommon)
201 sdc.download_vcpe_service_template()
205 logger = logging.getLogger(__name__)
207 vcpecommon = VcpeCommon()
209 svc_instance_uuid = vcpecommon.load_object(vcpecommon.svc_instance_uuid_file)
211 config_sniro(vcpecommon, svc_instance_uuid['gmux'], svc_instance_uuid['brg'])
215 vcpecommon = VcpeCommon()
216 print("oom-k8s-04 public ip: %s" % (vcpecommon.get_vm_public_ip_by_nova('oom-k8s-04')))
219 if __name__ == '__main__':
220 print('----------------------------------------------------------------------------------------------------')
221 print(' vcpe.py: Brief info about this program')
222 # print(' vcpe.py sdc: Onboard VNFs, design and distribute vCPE services (under development)')
223 print(' vcpe.py init: Add customer service data to SDNC and SO DBs.')
224 print(' vcpe.py infra: Deploy infrastructure, including DHCP, AAA, DNS, Web Server, vBNG, vGMUX, vBRG.')
225 print(' vcpe.py brg: Deploy brg only (for testing after infra succeeds).')
226 print(' vcpe.py customer: Deploy customer service, including vGW and VxLANs')
227 print(' vcpe.py loop: Test closed loop control')
228 print('----------------------------------------------------------------------------------------------------')
230 if len(sys.argv) != 2:
233 if sys.argv[1] == 'sdc':
234 print('Under development')
235 elif sys.argv[1] == 'init':
238 elif sys.argv[1] == 'infra':
239 if 'y' == raw_input('Ready to deploy infrastructure? y/n: ').lower():
241 elif sys.argv[1] == 'customer':
242 if 'y' == raw_input('Ready to deploy customer service? y/n: ').lower():
243 deploy_custom_service()
244 elif sys.argv[1] == 'loop':
246 elif sys.argv[1] == 'noloss':
248 elif sys.argv[1] == 'brg':
250 elif sys.argv[1] == 'sniro':
252 elif sys.argv[1] == 'test':