summaryrefslogtreecommitdiff
diff options
authorMaciej Kisielewski <maciej.kisielewski@canonical.com>2017-02-13 13:52:31 +0100
committerMaciej Kisielewski <maciej.kisielewski@canonical.com>2017-02-13 13:52:31 +0100
commit47684a3effff731c20190f940fda4a635d633138 (patch)
tree7d48cebf19ea18d24955bae4555013cfb79de538
parent0dfd39891cb4099086cd282517fc13371d3635ef (diff)
bring back ethtool
And use it as the main tool for determining NIC's speed. If it's not available try mii-tool. This should give us maximum resilience. Fixes: LP: #1662726 Signed-off-by: Maciej Kisielewski <maciej.kisielewski@canonical.com>
-rwxr-xr-xbin/network57
1 files changed, 37 insertions, 20 deletions
diff --git a/bin/network b/bin/network
index ae9cd38..88fd931 100755
--- a/bin/network
+++ b/bin/network
@@ -280,29 +280,46 @@ class Interface(socket.socket):
@property
def max_speed(self):
- # Parse mii-tool data for max speed
- # search for numbers in the line starting with 'capabilities'
- # return largest number as max_speed
+ speeds = [0]
+ # parse ethtool output, look for things like:
+ # 100baseSX, 40000baseNX, 10000baseT
try:
- info = check_output(['mii-tool', '-v', self.interface],
- universal_newlines=True,
- stderr=STDOUT).split('\n')
- except FileNotFoundError:
- logging.warning('mii-tool not found! Unable to get max speed')
- ethinfo = None
- except CalledProcessError as e:
- logging.error('mii-tool returned an error!')
- logging.error(e.output)
- ethinfo = None
- finally:
- regex = re.compile(r'(\d+)(base)([A-Z]+)')
- speeds = [0]
- for line in filter(lambda l: 'capabilities' in l, info):
- for s in line.split(' '):
- hit = regex.search(s)
+ ethinfo = check_output(['ethtool', self.interface],
+ universal_newlines=True,
+ stderr=STDOUT).split(' ')
+ expression = '(\\d+)(base)([A-Z]+)|(\d+)(Mb/s)'
+
+ regex = re.compile(expression)
+ if ethinfo:
+ for i in ethinfo:
+ hit = regex.search(i)
if hit:
speeds.append(int(re.sub("\D", "", hit.group(0))))
- return max(speeds)
+ except CalledProcessError as e:
+ logging.error('ethtool returned an error!')
+ logging.error(e.output)
+ except FileNotFoundError:
+ logging.warning('ethtool not found! Trying mii-tool')
+ # Parse mii-tool data for max speed
+ # search for numbers in the line starting with 'capabilities'
+ # return largest number as max_speed
+ try:
+ info = check_output(['mii-tool', '-v', self.interface],
+ universal_newlines=True,
+ stderr=STDOUT).split('\n')
+ regex = re.compile(r'(\d+)(base)([A-Z]+)')
+ speeds = [0]
+ for line in filter(lambda l: 'capabilities' in l, info):
+ for s in line.split(' '):
+ hit = regex.search(s)
+ if hit:
+ speeds.append(int(re.sub("\D", "", hit.group(0))))
+ except FileNotFoundError:
+ logging.warning('mii-tool not found! Unable to get max speed')
+ except CalledProcessError as e:
+ logging.error('mii-tool returned an error!')
+ logging.error(e.output)
+ return max(speeds)
@property
def macaddress(self):