diff options
| author | Ryu Ishimoto <ryu@midokura.jp> | 2011-07-11 04:38:27 +0900 |
|---|---|---|
| committer | Ryu Ishimoto <ryu@midokura.jp> | 2011-07-11 04:38:27 +0900 |
| commit | 1da51f7b07f0080c44063a355c84fafd1fdf02bc (patch) | |
| tree | b9c2b372da0b58b28ff7f6c48face9d7cfd64bd0 /nova/virt | |
| parent | e71cf10dcf88f4a2f695285b25af75d8a0df2b3e (diff) | |
Moved 'setup_compute_network' logic into the virt layer
Diffstat (limited to 'nova/virt')
| -rw-r--r-- | nova/virt/libvirt/connection.py | 13 | ||||
| -rw-r--r-- | nova/virt/libvirt/vif.py (renamed from nova/virt/libvirt/vif_drivers.py) | 43 | ||||
| -rw-r--r-- | nova/virt/vif.py | 29 |
3 files changed, 72 insertions, 13 deletions
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() |
