本文整理匯總了Python中vnc_api.vnc_api.VirtualMachineInterface.set_virtual_network方法的典型用法代碼示例。如果您正苦於以下問題:Python VirtualMachineInterface.set_virtual_network方法的具體用法?Python VirtualMachineInterface.set_virtual_network怎麽用?Python VirtualMachineInterface.set_virtual_network使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類vnc_api.vnc_api.VirtualMachineInterface
的用法示例。
在下文中一共展示了VirtualMachineInterface.set_virtual_network方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _create_virtual_interface
# 需要導入模塊: from vnc_api.vnc_api import VirtualMachineInterface [as 別名]
# 或者: from vnc_api.vnc_api.VirtualMachineInterface import set_virtual_network [as 別名]
def _create_virtual_interface(self, project, lb_id, subnet_id,
ip_address):
network_id = utils.get_subnet_network_id(self._api, subnet_id)
try:
vnet = self._api.virtual_network_read(id=network_id)
except NoIdError:
raise n_exc.NetworkNotFound(net_id=network_id)
vmi = VirtualMachineInterface(lb_id, project)
vmi.set_virtual_network(vnet)
vmi.set_virtual_machine_interface_device_owner(n_constants.DEVICE_OWNER_LOADBALANCER)
sg_obj = SecurityGroup("default", project)
vmi.add_security_group(sg_obj)
self._api.virtual_machine_interface_create(vmi)
iip_obj = InstanceIp(name=lb_id)
iip_obj.set_virtual_network(vnet)
iip_obj.set_virtual_machine_interface(vmi)
if ip_address and ip_address != attributes.ATTR_NOT_SPECIFIED:
iip_obj.set_instance_ip_address(ip_address)
self._api.instance_ip_create(iip_obj)
iip = self._api.instance_ip_read(id=iip_obj.uuid)
vip_address = iip.get_instance_ip_address()
return vmi, vip_address
示例2: test_virtual_port_group_delete
# 需要導入模塊: from vnc_api.vnc_api import VirtualMachineInterface [as 別名]
# 或者: from vnc_api.vnc_api.VirtualMachineInterface import set_virtual_network [as 別名]
def test_virtual_port_group_delete(self):
proj_obj = Project('%s-project' % (self.id()))
self.api.project_create(proj_obj)
vn = VirtualNetwork('vn-%s' % (self.id()), parent_obj=proj_obj)
self.api.virtual_network_create(vn)
vpg_name = "vpg-" + self.id()
vpg_obj = VirtualPortGroup(vpg_name)
self.api.virtual_port_group_create(vpg_obj)
vmi_id_list = []
for i in range(self.VMI_NUM):
vmi_obj = VirtualMachineInterface(self.id() + str(i),
parent_obj=proj_obj)
vmi_obj.set_virtual_network(vn)
vmi_id_list.append(
self.api.virtual_machine_interface_create(vmi_obj))
vpg_obj.add_virtual_machine_interface(vmi_obj)
self.api.virtual_port_group_update(vpg_obj)
self.api.ref_relax_for_delete(vpg_obj.uuid, vmi_id_list[i])
# Make sure when VPG doesn't get deleted, since associated VMIs
# still refers it.
with ExpectedException(BadRequest):
self.api.virtual_port_group_delete(id=vpg_obj.uuid)
# Cleanup
for i in range(self.VMI_NUM):
self.api.virtual_machine_interface_delete(id=vmi_id_list[i])
self.api.virtual_port_group_delete(id=vpg_obj.uuid)
示例3: _create_vmi
# 需要導入模塊: from vnc_api.vnc_api import VirtualMachineInterface [as 別名]
# 或者: from vnc_api.vnc_api.VirtualMachineInterface import set_virtual_network [as 別名]
def _create_vmi(self, pod_task_id, vm_obj, vn_obj):
proj_fq_name = vnc_mesos_config.cluster_project_fq_name('default')
proj_obj = self._vnc_lib.project_read(fq_name=proj_fq_name)
vmi_prop = None
obj_uuid = str(uuid.uuid1())
vmi_obj = VirtualMachineInterface(
name=vm_obj.name, parent_obj=proj_obj,
virtual_machine_interface_properties=vmi_prop,
display_name=vm_obj.name)
vmi_obj.uuid = obj_uuid
vmi_obj.set_virtual_network(vn_obj)
vmi_obj.set_virtual_machine(vm_obj)
vmi_obj.add_annotations(KeyValuePair(key='index', value='0/1'))
vmi_obj.port_security_enabled = True
VirtualMachineInterfaceMM.add_annotations(self, vmi_obj, pod_task_id)
try:
vmi_uuid = self._vnc_lib.virtual_machine_interface_create(vmi_obj)
except RefsExistError:
vmi_uuid = self._vnc_lib.virtual_machine_interface_update(vmi_obj)
VirtualMachineInterfaceMM.locate(vmi_uuid)
return vmi_uuid
示例4: _create_virtual_interface
# 需要導入模塊: from vnc_api.vnc_api import VirtualMachineInterface [as 別名]
# 或者: from vnc_api.vnc_api.VirtualMachineInterface import set_virtual_network [as 別名]
def _create_virtual_interface(self, project, vip_id, subnet_id,
ip_address):
network_id = utils.get_subnet_network_id(self._api, subnet_id)
try:
vnet = self._api.virtual_network_read(id=network_id)
except NoIdError:
raise n_exc.NetworkNotFound(net_id=network_id)
vmi = VirtualMachineInterface(vip_id, project)
vmi.set_virtual_network(vnet)
sg_obj = SecurityGroup("default", project)
vmi.add_security_group(sg_obj)
self._api.virtual_machine_interface_create(vmi)
fq_name = list(project.get_fq_name())
fq_name.append(vip_id)
iip_obj = InstanceIp(fq_name=fq_name)
iip_obj.set_virtual_network(vnet)
iip_obj.set_virtual_machine_interface(vmi)
if ip_address and ip_address != attributes.ATTR_NOT_SPECIFIED:
iip_obj.set_instance_ip_address(ip_address)
self._api.instance_ip_create(fq_name)
return vmi
示例5: test_valid_sub_interface_vlan_tag_id
# 需要導入模塊: from vnc_api.vnc_api import VirtualMachineInterface [as 別名]
# 或者: from vnc_api.vnc_api.VirtualMachineInterface import set_virtual_network [as 別名]
def test_valid_sub_interface_vlan_tag_id(self):
project = Project('%s-project' % self.id())
self.api.project_create(project)
vn = VirtualNetwork('%s-vn' % self.id(), parent_obj=project)
self.api.virtual_network_create(vn)
test_suite = [
(None, None),
(VMIPT(None), None),
(VMIPT(sub_interface_vlan_tag=None), None),
(VMIPT(sub_interface_vlan_tag=-42), BadRequest),
(VMIPT(sub_interface_vlan_tag=4095), BadRequest),
(VMIPT(sub_interface_vlan_tag='fo'), BadRequest),
(VMIPT(sub_interface_vlan_tag='42'), None),
(VMIPT(sub_interface_vlan_tag=42), None),
]
for (vmipt, result) in test_suite:
vmi = VirtualMachineInterface('%s-vmi' % self.id(),
parent_obj=project)
vmi.set_virtual_network(vn)
vmi.set_virtual_machine_interface_properties(vmipt)
if result and issubclass(result, Exception):
self.assertRaises(result,
self.api.virtual_machine_interface_create,
vmi)
else:
self.api.virtual_machine_interface_create(vmi)
self.api.virtual_machine_interface_delete(id=vmi.uuid)
示例6: test_disable_port_security_with_empty_allowed_address_pair_list
# 需要導入模塊: from vnc_api.vnc_api import VirtualMachineInterface [as 別名]
# 或者: from vnc_api.vnc_api.VirtualMachineInterface import set_virtual_network [as 別名]
def test_disable_port_security_with_empty_allowed_address_pair_list(self):
project = Project('%s-project' % self.id())
self.api.project_create(project)
vn = VirtualNetwork('vn-%s' % self.id(), parent_obj=project)
self._vnc_lib.virtual_network_create(vn)
addr_pair = AllowedAddressPairs()
vmi1 = VirtualMachineInterface(
'vmi1-%s' % self.id(),
parent_obj=project,
port_security_enabled=False,
virtual_machine_interface_allowed_address_pairs=addr_pair)
vmi1.set_virtual_network(vn)
self._vnc_lib.virtual_machine_interface_create(vmi1)
addr_pair = AllowedAddressPairs(
allowed_address_pair=[
AllowedAddressPair(ip=SubnetType('1.1.1.0', 24),
mac='02:ce:1b:d7:a6:e7')])
vmi2 = VirtualMachineInterface(
'vmi2-%s' % self.id(),
parent_obj=project,
port_security_enabled=True,
virtual_machine_interface_allowed_address_pairs=addr_pair)
vmi2.set_virtual_network(vn)
self._vnc_lib.virtual_machine_interface_create(vmi2)
addr_pair = AllowedAddressPairs()
vmi2.set_virtual_machine_interface_allowed_address_pairs(addr_pair)
self._vnc_lib.virtual_machine_interface_update(vmi2)
vmi2.set_port_security_enabled(False)
self._vnc_lib.virtual_machine_interface_update(vmi2)
示例7: test_port_security_and_allowed_address_pairs
# 需要導入模塊: from vnc_api.vnc_api import VirtualMachineInterface [as 別名]
# 或者: from vnc_api.vnc_api.VirtualMachineInterface import set_virtual_network [as 別名]
def test_port_security_and_allowed_address_pairs(self):
project = Project('%s-project' % self.id())
self.api.project_create(project)
vn = VirtualNetwork('vn-%s' % self.id(), parent_obj=project)
self._vnc_lib.virtual_network_create(vn)
addr_pair = AllowedAddressPairs(
allowed_address_pair=[
AllowedAddressPair(ip=SubnetType('1.1.1.0', 24),
mac='02:ce:1b:d7:a6:e7')])
msg = (r"^Allowed address pairs are not allowed when port security is "
"disabled$")
vmi = VirtualMachineInterface(
'vmi-%s' % self.id(),
parent_obj=project,
port_security_enabled=False,
virtual_machine_interface_allowed_address_pairs=addr_pair)
vmi.set_virtual_network(vn)
with self.assertRaisesRegexp(BadRequest, msg):
self._vnc_lib.virtual_machine_interface_create(vmi)
vmi = VirtualMachineInterface('vmi-%s' % self.id(), parent_obj=project,
port_security_enabled=False)
vmi.set_virtual_network(vn)
self._vnc_lib.virtual_machine_interface_create(vmi)
# updating a port with allowed address pair should throw an exception
# when port security enabled is set to false
vmi.virtual_machine_interface_allowed_address_pairs = addr_pair
with self.assertRaisesRegexp(BadRequest, msg):
self._vnc_lib.virtual_machine_interface_update(vmi)
示例8: test_create_pool
# 需要導入模塊: from vnc_api.vnc_api import VirtualMachineInterface [as 別名]
# 或者: from vnc_api.vnc_api.VirtualMachineInterface import set_virtual_network [as 別名]
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)
示例9: test_subnet_type_validation
# 需要導入模塊: from vnc_api.vnc_api import VirtualMachineInterface [as 別名]
# 或者: from vnc_api.vnc_api.VirtualMachineInterface import set_virtual_network [as 別名]
def test_subnet_type_validation(self):
test_suite = [
(SubnetType('0', 0), ('0.0.0.0', 0)),
(SubnetType('1.1.1.1'), BadRequest),
(SubnetType('1.1.1.1', 24), ('1.1.1.0', 24)),
(SubnetType('1.1.1.1', '24'), ('1.1.1.0', 24)),
(SubnetType('1.1.1.1', 32), ('1.1.1.1', 32)),
(SubnetType('1.1.1.e', 32), BadRequest),
(SubnetType('1.1.1.1', '32e'), BadRequest),
(SubnetType('1.1.1.0,2.2.2.0', 24), BadRequest),
(SubnetType(''), BadRequest),
(SubnetType('', 30), BadRequest),
(SubnetType('::', 0), ('::', 0)),
(SubnetType('::'), BadRequest),
(SubnetType('dead::beef', 128), ('dead::beef', 128)),
(SubnetType('dead::beef', '128'), ('dead::beef', 128)),
(SubnetType('dead::beef', 96), ('dead::', 96)),
(SubnetType('dead::beez', 96), BadRequest),
(SubnetType('dead::beef', '96e'), BadRequest),
(SubnetType('dead::,beef::', 64), BadRequest),
]
project = Project('%s-project' % self.id())
self.api.project_create(project)
vn = VirtualNetwork('vn-%s' % self.id(), parent_obj=project)
self.api.virtual_network_create(vn)
vmi = VirtualMachineInterface('vmi-%s' % self.id(), parent_obj=project)
vmi.set_virtual_network(vn)
self.api.virtual_machine_interface_create(vmi)
for subnet, expected_result in test_suite:
aaps = AllowedAddressPairs(
allowed_address_pair=[AllowedAddressPair(ip=subnet)])
vmi.set_virtual_machine_interface_allowed_address_pairs(aaps)
if (type(expected_result) == type and
issubclass(expected_result, Exception)):
self.assertRaises(
expected_result,
self.api.virtual_machine_interface_update,
vmi)
else:
self.api.virtual_machine_interface_update(vmi)
vmi = self.api.virtual_machine_interface_read(id=vmi.uuid)
returned_apps = vmi.\
get_virtual_machine_interface_allowed_address_pairs().\
get_allowed_address_pair()
self.assertEqual(len(returned_apps), 1)
returned_subnet = returned_apps[0].get_ip()
self.assertEqual(returned_subnet.ip_prefix,
expected_result[0])
self.assertEqual(returned_subnet.ip_prefix_len,
expected_result[1])
示例10: create_virtual_machine
# 需要導入模塊: from vnc_api.vnc_api import VirtualMachineInterface [as 別名]
# 或者: from vnc_api.vnc_api.VirtualMachineInterface import set_virtual_network [as 別名]
def create_virtual_machine(self, name, vn, ipaddress):
vm_instance = VirtualMachine(name)
self._vnc_lib.virtual_machine_create(vm_instance)
fq_name = [name, '0']
vmi = VirtualMachineInterface(parent_type='virtual-machine', fq_name=fq_name)
vmi.set_virtual_network(vn)
self._vnc_lib.virtual_machine_interface_create(vmi)
ip = InstanceIp(vm_instance.name + '.0')
ip.set_virtual_machine_interface(vmi)
ip.set_virtual_network(vn)
ip.set_instance_ip_address(ipaddress)
self._vnc_lib.instance_ip_create(ip)
return vm_instance
示例11: test_cannot_update_sub_interface_vlan_tag
# 需要導入模塊: from vnc_api.vnc_api import VirtualMachineInterface [as 別名]
# 或者: from vnc_api.vnc_api.VirtualMachineInterface import set_virtual_network [as 別名]
def test_cannot_update_sub_interface_vlan_tag(self):
project = Project('%s-project' % self.id())
self.api.project_create(project)
vn = VirtualNetwork('%s-vn' % self.id(), parent_obj=project)
self.api.virtual_network_create(vn)
vmi = VirtualMachineInterface('%s-vmi' % self.id(), parent_obj=project)
vmi.set_virtual_network(vn)
self.api.virtual_machine_interface_create(vmi)
vmi42 = VirtualMachineInterface('%s-vmi42' % self.id(),
parent_obj=project)
vmi42.set_virtual_machine_interface_properties(
VMIPT(sub_interface_vlan_tag=42))
vmi42.set_virtual_network(vn)
self.api.virtual_machine_interface_create(vmi42)
# if we don't touch VMI props, we can update the VMI with or without
# VLAN ID
vmi.set_display_name('new vmi name')
self.api.virtual_machine_interface_update(vmi)
vmi42.set_display_name('new vmi42 name')
self.api.virtual_machine_interface_update(vmi42)
# if we change VMI props without specifying anything, we can update the
# VMI if VLAN ID is not set or 0
vmi.set_virtual_machine_interface_properties(None)
self.api.virtual_machine_interface_update(vmi)
vmi.set_virtual_machine_interface_properties(
VMIPT(sub_interface_vlan_tag=None))
self.api.virtual_machine_interface_update(vmi)
# if we change VMI props without specifying anything, we cannot update
# the VMI if VLAN ID is not 0
vmi42.set_virtual_machine_interface_properties(None)
self.assertRaises(BadRequest,
self.api.virtual_machine_interface_update,
vmi42)
vmi42.set_virtual_machine_interface_properties(
VMIPT(sub_interface_vlan_tag=None))
self.assertRaises(BadRequest,
self.api.virtual_machine_interface_update,
vmi42)
# if we update VMI VLAN ID to the same VLAN ID, no error raised
vmi.set_virtual_machine_interface_properties(
VMIPT(sub_interface_vlan_tag=0))
self.api.virtual_machine_interface_update(vmi)
vmi42.set_virtual_machine_interface_properties(
VMIPT(sub_interface_vlan_tag=42))
self.api.virtual_machine_interface_update(vmi42)
示例12: create_virtual_machine
# 需要導入模塊: from vnc_api.vnc_api import VirtualMachineInterface [as 別名]
# 或者: from vnc_api.vnc_api.VirtualMachineInterface import set_virtual_network [as 別名]
def create_virtual_machine(self, name, vn, ipaddress):
vm = VirtualMachine(name)
self._vnc_lib.virtual_machine_create(vm)
VirtualMachineKM.locate(vm.uuid)
vmi = VirtualMachineInterface(
parent_type='virtual-machine', fq_name=[name, '0'])
vmi.set_virtual_machine(vm)
vmi.set_virtual_network(vn)
self._vnc_lib.virtual_machine_interface_create(vmi)
VirtualMachineInterfaceKM.locate(vmi.uuid)
ip = InstanceIp(vm.name + '.0')
ip.set_virtual_machine_interface(vmi)
ip.set_virtual_network(vn)
ip.set_instance_ip_address(ipaddress)
self._vnc_lib.instance_ip_create(ip)
InstanceIpKM.locate(ip.uuid)
return vm, vmi, ip
示例13: create_virtual_machine
# 需要導入模塊: from vnc_api.vnc_api import VirtualMachineInterface [as 別名]
# 或者: from vnc_api.vnc_api.VirtualMachineInterface import set_virtual_network [as 別名]
def create_virtual_machine(self, name, vn, ipaddress):
vm = VirtualMachine(name)
self._vnc_lib.virtual_machine_create(vm)
VirtualMachineKM.locate(vm.uuid)
vmi = VirtualMachineInterface(
parent_type='virtual-machine', fq_name=[name, '0'])
vmi.set_virtual_machine(vm)
vmi.set_virtual_network(vn)
if DBBaseKM.is_nested():
vmi.set_virtual_machine_interface_bindings(
KeyValuePairs([KeyValuePair('host_id', 'WHATEVER')]))
self._vnc_lib.virtual_machine_interface_create(vmi)
VirtualMachineInterfaceKM.locate(vmi.uuid)
ip = InstanceIp(vm.name + '.0')
ip.set_virtual_machine_interface(vmi)
ip.set_virtual_network(vn)
ip.set_instance_ip_address(ipaddress)
self._vnc_lib.instance_ip_create(ip)
InstanceIpKM.locate(ip.uuid)
return vm, vmi, ip
示例14: _create_vmi
# 需要導入模塊: from vnc_api.vnc_api import VirtualMachineInterface [as 別名]
# 或者: from vnc_api.vnc_api.VirtualMachineInterface import set_virtual_network [as 別名]
def _create_vmi(self, pod_name, pod_namespace, pod_id, vm_obj, vn_obj,
parent_vmi, idx, nw_name=''):
proj_fq_name = vnc_kube_config.cluster_project_fq_name(pod_namespace)
proj_obj = self._vnc_lib.project_read(fq_name=proj_fq_name)
vmi_prop = None
if self._is_pod_nested() and parent_vmi:
# Pod is nested.
# Allocate a vlan-id for this pod from the vlan space managed
# in the VMI of the underlay VM.
parent_vmi = VirtualMachineInterfaceKM.get(parent_vmi.uuid)
vlan_id = parent_vmi.alloc_vlan()
vmi_prop = VirtualMachineInterfacePropertiesType(
sub_interface_vlan_tag=vlan_id)
obj_uuid = str(uuid.uuid1())
name = VncCommon.make_name(pod_name, obj_uuid)
vmi_obj = VirtualMachineInterface(
name=name, parent_obj=proj_obj,
virtual_machine_interface_properties=vmi_prop,
display_name=name)
vmi_obj.uuid = obj_uuid
vmi_obj.set_virtual_network(vn_obj)
vmi_obj.set_virtual_machine(vm_obj)
self._associate_security_groups(vmi_obj, proj_obj, pod_namespace)
vmi_obj.port_security_enabled = True
VirtualMachineInterfaceKM.add_annotations(self, vmi_obj, pod_namespace,
pod_name, index=idx, network=nw_name)
try:
vmi_uuid = self._vnc_lib.virtual_machine_interface_create(vmi_obj)
except RefsExistError:
vmi_uuid = self._vnc_lib.virtual_machine_interface_update(vmi_obj)
VirtualMachineInterfaceKM.locate(vmi_uuid)
return vmi_uuid