4 logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s %(name)s.%(funcName)s(): %(message)s')
7 from vcpecommon import *
10 from datetime import datetime
12 import vcpe_custom_service
18 def config_sniro(vcpecommon, vgmux_svc_instance_uuid, vbrg_svc_instance_uuid):
19 logger = logging.getLogger(__name__)
21 logger.info('\n----------------------------------------------------------------------------------')
22 logger.info('Start to config SNIRO homing emulator')
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')
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
34 for model in parser.vnf_models:
35 logger.info('modelCustomizationName = %s', model['modelCustomizationName'])
36 if 'tunnel' in model['modelCustomizationName'].lower():
37 logger.info('tunnel is in %s', model['modelCustomizationName'])
38 tunnelxconn_ar_name = model['modelCustomizationName']
39 elif 'brg' in model['modelCustomizationName'].lower():
40 logger.info('brg is in %s', model['modelCustomizationName'])
41 brg_ar_name = model['modelCustomizationName']
42 #elif 'vgw' in model['modelCustomizationName']:
44 vgw_name = model['modelCustomizationName']
46 if not (tunnelxconn_ar_name and brg_ar_name and vgw_name):
47 logger.error('Cannot find all names from %s.', vcperescust_csar)
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)
54 def create_one_service(vcpecommon, csar_file, vnf_template_file, preload_dict, suffix, heatbridge=False):
56 :return: service instance UUID
58 so = soutils.SoUtils(vcpecommon, 'v4')
59 return so.create_entire_service(csar_file, vnf_template_file, preload_dict, suffix, heatbridge)
62 def deploy_brg_only():
63 logger = logging.getLogger(__name__)
65 vcpecommon = VcpeCommon()
66 preload_dict = vcpecommon.load_preload_data()
67 # name_suffix = preload_dict['${brg_bng_net}'].split('_')[-1]
68 name_suffix = datetime.now().strftime('%Y%m%d%H%M')
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')
76 vcpecommon.increase_ip_address_or_vni_in_template(vnf_template_file, ['vbrgemu_private_ip_0'])
77 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]:
83 config_sniro(vcpecommon, svc_instance_uuid['gmux'], svc_instance_uuid['brg'])
87 logger = logging.getLogger(__name__)
89 vcpecommon = VcpeCommon()
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))
99 logger.error("Failed to preload networks.")
101 vcpecommon.save_preload_data(preload_dict)
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]:
114 vcpecommon.save_object(svc_instance_uuid, vcpecommon.svc_instance_uuid_file)
116 config_sniro(vcpecommon, svc_instance_uuid['gmux'], svc_instance_uuid['brg'])
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.')
135 def deploy_custom_service():
136 nodes = ['brg', 'mux']
137 vcpecommon = VcpeCommon(nodes)
138 custom_service = vcpe_custom_service.CustomService(vcpecommon)
141 host_dic = {k: vcpecommon.hosts[k] for k in nodes}
143 if not vcpecommon.delete_vxlan_interfaces(host_dic):
145 custom_service.del_all_vgw_stacks(vcpecommon.vgw_name_keyword)
147 #custom_service.clean_up_sdnc()
150 csar_file = vcpecommon.find_file('rescust', 'csar', 'csar')
151 vgw_template_file = vcpecommon.find_file('vgw', 'json', 'preload_templates')
152 vgw_gra_template_file = vcpecommon.find_file('gwgra', 'json', 'preload_templates')
153 preload_dict = vcpecommon.load_preload_data()
154 custom_service.create_custom_service(csar_file, vgw_template_file, vgw_gra_template_file, preload_dict)
157 def closed_loop(lossrate=0):
158 nodes = ['brg', 'mux']
159 logger = logging.getLogger('__name__')
160 vcpecommon = VcpeCommon(nodes)
162 logger.info('Setting up closed loop policy')
163 policy_template_file = vcpecommon.find_file('operational.vcpe', 'json', 'preload_templates')
164 vcpecommon.set_closed_loop_policy(policy_template_file)
166 logger.info('Cleaning up vGMUX data reporting settings')
167 vcpecommon.del_vgmux_ves_mode()
169 vcpecommon.del_vgmux_ves_collector()
171 logger.info('Starting vGMUX data reporting to DCAE')
173 vcpecommon.set_vgmux_ves_collector()
175 logger.info('Setting vGMUX to report packet loss rate: %s', lossrate)
177 vcpecommon.set_vgmux_packet_loss_rate(lossrate, vcpecommon.load_vgmux_vnf_name())
179 print('Now please observe vGMUX being restarted')
183 logger = logging.getLogger('__name__')
184 vcpecommon = VcpeCommon()
185 config_sdnc_so.insert_sdnc_ip_pool(vcpecommon)
186 config_sdnc_so.insert_customer_service_to_so(vcpecommon)
187 #config_sdnc_so.insert_customer_service_to_sdnc(vcpecommon)
188 vgw_vfmod_name_index= 0
189 vcpecommon.save_object(vgw_vfmod_name_index, vcpecommon.vgw_vfmod_name_index_file)
193 vcpecommon = VcpeCommon()
195 download_vcpe_service_templates(vcpecommon)
198 def init_sdc(vcpecommon):
199 sdc = sdcutils.SdcUtils(vcpecommon)
200 # default SDC creates BRG - remove this in frankfurt
201 #sdc.create_allotted_resource_subcategory('BRG')
204 def download_vcpe_service_templates(vcpecommon):
205 sdc = sdcutils.SdcUtils(vcpecommon)
206 sdc.download_vcpe_service_template()
210 logger = logging.getLogger(__name__)
212 vcpecommon = VcpeCommon()
214 svc_instance_uuid = vcpecommon.load_object(vcpecommon.svc_instance_uuid_file)
216 config_sniro(vcpecommon, svc_instance_uuid['gmux'], svc_instance_uuid['brg'])
220 vcpecommon = VcpeCommon()
221 print("oom-k8s-04 public ip: %s" % (vcpecommon.get_vm_public_ip_by_nova('oom-k8s-04')))
224 if __name__ == '__main__':
225 print('----------------------------------------------------------------------------------------------------')
226 print(' vcpe.py: Brief info about this program')
227 # print(' vcpe.py sdc: Onboard VNFs, design and distribute vCPE services (under development)')
228 print(' vcpe.py init: Add customer service data to SDNC and SO DBs.')
229 print(' vcpe.py infra: Deploy infrastructure, including DHCP, AAA, DNS, Web Server, vBNG, vGMUX, vBRG.')
230 print(' vcpe.py brg: Deploy brg only (for testing after infra succeeds).')
231 print(' vcpe.py customer: Deploy customer service, including vGW and VxLANs')
232 print(' vcpe.py loop: Test closed loop control (packet loss set to 22)')
233 print(' vcpe.py noloss: Set vGMUX packet loss to 0')
234 print('----------------------------------------------------------------------------------------------------')
236 if len(sys.argv) != 2:
239 if sys.argv[1] == 'sdc':
240 print('Under development')
241 elif sys.argv[1] == 'init':
244 elif sys.argv[1] == 'infra':
245 if 'y' == raw_input('Ready to deploy infrastructure? y/n: ').lower():
247 elif sys.argv[1] == 'customer':
248 if 'y' == raw_input('Ready to deploy customer service? y/n: ').lower():
249 deploy_custom_service()
250 elif sys.argv[1] == 'loop':
252 elif sys.argv[1] == 'noloss':
254 elif sys.argv[1] == 'brg':
256 elif sys.argv[1] == 'sniro':
258 elif sys.argv[1] == 'test':