summaryrefslogtreecommitdiff
path: root/python
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
parent0588c120b8c2041b60e83effe15303af1e1cdbef (diff)
downloadvyos-1x-0e19d622a04100f7b6e53b3fe601873412609057.tar.gz
vyos-1x-0e19d622a04100f7b6e53b3fe601873412609057.zip
bridge: T2232: move helper to vyos.validate
Diffstat (limited to 'python')
-rw-r--r--python/vyos/util.py18
-rw-r--r--python/vyos/validate.py29
2 files changed, 27 insertions, 20 deletions
diff --git a/python/vyos/util.py b/python/vyos/util.py
index c70bff091..b1d95fbbf 100644
--- a/python/vyos/util.py
+++ b/python/vyos/util.py
@@ -429,24 +429,6 @@ def mac2eui64(mac, prefix=None):
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
-
def get_half_cpus():
""" return 1/2 of the numbers of available CPUs """
cpu = os.cpu_count()
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
+