summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--nova/compute/manager.py11
-rw-r--r--nova/network/l2_drivers.py56
-rw-r--r--nova/network/linux_net.py1
-rw-r--r--nova/network/manager.py56
-rw-r--r--nova/virt/libvirt/connection.py13
-rw-r--r--nova/virt/libvirt/vif.py (renamed from nova/virt/libvirt/vif_drivers.py)43
-rw-r--r--nova/virt/vif.py29
7 files changed, 84 insertions, 125 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index bbbddde0a..753240614 100644
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -293,8 +293,7 @@ class ComputeManager(manager.SchedulerDependentManager):
network_info = self.network_api.allocate_for_instance(context,
instance, vpn=is_vpn)
LOG.debug(_("instance network_info: |%s|"), network_info)
- self.network_manager.setup_compute_network(context,
- instance_id)
+ self.driver.setup_vif_network(context, instance, network_info)
else:
# TODO(tr3buchet) not really sure how this should be handled.
# virt requires network_info to be passed in but stub_network
@@ -444,7 +443,6 @@ class ComputeManager(manager.SchedulerDependentManager):
instance_id,
power_state.NOSTATE,
'rebooting')
- self.network_manager.setup_compute_network(context, instance_id)
self.driver.reboot(instance_ref)
self._update_state(context, instance_id)
@@ -635,7 +633,7 @@ class ComputeManager(manager.SchedulerDependentManager):
instance_id,
power_state.NOSTATE,
'rescuing')
- self.network_manager.setup_compute_network(context, instance_id)
+ self.driver.setup_vif_network(context, instance_id)
_update_state = lambda result: self._update_state_callback(
self, context, instance_id, result)
self.driver.rescue(instance_ref, _update_state)
@@ -1176,14 +1174,13 @@ class ComputeManager(manager.SchedulerDependentManager):
max_retry = FLAGS.live_migration_retry_count
for cnt in range(max_retry):
try:
- self.network_manager.setup_compute_network(context,
- instance_id)
+ self.driver.setup_vif_network(context, instance_id)
break
except exception.ProcessExecutionError:
if cnt == max_retry - 1:
raise
else:
- LOG.warn(_("setup_compute_network() failed %(cnt)d."
+ LOG.warn(_("setup_vif_network() failed %(cnt)d."
"Retry up to %(max_retry)d for %(hostname)s.")
% locals())
time.sleep(1)
diff --git a/nova/network/l2_drivers.py b/nova/network/l2_drivers.py
deleted file mode 100644
index 23d05cda4..000000000
--- a/nova/network/l2_drivers.py
+++ /dev/null
@@ -1,56 +0,0 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
-# Copyright (C) 2011 Midokura KK
-# All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-"""Drivers responsible for managing L2 connectivity for Nova."""
-
-from nova.network import linux_net
-
-class L2Driver(object):
- """Base class that defines interfaces for L2 drivers."""
-
- def ensure_bridge(self, bridge, interface, net_attrs=None):
- """Create a bridge unless it already exists."""
- raise NotImplementedError()
-
- def ensure_vlan(self, vlan_num, bridge_interface, net_attrs=None):
- """Create a vlan unless it already exists."""
- raise NotImplementedError()
-
-
-class LinuxBridgeDriver(L2Driver):
- """L2 driver based on Linux Bridge."""
-
- def ensure_bridge(self, bridge, interface, net_attrs=None):
- """Create a Linux bridge unless it already eixsts."""
- linux_net.ensure_bridge(bridge, interface, net_attrs)
-
- def ensure_vlan(self, vlan_num, bridge_interface, net_attrs=None):
- """Create a vlan unless it already exists."""
- return linux_net.ensure_vlan(vlan_num, bridge_interface, net_attrs)
-
-
-class QuantumDriver(L2Driver):
- """L2 driver based on Quantum network service."""
-
- def ensure_bridge(self, bridge, interface, net_attrs=None):
- """Do nothing."""
- pass
-
- def ensure_vlan(self, vlan_num, bridge_interface, net_attrs=None):
- """Return None."""
- return None
-
diff --git a/nova/network/linux_net.py b/nova/network/linux_net.py
index 283a5aca1..4e39a57c4 100644
--- a/nova/network/linux_net.py
+++ b/nova/network/linux_net.py
@@ -455,6 +455,7 @@ def ensure_vlan_bridge(vlan_num, bridge, bridge_interface, net_attrs=None):
"""Create a vlan and bridge unless they already exist."""
interface = ensure_vlan(vlan_num, bridge_interface)
ensure_bridge(bridge, interface, net_attrs)
+ return interface
@utils.synchronized('ensure_vlan', external=True)
diff --git a/nova/network/manager.py b/nova/network/manager.py
index 3d6388259..0689759d7 100644
--- a/nova/network/manager.py
+++ b/nova/network/manager.py
@@ -111,8 +111,6 @@ flags.DEFINE_string('network_host', socket.gethostname(),
'Network host to use for ip allocation in flat modes')
flags.DEFINE_bool('fake_call', False,
'If True, skip using the queue and make local calls')
-flags.DEFINE_string('l2_driver', 'nova.network.l2_drivers.LinuxBridgeDriver',
- 'L2 network connectivity driver.')
class AddressAlreadyAllocated(exception.Error):
@@ -296,7 +294,6 @@ class NetworkManager(manager.SchedulerDependentManager):
if not network_driver:
network_driver = FLAGS.network_driver
self.driver = utils.import_object(network_driver)
- self.l2_driver = utils.import_object(FLAGS.l2_driver)
self.network_api = network_api.API()
super(NetworkManager, self).__init__(service_name='network',
*args, **kwargs)
@@ -648,14 +645,6 @@ class NetworkManager(manager.SchedulerDependentManager):
"""Called when this host becomes the host for a network."""
raise NotImplementedError()
- def setup_compute_network(self, context, instance_id):
- """Sets up matching network for compute hosts.
-
- this code is run on and by the compute host, not on network
- hosts
- """
- raise NotImplementedError()
-
class FlatManager(NetworkManager):
"""Basic network where no vlans are used.
@@ -698,13 +687,6 @@ class FlatManager(NetworkManager):
**kwargs)
self.db.fixed_ip_disassociate(context, address)
- def setup_compute_network(self, context, instance_id):
- """Network is created manually.
-
- this code is run on and by the compute host, not on network hosts
- """
- pass
-
def _on_set_network_host(self, context, network_id):
"""Called when this host becomes the host for a network."""
net = {}
@@ -734,16 +716,6 @@ class FlatDHCPManager(FloatingIP, RPCAllocateFixedIP, NetworkManager):
self.driver.metadata_forward()
- def setup_compute_network(self, context, instance_id):
- """Sets up matching networks for compute hosts.
-
- this code is run on and by the compute host, not on network hosts
- """
- networks = db.network_get_all_by_instance(context, instance_id)
- for network in networks:
- self.l2_driver.ensure_bridge(network['bridge'],
- network['bridge_interface'])
-
def allocate_fixed_ip(self, context, instance_id, network):
"""Allocate flat_network fixed_ip, then setup dhcp for this network."""
address = super(FlatDHCPManager, self).allocate_fixed_ip(context,
@@ -758,9 +730,9 @@ class FlatDHCPManager(FloatingIP, RPCAllocateFixedIP, NetworkManager):
net['dhcp_start'] = FLAGS.flat_network_dhcp_start
self.db.network_update(context, network_id, net)
network = db.network_get(context, network_id)
- self.l2_driver.ensure_bridge(network['bridge'],
- network['bridge_interface'],
- network)
+ self.driver.ensure_bridge(network['bridge'],
+ network['bridge_interface'],
+ network)
if not FLAGS.fake_network:
self.driver.update_dhcp(context, network_id)
if(FLAGS.use_ipv6):
@@ -819,18 +791,6 @@ class VlanManager(RPCAllocateFixedIP, FloatingIP, NetworkManager):
"""Force adds another network to a project."""
self.db.network_associate(context, project_id, force=True)
- def setup_compute_network(self, context, instance_id):
- """Sets up matching network for compute hosts.
- this code is run on and by the compute host, not on network hosts
- """
- networks = self.db.network_get_all_by_instance(context, instance_id)
- for network in networks:
- interface = self.l2_driver.ensure_vlan(network['vlan'],
- network['bridge_interface'])
- if interface:
- self.l2_driver.ensure_bridge(network['bridge'], interface,
- network['bridge_interface'])
-
def _get_networks_for_instance(self, context, instance_id, project_id):
"""Determine which networks an instance should connect to."""
# get networks associated with project
@@ -867,12 +827,10 @@ class VlanManager(RPCAllocateFixedIP, FloatingIP, NetworkManager):
else:
address = network['vpn_public_address']
- interface = self.l2_driver.ensure_vlan(network['vlan'],
- network['bridge_interface'])
- if interface:
- self.l2_driver.ensure_bridge(network['bridge'], interface,
- network['bridge_interface'],
- network)
+ self.driver.ensure_vlan_bridge(network['vlan'],
+ network['bridge'],
+ network['bridge_interface'],
+ network)
# NOTE(vish): only ensure this forward if the address hasn't been set
# manually.
diff --git a/nova/virt/libvirt/connection.py b/nova/virt/libvirt/connection.py
index 606bc18bc..15ad85176 100644
--- a/nova/virt/libvirt/connection.py
+++ b/nova/virt/libvirt/connection.py
@@ -123,8 +123,8 @@ flags.DEFINE_bool('start_guests_on_host_boot', False,
flags.DEFINE_string('libvirt_vif_type', 'bridge',
'Type of VIF to create.')
flags.DEFINE_string('libvirt_vif_driver',
- 'nova.virt.libvirt.vif_drivers.BridgeDriver',
- 'The VIF driver to configure the VIFs.')
+ 'nova.virt.libvirt.vif.LibvirtVlanBridgeDriver',
+ 'The libvirt VIF driver to configure the VIFs.')
def get_connection(read_only):
@@ -259,6 +259,12 @@ class LibvirtConnection(driver.ComputeDriver):
infos.append(info)
return infos
+ def setup_vif_network(self, ctxt, instance_id):
+ """Set up VIF networking on the host."""
+ networks = db.network_get_all_by_instance(ctxt, instance_id)
+ for network in networks:
+ self.vif_driver.plug(network)
+
def destroy(self, instance, cleanup=True):
instance_name = instance['name']
@@ -950,7 +956,8 @@ class LibvirtConnection(driver.ComputeDriver):
nics = []
for (network, mapping) in network_info:
- nics.append(self.vif_driver(instance, network, mapping))
+ nics.append(self.vif_driver.get_configurations(instance, network,
+ mapping))
# FIXME(vish): stick this in db
inst_type_id = instance['instance_type_id']
inst_type = instance_types.get_instance_type(inst_type_id)
diff --git a/nova/virt/libvirt/vif_drivers.py b/nova/virt/libvirt/vif.py
index 9ef218a21..50c2d444c 100644
--- a/nova/virt/libvirt/vif_drivers.py
+++ b/nova/virt/libvirt/vif.py
@@ -1,9 +1,7 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright (C) 2011 Midokura KK
-# Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
-# Copyright (c) 2010 Citrix Systems, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
@@ -17,10 +15,12 @@
# License for the specific language governing permissions and limitations
# under the License.
-"""Drivers responsible for VIF creation in libvirt."""
+"""VIF drivers for libvirt."""
from nova import flags
+from nova.network import linux_net
from nova.virt.libvirt import netutils
+from nova.virt.vif import VIFDriver
FLAGS = flags.FLAGS
flags.DEFINE_bool('allow_project_net_traffic',
@@ -28,18 +28,18 @@ flags.DEFINE_bool('allow_project_net_traffic',
'Whether to allow in project network traffic')
-class VIFDriver(object):
- """Base class that defines generic interfaces for VIF drivers."""
+class LibvirtVIF(object):
+ """VIF class for libvirt"""
- def get_configuration(self, instance, network, mapping):
+ def get_configurations(self, instance, network, mapping):
"""Get a dictionary of VIF configuration for libvirt interfaces."""
raise NotImplementedError()
-class BridgeDriver(VIFDriver):
- """Class that generates VIF configuration of bridge interface type."""
+class LibvirtBridge(LibvirtVIF):
+ """Linux bridge VIF for Libvirt."""
- def get_configuration(self, instance, network, mapping):
+ def get_configurations(self, instance, network, mapping):
"""Get a dictionary of VIF configurations for bridge type."""
# Assume that the gateway also acts as the dhcp server.
dhcp_server = mapping['gateway']
@@ -73,4 +73,27 @@ class BridgeDriver(VIFDriver):
result['gateway6'] = gateway6 + "/128"
return result
-
+
+
+class LibvirtBridgeDriver(VIFDriver, LibvirtBridge):
+ """VIF driver for Linux bridge."""
+
+ def plug(self, network):
+ """Ensure that the bridge exists, and add VIF to it."""
+ linux_net.ensure_bridge(network['bridge'],
+ network['bridge_interface'])
+
+ def unplug(self, network):
+ pass
+
+
+class LibvirtVlanBridgeDriver(VIFDriver, LibvirtBridge):
+ """VIF driver for Linux bridge with VLAN."""
+
+ def plug(self, network):
+ """Ensure that VLAN and bridge exist and add VIF to the bridge."""
+ linux_net.ensure_vlan_bridge(network['vlan'], network['bridge'],
+ network['bridge_interface'])
+
+ def unplug(self, network):
+ pass
diff --git a/nova/virt/vif.py b/nova/virt/vif.py
new file mode 100644
index 000000000..1ff41ed7e
--- /dev/null
+++ b/nova/virt/vif.py
@@ -0,0 +1,29 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright (C) 2011 Midokura KK
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+"""VIF module common to all virt layers."""
+
+class VIFDriver(object):
+ """Abstract class that defines generic interfaces for all VIF drivers."""
+
+ def plug(self, network):
+ """Plug VIF into network."""
+ raise NotImplementedError()
+
+ def unplug(self, network):
+ """Unplug VIF from network."""
+ raise NotImplementedError()