本文整理汇总了Python中vnc_api.vnc_api.VirtualNetwork类的典型用法代码示例。如果您正苦于以下问题:Python VirtualNetwork类的具体用法?Python VirtualNetwork怎么用?Python VirtualNetwork使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VirtualNetwork类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_network
def create_network(self, name, proj_obj, pod_subnet, service_subnet):
vn = VirtualNetwork(
name=name, parent_obj=proj_obj,
virtual_network_properties=VirtualNetworkType(forwarding_mode='l3'),
address_allocation_mode='user-defined-subnet-only')
try:
vn_obj = self._vnc_lib.virtual_network_read(
fq_name=vn.get_fq_name())
except NoIdError:
# Virtual network does not exist. Create one.
vn_uuid = self._vnc_lib.virtual_network_create(vn)
vn_obj = self._vnc_lib.virtual_network_read(id=vn_uuid)
pod_ipam_obj = self._create_network_ipam('pod-ipam', 'flat-subnet',
pod_subnet, proj_obj, vn_obj)
self._create_network_ipam('service-ipam', '', service_subnet, proj_obj,
vn_obj)
try:
self._vnc_lib.virtual_network_update(vn_obj)
except Exception as e:
self.logger.error("%s - failed to update virtual network %s %s. %s"
% (self._name, vn_obj.uuid, str(vn_obj.fq_name),
str(e)))
vn_obj = self._vnc_lib.virtual_network_read(
fq_name=vn_obj.get_fq_name())
kube = vnc_kubernetes.VncKubernetes.get_instance()
kube._create_cluster_service_fip_pool(vn_obj, pod_ipam_obj)
return vn_obj
示例2: test_unset_tag_from_a_resource
def test_unset_tag_from_a_resource(self):
project = Project('project-%s' % self.id())
self.api.project_create(project)
vn = VirtualNetwork('vn-%s' % self.id(), parent_obj=project)
vn_uuid = self.api.virtual_network_create(vn)
type = 'fake_type-%s' % self.id()
value = 'fake_value-%s' % self.id()
tag = Tag(tag_type_name=type, tag_value=value, parent_obj=project)
self.api.tag_create(tag)
self.api.set_tag(vn, type, value)
for system_type in constants.TagTypeNameToId:
self.api.tag_create(
Tag(tag_type_name=system_type, tag_value=value))
self.api.set_tag(vn, system_type, value, is_global=True)
vn = self._vnc_lib.virtual_network_read(id=vn_uuid)
self.assertEqual(len(vn.get_tag_refs()),
len(constants.TagTypeNameToId) + 1)
self.assertTrue(tag.uuid in {ref['uuid'] for ref in vn.get_tag_refs()})
self.api.unset_tag(vn, type)
vn = self._vnc_lib.virtual_network_read(id=vn_uuid)
self.assertEqual(len(vn.get_tag_refs()),
len(constants.TagTypeNameToId))
self.assertFalse(tag.uuid in
{ref['uuid'] for ref in vn.get_tag_refs()})
示例3: test_deallocate_vxlan_id
def test_deallocate_vxlan_id(self):
# enable vxlan routing on project
proj = self._vnc_lib.project_read(
fq_name=["default-domain", "default-project"])
proj.set_vxlan_routing(True)
self._vnc_lib.project_update(proj)
mock_zk = self._api_server._db_conn._zk_db
vn_obj = VirtualNetwork('%s-vn' % self.id())
vn_obj_properties = VirtualNetworkType(forwarding_mode='l3')
vn_obj_properties.set_vxlan_network_identifier(6002)
vn_obj.set_virtual_network_properties(vn_obj_properties)
self.api.virtual_network_create(vn_obj)
# VN created, now read back the VN data to check if vxlan_id is set
vn_obj = self.api.virtual_network_read(id=vn_obj.uuid)
vn_obj_properties = vn_obj.get_virtual_network_properties()
if not vn_obj_properties:
self.fail("VN properties are not set")
vxlan_id = vn_obj_properties.get_vxlan_network_identifier()
self.assertEqual(vxlan_id, 6002)
self.api.virtual_network_delete(id=vn_obj.uuid)
self.assertNotEqual(vn_obj.get_fq_name_str() + "_vxlan",
mock_zk.get_vn_from_id(vxlan_id))
logger.debug('PASS - test_deallocate_vxlan_id')
示例4: test_create_pool
def test_create_pool(self):
tenant_id = _uuid()
pool_id = _uuid()
vip_id = _uuid()
subnet_id = _uuid()
api = self.api_server
project = Project(name='test')
project.uuid = tenant_id
template = ServiceTemplate('lb-test', project)
template.uuid = _uuid()
pool_attrs = LoadbalancerPoolType()
pool_attrs.subnet_id = subnet_id
pool = LoadbalancerPool(
pool_id, project, loadbalancer_pool_properties=pool_attrs)
pool.uuid = pool_id
vip_attrs = VirtualIpType()
vip_attrs.subnet_id = subnet_id
vip_attrs.address = '127.0.0.1'
vip = VirtualIp(vip_id, project, virtual_ip_properties=vip_attrs)
vip.uuid = vip_id
vip.set_loadbalancer_pool(pool)
vnet = VirtualNetwork('test', project)
vnet.uuid = _uuid()
vmi = VirtualMachineInterface(vip_id, project)
vmi.uuid = _uuid()
vmi.set_virtual_network(vnet)
iip = InstanceIp(vip_id, instance_ip_address='127.0.0.1')
iip.uuid = _uuid()
iip.set_virtual_machine_interface(vmi)
iip_refs = [
{'to': iip.get_fq_name(), 'uuid': iip.uuid}
]
vmi.get_instance_ip_back_refs = mock.Mock()
vmi.get_instance_ip_back_refs.return_value = iip_refs
vip.set_virtual_machine_interface(vmi)
api.virtual_service_template_read = template
api.loadbalancer_pool_read.return_value = pool
api.virtual_ip_read.return_value = vip
api.kv_retrieve.return_value = '%s %s' % (vnet.uuid, subnet_id)
api.virtual_machine_interface_read.return_value = vmi
api.instance_ip_read.return_value = iip
api.service_instance_read.side_effect = NoIdError('404')
context = {}
pool_data = {
'id': pool_id,
'vip_id': vip_id
}
self.driver.create_pool(context, pool_data)
api.service_instance_create.assert_called_with(mock.ANY)
示例5: _create_virtual_network
def _create_virtual_network(self, vn_name, proj_obj, ipam_obj, \
ipam_update, provider=None, subnets=None, \
type='flat-subnet-only'):
vn_exists = False
vn = VirtualNetwork(name=vn_name, parent_obj=proj_obj,
address_allocation_mode=type)
try:
vn_obj = self._vnc_lib.virtual_network_read(
fq_name=vn.get_fq_name())
vn_exists = True
except NoIdError:
# VN does not exist. Create one.
vn_obj = vn
if vn_exists:
return vn_obj
# Attach IPAM to virtual network.
#
# For flat-subnets, the subnets are specified on the IPAM and
# not on the virtual-network to IPAM link. So pass an empty
# list of VnSubnetsType.
# For user-defined-subnets, use the provided subnets
if ipam_update or \
not self._is_ipam_exists(vn_obj, ipam_obj.get_fq_name()):
if subnets and type == 'user-defined-subnet-only':
vn_obj.add_network_ipam(ipam_obj, subnets)
else:
vn_obj.add_network_ipam(ipam_obj, VnSubnetsType([]))
vn_obj.set_virtual_network_properties(
VirtualNetworkType(forwarding_mode='l3'))
fabric_snat = False
if self.ip_fabric_snat:
fabric_snat = True
if not vn_exists:
if self.ip_fabric_forwarding:
if provider:
#enable ip_fabric_forwarding
vn_obj.add_virtual_network(provider)
elif fabric_snat:
#enable fabric_snat
vn_obj.set_fabric_snat(True)
else:
#disable fabric_snat
vn_obj.set_fabric_snat(False)
# Create VN.
self._vnc_lib.virtual_network_create(vn_obj)
else:
# TODO: Handle Network update
pass
vn_obj = self._vnc_lib.virtual_network_read(
fq_name=vn_obj.get_fq_name())
VirtualNetworkKM.locate(vn_obj.uuid)
return vn_obj
示例6: test_create_vn_with_configured_rt_in_system_range
def test_create_vn_with_configured_rt_in_system_range(self):
gsc = self.api.global_system_config_read(GlobalSystemConfig().fq_name)
vn = VirtualNetwork('%s-vn' % self.id())
rt_name = 'target:%d:%d' % (gsc.autonomous_system,
BGP_RTGT_MIN_ID + 1000)
vn.set_route_target_list(RouteTargetList([rt_name]))
self.assertRaises(BadRequest, self.api.virtual_network_create, vn)
示例7: test_only_one_value_for_a_type_can_be_associate_to_a_resource2
def test_only_one_value_for_a_type_can_be_associate_to_a_resource2(self):
project = Project('project-%s' % self.id())
self.api.project_create(project)
tag_type = 'fake_type-%s' % self.id()
global_tag = Tag(tag_type_name=tag_type,
tag_value='global_fake_value-%s' % self.id())
self.api.tag_create(global_tag)
scoped_tag = Tag(tag_type_name=tag_type,
tag_value='scoped_fake_value-%s' % self.id(),
parent_obj=project)
self.api.tag_create(scoped_tag)
vn = VirtualNetwork('vn-%s' % self.id(), parent_obj=project)
vn.add_tag(global_tag)
vn.add_tag(scoped_tag)
self.assertRaises(BadRequest, self.api.virtual_network_create, vn)
vn.set_tag(global_tag)
self.api.virtual_network_create(vn)
vn = self._vnc_lib.virtual_network_read(id=vn.uuid)
self.assertEqual(len(vn.get_tag_refs()), 1)
self.assertEqual(vn.get_tag_refs()[0]['uuid'], global_tag.uuid)
vn.add_tag(scoped_tag)
self.assertRaises(BadRequest, self.api.virtual_network_update, vn)
示例8: test_deallocate_vn_id
def test_deallocate_vn_id(self):
mock_zk = self._api_server._db_conn._zk_db
vn_obj = VirtualNetwork('%s-vn' % self.id())
self.api.virtual_network_create(vn_obj)
vn_obj = self.api.virtual_network_read(id=vn_obj.uuid)
vn_id = vn_obj.virtual_network_network_id
self.api.virtual_network_delete(id=vn_obj.uuid)
self.assertNotEqual(mock_zk.get_vn_from_id(vn_id),
vn_obj.get_fq_name_str())
示例9: test_allocate_vn_id
def test_allocate_vn_id(self):
mock_zk = self._api_server._db_conn._zk_db
vn_obj = VirtualNetwork('%s-vn' % self.id())
self.api.virtual_network_create(vn_obj)
vn_obj = self.api.virtual_network_read(id=vn_obj.uuid)
vn_id = vn_obj.virtual_network_network_id
self.assertEqual(vn_obj.get_fq_name_str(),
mock_zk.get_vn_from_id(vn_id))
self.assertGreaterEqual(vn_id, VNID_MIN_ALLOC)
示例10: create_network
def create_network(self, name, proj_obj):
vn = VirtualNetwork(
name=name,
parent_obj=proj_obj,
virtual_network_properties=VirtualNetworkType(forwarding_mode='l3'),
address_allocation_mode='flat-subnet-only')
try:
vn_obj = self._vnc_lib.virtual_network_read(
fq_name=vn.get_fq_name())
except NoIdError:
# Virtual network does not exist. Create one.
uid = self._vnc_lib.virtual_network_create(vn)
vn_obj = self._vnc_lib.virtual_network_read(id=uid)
return vn_obj
示例11: test_cannot_update_vn_id
def test_cannot_update_vn_id(self):
vn_obj = VirtualNetwork('%s-vn' % self.id())
self.api.virtual_network_create(vn_obj)
vn_obj = self.api.virtual_network_read(id=vn_obj.uuid)
vn_obj.set_virtual_network_network_id(42)
with ExpectedException(PermissionDenied):
self.api.virtual_network_update(vn_obj)
# test can update with same value, needed internally
# TODO(ethuleau): not sure why it's needed
vn_obj = self.api.virtual_network_read(id=vn_obj.uuid)
vn_obj.set_virtual_network_network_id(
vn_obj.virtual_network_network_id)
self.api.virtual_network_update(vn_obj)
示例12: test_resources_exists
def test_resources_exists(self):
api = VncApiMock(
self.args.auth_user,
self.args.auth_password,
self.args.auth_tenant,
self.args.vnc_endpoint_ip,
self.args.vnc_endpoint_port,
self.args.auth_token_url
)
domain_uuid = api.domain_create(Domain("default-domain"))
domain = api.domain_read(id=domain_uuid)
proj_uuid = api.project_create(Project("default", parent_obj=domain))
proj = api.project_read(id=proj_uuid)
ipam_uuid = api.network_ipam_create(NetworkIpam("pod-ipam", proj))
ipam = api.network_ipam_read(id=ipam_uuid)
net = VirtualNetwork("cluster-network", proj)
net.add_network_ipam(ipam, VnSubnetsType([]))
api.virtual_network_create(net)
vnc_kubernetes.VncKubernetes(self.args, Mock())
示例13: test_resources_exists
def test_resources_exists(self):
api = VncApiMock(
self.args.auth_user,
self.args.auth_password,
self.args.auth_tenant,
self.args.vnc_endpoint_ip,
self.args.vnc_endpoint_port,
self.args.auth_token_url
)
domain_fq_name = ['default-domain']
domain = api.domain_read(fq_name=domain_fq_name)
proj_uuid = api.project_create(Project("default", parent_obj=domain))
proj = api.project_read(id=proj_uuid)
# Create cluster-default-pod-network
ipam_uuid = api.network_ipam_create(NetworkIpam("pod-ipam", proj))
ipam = api.network_ipam_read(id=ipam_uuid)
net = VirtualNetwork("cluster-default-pod-network", proj)
# No subnets are associated with IPAM at this point.
# Subnets will be updated in the IPAM, when cluster is created.
net.add_network_ipam(ipam, VnSubnetsType([]))
api.virtual_network_create(net)
# Create cluster-default-service-network
ipam_uuid = api.network_ipam_create(NetworkIpam("service-ipam", proj))
ipam = api.network_ipam_read(id=ipam_uuid)
net = VirtualNetwork("cluster-default-service-network", proj)
# No subnets are associated with IPAM at this point.
# Subnets will be updated in the IPAM, when cluster is created.
net.add_network_ipam(ipam, VnSubnetsType([]))
api.virtual_network_create(net)
vnc_kubernetes.VncKubernetes(self.args, Mock())
示例14: test_only_one_value_for_a_type_can_be_associate_to_a_resource
def test_only_one_value_for_a_type_can_be_associate_to_a_resource(self):
project = Project('project-%s' % self.id())
self.api.project_create(project)
vn = VirtualNetwork('vn-%s' % self.id(), parent_obj=project)
vn_uuid = self.api.virtual_network_create(vn)
tag_type = 'fake_type-%s' % self.id()
global_tag_value = 'global_fake_value-%s' % self.id()
global_tag = Tag(tag_type_name=tag_type, tag_value=global_tag_value)
self.api.tag_create(global_tag)
tags_dict = {
tag_type: {
'is_global': True,
'value': global_tag_value,
},
}
self.api.set_tags(vn, tags_dict)
vn = self._vnc_lib.virtual_network_read(id=vn_uuid)
self.assertEqual(len(vn.get_tag_refs()), 1)
self.assertEqual(vn.get_tag_refs()[0]['uuid'], global_tag.uuid)
scoped_tag_value = 'scoped_fake_value-%s' % self.id()
scoped_tag = Tag(tag_type_name=tag_type, tag_value=scoped_tag_value,
parent_obj=project)
self.api.tag_create(scoped_tag)
tags_dict = {
tag_type: {
'value': scoped_tag_value,
},
}
self.api.set_tags(vn, tags_dict)
# Scoped tag which is the same type as the global tag but with a
# different value, replaced the global tag ref of the VN. One at a time
vn = self._vnc_lib.virtual_network_read(id=vn_uuid)
self.assertEqual(len(vn.get_tag_refs()), 1)
self.assertEqual(vn.get_tag_refs()[0]['uuid'], scoped_tag.uuid)
示例15: test_associate_scoped_tag_to_a_resource
def test_associate_scoped_tag_to_a_resource(self):
project = Project('project-%s' % self.id())
self.api.project_create(project)
vn = VirtualNetwork('vn-%s' % self.id(), parent_obj=project)
vn_uuid = self.api.virtual_network_create(vn)
type = 'fake_type-%s' % self.id()
value = 'fake_value-%s' % self.id()
scoped_tag = Tag(tag_type_name=type, tag_value=value,
parent_obj=project)
self.api.tag_create(scoped_tag)
tags_dict = {
type: {
'value': value,
},
}
self.api.set_tags(vn, tags_dict)
vn = self._vnc_lib.virtual_network_read(id=vn_uuid)
self.assertEqual(len(vn.get_tag_refs()), 1)
self.assertEqual(vn.get_tag_refs()[0]['uuid'], scoped_tag.uuid)