summaryrefslogtreecommitdiff
path: root/python/vyos
diff options
context:
space:
mode:
authorJernej Jakob <jernej.jakob@gmail.com>2020-05-03 15:47:11 +0200
committerJernej Jakob <jernej.jakob@gmail.com>2020-05-04 22:25:41 +0200
commite35807b209e3de77b09082a74d2b0f0b1a802206 (patch)
tree9f0fd5a6e949f42734a3ad76c761597ee466e81f /python/vyos
parent347347c68687849822912e5e26febc5f92955b8b (diff)
downloadvyos-1x-e35807b209e3de77b09082a74d2b0f0b1a802206.tar.gz
vyos-1x-e35807b209e3de77b09082a74d2b0f0b1a802206.zip
interface: T2241: add function to add self to bridge
Will be called by all interface scripts to re-add themselves to a bridge after deleting and recreating themselves.
Diffstat (limited to 'python/vyos')
-rw-r--r--python/vyos/ifconfig/interface.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/python/vyos/ifconfig/interface.py b/python/vyos/ifconfig/interface.py
index 5b3da228e..7b42e3399 100644
--- a/python/vyos/ifconfig/interface.py
+++ b/python/vyos/ifconfig/interface.py
@@ -42,6 +42,7 @@ from vyos.ifconfig.control import Control
from vyos.ifconfig.dhcp import DHCP
from vyos.ifconfig.vrrp import VRRP
from vyos.ifconfig.operational import Operational
+from vyos.ifconfig import Section
class Interface(Control):
@@ -718,3 +719,22 @@ class Interface(Control):
# flush all addresses
self._cmd(f'ip addr flush dev "{self.ifname}"')
+
+ def add_to_bridge(self, br):
+ """
+ Adds the interface to the bridge with the passed port config.
+
+ Returns False if bridge doesn't exist.
+ """
+
+ # check if the bridge exists (on boot it doesn't)
+ if br not in Section.interfaces('bridge'):
+ return False
+
+ self.flush_addrs()
+ # add interface to bridge - use Section.klass to get BridgeIf class
+ Section.klass(br)(br, create=False).add_port(self.ifname)
+
+ # TODO: port config (STP)
+
+ return True