From fcce4714146a39f608ddd141338547a5a952c63f Mon Sep 17 00:00:00 2001
From: Christian Poessinger <christian@poessinger.com>
Date: Tue, 7 Apr 2020 22:02:49 +0200
Subject: bridge: T2232: prevent deletion of enslaved interfaces

Interfaces enslaved to a bridge are not allowed to be deleted. If an interface
is deleted from the config but it is still enslaved to a bridge will cause a
configuration error on the subsequent boot.
---
 python/vyos/util.py | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

(limited to 'python')

diff --git a/python/vyos/util.py b/python/vyos/util.py
index 3d5bbf094..16cfae92d 100644
--- a/python/vyos/util.py
+++ b/python/vyos/util.py
@@ -321,3 +321,22 @@ def mac2eui64(mac, prefix=None):
             return str(net[euil])
         except:  # pylint: disable=bare-except
             return
+
+def is_bridge_member(interface):
+    """
+    Checks if passed interfaces is part of a bridge device or not.
+
+    Returns a tuple:
+    False, None -> Not part of a bridge
+    True, bridge-name -> If it is assigned to a bridge
+    """
+    from vyos.config import Config
+    c = Config()
+    base = ['interfaces', 'bridge']
+    for bridge in c.list_nodes(base):
+        members = c.list_nodes(base + [bridge, 'member', 'interface'])
+        if interface in members:
+            return (True, bridge)
+
+    return False, None
+
-- 
cgit v1.2.3