diff options
author | Christian Poessinger <christian.poessinger@rohde-schwarz.com> | 2021-12-06 18:49:30 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-06 18:49:30 +0100 |
commit | 84455522574afb9286803f4e192a3d99c259618c (patch) | |
tree | 01ab634d8e5a9c40061f2b8150245319c44746a4 /python/vyos/util.py | |
parent | 5b3ff8574c8265cf308b225c1a39503712f0b21d (diff) | |
parent | 47584e030f3341b265e826643951648982cb20d0 (diff) | |
download | vyos-1x-84455522574afb9286803f4e192a3d99c259618c.tar.gz vyos-1x-84455522574afb9286803f4e192a3d99c259618c.zip |
Merge pull request #1077 from sever-sever/T3829
netns: T3829: Ability to configure network namespaces
Diffstat (limited to 'python/vyos/util.py')
-rw-r--r-- | python/vyos/util.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/python/vyos/util.py b/python/vyos/util.py index d8e83ab8d..157b26bf7 100644 --- a/python/vyos/util.py +++ b/python/vyos/util.py @@ -794,6 +794,24 @@ def get_interface_address(interface): tmp = loads(cmd(f'ip -d -j addr show {interface}'))[0] return tmp +def get_interface_namespace(iface): + """ + Returns wich netns the interface belongs to + """ + from json import loads + # Check if netns exist + tmp = loads(cmd(f'ip --json netns ls')) + if len(tmp) == 0: + return None + + for ns in tmp: + namespace = f'{ns["name"]}' + # Search interface in each netns + data = loads(cmd(f'ip netns exec {namespace} ip -j link show')) + for compare in data: + if iface == compare["ifname"]: + return namespace + def get_all_vrfs(): """ Return a dictionary of all system wide known VRF instances """ from json import loads |