From e35feaa8dd7e5b42d4a5d13dd224acdffb45f123 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Fri, 4 Jan 2013 13:50:54 +0000 Subject: [PATCH] Remove duplicated tapdev creation code from libvirt VIF Move the 'create_tap_dev' method out of the linux_net class QuantumLinuxBridgeInterfaceDriver, to be a standalone method. Make the libvirt LibvirtOpenVswitchDriver call this method instead of duplicating the tapdev creation code Blueprint: libvirt-vif-driver Change-Id: Ib9b5fb3aed5e339464c4f367179911166f2cddfb Signed-off-by: Daniel P. Berrange --- nova/network/linux_net.py | 34 +++++++++++++++++----------------- nova/virt/libvirt/vif.py | 15 +-------------- 2 files changed, 18 insertions(+), 31 deletions(-) diff --git a/nova/network/linux_net.py b/nova/network/linux_net.py index d849441ab93d..4af604fa1ecf 100644 --- a/nova/network/linux_net.py +++ b/nova/network/linux_net.py @@ -1142,6 +1142,22 @@ def delete_ovs_vif_port(bridge, dev): run_as_root=True) +def create_tap_dev(dev, mac_address=None): + if not device_exists(dev): + try: + # First, try with 'ip' + utils.execute('ip', 'tuntap', 'add', dev, 'mode', 'tap', + run_as_root=True, check_exit_code=[0, 2, 254]) + except exception.ProcessExecutionError: + # Second option: tunctl + utils.execute('tunctl', '-b', '-t', dev, run_as_root=True) + if mac_address: + utils.execute('ip', 'link', 'set', dev, 'address', mac_address, + run_as_root=True, check_exit_code=[0, 2, 254]) + utils.execute('ip', 'link', 'set', dev, 'up', run_as_root=True, + check_exit_code=[0, 2, 254]) + + # Similar to compute virt layers, the Linux network node # code uses a flexible driver model to support different ways # of creating ethernet interfaces and attaching them to the network. @@ -1553,7 +1569,7 @@ class QuantumLinuxBridgeInterfaceDriver(LinuxNetInterfaceDriver): iptables_manager.ipv4['filter'].add_rule('FORWARD', '--out-interface %s -j ACCEPT' % bridge) - QuantumLinuxBridgeInterfaceDriver.create_tap_dev(dev, mac_address) + create_tap_dev(dev, mac_address) if not device_exists(bridge): LOG.debug(_("Starting bridge %s "), bridge) @@ -1588,22 +1604,6 @@ class QuantumLinuxBridgeInterfaceDriver(LinuxNetInterfaceDriver): LOG.debug(_("Unplugged gateway interface '%s'"), dev) return dev - @classmethod - def create_tap_dev(_self, dev, mac_address=None): - if not device_exists(dev): - try: - # First, try with 'ip' - utils.execute('ip', 'tuntap', 'add', dev, 'mode', 'tap', - run_as_root=True, check_exit_code=[0, 2, 254]) - except exception.ProcessExecutionError: - # Second option: tunctl - utils.execute('tunctl', '-b', '-t', dev, run_as_root=True) - if mac_address: - utils.execute('ip', 'link', 'set', dev, 'address', mac_address, - run_as_root=True, check_exit_code=[0, 2, 254]) - utils.execute('ip', 'link', 'set', dev, 'up', run_as_root=True, - check_exit_code=[0, 2, 254]) - def get_dev(self, network): dev = self.GATEWAY_INTERFACE_PREFIX + str(network['uuid'][0:11]) return dev diff --git a/nova/virt/libvirt/vif.py b/nova/virt/libvirt/vif.py index 422a8e716773..d90a5e2952e5 100644 --- a/nova/virt/libvirt/vif.py +++ b/nova/virt/libvirt/vif.py @@ -169,20 +169,7 @@ class LibvirtOpenVswitchDriver(LibvirtBaseVIFDriver): network, mapping = vif iface_id = self.get_ovs_interfaceid(mapping) dev = self.get_vif_devname(mapping) - if not linux_net.device_exists(dev): - # Older version of the command 'ip' from the iproute2 package - # don't have support for the tuntap option (lp:882568). If it - # turns out we're on an old version we work around this by using - # tunctl. - try: - # First, try with 'ip' - utils.execute('ip', 'tuntap', 'add', dev, 'mode', 'tap', - run_as_root=True) - except exception.ProcessExecutionError: - # Second option: tunctl - utils.execute('tunctl', '-b', '-t', dev, run_as_root=True) - utils.execute('ip', 'link', 'set', dev, 'up', run_as_root=True) - + linux_net.create_tap_dev(dev) linux_net.create_ovs_vif_port(self.get_bridge_name(network), dev, iface_id, mapping['mac'], instance['uuid'])