Define constants for the VIF model types
Define constants for the common VIF model types. This will ensure that all of the drivers will make use of the same values. Change-Id: I2099bbe92906ac0b1b54f1819113b33565e78980
This commit is contained in:
parent
a03a9779bc
commit
0f263d767a
@ -44,6 +44,15 @@ VIF_TYPE_OTHER = 'other'
|
||||
VIF_DETAIL_PORT_FILTER = 'port_filter'
|
||||
VIF_DETAIL_OVS_HYBRID_PLUG = 'ovs_hybrid_plug'
|
||||
|
||||
# Constants for the 'vif_model' values
|
||||
VIF_MODEL_VIRTIO = 'virtio'
|
||||
VIF_MODEL_NE2K_PCI = 'ne2k_pci'
|
||||
VIF_MODEL_PCNET = 'pcnet'
|
||||
VIF_MODEL_RTL8139 = 'rtl8139'
|
||||
VIF_MODEL_E1000 = 'e1000'
|
||||
VIF_MODEL_E1000E = 'e1000e'
|
||||
VIF_MODEL_NETFRONT = 'netfront'
|
||||
|
||||
# Constant for max length of network interface names
|
||||
# eg 'bridge' in the Network class or 'devname' in
|
||||
# the VIF class
|
||||
|
@ -356,7 +356,7 @@ class LibvirtVifTestCase(test.TestCase):
|
||||
d = vif.LibvirtGenericVIFDriver(self._get_conn())
|
||||
xml = self._get_instance_xml(d, self.vif_bridge)
|
||||
|
||||
self._assertModel(xml, "virtio")
|
||||
self._assertModel(xml, network_model.VIF_MODEL_VIRTIO)
|
||||
|
||||
def test_model_kvm_custom(self):
|
||||
self.flags(use_virtio_for_bridges=True,
|
||||
@ -364,10 +364,11 @@ class LibvirtVifTestCase(test.TestCase):
|
||||
group='libvirt')
|
||||
|
||||
d = vif.LibvirtGenericVIFDriver(self._get_conn())
|
||||
image_meta = {'properties': {'hw_vif_model': 'e1000'}}
|
||||
image_meta = {'properties': {'hw_vif_model':
|
||||
network_model.VIF_MODEL_E1000}}
|
||||
xml = self._get_instance_xml(d, self.vif_bridge,
|
||||
image_meta)
|
||||
self._assertModel(xml, "e1000")
|
||||
self._assertModel(xml, network_model.VIF_MODEL_E1000)
|
||||
|
||||
def test_model_kvm_bogus(self):
|
||||
self.flags(use_virtio_for_bridges=True,
|
||||
@ -416,7 +417,7 @@ class LibvirtVifTestCase(test.TestCase):
|
||||
self.assertEqual(outbound.get("burst"),
|
||||
self.bandwidth['quota:vif_outbound_burst'])
|
||||
|
||||
self._assertModel(xml, "virtio", "qemu")
|
||||
self._assertModel(xml, network_model.VIF_MODEL_VIRTIO, "qemu")
|
||||
|
||||
def test_model_qemu_no_firewall(self):
|
||||
self.flags(firewall_driver="nova.virt.firewall.NoopFirewallDriver")
|
||||
@ -760,7 +761,7 @@ class LibvirtVifTestCase(test.TestCase):
|
||||
self._assertTypeEquals(node, "direct", "source",
|
||||
"mode", "passthrough")
|
||||
self._assertMacEquals(node, self.vif_mlnx)
|
||||
self._assertModel(xml, "virtio")
|
||||
self._assertModel(xml, network_model.VIF_MODEL_VIRTIO)
|
||||
|
||||
def test_midonet_ethernet_vif_driver(self):
|
||||
d = vif.LibvirtGenericVIFDriver(self._get_conn())
|
||||
|
@ -20,6 +20,7 @@ import re
|
||||
import mock
|
||||
|
||||
from nova import exception
|
||||
from nova.network import model as network_model
|
||||
from nova.openstack.common.gettextutils import _
|
||||
from nova.openstack.common import units
|
||||
from nova.openstack.common import uuidutils
|
||||
@ -630,3 +631,19 @@ class VMwareVMUtilTestCase(test.NoDBTestCase):
|
||||
expected = re.sub(r'\s+', '', expected)
|
||||
result = re.sub(r'\s+', '', repr(result))
|
||||
self.assertEqual(expected, result)
|
||||
|
||||
def test_convert_vif_model(self):
|
||||
expected = "VirtualE1000"
|
||||
result = vm_util._convert_vif_model(network_model.VIF_MODEL_E1000)
|
||||
self.assertEqual(expected, result)
|
||||
expected = "VirtualE1000e"
|
||||
result = vm_util._convert_vif_model(network_model.VIF_MODEL_E1000E)
|
||||
self.assertEqual(expected, result)
|
||||
types = ["VirtualE1000", "VirtualE1000e", "VirtualPCNet32",
|
||||
"VirtualVmxnet"]
|
||||
for type in types:
|
||||
self.assertEqual(type,
|
||||
vm_util._convert_vif_model(type))
|
||||
self.assertRaises(exception.Invalid,
|
||||
vm_util._convert_vif_model,
|
||||
"InvalidVifModel")
|
||||
|
@ -54,9 +54,21 @@ DEV_PREFIX_ETH = 'eth'
|
||||
|
||||
def is_vif_model_valid_for_virt(virt_type, vif_model):
|
||||
valid_models = {
|
||||
'qemu': ['virtio', 'ne2k_pci', 'pcnet', 'rtl8139', 'e1000'],
|
||||
'kvm': ['virtio', 'ne2k_pci', 'pcnet', 'rtl8139', 'e1000'],
|
||||
'xen': ['netfront', 'ne2k_pci', 'pcnet', 'rtl8139', 'e1000'],
|
||||
'qemu': [network_model.VIF_MODEL_VIRTIO,
|
||||
network_model.VIF_MODEL_NE2K_PCI,
|
||||
network_model.VIF_MODEL_PCNET,
|
||||
network_model.VIF_MODEL_RTL8139,
|
||||
network_model.VIF_MODEL_E1000],
|
||||
'kvm': [network_model.VIF_MODEL_VIRTIO,
|
||||
network_model.VIF_MODEL_NE2K_PCI,
|
||||
network_model.VIF_MODEL_PCNET,
|
||||
network_model.VIF_MODEL_RTL8139,
|
||||
network_model.VIF_MODEL_E1000],
|
||||
'xen': [network_model.VIF_MODEL_NETFRONT,
|
||||
network_model.VIF_MODEL_NE2K_PCI,
|
||||
network_model.VIF_MODEL_PCNET,
|
||||
network_model.VIF_MODEL_RTL8139,
|
||||
network_model.VIF_MODEL_E1000],
|
||||
'lxc': [],
|
||||
'uml': [],
|
||||
}
|
||||
@ -113,11 +125,12 @@ class LibvirtBaseVIFDriver(object):
|
||||
if (model is None and
|
||||
CONF.libvirt.virt_type in ('kvm', 'qemu') and
|
||||
CONF.libvirt.use_virtio_for_bridges):
|
||||
model = "virtio"
|
||||
model = network_model.VIF_MODEL_VIRTIO
|
||||
|
||||
# Workaround libvirt bug, where it mistakenly
|
||||
# enables vhost mode, even for non-KVM guests
|
||||
if model == "virtio" and CONF.libvirt.virt_type == "qemu":
|
||||
if (model == network_model.VIF_MODEL_VIRTIO and
|
||||
CONF.libvirt.virt_type == "qemu"):
|
||||
driver = "qemu"
|
||||
|
||||
if not is_vif_model_valid_for_virt(CONF.libvirt.virt_type,
|
||||
|
@ -25,6 +25,7 @@ import functools
|
||||
from oslo.config import cfg
|
||||
|
||||
from nova import exception
|
||||
from nova.network import model as network_model
|
||||
from nova.openstack.common.gettextutils import _
|
||||
from nova.openstack.common import log as logging
|
||||
from nova.openstack.common import units
|
||||
@ -35,6 +36,9 @@ from nova.virt.vmwareapi import vim_util
|
||||
CONF = cfg.CONF
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
ALL_SUPPORTED_NETWORK_DEVICES = ['VirtualE1000', 'VirtualE1000e',
|
||||
'VirtualPCNet32', 'VirtualSriovEthernetCard',
|
||||
'VirtualVmxnet']
|
||||
DSRecord = collections.namedtuple(
|
||||
'DSRecord', ['datastore', 'name', 'capacity', 'freespace'])
|
||||
|
||||
@ -183,6 +187,18 @@ def create_controller_spec(client_factory, key, adapter_type="lsiLogic"):
|
||||
return virtual_device_config
|
||||
|
||||
|
||||
def _convert_vif_model(name):
|
||||
"""Converts standard VIF_MODEL types to the internal VMware ones."""
|
||||
if name == network_model.VIF_MODEL_E1000:
|
||||
return 'VirtualE1000'
|
||||
if name == network_model.VIF_MODEL_E1000E:
|
||||
return 'VirtualE1000e'
|
||||
if name not in ALL_SUPPORTED_NETWORK_DEVICES:
|
||||
msg = _('%s is not supported.') % name
|
||||
raise exception.Invalid(msg)
|
||||
return name
|
||||
|
||||
|
||||
def create_network_spec(client_factory, vif_info):
|
||||
"""Builds a config spec for the addition of a new network
|
||||
adapter to the VM.
|
||||
@ -191,8 +207,7 @@ def create_network_spec(client_factory, vif_info):
|
||||
network_spec.operation = "add"
|
||||
|
||||
# Keep compatible with other Hyper vif model parameter.
|
||||
if vif_info['vif_model'] == "e1000":
|
||||
vif_info['vif_model'] = "VirtualE1000"
|
||||
vif_info['vif_model'] = _convert_vif_model(vif_info['vif_model'])
|
||||
|
||||
vif = 'ns0:' + vif_info['vif_model']
|
||||
net_device = client_factory.create(vif)
|
||||
|
@ -31,6 +31,7 @@ from nova.compute import power_state
|
||||
from nova.compute import task_states
|
||||
from nova import context as nova_context
|
||||
from nova import exception
|
||||
from nova.network import model as network_model
|
||||
from nova.openstack.common import excutils
|
||||
from nova.openstack.common.gettextutils import _
|
||||
from nova.openstack.common import lockutils
|
||||
@ -235,7 +236,8 @@ class VMwareVMOps(object):
|
||||
disk_type = image_properties.get("vmware_disktype",
|
||||
"preallocated")
|
||||
# Get the network card type from the image properties.
|
||||
vif_model = image_properties.get("hw_vif_model", "VirtualE1000")
|
||||
vif_model = image_properties.get("hw_vif_model",
|
||||
network_model.VIF_MODEL_E1000)
|
||||
|
||||
# Fetch the image_linked_clone data here. It is retrieved
|
||||
# with the above network based API call. To retrieve it
|
||||
|
Loading…
Reference in New Issue
Block a user