本文整理匯總了Python中vnc_api.vnc_api.VirtualMachineInterface.add_virtual_network方法的典型用法代碼示例。如果您正苦於以下問題:Python VirtualMachineInterface.add_virtual_network方法的具體用法?Python VirtualMachineInterface.add_virtual_network怎麽用?Python VirtualMachineInterface.add_virtual_network使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類vnc_api.vnc_api.VirtualMachineInterface
的用法示例。
在下文中一共展示了VirtualMachineInterface.add_virtual_network方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_firewall_group_port_association
# 需要導入模塊: from vnc_api.vnc_api import VirtualMachineInterface [as 別名]
# 或者: from vnc_api.vnc_api.VirtualMachineInterface import add_virtual_network [as 別名]
def test_firewall_group_port_association(self):
vn = VirtualNetwork('%s-vn' % self.id(), parent_obj=self.project)
self._vnc_lib.virtual_network_create(vn)
vmi_ids = []
for i in range(3):
vmi = VirtualMachineInterface(
'%s-vmi%d' % (self.id(), i), parent_obj=self.project)
vmi.add_virtual_network(vn)
vmi_ids.append(self._vnc_lib.virtual_machine_interface_create(vmi))
neutron_fg = self.create_resource(
'firewall_group',
self.project_id,
extra_res_fields={
'ports': vmi_ids[:-1],
},
)
self.assertEquals(set(neutron_fg['ports']), set(vmi_ids[:-1]))
neutron_fg = self.update_resource(
'firewall_group',
neutron_fg['id'],
self.project_id,
extra_res_fields={
'ports': vmi_ids[1:],
},
)
self.assertEquals(set(neutron_fg['ports']), set(vmi_ids[1:]))
示例2: test_dedicated_tag_and_refs_deleted
# 需要導入模塊: from vnc_api.vnc_api import VirtualMachineInterface [as 別名]
# 或者: from vnc_api.vnc_api.VirtualMachineInterface import add_virtual_network [as 別名]
def test_dedicated_tag_and_refs_deleted(self):
vn = VirtualNetwork('%s-vn' % self.id(), parent_obj=self.project)
self._vnc_lib.virtual_network_create(vn)
vmi_ids = []
for i in range(3):
vmi = VirtualMachineInterface(
'%s-vmi%d' % (self.id(), i), parent_obj=self.project)
vmi.add_virtual_network(vn)
vmi_ids.append(self._vnc_lib.virtual_machine_interface_create(vmi))
neutron_fg = self.create_resource(
'firewall_group',
self.project_id,
extra_res_fields={
'ports': vmi_ids,
},
)
tag_fq_name = self._get_tag_fq_name(neutron_fg, self.project)
try:
self._vnc_lib.tag_read(tag_fq_name)
except NoIdError:
msg = ("Dedicated Tag %s for firewall group %s was not created" %
(':'.join(tag_fq_name), neutron_fg['id']))
self.fail(msg)
self.delete_resource('firewall_group', self.project_id,
neutron_fg['id'])
self.assertRaises(NoIdError, self._vnc_lib.tag_read, tag_fq_name)
示例3: test_bgpaas_shared
# 需要導入模塊: from vnc_api.vnc_api import VirtualMachineInterface [as 別名]
# 或者: from vnc_api.vnc_api.VirtualMachineInterface import add_virtual_network [as 別名]
def test_bgpaas_shared(self):
vn1_name = self.id() + 'vn1'
vn1_obj = self.create_virtual_network(vn1_name,
['10.0.0.0/24', '1000::/16'])
project_name = ['default-domain', 'default-project']
project_obj = self._vnc_lib.project_read(fq_name=project_name)
port_name1 = self.id() + 'p1'
port_obj1 = VirtualMachineInterface(port_name1, parent_obj=project_obj)
port_obj1.add_virtual_network(vn1_obj)
self._vnc_lib.virtual_machine_interface_create(port_obj1)
port_name2 = self.id() + 'p2'
port_obj2 = VirtualMachineInterface(port_name2, parent_obj=project_obj)
port_obj2.add_virtual_network(vn1_obj)
self._vnc_lib.virtual_machine_interface_create(port_obj2)
# Create a shared BGPaaS server. It means BGP Router object
# does not get created for VMI on the network.
bgpaas_name = self.id() + 'bgp1'
bgpaas = BgpAsAService(bgpaas_name, parent_obj=project_obj,
autonomous_system=64512, bgpaas_shared=True,
bgpaas_ip_address = '1.1.1.1')
bgpaas.add_virtual_machine_interface(port_obj1)
self._vnc_lib.bgp_as_a_service_create(bgpaas)
self.wait_to_get_object(config_db.BgpAsAServiceST,
bgpaas.get_fq_name_str())
router1_name = vn1_obj.get_fq_name_str() + ':' + vn1_name + ':' + bgpaas_name
router2_name = vn1_obj.get_fq_name_str() + ':' + vn1_name + ':' + 'bgpaas-server'
# Check for two BGP routers - one with the BGPaaS name and not with Port name
self.wait_to_get_object(config_db.BgpRouterST, router1_name)
self.wait_to_get_object(config_db.BgpRouterST, router2_name)
# check whether shared IP address is assigned to the BGP rotuer
self.check_bgp_router_ip(router1_name, '1.1.1.1')
# Add a new VMI to the BGPaaS. This should not create a new BGP router
bgpaas = self._vnc_lib.bgp_as_a_service_read(fq_name_str=bgpaas.get_fq_name_str())
bgpaas.add_virtual_machine_interface(port_obj2)
self._vnc_lib.bgp_as_a_service_update(bgpaas)
# Check for the absence of BGP router along with the new VMI.
router3_name = vn1_obj.get_fq_name_str() + ':' + vn1_name + ':' + port_name2
try:
bgp_router = self._vnc_lib.bgp_router_read(fq_name_str=router3_name)
except NoIdError:
print 'Second BGP Router not created for second port - PASS'
else:
assert(True)
bgpaas.del_virtual_machine_interface(port_obj1)
bgpaas.del_virtual_machine_interface(port_obj2)
self._vnc_lib.bgp_as_a_service_update(bgpaas)
self._vnc_lib.bgp_as_a_service_delete(id=bgpaas.uuid)
self._vnc_lib.virtual_machine_interface_delete(id=port_obj1.uuid)
self._vnc_lib.virtual_machine_interface_delete(id=port_obj2.uuid)
self._vnc_lib.virtual_network_delete(fq_name=vn1_obj.get_fq_name())
self.check_ri_is_deleted(vn1_obj.fq_name+[vn1_obj.name])
示例4: test_firewall_group_status
# 需要導入模塊: from vnc_api.vnc_api import VirtualMachineInterface [as 別名]
# 或者: from vnc_api.vnc_api.VirtualMachineInterface import add_virtual_network [as 別名]
def test_firewall_group_status(self):
neutron_fg = self.create_resource(
'firewall_group',
self.project_id,
extra_res_fields={
'admin_state_up': False,
},
)
self.assertEquals(neutron_fg['status'], constants.DOWN)
neutron_fg = self.update_resource(
'firewall_group',
neutron_fg['id'],
self.project_id,
extra_res_fields={
'admin_state_up': True,
},
)
self.assertEquals(neutron_fg['status'], constants.INACTIVE)
vn = VirtualNetwork('%s-vn' % self.id(), parent_obj=self.project)
self._vnc_lib.virtual_network_create(vn)
vmi = VirtualMachineInterface(
'%s-vmi' % self.id(), parent_obj=self.project)
vmi.add_virtual_network(vn)
self._vnc_lib.virtual_machine_interface_create(vmi)
neutron_fg = self.update_resource(
'firewall_group',
neutron_fg['id'],
self.project_id,
extra_res_fields={
'ports': [vmi.uuid],
},
)
self.assertEquals(neutron_fg['status'], constants.INACTIVE)
fp = FirewallPolicy('%s-fp' % self.id(), parent_obj=self.project)
self._vnc_lib.firewall_policy_create(fp)
neutron_fg = self.update_resource(
'firewall_group',
neutron_fg['id'],
self.project_id,
extra_res_fields={
'egress_firewall_policy_id': fp.uuid,
},
)
self.assertEquals(neutron_fg['status'], constants.ACTIVE)
neutron_fg = self.update_resource(
'firewall_group',
neutron_fg['id'],
self.project_id,
extra_res_fields={
'ports': [],
},
)
self.assertEquals(neutron_fg['status'], constants.INACTIVE)
示例5: test_asn
# 需要導入模塊: from vnc_api.vnc_api import VirtualMachineInterface [as 別名]
# 或者: from vnc_api.vnc_api.VirtualMachineInterface import add_virtual_network [as 別名]
def test_asn(self):
# create vn1
vn1_name = self.id() + 'vn1'
vn1_obj = self.create_virtual_network(vn1_name, '10.0.0.0/24')
ident_name = self.get_obj_imid(vn1_obj)
gevent.sleep(2)
ifmap_ident = self.assertThat(FakeIfmapClient._graph, Contains(ident_name))
self.check_ri_asn(self.get_ri_name(vn1_obj), 'target:64512:8000001')
# create router1
r1_name = self.id() + 'router1'
router1 = self.create_bgp_router(r1_name, 'contrail')
self.check_bgp_asn(router1.get_fq_name(), 64512)
# create virtual machine interface
vmi_name = self.id() + 'vmi1'
vmi = VirtualMachineInterface(vmi_name, parent_type='project',
fq_name=['default-domain',
'default-project', vmi_name])
vmi.add_virtual_network(vn1_obj)
self._vnc_lib.virtual_machine_interface_create(vmi)
# create logical router
lr_name = self.id() + 'lr1'
lr = LogicalRouter(lr_name)
lr.add_virtual_machine_interface(vmi)
self._vnc_lib.logical_router_create(lr)
self.check_lr_asn(lr.get_fq_name(), 'target:64512:8000002')
#update global system config but dont change asn value for equality path
gs = self._vnc_lib.global_system_config_read(
fq_name=['default-global-system-config'])
gs.set_autonomous_system(64512)
self._vnc_lib.global_system_config_update(gs)
# check route targets
self.check_ri_asn(self.get_ri_name(vn1_obj), 'target:64512:8000001')
self.check_bgp_asn(router1.get_fq_name(), 64512)
self.check_lr_asn(lr.get_fq_name(), 'target:64512:8000002')
#update ASN value
gs = self._vnc_lib.global_system_config_read(
fq_name=[u'default-global-system-config'])
gs.set_autonomous_system(50000)
self._vnc_lib.global_system_config_update(gs)
# check new route targets
self.check_ri_asn(self.get_ri_name(vn1_obj), 'target:50000:8000001')
self.check_bgp_asn(router1.get_fq_name(), 50000)
self.check_lr_asn(lr.get_fq_name(), 'target:50000:8000002')
self._vnc_lib.logical_router_delete(id=lr.uuid)
self._vnc_lib.virtual_machine_interface_delete(id=vmi.uuid)
self._vnc_lib.virtual_network_delete(id=vn1_obj.uuid)
self.check_ri_is_deleted(fq_name=vn1_obj.fq_name+[vn1_obj.name])
self._vnc_lib.bgp_router_delete(id=router1.uuid)
示例6: test_asn
# 需要導入模塊: from vnc_api.vnc_api import VirtualMachineInterface [as 別名]
# 或者: from vnc_api.vnc_api.VirtualMachineInterface import add_virtual_network [as 別名]
def test_asn(self):
# create vn1
vn1_name = self.id() + 'vn1'
vn1_obj = self.create_virtual_network(vn1_name, '10.0.0.0/24')
self.assertTill(self.vnc_db_has_ident, obj=vn1_obj)
ri_target = self.check_ri_target(self.get_ri_name(vn1_obj))
# create router1
r1_name = self.id() + 'router1'
router1 = self.create_bgp_router(r1_name, 'contrail')
self.check_bgp_asn(router1.get_fq_name(), 64512)
# create virtual machine interface
vmi_name = self.id() + 'vmi1'
vmi = VirtualMachineInterface(vmi_name, parent_type='project',
fq_name=['default-domain',
'default-project', vmi_name])
vmi.add_virtual_network(vn1_obj)
self._vnc_lib.virtual_machine_interface_create(vmi)
# create logical router
lr_name = self.id() + 'lr1'
lr = LogicalRouter(lr_name)
lr.add_virtual_machine_interface(vmi)
self._vnc_lib.logical_router_create(lr)
lr_target = self.check_lr_target(lr.get_fq_name())
#update global system config but dont change asn value for equality path
gs = self._vnc_lib.global_system_config_read(
fq_name=['default-global-system-config'])
gs.set_autonomous_system(64512)
self._vnc_lib.global_system_config_update(gs)
# check route targets
self.check_ri_target(self.get_ri_name(vn1_obj), ri_target)
self.check_bgp_asn(router1.get_fq_name(), 64512)
self.check_lr_target(lr.get_fq_name(), lr_target)
#update ASN value
gs = self._vnc_lib.global_system_config_read(
fq_name=[u'default-global-system-config'])
gs.set_autonomous_system(50000)
self._vnc_lib.global_system_config_update(gs)
# check new route targets
self.check_ri_target(self.get_ri_name(vn1_obj), ri_target.replace('64512', '50000'))
self.check_bgp_asn(router1.get_fq_name(), 50000)
self.check_lr_target(lr.get_fq_name(), lr_target.replace('64512', '50000'))
self._vnc_lib.logical_router_delete(id=lr.uuid)
self._vnc_lib.virtual_machine_interface_delete(id=vmi.uuid)
self._vnc_lib.virtual_network_delete(id=vn1_obj.uuid)
self.check_ri_is_deleted(fq_name=vn1_obj.fq_name+[vn1_obj.name])
self._vnc_lib.bgp_router_delete(id=router1.uuid)
示例7: test_logical_router
# 需要導入模塊: from vnc_api.vnc_api import VirtualMachineInterface [as 別名]
# 或者: from vnc_api.vnc_api.VirtualMachineInterface import add_virtual_network [as 別名]
def test_logical_router(self):
# create vn1
vn1_name = self.id() + 'vn1'
vn1_obj = self.create_virtual_network(vn1_name, '10.0.0.0/24')
# create virtual machine interface
vmi_name = self.id() + 'vmi1'
vmi = VirtualMachineInterface(vmi_name, parent_type='project', fq_name=['default-domain', 'default-project', vmi_name])
vmi.add_virtual_network(vn1_obj)
self._vnc_lib.virtual_machine_interface_create(vmi)
# create logical router
lr_name = self.id() + 'lr1'
lr = LogicalRouter(lr_name)
rtgt_list = RouteTargetList(route_target=['target:1:1'])
lr.set_configured_route_target_list(rtgt_list)
lr.add_virtual_machine_interface(vmi)
self._vnc_lib.logical_router_create(lr)
ri_name = self.get_ri_name(vn1_obj)
self.check_route_target_in_routing_instance(ri_name,rtgt_list.get_route_target())
rtgt_list.add_route_target('target:1:2')
lr.set_configured_route_target_list(rtgt_list)
self._vnc_lib.logical_router_update(lr)
self.check_route_target_in_routing_instance(ri_name, rtgt_list.get_route_target())
rtgt_list.delete_route_target('target:1:1')
lr.set_configured_route_target_list(rtgt_list)
self._vnc_lib.logical_router_update(lr)
self.check_route_target_in_routing_instance(ri_name, rtgt_list.get_route_target())
lr.del_virtual_machine_interface(vmi)
self._vnc_lib.logical_router_update(lr)
self._vnc_lib.virtual_machine_interface_delete(id=vmi.uuid)
self._vnc_lib.virtual_network_delete(id=vn1_obj.uuid)
self.check_vn_is_deleted(uuid=vn1_obj.uuid)
self._vnc_lib.logical_router_delete(id=lr.uuid)
self.check_lr_is_deleted(uuid=lr.uuid)
self.check_rt_is_deleted(name='target:64512:8000002')
示例8: test_list_firewall_group
# 需要導入模塊: from vnc_api.vnc_api import VirtualMachineInterface [as 別名]
# 或者: from vnc_api.vnc_api.VirtualMachineInterface import add_virtual_network [as 別名]
def test_list_firewall_group(self):
vn = VirtualNetwork('%s-vn' % self.id(), parent_obj=self.project)
self._vnc_lib.virtual_network_create(vn)
neutron_fgs = []
fp_ids = []
vmi_ids = []
for i in range(2):
fp = FirewallPolicy('%s-fp%d' % (self.id(), i),
parent_obj=self.project)
fp_ids.append(self._vnc_lib.firewall_policy_create(fp))
vmi = VirtualMachineInterface(
'%s-vmi%d' % (self.id(), i), parent_obj=self.project)
vmi.add_virtual_network(vn)
vmi_ids.append(self._vnc_lib.virtual_machine_interface_create(vmi))
neutron_fgs.append(
self.create_resource(
'firewall_group',
self.project_id,
extra_res_fields={
'name': '%s-fg%d' % (self.id(), i),
'ingress_firewall_policy_id': fp.uuid,
'ports': [vmi.uuid],
},
),
)
list_result = self.list_resource(
'firewall_group',
self.project_id,
req_filters={
'ingress_firewall_policy_id': fp_ids,
},
)
self.assertEquals(len(list_result), len(neutron_fgs))
self.assertEquals({r['id'] for r in list_result},
{r['id'] for r in neutron_fgs})
list_result = self.list_resource(
'firewall_group',
self.project_id,
req_filters={
'egress_firewall_policy_id': fp_ids,
},
)
self.assertEquals(len(list_result), len(neutron_fgs))
self.assertEquals({r['id'] for r in list_result},
{r['id'] for r in neutron_fgs})
list_result = self.list_resource(
'firewall_group',
self.project_id,
req_filters={
'ports': vmi_ids,
},
)
self.assertEquals(len(list_result), len(neutron_fgs))
self.assertEquals({r['id'] for r in list_result},
{r['id'] for r in neutron_fgs})
list_result = self.list_resource(
'firewall_group',
self.project_id,
req_filters={
'ingress_firewall_policy_id': [fp_ids[0]],
},
)
self.assertEquals(len(list_result), 1)
self.assertEquals(list_result[0], neutron_fgs[0])
list_result = self.list_resource(
'firewall_group',
self.project_id,
req_filters={
'egress_firewall_policy_id': [fp_ids[1]],
},
)
self.assertEquals(len(list_result), 1)
self.assertEquals(list_result[0], neutron_fgs[1])
list_result = self.list_resource(
'firewall_group',
self.project_id,
req_filters={
'ports': [vmi_ids[0]],
},
)
self.assertEquals(len(list_result), 1)
self.assertEquals(list_result[0], neutron_fgs[0])
示例9: test_multiple_firewall_group_port_association
# 需要導入模塊: from vnc_api.vnc_api import VirtualMachineInterface [as 別名]
# 或者: from vnc_api.vnc_api.VirtualMachineInterface import add_virtual_network [as 別名]
def test_multiple_firewall_group_port_association(self):
vn = VirtualNetwork('%s-vn' % self.id(), parent_obj=self.project)
self._vnc_lib.virtual_network_create(vn)
vmi = VirtualMachineInterface('%s-vmi' % self.id(),
parent_obj=self.project)
vmi.add_virtual_network(vn)
vmi_id = self._vnc_lib.virtual_machine_interface_create(vmi)
neutron_fg1 = self.create_resource(
'firewall_group',
self.project_id,
extra_res_fields={
'name': '%s-fg1' % self.id(),
'ports': [vmi_id],
},
)
neutron_fg2 = self.create_resource(
'firewall_group',
self.project_id,
extra_res_fields={
'name': '%s-fg2' % self.id(),
},
)
tag1_fq_name = self._get_tag_fq_name(neutron_fg1, self.project)
tag2_fq_name = self._get_tag_fq_name(neutron_fg2, self.project)
self.assertEquals(set(neutron_fg1['ports']), set([vmi_id]))
vmi = self._vnc_lib.virtual_machine_interface_read(id=vmi_id)
tag_refs = [r['to'] for r in vmi.get_tag_refs() or []]
self.assertEquals(len(tag_refs), 1)
self.assertEquals(tag1_fq_name, tag_refs[0])
neutron_fg2 = self.update_resource(
'firewall_group',
neutron_fg2['id'],
self.project_id,
extra_res_fields={
'ports': [vmi_id],
},
)
neutron_fg1 = self.read_resource('firewall_group', neutron_fg1['id'])
self.assertEquals(set(neutron_fg1['ports']), set([vmi_id]))
self.assertEquals(set(neutron_fg2['ports']), set([vmi_id]))
vmi = self._vnc_lib.virtual_machine_interface_read(id=vmi_id)
tag_refs = [r['to'] for r in vmi.get_tag_refs() or []]
self.assertEquals(len(tag_refs), 2)
self.assertIn(tag1_fq_name, tag_refs)
self.assertIn(tag2_fq_name, tag_refs)
neutron_fg1 = self.update_resource(
'firewall_group',
neutron_fg1['id'],
self.project_id,
extra_res_fields={
'ports': [],
},
)
neutron_fg2 = self.read_resource('firewall_group', neutron_fg2['id'])
self.assertFalse(neutron_fg1['ports'])
self.assertEquals(set(neutron_fg2['ports']), set([vmi_id]))
vmi = self._vnc_lib.virtual_machine_interface_read(id=vmi_id)
tag_refs = [r['to'] for r in vmi.get_tag_refs() or []]
self.assertEquals(len(tag_refs), 1)
self.assertEquals(tag2_fq_name, tag_refs[0])
示例10: test_bgpaas
# 需要導入模塊: from vnc_api.vnc_api import VirtualMachineInterface [as 別名]
# 或者: from vnc_api.vnc_api.VirtualMachineInterface import add_virtual_network [as 別名]
def test_bgpaas(self):
# create vn1
vn1_name = self.id() + 'vn1'
vn1_obj = self.create_virtual_network(vn1_name,
['10.0.0.0/24', '1000::/16'])
project_name = ['default-domain', 'default-project']
project_obj = self._vnc_lib.project_read(fq_name=project_name)
port_name = self.id() + 'p1'
port_obj = VirtualMachineInterface(port_name, parent_obj=project_obj)
port_obj.add_virtual_network(vn1_obj)
self._vnc_lib.virtual_machine_interface_create(port_obj)
v6_obj = InstanceIp(name=port_name+'-v6')
v6_obj.set_virtual_machine_interface(port_obj)
v6_obj.set_virtual_network(vn1_obj)
v6_obj.set_instance_ip_family('v6')
self._vnc_lib.instance_ip_create(v6_obj)
v4_obj = InstanceIp(name=port_name+'-v4')
v4_obj.set_virtual_machine_interface(port_obj)
v4_obj.set_virtual_network(vn1_obj)
v4_obj.set_instance_ip_family('v4')
self._vnc_lib.instance_ip_create(v4_obj)
bgpaas_name = self.id() + 'bgp1'
bgpaas = BgpAsAService(bgpaas_name, parent_obj=project_obj,
autonomous_system=64512)
bgpaas.add_virtual_machine_interface(port_obj)
self._vnc_lib.bgp_as_a_service_create(bgpaas)
router1_name = vn1_obj.get_fq_name_str() + ':' + vn1_name + ':' + port_name
self.wait_to_get_object(config_db.BgpAsAServiceST,
bgpaas.get_fq_name_str())
self.wait_to_get_object(config_db.BgpRouterST, router1_name)
server_fq_name = ':'.join(self.get_ri_name(vn1_obj)) + ':bgpaas-server'
self.wait_to_get_object(config_db.BgpRouterST, server_fq_name)
server_router_obj = self._vnc_lib.bgp_router_read(fq_name_str=server_fq_name)
mx_bgp_router = self.create_bgp_router("mx-bgp-router", "contrail")
mx_bgp_router_name = mx_bgp_router.get_fq_name_str()
self.wait_to_get_object(config_db.BgpRouterST, mx_bgp_router_name)
mx_bgp_router = self._vnc_lib.bgp_router_read(fq_name_str=mx_bgp_router_name)
self.check_bgp_no_peering(server_router_obj, mx_bgp_router)
router1_obj = self._vnc_lib.bgp_router_read(fq_name_str=router1_name)
self.assertEqual(router1_obj.get_bgp_router_parameters().address,
'10.0.0.252')
self.assertEqual(router1_obj.get_bgp_router_parameters().identifier,
'10.0.0.252')
self.check_bgp_peering(server_router_obj, router1_obj, 1)
self.check_v4_bgp_gateway(router1_name, '10.0.0.254')
self.check_v6_bgp_gateway(router1_name,
'1000:ffff:ffff:ffff:ffff:ffff:ffff:fffe')
# Set suppress_route_advertisement; and expect the gateways
# to be reset to None in bgpaas-client router
bgpaas.set_bgpaas_suppress_route_advertisement(True)
self._vnc_lib.bgp_as_a_service_update(bgpaas)
self.check_v4_bgp_gateway(router1_name, None)
self.check_v6_bgp_gateway(router1_name, None)
# Unset suppress_route_advertisement; and expect the gateways
# to be set to gateway addresses in bgpaas-client router
bgpaas.set_bgpaas_suppress_route_advertisement(False)
self._vnc_lib.bgp_as_a_service_update(bgpaas)
self.check_v4_bgp_gateway(router1_name, '10.0.0.254')
self.check_v6_bgp_gateway(router1_name,
'1000:ffff:ffff:ffff:ffff:ffff:ffff:fffe')
# Set bgpaas_ipv4_mapped_ipv6_nexthop and expect the
# ipv4-mapped ipv6 address is set as gateway
bgpaas.set_bgpaas_ipv4_mapped_ipv6_nexthop(True)
self._vnc_lib.bgp_as_a_service_update(bgpaas)
self.check_v6_bgp_gateway(router1_name, '::ffff:10.0.0.254')
# unset bgpaas_ipv4_mapped_ipv6_nexthop and expect the
# subnets ipv6 gateway address is set as gateway
bgpaas.set_bgpaas_ipv4_mapped_ipv6_nexthop(False)
self._vnc_lib.bgp_as_a_service_update(bgpaas)
self.check_v6_bgp_gateway(router1_name,
'1000:ffff:ffff:ffff:ffff:ffff:ffff:fffe')
v4_obj.set_instance_ip_address('10.0.0.60')
self._vnc_lib.instance_ip_update(v4_obj)
self.check_bgp_router_ip(router1_name, '10.0.0.60')
self.check_bgp_router_identifier(router1_name, '10.0.0.60')
bgpaas.set_bgpaas_ip_address('10.0.0.70')
self._vnc_lib.bgp_as_a_service_update(bgpaas)
self.check_bgp_router_ip(router1_name, '10.0.0.70')
v4_obj.del_virtual_machine_interface(port_obj)
v4_obj.del_virtual_network(vn1_obj)
self._vnc_lib.instance_ip_delete(id=v4_obj.uuid)
self.check_bgp_router_ip(router1_name, '10.0.0.70')
self.check_bgp_router_identifier(router1_name, '10.0.0.70')
port2_name = self.id() + 'p2'
port2_obj = VirtualMachineInterface(port2_name, parent_obj=project_obj)
port2_obj.add_virtual_network(vn1_obj)
self._vnc_lib.virtual_machine_interface_create(port2_obj)
bgpaas.add_virtual_machine_interface(port2_obj)
self._vnc_lib.bgp_as_a_service_update(bgpaas)
#.........這裏部分代碼省略.........
示例11: test_public_snat_routes
# 需要導入模塊: from vnc_api.vnc_api import VirtualMachineInterface [as 別名]
# 或者: from vnc_api.vnc_api.VirtualMachineInterface import add_virtual_network [as 別名]
def test_public_snat_routes(self):
#create private vn
vn_private_name = self.id() + 'vn1'
vn_private = self.create_virtual_network(vn_private_name, "1.0.0.0/24")
# create virtual machine interface
vmi_name = self.id() + 'vmi1'
vmi = VirtualMachineInterface(vmi_name, parent_type='project',
fq_name=['default-domain', 'default-project', vmi_name])
vmi.add_virtual_network(vn_private)
self._vnc_lib.virtual_machine_interface_create(vmi)
#create public vn
vn_public_name = 'vn-public'
vn_public = VirtualNetwork(vn_public_name)
vn_public.set_router_external(True)
ipam_obj = NetworkIpam('ipam')
self._vnc_lib.network_ipam_create(ipam_obj)
vn_public.add_network_ipam(ipam_obj, VnSubnetsType(
[IpamSubnetType(SubnetType("192.168.7.0", 24))]))
self._vnc_lib.virtual_network_create(vn_public)
#create logical router, set route targets,
#add private network and extend lr to public network
lr_name = self.id() + 'lr1'
lr = LogicalRouter(lr_name)
rtgt_list = RouteTargetList(route_target=['target:1:1'])
lr.set_configured_route_target_list(rtgt_list)
lr.add_virtual_machine_interface(vmi)
lr.add_virtual_network(vn_public)
self._vnc_lib.logical_router_create(lr)
@retries(5)
def _match_route_table(rtgt_list, ri_name):
lri = self._vnc_lib.routing_instance_read(
fq_name_str=ri_name)
sr = lri.get_static_route_entries()
if sr is None:
raise Exception("sr is None")
route = sr.route[0]
self.assertEqual(route.prefix, "0.0.0.0/0")
self.assertEqual(route.next_hop, "100.64.0.4")
for rtgt in rtgt_list:
self.assertIn(rtgt, route.route_target)
@retries(5)
def _wait_to_get_si():
si_list = self._vnc_lib.service_instances_list()
si = si_list.get("service-instances")[0]
si = self._vnc_lib.service_instance_read(id=si.get("uuid"))
return si
@retries(5)
def _wait_to_delete_si():
si_list = self._vnc_lib.service_instances_list()
try:
si = si_list.get("service-instances")[0]
si = self._vnc_lib.service_instance_read(id=si.get("uuid"))
raise
except:
pass
@retries(5)
def _wait_to_delete_ip(vn_fq_name):
vn = self._vnc_lib.virtual_network_read(fq_name=vn_fq_name)
ip_refs = vn.get_instance_ip_back_refs()
if ip_refs:
raise
return
# end
si = _wait_to_get_si()
si_props = si.get_service_instance_properties().get_interface_list()[1]
ri_name = si_props.virtual_network + ":" + si_props.virtual_network.split(':')[-1]
lr_rtgt = self._vnc_lib.logical_router_read(id=lr.uuid).route_target_refs[0]['to'][0]
_match_route_table(['target:1:1', lr_rtgt], ri_name)
rtgt_list = RouteTargetList(route_target=['target:2:2'])
lr.set_configured_route_target_list(rtgt_list)
self._vnc_lib.logical_router_update(lr)
_match_route_table(['target:2:2', lr_rtgt], ri_name)
lr.del_virtual_network(vn_public)
self._vnc_lib.logical_router_update(lr)
_wait_to_delete_si()
#cleanup
self._vnc_lib.logical_router_delete(fq_name=lr.get_fq_name())
self._vnc_lib.virtual_machine_interface_delete(fq_name=vmi.get_fq_name())
_wait_to_delete_ip(vn_private.get_fq_name())
self._vnc_lib.virtual_network_delete(fq_name=vn_private.get_fq_name())
_wait_to_delete_ip(vn_public.get_fq_name())
self._vnc_lib.virtual_network_delete(fq_name=vn_public.get_fq_name())
示例12: test_bgpaas
# 需要導入模塊: from vnc_api.vnc_api import VirtualMachineInterface [as 別名]
# 或者: from vnc_api.vnc_api.VirtualMachineInterface import add_virtual_network [as 別名]
def test_bgpaas(self):
# create vn1
vn1_name = self.id() + 'vn1'
vn1_obj = self.create_virtual_network(vn1_name,
['10.0.0.0/24', '1000::/16'])
project_name = ['default-domain', 'default-project']
project_obj = self._vnc_lib.project_read(fq_name=project_name)
port_name = self.id() + 'p1'
port_obj = VirtualMachineInterface(port_name, parent_obj=project_obj)
port_obj.add_virtual_network(vn1_obj)
self._vnc_lib.virtual_machine_interface_create(port_obj)
v6_obj = InstanceIp(name=port_name+'-v6')
v6_obj.set_virtual_machine_interface(port_obj)
v6_obj.set_virtual_network(vn1_obj)
v6_obj.set_instance_ip_family('v6')
self._vnc_lib.instance_ip_create(v6_obj)
v4_obj = InstanceIp(name=port_name+'-v4')
v4_obj.set_virtual_machine_interface(port_obj)
v4_obj.set_virtual_network(vn1_obj)
v4_obj.set_instance_ip_family('v4')
self._vnc_lib.instance_ip_create(v4_obj)
bgpaas_name = self.id() + 'bgp1'
bgpaas = BgpAsAService(bgpaas_name, parent_obj=project_obj,
autonomous_system=64512)
bgpaas.add_virtual_machine_interface(port_obj)
self._vnc_lib.bgp_as_a_service_create(bgpaas)
router1_name = vn1_obj.get_fq_name_str() + ':' + vn1_name + ':' + port_name
self.wait_to_get_object(config_db.BgpAsAServiceST,
bgpaas.get_fq_name_str())
self.wait_to_get_object(config_db.BgpRouterST, router1_name)
server_fq_name = ':'.join(self.get_ri_name(vn1_obj)) + ':bgpaas-server'
self.wait_to_get_object(config_db.BgpRouterST, server_fq_name)
server_router_obj = self._vnc_lib.bgp_router_read(fq_name_str=server_fq_name)
router1_name = vn1_obj.get_fq_name_str() + ':' + vn1_name + ':' + port_name
mx_bgp_router = self.create_bgp_router("mx-bgp-router", "contrail")
mx_bgp_router_name = mx_bgp_router.get_fq_name_str()
self.wait_to_get_object(config_db.BgpRouterST, mx_bgp_router_name)
mx_bgp_router = self._vnc_lib.bgp_router_read(fq_name_str=mx_bgp_router_name)
self.check_bgp_no_peering(server_router_obj, mx_bgp_router)
for i in range(5):
router1_obj = self._vnc_lib.bgp_router_read(fq_name_str=router1_name)
params = router1_obj.get_bgp_router_parameters()
if not params:
gevent.sleep(1)
continue
self.assertEqual(router1_obj.get_bgp_router_parameters().address,
'10.0.0.252')
self.assertEqual(router1_obj.get_bgp_router_parameters().identifier,
'10.0.0.252')
self.assertNotEqual(params, None)
# verify ref from vmi to bgp-router is created
port_obj_updated = self._vnc_lib.virtual_machine_interface_read(id=port_obj.uuid)
self.assertEqual(port_obj_updated.bgp_router_refs[0]['to'],
router1_obj.fq_name)
# remove bgp-router ref from vmi
self._vnc_lib.ref_update(obj_uuid=port_obj_updated.uuid,
obj_type='virtual_machine_interface',
ref_uuid=router1_obj.uuid,
ref_fq_name=router1_obj.fq_name,
ref_type='bgp-router',
operation='DELETE')
port_obj_updated = self._vnc_lib.virtual_machine_interface_read(id=port_obj.uuid)
self.assertIsNone(port_obj_updated.get_bgp_router_refs())
# check bgp-router ref in vmi is restored during reinit
config_db.VirtualMachineST._dict = {}
config_db.BgpRouterST._dict = {}
config_db.BgpAsAServiceST._dict = {}
to_bgp.transformer.reinit()
gevent.sleep(1)
port_obj_updated = self._vnc_lib.virtual_machine_interface_read(id=port_obj.uuid)
refs = port_obj_updated.get_bgp_router_refs()
self.assertNotEqual(refs, None)
self.assertEqual(refs[0]['to'], router1_obj.fq_name)
# remove VMI from bgpaas and ensure
bgpaas = self._vnc_lib.bgp_as_a_service_read(fq_name=bgpaas.fq_name)
port_obj_updated = self._vnc_lib.virtual_machine_interface_read(id=port_obj.uuid)
bgpaas.del_virtual_machine_interface(port_obj_updated)
self._vnc_lib.bgp_as_a_service_update(bgpaas)
gevent.sleep(1)
bgpaas = self._vnc_lib.bgp_as_a_service_read(fq_name=bgpaas.fq_name)
port_obj_updated = self._vnc_lib.virtual_machine_interface_read(id=port_obj.uuid)
# ensure vmi is not attached to bpgaas
self.assertEqual(bgpaas.get_virtual_machine_interface_refs(), None)
# vmi loses vmi->bgp-router ref
self.assertEqual(port_obj_updated.get_bgp_router_refs(), None)
# ensure VMI has no bgpaas ref
#.........這裏部分代碼省略.........
示例13: test_logical_router_delete
# 需要導入模塊: from vnc_api.vnc_api import VirtualMachineInterface [as 別名]
# 或者: from vnc_api.vnc_api.VirtualMachineInterface import add_virtual_network [as 別名]
def test_logical_router_delete(self):
# configure vxlan routing
proj_obj = self._vnc_lib.project_read(
fq_name=['default-domain', 'default-project'])
proj_obj.set_vxlan_routing(True)
self._vnc_lib.project_update(proj_obj)
# create vn1
vn1_name = self.id() + 'vn1'
vn1_obj = self.create_virtual_network(vn1_name, '10.0.0.0/24')
# create virtual machine interface
vmi_name = self.id() + 'vmi1'
vmi = VirtualMachineInterface(vmi_name, parent_type='project',
fq_name=['default-domain',
'default-project', vmi_name])
vmi.add_virtual_network(vn1_obj)
self._vnc_lib.virtual_machine_interface_create(vmi)
# create logical router
lr_name = self.id() + 'lr1'
lr = LogicalRouter(lr_name)
rtgt_list = RouteTargetList(route_target=['target:1:1'])
lr.set_configured_route_target_list(rtgt_list)
lr.add_virtual_machine_interface(vmi)
self._vnc_lib.logical_router_create(lr)
lr = self._vnc_lib.logical_router_read(id=lr.uuid)
lr_target = self.check_lr_target(lr.get_fq_name())
intvns = self.get_lr_internal_vn(lr.get_fq_name())
# Deletion
lr.del_virtual_machine_interface(vmi)
self._vnc_lib.logical_router_update(lr)
self._vnc_lib.virtual_machine_interface_delete(id=vmi.uuid)
self._vnc_lib.virtual_network_delete(id=vn1_obj.uuid)
self.check_vn_is_deleted(uuid=vn1_obj.uuid)
# internalVN should be restored when LR delete fails
try:
# override libs
org_dbe_delete = self._server_info['api_server']._db_conn.dbe_delete
def tmp_dbe_delete(obj_type, id, read_result):
if obj_type == 'logical_router':
return False, (400, 'Fake LR delete failure')
else:
return org_dbe_delete(obj_type, id, read_result)
self._server_info['api_server']._db_conn.dbe_delete = tmp_dbe_delete
try:
self._vnc_lib.logical_router_delete(id=lr.uuid)
except BadRequest as err:
lr = self._vnc_lib.logical_router_read(id=lr.uuid)
self.get_lr_internal_vn(lr.get_fq_name())
else:
raise Exception('UT: Fake LR delete didnt create BadRequest exception')
finally:
self._server_info['api_server']._db_conn.dbe_delete = org_dbe_delete
# internalVN should be removed when LR is deleted successfully
self._vnc_lib.logical_router_delete(id=lr.uuid)
self.check_lr_is_deleted(uuid=lr.uuid)
self.assertRaises(NoIdError, self._vnc_lib.virtual_network_read,
intvns[0]['uuid'])
self.check_rt_is_deleted(name=lr_target)
示例14: test_vxlan_routing
# 需要導入模塊: from vnc_api.vnc_api import VirtualMachineInterface [as 別名]
# 或者: from vnc_api.vnc_api.VirtualMachineInterface import add_virtual_network [as 別名]
def test_vxlan_routing(self):
proj_obj = self._vnc_lib.project_read(
fq_name=['default-domain', 'default-project'])
# create vn1
vn1_name = self.id() + '_vn1'
vn1_obj = self.create_virtual_network(vn1_name, '10.0.0.0/24')
# create virtual machine interface
vmi_name = self.id() + '_vmi1'
vmi = VirtualMachineInterface(vmi_name,
parent_type='project',
fq_name=['default-domain',
'default-project',
vmi_name])
vmi.add_virtual_network(vn1_obj)
self._vnc_lib.virtual_machine_interface_create(vmi)
# Enable vxlan_routing in the project
# and verify RT not attached to LR
proj_obj.set_vxlan_routing(True)
self._vnc_lib.project_update(proj_obj)
ri_name = self.get_ri_name(vn1_obj)
ri_obj = self._vnc_lib.routing_instance_read(fq_name=ri_name)
vn_rt_refs = set([ref['to'][0]
for ref in ri_obj.get_route_target_refs() or []])
# create logical router with RT
lr_name = self.id() + '_lr1'
lr = LogicalRouter(lr_name)
rtgt_list = RouteTargetList(route_target=['target:1:1'])
lr.set_configured_route_target_list(rtgt_list)
lr.add_virtual_machine_interface(vmi)
self._vnc_lib.logical_router_create(lr)
lr = self._vnc_lib.logical_router_read(fq_name=lr.get_fq_name())
lr_target = self.check_lr_target(lr.get_fq_name())
ri_obj = self._vnc_lib.routing_instance_read(fq_name=ri_name)
vn_rt_refs_with_lr = set([ref['to'][0]
for ref in ri_obj.get_route_target_refs() or []])
# ensure no RT from LR is attached to VN
self.assertTrue(vn_rt_refs_with_lr == vn_rt_refs,
msg='RT attached to VN is different after LR creation')
# configure a new route target after
# LR is created
rtgt_list.add_route_target('target:1:2')
lr.set_configured_route_target_list(rtgt_list)
self._vnc_lib.logical_router_update(lr)
lr = self._vnc_lib.logical_router_read(fq_name=lr.get_fq_name())
lr_target = self.check_lr_target(lr.get_fq_name())
ri_obj = self._vnc_lib.routing_instance_read(fq_name=ri_name)
vn_rt_refs_with_lr = set([ref['to'][0]
for ref in ri_obj.get_route_target_refs() or []])
# ensure no RT from LR is attached to VN
self.assertTrue(vn_rt_refs_with_lr == vn_rt_refs,
msg='RT attached to VN is different after LR creation')
# check no service instance generated
self.check_no_si_in_lr(lr.get_fq_name())
# cleanup
lr.del_virtual_machine_interface(vmi)
self._vnc_lib.logical_router_update(lr)
self._vnc_lib.virtual_machine_interface_delete(id=vmi.uuid)
self._vnc_lib.virtual_network_delete(id=vn1_obj.uuid)
self.check_vn_is_deleted(uuid=vn1_obj.uuid)
self._vnc_lib.logical_router_delete(id=lr.uuid)
self.check_lr_is_deleted(uuid=lr.uuid)