Remove unused VMWare VIF driver abstraction

There is only a single VMWare VIF driver impl and that is
entirely a no-op in the plug & unplug methods. The VMWare
driver does call a 'ensure_vlan_bridge' method, which is
essentially a static helper for creating a bridge device.

Remove the VMWareVlanBridgeDriver class entirely and simply
have a single static method instead

Change-Id: I7d0873798e0e7261e17e8894237fd4339be7c3cd
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrange 2012-12-17 20:52:55 +00:00
parent b1298cc990
commit 340c35865e
3 changed files with 50 additions and 68 deletions

View File

@ -75,9 +75,6 @@ vmwareapi_opts = [
'socket error, etc. '
'Used only if compute_driver is '
'vmwareapi.VMWareESXDriver.'),
cfg.StrOpt('vmwareapi_vlan_interface',
default='vmnic0',
help='Physical ethernet adapter name for vlan networking'),
]
CONF = cfg.CONF

View File

@ -26,63 +26,55 @@ from nova.virt.vmwareapi import network_utils
LOG = logging.getLogger(__name__)
CONF = cfg.CONF
CONF.set_default('vmwareapi_vlan_interface', 'vmnic0')
vmwareapi_vif_opts = [
cfg.StrOpt('vmwareapi_vlan_interface',
default='vmnic0',
help='Physical ethernet adapter name for vlan networking'),
]
CONF.register_opts(vmwareapi_vif_opts)
class VMWareVlanBridgeDriver(object):
"""VIF Driver to setup bridge/VLAN networking using VMWare API."""
def ensure_vlan_bridge(self, session, network):
"""Create a vlan and bridge unless they already exist."""
vlan_num = network['vlan']
bridge = network['bridge']
vlan_interface = CONF.vmwareapi_vlan_interface
def plug(self, instance, vif):
"""Plug the VIF to specified instance using information passed.
Currently we are plugging the VIF(s) during instance creation itself.
We can use this method when we add support to add additional NIC to
an existing instance."""
pass
# Check if the vlan_interface physical network adapter exists on the
# host.
if not network_utils.check_if_vlan_interface_exists(session,
vlan_interface):
raise exception.NetworkAdapterNotFound(adapter=vlan_interface)
def ensure_vlan_bridge(self, session, network):
"""Create a vlan and bridge unless they already exist."""
vlan_num = network['vlan']
bridge = network['bridge']
vlan_interface = CONF.vmwareapi_vlan_interface
# Check if the vlan_interface physical network adapter exists on the
# Get the vSwitch associated with the Physical Adapter
vswitch_associated = network_utils.get_vswitch_for_vlan_interface(
session, vlan_interface)
if vswitch_associated is None:
raise exception.SwitchNotFoundForNetworkAdapter(
adapter=vlan_interface)
# Check whether bridge already exists and retrieve the the ref of the
# network whose name_label is "bridge"
network_ref = network_utils.get_network_with_the_name(session, bridge)
if network_ref is None:
# Create a port group on the vSwitch associated with the
# vlan_interface corresponding physical network adapter on the ESX
# host.
if not network_utils.check_if_vlan_interface_exists(session,
vlan_interface):
raise exception.NetworkAdapterNotFound(adapter=vlan_interface)
network_utils.create_port_group(session, bridge,
vswitch_associated, vlan_num)
else:
# Get the vlan id and vswitch corresponding to the port group
_get_pg_info = network_utils.get_vlanid_and_vswitch_for_portgroup
pg_vlanid, pg_vswitch = _get_pg_info(session, bridge)
# Get the vSwitch associated with the Physical Adapter
vswitch_associated = network_utils.get_vswitch_for_vlan_interface(
session, vlan_interface)
if vswitch_associated is None:
raise exception.SwitchNotFoundForNetworkAdapter(
adapter=vlan_interface)
# Check whether bridge already exists and retrieve the the ref of the
# network whose name_label is "bridge"
network_ref = network_utils.get_network_with_the_name(session, bridge)
if network_ref is None:
# Create a port group on the vSwitch associated with the
# vlan_interface corresponding physical network adapter on the ESX
# host.
network_utils.create_port_group(session, bridge,
vswitch_associated, vlan_num)
else:
# Get the vlan id and vswitch corresponding to the port group
_get_pg_info = network_utils.get_vlanid_and_vswitch_for_portgroup
pg_vlanid, pg_vswitch = _get_pg_info(session, bridge)
# Check if the vswitch associated is proper
if pg_vswitch != vswitch_associated:
raise exception.InvalidVLANPortGroup(
bridge=bridge, expected=vswitch_associated,
actual=pg_vswitch)
# Check if the vswitch associated is proper
if pg_vswitch != vswitch_associated:
raise exception.InvalidVLANPortGroup(
bridge=bridge, expected=vswitch_associated,
actual=pg_vswitch)
# Check if the vlan id is proper for the port group
if pg_vlanid != vlan_num:
raise exception.InvalidVLANTag(bridge=bridge, tag=vlan_num,
pgroup=pg_vlanid)
def unplug(self, instance, vif):
"""Cleanup operations like deleting port group if no instance
is associated with it."""
pass
# Check if the vlan id is proper for the port group
if pg_vlanid != vlan_num:
raise exception.InvalidVLANTag(bridge=bridge, tag=vlan_num,
pgroup=pg_vlanid)

View File

@ -32,17 +32,13 @@ from nova.openstack.common import cfg
from nova.openstack.common import importutils
from nova.openstack.common import log as logging
from nova.virt.vmwareapi import network_utils
from nova.virt.vmwareapi import vif as vmwarevif
from nova.virt.vmwareapi import vim_util
from nova.virt.vmwareapi import vm_util
from nova.virt.vmwareapi import vmware_images
vmware_vif_driver_opt = cfg.StrOpt('vmware_vif_driver',
default='nova.virt.vmwareapi.vif.VMWareVlanBridgeDriver',
help='The VMWare VIF driver to configure the VIFs.')
CONF = cfg.CONF
CONF.register_opt(vmware_vif_driver_opt)
LOG = logging.getLogger(__name__)
@ -58,7 +54,6 @@ class VMWareVMOps(object):
def __init__(self, session):
"""Initializer."""
self._session = session
self._vif_driver = importutils.import_object(CONF.vmware_vif_driver)
def list_instances(self):
"""Lists the VM instances that are registered with the ESX host."""
@ -173,8 +168,8 @@ class VMWareVMOps(object):
mac_address = mapping['mac']
network_name = network['bridge']
if mapping.get('should_create_vlan'):
network_ref = self._vif_driver.ensure_vlan_bridge(
self._session, network)
network_ref = vmwarevif.ensure_vlan_bridge(
self._session, network)
else:
network_ref = _check_if_network_bridge_exists(network_name)
vif_infos.append({'network_name': network_name,
@ -823,10 +818,8 @@ class VMWareVMOps(object):
def plug_vifs(self, instance, network_info):
"""Plug VIFs into networks."""
for (network, mapping) in network_info:
self._vif_driver.plug(instance, (network, mapping))
pass
def unplug_vifs(self, instance, network_info):
"""Unplug VIFs from networks."""
for (network, mapping) in network_info:
self._vif_driver.unplug(instance, (network, mapping))
pass