diff options
author | Christian Poessinger <christian@poessinger.com> | 2021-08-31 21:28:08 +0200 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2021-08-31 21:29:41 +0200 |
commit | 5cbb1f3e4adba39d790f378afabb1e45416aff7c (patch) | |
tree | cb5964dcd79b034de865f82dbee5920de2cb2fbf /python/vyos/ethtool.py | |
parent | 2bfd809e9ae198d95b9fcb556440637fdcc4005c (diff) | |
download | vyos-1x-5cbb1f3e4adba39d790f378afabb1e45416aff7c.tar.gz vyos-1x-5cbb1f3e4adba39d790f378afabb1e45416aff7c.zip |
vyos.ethtool: T3163: purify code to read current speed and duplex settings
It makes no sense to have a parser for the ethtool value sin ethtool.py
and ethernet.py - one instance ios more then enough!
(cherry picked from commit 6f5fb5c503b5df96d0686002355da3633b1fc597)
Diffstat (limited to 'python/vyos/ethtool.py')
-rw-r--r-- | python/vyos/ethtool.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/python/vyos/ethtool.py b/python/vyos/ethtool.py index fb2e49c1d..e803e28a1 100644 --- a/python/vyos/ethtool.py +++ b/python/vyos/ethtool.py @@ -44,6 +44,7 @@ class Ethtool: _speed_duplex = { } _ring_buffers = { } _driver_name = None + _auto_negotiation = None def __init__(self, ifname): # Get driver used for interface @@ -65,7 +66,6 @@ class Ethtool: reading = True if 'Supported pause frame use:' in line: reading = False - break if reading: for block in line.split(): if pattern.search(block): @@ -75,6 +75,15 @@ class Ethtool: self._speed_duplex.update({ speed : {}}) if duplex not in self._speed_duplex[speed]: self._speed_duplex[speed].update({ duplex : ''}) + if 'Auto-negotiation:' in line: + # Split the following string: Auto-negotiation: off + # we are only interested in off or on + tmp = line.split()[-1] + self._auto_negotiation = bool(tmp == 'on') + + if self._auto_negotiation == None: + raise ValueError(f'Could not determine auto-negotiation settings '\ + f'for interface {ifname}!') # Now populate features dictionaty out, err = popen(f'ethtool --show-features {ifname}') @@ -161,3 +170,6 @@ class Ethtool: if duplex in self._speed_duplex[speed]: return True return False + + def get_auto_negotiation(self): + return self._auto_negotiation |