fall back to ip link
when ip tuntap
unavailable
bug 989868 In the event that the command "ip tuntap" is not found then a exception will be raised and the command "ip link" will be perfomed. Changes following comments More appropriate error message Same style for log/error messages Change-Id: Ia912e189b73dd0d112b7ef4eefbb7245ee595b54
This commit is contained in:
parent
91c511d7ce
commit
d5888a07c3
@ -34,6 +34,8 @@ import time
|
|||||||
|
|
||||||
from sqlalchemy.ext.sqlsoup import SqlSoup
|
from sqlalchemy.ext.sqlsoup import SqlSoup
|
||||||
|
|
||||||
|
from quantum.common import exceptions as exception
|
||||||
|
|
||||||
logging.basicConfig()
|
logging.basicConfig()
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -62,7 +64,7 @@ class LinuxBridge:
|
|||||||
self.physical_interface = physical_interface
|
self.physical_interface = physical_interface
|
||||||
self.root_helper = root_helper
|
self.root_helper = root_helper
|
||||||
|
|
||||||
def run_cmd(self, args):
|
def run_cmd(self, args, check_return=False):
|
||||||
cmd = shlex.split(self.root_helper) + args
|
cmd = shlex.split(self.root_helper) + args
|
||||||
LOG.debug("Running command: " + " ".join(cmd))
|
LOG.debug("Running command: " + " ".join(cmd))
|
||||||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
|
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
|
||||||
@ -71,6 +73,10 @@ class LinuxBridge:
|
|||||||
LOG.debug("Timeout running command: " + " ".join(cmd))
|
LOG.debug("Timeout running command: " + " ".join(cmd))
|
||||||
if retval:
|
if retval:
|
||||||
LOG.debug("Command returned: %s" % retval)
|
LOG.debug("Command returned: %s" % retval)
|
||||||
|
if (p.returncode != 0 and check_return):
|
||||||
|
msg = "Command failed: " + " ".join(cmd)
|
||||||
|
LOG.debug(msg)
|
||||||
|
raise exception.ProcessExecutionError(msg)
|
||||||
return retval
|
return retval
|
||||||
|
|
||||||
def device_exists(self, device):
|
def device_exists(self, device):
|
||||||
@ -116,27 +122,39 @@ class LinuxBridge:
|
|||||||
BRIDGE_NAME_PLACEHOLDER, bridge_name)
|
BRIDGE_NAME_PLACEHOLDER, bridge_name)
|
||||||
return os.listdir(bridge_interface_path)
|
return os.listdir(bridge_interface_path)
|
||||||
|
|
||||||
def get_all_tap_devices(self):
|
def _get_prefixed_ip_link_devices(self, prefix):
|
||||||
tap_devices = []
|
prefixed_devices = []
|
||||||
retval = self.run_cmd(['ip', 'tuntap'])
|
retval = self.run_cmd(['ip', 'link'])
|
||||||
|
rows = retval.split('\n')
|
||||||
|
for row in rows:
|
||||||
|
values = row.split(':')
|
||||||
|
if (len(values) > 2):
|
||||||
|
value = values[1].strip(' ')
|
||||||
|
if (value.startswith(prefix)):
|
||||||
|
prefixed_devices.append(value)
|
||||||
|
return prefixed_devices
|
||||||
|
|
||||||
|
def _get_prefixed_tap_devices(self, prefix):
|
||||||
|
prefixed_devices = []
|
||||||
|
retval = self.run_cmd(['ip', 'tuntap'], check_return=True)
|
||||||
rows = retval.split('\n')
|
rows = retval.split('\n')
|
||||||
for row in rows:
|
for row in rows:
|
||||||
split_row = row.split(':')
|
split_row = row.split(':')
|
||||||
if split_row[0].startswith(TAP_INTERFACE_PREFIX):
|
if split_row[0].startswith(prefix):
|
||||||
tap_devices.append(split_row[0])
|
prefixed_devices.append(split_row[0])
|
||||||
|
return prefixed_devices
|
||||||
|
|
||||||
return tap_devices
|
def get_all_tap_devices(self):
|
||||||
|
try:
|
||||||
|
return self._get_prefixed_tap_devices(TAP_INTERFACE_PREFIX)
|
||||||
|
except exception.ProcessExecutionError:
|
||||||
|
return self._get_prefixed_ip_link_devices(TAP_INTERFACE_PREFIX)
|
||||||
|
|
||||||
def get_all_gateway_devices(self):
|
def get_all_gateway_devices(self):
|
||||||
gw_devices = []
|
try:
|
||||||
retval = self.run_cmd(['ip', 'tuntap'])
|
return self._get_prefixed_tap_devices(GATEWAY_INTERFACE_PREFIX)
|
||||||
rows = retval.split('\n')
|
except exception.ProcessExecutionError:
|
||||||
for row in rows:
|
return self._get_prefixed_ip_link_devices(GATEWAY_INTERFACE_PREFIX)
|
||||||
split_row = row.split(':')
|
|
||||||
if split_row[0].startswith(GATEWAY_INTERFACE_PREFIX):
|
|
||||||
gw_devices.append(split_row[0])
|
|
||||||
|
|
||||||
return gw_devices
|
|
||||||
|
|
||||||
def get_bridge_for_tap_device(self, tap_device_name):
|
def get_bridge_for_tap_device(self, tap_device_name):
|
||||||
bridges = self.get_all_quantum_bridges()
|
bridges = self.get_all_quantum_bridges()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user