summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorJohannes Erdfelt <johannes.erdfelt@rackspace.com>2012-05-31 21:41:30 +0000
committerJohannes Erdfelt <johannes.erdfelt@rackspace.com>2012-06-01 00:03:04 +0000
commit3ae2c6abcde71564e7ee9f73ea86a6c5acc78029 (patch)
treee234e6dea664606c43e34614e19286ac56dc49a2 /nova
parent791ea7e3b7b4155257b588a2827cdd2c86735c1b (diff)
Remove network_util.NetworkHelper class
The XenAPI driver has the concept of helper classes. All methods have been classmethods and the classes themselves are never instantiated. As a result, they only add an extra namespace lookup and provide no value. Change-Id: Ief7d51013d8f313ca8c78cb157599858b156ac3f
Diffstat (limited to 'nova')
-rw-r--r--nova/virt/xenapi/network_utils.py53
-rw-r--r--nova/virt/xenapi/vif.py10
-rw-r--r--nova/virt/xenapi/vmops.py1
3 files changed, 27 insertions, 37 deletions
diff --git a/nova/virt/xenapi/network_utils.py b/nova/virt/xenapi/network_utils.py
index 50b36933c..dceaed949 100644
--- a/nova/virt/xenapi/network_utils.py
+++ b/nova/virt/xenapi/network_utils.py
@@ -21,38 +21,29 @@ their lookup functions.
"""
-from nova.virt import xenapi
+def find_network_with_name_label(session, name_label):
+ networks = session.call_xenapi('network.get_by_name_label', name_label)
+ if len(networks) == 1:
+ return networks[0]
+ elif len(networks) > 1:
+ raise Exception(_('Found non-unique network for name_label %s') %
+ name_label)
+ else:
+ return None
-class NetworkHelper(xenapi.HelperBase):
+def find_network_with_bridge(session, bridge):
"""
- The class that wraps the helper methods together.
+ Return the network on which the bridge is attached, if found.
+ The bridge is defined in the nova db and can be found either in the
+ 'bridge' or 'name_label' fields of the XenAPI network record.
"""
- @classmethod
- def find_network_with_name_label(cls, session, name_label):
- networks = session.call_xenapi('network.get_by_name_label', name_label)
- if len(networks) == 1:
- return networks[0]
- elif len(networks) > 1:
- raise Exception(_('Found non-unique network'
- ' for name_label %s') % name_label)
- else:
- return None
-
- @classmethod
- def find_network_with_bridge(cls, session, bridge):
- """
- Return the network on which the bridge is attached, if found.
- The bridge is defined in the nova db and can be found either in the
- 'bridge' or 'name_label' fields of the XenAPI network record.
- """
- expr = ('field "name__label" = "%s" or field "bridge" = "%s"' %
- (bridge, bridge))
- networks = session.call_xenapi('network.get_all_records_where', expr)
- if len(networks) == 1:
- return networks.keys()[0]
- elif len(networks) > 1:
- raise Exception(_('Found non-unique network'
- ' for bridge %s') % bridge)
- else:
- raise Exception(_('Found no network for bridge %s') % bridge)
+ expr = ('field "name__label" = "%s" or field "bridge" = "%s"' %
+ (bridge, bridge))
+ networks = session.call_xenapi('network.get_all_records_where', expr)
+ if len(networks) == 1:
+ return networks.keys()[0]
+ elif len(networks) > 1:
+ raise Exception(_('Found non-unique network for bridge %s') % bridge)
+ else:
+ raise Exception(_('Found no network for bridge %s') % bridge)
diff --git a/nova/virt/xenapi/vif.py b/nova/virt/xenapi/vif.py
index c2885cc4d..39778521b 100644
--- a/nova/virt/xenapi/vif.py
+++ b/nova/virt/xenapi/vif.py
@@ -53,8 +53,8 @@ class XenAPIBridgeDriver(XenVIFDriver):
if vif['network'].get_meta('should_create_vlan'):
network_ref = self._ensure_vlan_bridge(vif['network'])
else:
- network_ref = network_utils.NetworkHelper.find_network_with_bridge(
- self._session, vif['network']['bridge'])
+ network_ref = network_utils.find_network_with_bridge(
+ self._session, vif['network']['bridge'])
vif_rec = {}
vif_rec['device'] = str(device)
vif_rec['network'] = network_ref
@@ -80,7 +80,7 @@ class XenAPIBridgeDriver(XenVIFDriver):
network.get_meta('bridge_interface'))
# Check whether bridge already exists
# Retrieve network whose name_label is "bridge"
- network_ref = network_utils.NetworkHelper.find_network_with_name_label(
+ network_ref = network_utils.find_network_with_name_label(
self._session, bridge)
if network_ref is None:
# If bridge does not exists
@@ -143,8 +143,8 @@ class XenAPIOpenVswitchDriver(XenVIFDriver):
# with OVS model, always plug into an OVS integration bridge
# that is already created
- network_ref = network_utils.NetworkHelper.find_network_with_bridge(
- self._session, FLAGS.xenapi_ovs_integration_bridge)
+ network_ref = network_utils.find_network_with_bridge(
+ self._session, FLAGS.xenapi_ovs_integration_bridge)
vif_rec = {}
vif_rec['device'] = str(device)
vif_rec['network'] = network_ref
diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py
index 031668d29..c79f09026 100644
--- a/nova/virt/xenapi/vmops.py
+++ b/nova/virt/xenapi/vmops.py
@@ -49,7 +49,6 @@ from nova.virt.xenapi import vm_utils
from nova.virt.xenapi import volume_utils
-NetworkHelper = network_utils.NetworkHelper
LOG = logging.getLogger(__name__)
xenapi_vmops_opts = [