Add delete_net_interface function

This commit adds a new function that deletes a specific
tap device. This bug fix is targeted for Havana.

Change-Id: I26be5d94550db35358caae642fb9000953346826
fixes: bug #1138408
This commit is contained in:
Edgar Magana 2013-03-11 11:46:27 -07:00
parent bfb8ca3e6e
commit 9c86567201
1 changed files with 17 additions and 37 deletions

View File

@ -1219,12 +1219,7 @@ def _create_veth_pair(dev1_name, dev2_name):
deleting any previous devices with those names.
"""
for dev in [dev1_name, dev2_name]:
if device_exists(dev):
try:
utils.execute('ip', 'link', 'delete', dev1_name,
run_as_root=True, check_exit_code=[0, 2, 254])
except exception.ProcessExecutionError:
LOG.exception(_("Error clearing stale veth %s") % dev)
delete_net_dev(dev)
utils.execute('ip', 'link', 'add', dev1_name, 'type', 'veth', 'peer',
'name', dev2_name, run_as_root=True)
@ -1248,8 +1243,7 @@ def create_ovs_vif_port(bridge, dev, iface_id, mac, instance_id):
def delete_ovs_vif_port(bridge, dev):
utils.execute('ovs-vsctl', 'del-port', bridge, dev,
run_as_root=True)
utils.execute('ip', 'link', 'delete', dev,
run_as_root=True)
delete_net_dev(dev)
def create_tap_dev(dev, mac_address=None):
@ -1268,6 +1262,18 @@ def create_tap_dev(dev, mac_address=None):
check_exit_code=[0, 2, 254])
def delete_net_dev(dev):
"""Delete a network device only if it exists."""
if device_exists(dev):
try:
utils.execute('ip', 'link', 'delete', dev, run_as_root=True,
check_exit_code=[0, 2, 254])
LOG.debug(_("Net device removed: '%s'"), dev)
except exception.ProcessExecutionError:
with excutils.save_and_reraise_exception():
LOG.error(_("Failed removing net device: '%s'"), dev)
# 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.
@ -1407,17 +1413,7 @@ class LinuxBridgeInterfaceDriver(LinuxNetInterfaceDriver):
def remove_vlan(cls, vlan_num):
"""Delete a vlan."""
vlan_interface = 'vlan%s' % vlan_num
if not device_exists(vlan_interface):
return
else:
try:
utils.execute('ip', 'link', 'delete', vlan_interface,
run_as_root=True, check_exit_code=[0, 2, 254])
except exception.ProcessExecutionError:
with excutils.save_and_reraise_exception():
LOG.error(_("Failed unplugging VLAN interface '%s'"),
vlan_interface)
LOG.debug(_("Unplugged VLAN interface '%s'"), vlan_interface)
delete_net_dev(vlan_interface)
@classmethod
@lockutils.synchronized('lock_bridge', 'nova-', external=True)
@ -1528,15 +1524,7 @@ class LinuxBridgeInterfaceDriver(LinuxNetInterfaceDriver):
ipv4_filter.remove_rule('FORWARD',
('--out-interface %s -j %s'
% (bridge, drop_action)))
try:
utils.execute('ip', 'link', 'delete', bridge, run_as_root=True,
check_exit_code=[0, 2, 254])
except exception.ProcessExecutionError:
with excutils.save_and_reraise_exception():
LOG.error(_("Failed unplugging bridge interface '%s'"),
bridge)
LOG.debug(_("Unplugged bridge interface '%s'"), bridge)
delete_net_dev(bridge)
@lockutils.synchronized('ebtables', 'nova-', external=True)
@ -1751,18 +1739,10 @@ class QuantumLinuxBridgeInterfaceDriver(LinuxNetInterfaceDriver):
def unplug(self, network):
dev = self.get_dev(network)
if not device_exists(dev):
return None
else:
try:
utils.execute('ip', 'link', 'delete', dev, run_as_root=True,
check_exit_code=[0, 2, 254])
except exception.ProcessExecutionError:
with excutils.save_and_reraise_exception():
LOG.error(_("Failed unplugging gateway interface '%s'"),
dev)
LOG.debug(_("Unplugged gateway interface '%s'"), dev)
delete_net_dev(dev)
return dev
def get_dev(self, network):