Skip to content

Commit

Permalink
Add delete_net_interface function
Browse files Browse the repository at this point in the history
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
  • Loading branch information
emagana committed Apr 30, 2013
1 parent bfb8ca3 commit 9c86567
Showing 1 changed file with 17 additions and 37 deletions.
54 changes: 17 additions & 37 deletions nova/network/linux_net.py
Expand Up @@ -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)
Expand All @@ -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):
Expand All @@ -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.
Expand Down Expand Up @@ -1407,17 +1413,7 @@ def ensure_vlan(_self, vlan_num, bridge_interface, mac_address=None):
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)
Expand Down Expand Up @@ -1528,15 +1524,7 @@ def remove_bridge(cls, bridge, gateway=True, filtering=True):
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)
Expand Down Expand Up @@ -1751,18 +1739,10 @@ def plug(self, network, mac_address, gateway=True):

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):
Expand Down

0 comments on commit 9c86567

Please sign in to comment.