From 0588f5409f57a8d8577bc9bd23c393487fd2987b Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Tue, 24 Sep 2019 22:08:21 +0200 Subject: Python/ifconfig: T1557: add STPIf class (spanning tree) bridge member --- python/vyos/ifconfig.py | 66 ++++++++++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 25 deletions(-) (limited to 'python') diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py index a959e55d8..a77cde5e7 100644 --- a/python/vyos/ifconfig.py +++ b/python/vyos/ifconfig.py @@ -641,6 +641,47 @@ class DummyIf(Interface): super().__init__(ifname, type='dummy') +class STPIf(Interface): + """ + A spanning-tree capable interface. This applies only to bridge port member + interfaces! + """ + def __init__(self, ifname): + super().__init__(ifname) + + def set_path_cost(self, cost): + """ + Set interface path cost, only relevant for STP enabled interfaces + + Example: + + >>> from vyos.ifconfig import Interface + >>> Interface('eth0').set_path_cost(4) + """ + if not os.path.isfile('/sys/class/net/{}/brport/path_cost' + .format(self._ifname)): + raise TypeError('{} is not a bridge port member'.format(self._ifname)) + + return self._write_sysfs('/sys/class/net/{}/brport/path_cost' + .format(self._ifname), cost) + + def set_path_priority(self, priority): + """ + Set interface path priority, only relevant for STP enabled interfaces + + Example: + + >>> from vyos.ifconfig import Interface + >>> Interface('eth0').set_path_priority(4) + """ + if not os.path.isfile('/sys/class/net/{}/brport/priority' + .format(self._ifname)): + raise TypeError('{} is not a bridge port member'.format(self._ifname)) + + return self._write_sysfs('/sys/class/net/{}/brport/priority' + .format(self._ifname), priority) + + class BridgeIf(Interface): """ @@ -774,31 +815,6 @@ class BridgeIf(Interface): cmd = 'ip link set dev {} nomaster'.format(interface) self._cmd(cmd) - def set_path_cost(self, interface, cost): - """ - Set interface path cost, only relevant for STP enabled interfaces - - Example: - - >>> from vyos.ifconfig import Interface - >>> Interface('eth0').path_cost(4) - """ - return self._write_sysfs('/sys/class/net/{}/brif/{}/path_cost' - .format(self._ifname, interface), cost) - - def set_path_priority(self, interface, priority): - """ - Set interface path priority, only relevant for STP enabled interfaces - - Example: - - >>> from vyos.ifconfig import Interface - >>> Interface('eth0').priority(4) - """ - return self._write_sysfs('/sys/class/net/{}/brif/{}/priority' - .format(self._ifname, interface), priority) - - class VLANIf(Interface): """ This class handels the creation and removal of a VLAN interface. It serves -- cgit v1.2.3