summaryrefslogtreecommitdiff
path: root/python/vyos/validate.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-04-19 11:55:09 +0200
committerChristian Poessinger <christian@poessinger.com>2020-04-19 11:55:12 +0200
commit0e19d622a04100f7b6e53b3fe601873412609057 (patch)
treebcb4b82523233eabdde9ccb892b3c547b56c294b /python/vyos/validate.py
parent0588c120b8c2041b60e83effe15303af1e1cdbef (diff)
downloadvyos-1x-0e19d622a04100f7b6e53b3fe601873412609057.tar.gz
vyos-1x-0e19d622a04100f7b6e53b3fe601873412609057.zip
bridge: T2232: move helper to vyos.validate
Diffstat (limited to 'python/vyos/validate.py')
-rw-r--r--python/vyos/validate.py29
1 files changed, 27 insertions, 2 deletions
diff --git a/python/vyos/validate.py b/python/vyos/validate.py
index 9d413ffab..15716ada4 100644
--- a/python/vyos/validate.py
+++ b/python/vyos/validate.py
@@ -86,8 +86,8 @@ def _is_intf_addr_assigned(intf, address, netmask=''):
# check if the requested address type is configured at all
# {
- # 17: [{'addr': '08:00:27:d9:5b:04', 'broadcast': 'ff:ff:ff:ff:ff:ff'}],
- # 2: [{'addr': '10.0.2.15', 'netmask': '255.255.255.0', 'broadcast': '10.0.2.255'}],
+ # 17: [{'addr': '08:00:27:d9:5b:04', 'broadcast': 'ff:ff:ff:ff:ff:ff'}],
+ # 2: [{'addr': '10.0.2.15', 'netmask': '255.255.255.0', 'broadcast': '10.0.2.255'}],
# 10: [{'addr': 'fe80::a00:27ff:fed9:5b04%eth0', 'netmask': 'ffff:ffff:ffff:ffff::'}]
# }
try:
@@ -240,3 +240,28 @@ def assert_mac(m):
if octets[:5] == (0, 0, 94, 0, 1):
raise ValueError(f'{m} is a VRRP MAC address')
+
+def is_bridge_member(conf, interface):
+ """
+ Checks if passed interfaces is part of a bridge device or not.
+
+ Returns a tuple:
+ None -> Interface not a bridge member
+ Bridge -> Interface is a member of this bridge
+ """
+ ret_val = None
+ old_level = conf.get_level()
+
+ # set config level to root
+ conf.set_level([])
+ base = ['interfaces', 'bridge']
+ for bridge in conf.list_nodes(base):
+ members = conf.list_nodes(base + [bridge, 'member', 'interface'])
+ print(members)
+ if interface in members:
+ ret_val = bridge
+ break
+
+ old_level = conf.set_level(old_level)
+ return ret_val
+