- print(juniper_contrail.used_vni)
- # 1. Read virtual networks from overlay controller
- print('1. Read virtual networks from overlay controller')
- try:
- vnets = juniper_contrail._get_virtual_networks(overlay_url)
- logger.debug(yaml.safe_dump(vnets, indent=4, default_flow_style=False))
- print('OK')
- except Exception as e:
- logger.error('Exception reading virtual networks from overlay controller: %s', e)
- print('FAILED')
- # 2. Read virtual networks from underlay controller
- print('2. Read virtual networks from underlay controller')
- vnets = juniper_contrail._get_virtual_networks(underlay_url)
- logger.debug(yaml.safe_dump(vnets, indent=4, default_flow_style=False))
- print('OK')
- # 3. Delete virtual networks gerardoX from underlay controller
- print('3. Delete virtual networks gerardoX from underlay controller')
- for vn in vnets:
- name = vn['fq_name'][2]
- logger.debug('Virtual network: {}'.format(name))
- for vn in vnets:
- name = vn['fq_name'][2]
- if 'gerardo' in name:
- logger.info('Virtual Network *gerardo*: {}, {}'.format(name,vn['uuid']))
- if name != "gerardo":
- print('Deleting Virtual Network: {}, {}'.format(name,vn['uuid']))
- logger.info('Deleting Virtual Network: {}, {}'.format(name,vn['uuid']))
- juniper_contrail._delete_virtual_network(underlay_url, vn['uuid'])
- print('OK')
- # 4. Get virtual network (gerardo) from underlay controller
- print('4. Get virtual network (gerardo) from underlay controller')
- vnet1_info = juniper_contrail._get_virtual_network(underlay_url, 'c5d332f7-420a-4e2b-a7b1-b56a59f20c97')
- print(yaml.safe_dump(vnet1_info, indent=4, default_flow_style=False))
- print('OK')
- # 5. Create virtual network in underlay controller
- print('5. Create virtual network in underlay controller')
- myname = 'gerardo4'
- myvni = 20004
- vnet2_id, _ = juniper_contrail._create_virtual_network(underlay_url, myname, myvni)
- vnet2_info = juniper_contrail._get_virtual_network(underlay_url, vnet2_id)
- print(yaml.safe_dump(vnet2_info, indent=4, default_flow_style=False))
- print('OK')
- # 6. Delete virtual network in underlay controller
- print('6. Delete virtual network in underlay controller')
- juniper_contrail._delete_virtual_network(underlay_url, vnet2_id)
- print('OK')
- # 7. Read previously deleted virtual network in underlay controller
- print('7. Read previously deleted virtual network in underlay controller')
- try:
- vnet2_info = juniper_contrail._get_virtual_network(underlay_url, vnet2_id)
- if vnet2_info:
- print('FAILED. Network {} exists'.format(vnet2_id))
- else:
- print('OK. Network {} does not exist because it has been deleted'.format(vnet2_id))
- except Exception as e:
- logger.info('Exception reading virtual networks from overlay controller: %s', e)
- exit(0)
-
- # Test CRUD:
- net_name = "gerardo"
- net_vni = "2000"
- net_vlan = "501"
- switch_1 = "LEAF-2"
- port_1 = "xe-0/0/18"
- switch_2 = "LEAF-1"
- port_2 = "xe-0/0/18"
-
- # 1 - Create a new virtual network
- vnet2_id, vnet2_created = juniper_contrail._create_virtual_network(underlay_url, net_name, net_vni)
- print("Created virtual network:")
- print(vnet2_id)
- print(yaml.safe_dump(vnet2_created, indent=4, default_flow_style=False))
- print("Get virtual network:")
- vnet2_info = juniper_contrail._get_virtual_network(underlay_url, vnet2_id)
- print(json.dumps(vnet2_info, indent=4))
- print('OK')
-
- # 2 - Create a new virtual port group
- vpg_id, vpg_info = juniper_contrail._create_vpg(underlay_url, switch_1, port_1, net_name, net_vlan)
- print("Created virtual port group:")
- print(vpg_id)
- print(json.dumps(vpg_info, indent=4))
-
- print("Get virtual network:")
- vnet2_info = juniper_contrail._get_virtual_network(underlay_url, vnet2_id)
- print(yaml.safe_dump(vnet2_info, indent=4, default_flow_style=False))
- print('OK')
-
- # 3 - Create a new virtual machine interface
- vmi_id, vmi_info = juniper_contrail._create_vmi(underlay_url, switch_1, port_1, net_name, net_vlan)
- print("Created virtual machine interface:")
- print(vmi_id)
- print(yaml.safe_dump(vmi_info, indent=4, default_flow_style=False))
-
- # 4 - Create a second virtual port group
- # 5 - Create a second virtual machine interface
-
- ### Test rapido de modificación de requests:
- # Ver que metodos siguen funcionando y cuales no e irlos corrigiendo
-
- """
- vnets = juniper_contrail._get_virtual_networks(underlay_url)
- logger.debug("Virtual networks:")
- logger.debug(json.dumps(vnets, indent=2))