diff options
author | Christian Poessinger <christian@poessinger.com> | 2021-08-31 23:03:01 +0200 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2021-08-31 23:36:14 +0200 |
commit | b0d4112bd6073e4a947869c3bd80f8e87783fbfa (patch) | |
tree | c8266c7b3c60625072eec0706d89ad0ab37cf4a5 /python/vyos/ifconfig | |
parent | 56fa0d4baaeb7624918d77172fa7e1500d694b93 (diff) | |
download | vyos-1x-b0d4112bd6073e4a947869c3bd80f8e87783fbfa.tar.gz vyos-1x-b0d4112bd6073e4a947869c3bd80f8e87783fbfa.zip |
vyos.ethtool: T3163: purify code to read and change flow-control settings
It makes no sense to have a parser for the ethtool values in ethtool.py
and ethernet.py - one instance ios more then enough!
(cherry picked from commit 0229645c8248decb5664056df8aa5cd5dff41802)
Diffstat (limited to 'python/vyos/ifconfig')
-rw-r--r-- | python/vyos/ifconfig/ethernet.py | 42 |
1 files changed, 10 insertions, 32 deletions
diff --git a/python/vyos/ifconfig/ethernet.py b/python/vyos/ifconfig/ethernet.py index 5974a3d8f..cb07693c3 100644 --- a/python/vyos/ifconfig/ethernet.py +++ b/python/vyos/ifconfig/ethernet.py @@ -122,38 +122,16 @@ class EthernetIf(Interface): 'flow control settings!') return - # Get current flow control settings: - cmd = f'ethtool --show-pause {ifname}' - output, code = self._popen(cmd) - if code == 76: - # the interface does not support it - return '' - if code: - # never fail here as it prevent vyos to boot - print(f'unexpected return code {code} from {cmd}') - return '' - - # The above command returns - with tabs: - # - # Pause parameters for eth0: - # Autonegotiate: on - # RX: off - # TX: off - if re.search("Autonegotiate:\ton", output): - if enable == "on": - # flowcontrol is already enabled - no need to re-enable it again - # this will prevent the interface from flapping as applying the - # flow-control settings will take the interface down and bring - # it back up every time. - return '' - - # Assemble command executed on system. Unfortunately there is no way - # to change this setting via sysfs - cmd = f'ethtool --pause {ifname} autoneg {enable} tx {enable} rx {enable}' - output, code = self._popen(cmd) - if code: - print(f'could not set flowcontrol for {ifname}') - return output + current = self.ethtool.get_flow_control() + if current != enable: + # Assemble command executed on system. Unfortunately there is no way + # to change this setting via sysfs + cmd = f'ethtool --pause {ifname} autoneg {enable} tx {enable} rx {enable}' + output, code = self._popen(cmd) + if code: + print(f'Could not set flowcontrol for {ifname}') + return output + return None def set_speed_duplex(self, speed, duplex): """ |