diff options
| author | Christian Poessinger <christian@poessinger.com> | 2019-09-13 16:36:08 +0200 | 
|---|---|---|
| committer | Christian Poessinger <christian@poessinger.com> | 2019-09-20 21:28:53 +0200 | 
| commit | 66884984c7b4b5b445322828541a942fa9e705c1 (patch) | |
| tree | 9864c639b5ae80310a8946ae993b6471ed1f14f7 /python | |
| parent | f107a252020d225b4e7429cc5c3a61af6cb2e1d9 (diff) | |
| download | vyos-1x-66884984c7b4b5b445322828541a942fa9e705c1.tar.gz vyos-1x-66884984c7b4b5b445322828541a942fa9e705c1.zip | |
Python/ifconfig: T1557: ethernet: add method for changing speed and duplex
Diffstat (limited to 'python')
| -rw-r--r-- | python/vyos/ifconfig.py | 22 | 
1 files changed, 22 insertions, 0 deletions
| diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py index ab8799e54..507df0d71 100644 --- a/python/vyos/ifconfig.py +++ b/python/vyos/ifconfig.py @@ -1095,6 +1095,28 @@ class EthernetIf(VLANIf):          except CalledProcessError:              pass +    def set_speed_duplex(self, speed, duplex): +        """ +        Set link speed in Mbit/s and duplex. + +        @speed can be any link speed in MBit/s, e.g. 10, 100, 1000 auto +        @duplex can be half, full, auto +        """ + +        if speed not in ['auto', '10', '100', '1000', '2500', '5000', '10000', '25000', '40000', '50000', '100000', '400000']: +            raise ValueError("Value out of range (speed)") + +        if duplex not in ['auto', 'full', 'half']: +            raise ValueError("Value out of range (duplex)") + +        cmd = 'ethtool -s {}'.format(self._ifname) +        if speed == 'auto' or duplex == 'auto': +            cmd += ' autoneg on' +        else: +            cmd += ' speed {} duplex {} autoneg off'.format(speed, duplex) + +        return self._cmd(cmd) +  class BondIf(VLANIf):      """ | 
