summaryrefslogtreecommitdiff
path: root/python/vyos/ifconfig
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2021-08-31 21:28:08 +0200
committerChristian Poessinger <christian@poessinger.com>2021-08-31 21:28:08 +0200
commit6f5fb5c503b5df96d0686002355da3633b1fc597 (patch)
tree1d6293a5262f5c25597dde9c9c812839849b88c0 /python/vyos/ifconfig
parentcc742d48579e4f76e5d3230d87e22f71f76f9301 (diff)
downloadvyos-1x-6f5fb5c503b5df96d0686002355da3633b1fc597.tar.gz
vyos-1x-6f5fb5c503b5df96d0686002355da3633b1fc597.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!
Diffstat (limited to 'python/vyos/ifconfig')
-rw-r--r--python/vyos/ifconfig/ethernet.py22
1 files changed, 5 insertions, 17 deletions
diff --git a/python/vyos/ifconfig/ethernet.py b/python/vyos/ifconfig/ethernet.py
index 76ed3fd92..d4fa3f655 100644
--- a/python/vyos/ifconfig/ethernet.py
+++ b/python/vyos/ifconfig/ethernet.py
@@ -20,6 +20,7 @@ from vyos.ethtool import Ethtool
from vyos.ifconfig.interface import Interface
from vyos.util import run
from vyos.util import dict_search
+from vyos.util import read_file
from vyos.validate import assert_list
@Interface.register
@@ -181,32 +182,19 @@ class EthernetIf(Interface):
# Get current speed and duplex settings:
ifname = self.config['ifname']
- cmd = f'ethtool {ifname}'
- tmp = self._cmd(cmd)
-
- if re.search("\tAuto-negotiation: on", tmp):
+ if self.ethtool.get_auto_negotiation():
if speed == 'auto' and duplex == 'auto':
# bail out early as nothing is to change
return
else:
# read in current speed and duplex settings
- cur_speed = 0
- cur_duplex = ''
- for line in tmp.splitlines():
- if line.lstrip().startswith("Speed:"):
- non_decimal = re.compile(r'[^\d.]+')
- cur_speed = non_decimal.sub('', line)
- continue
-
- if line.lstrip().startswith("Duplex:"):
- cur_duplex = line.split()[-1].lower()
- break
-
+ cur_speed = read_file(f'/sys/class/net/{ifname}/speed')
+ cur_duplex = read_file(f'/sys/class/net/{ifname}/duplex')
if (cur_speed == speed) and (cur_duplex == duplex):
# bail out early as nothing is to change
return
- cmd = f'ethtool -s {ifname}'
+ cmd = f'ethtool --change {ifname}'
if speed == 'auto' or duplex == 'auto':
cmd += ' autoneg on'
else: