summaryrefslogtreecommitdiff
path: root/python/vyos/util.py
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2023-09-02 19:02:55 +0200
committerGitHub <noreply@github.com>2023-09-02 19:02:55 +0200
commite74b38c4d862feed7a401723c1f0b1c9d9a03324 (patch)
tree3b7e21cb3462ce3d026b32de6e73c54faad7d98b /python/vyos/util.py
parent0ba723bcdbf608ba73bedbba74a8aa9be1d7df7b (diff)
parentf7473c735ab2d5b74718012cbd27a6ca38e5dfa1 (diff)
downloadvyos-1x-e74b38c4d862feed7a401723c1f0b1c9d9a03324.tar.gz
vyos-1x-e74b38c4d862feed7a401723c1f0b1c9d9a03324.zip
Merge pull request #2191 from c-po/equuleus
T5428: fix DHCP client running in VRF context
Diffstat (limited to 'python/vyos/util.py')
-rw-r--r--python/vyos/util.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/python/vyos/util.py b/python/vyos/util.py
index 03809fc83..20c743b35 100644
--- a/python/vyos/util.py
+++ b/python/vyos/util.py
@@ -788,6 +788,13 @@ def get_interface_config(interface):
tmp = loads(cmd(f'ip -d -j link show {interface}'))[0]
return tmp
+def get_interface_vrf(interface):
+ """ Returns VRF of given interface """
+ tmp = get_interface_config(interface)
+ if dict_search('linkinfo.info_slave_kind', tmp) == 'vrf':
+ return tmp['master']
+ return 'default'
+
def print_error(str='', end='\n'):
"""
Print `str` to stderr, terminated with `end`.
@@ -912,3 +919,24 @@ def sysctl_write(name, value):
def is_ipv6_enabled() -> bool:
""" Check if IPv6 support on the system is enabled or not """
return (sysctl_read('net.ipv6.conf.all.disable_ipv6') == '0')
+
+def interface_exists(interface) -> bool:
+ import os
+ return os.path.exists(f'/sys/class/net/{interface}')
+
+def get_vrf_members(vrf: str) -> list:
+ """
+ Get list of interface VRF members
+ :param vrf: str
+ :return: list
+ """
+ import json
+ if not interface_exists(vrf):
+ raise ValueError(f'VRF "{vrf}" does not exist!')
+ output = cmd(f'ip --json --brief link show master {vrf}')
+ answer = json.loads(output)
+ interfaces = []
+ for data in answer:
+ if 'ifname' in data:
+ interfaces.append(data.get('ifname'))
+ return interfaces