diff options
author | Christian Poessinger <christian@poessinger.com> | 2020-04-07 22:02:49 +0200 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2020-04-07 22:02:49 +0200 |
commit | fcce4714146a39f608ddd141338547a5a952c63f (patch) | |
tree | 3b521908928e0cae15c2e8f8979088b5f7d2c0a5 /python | |
parent | 681576fff6a268ed04ae1a73ad7771882672cdb6 (diff) | |
download | vyos-1x-fcce4714146a39f608ddd141338547a5a952c63f.tar.gz vyos-1x-fcce4714146a39f608ddd141338547a5a952c63f.zip |
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.
Diffstat (limited to 'python')
-rw-r--r-- | python/vyos/util.py | 19 |
1 files changed, 19 insertions, 0 deletions
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 + |