summaryrefslogtreecommitdiff
path: root/python/vyos/util.py
diff options
context:
space:
mode:
authorViacheslav <v.gletenko@vyos.io>2021-11-23 18:11:10 +0000
committerViacheslav <v.gletenko@vyos.io>2021-11-26 09:43:13 +0000
commit47584e030f3341b265e826643951648982cb20d0 (patch)
tree60a6861e2c84da01722ec39384b254be488c4c46 /python/vyos/util.py
parenta2fe5dc40d439a28deb4d09e78fcf93aba4555a4 (diff)
downloadvyos-1x-47584e030f3341b265e826643951648982cb20d0.tar.gz
vyos-1x-47584e030f3341b265e826643951648982cb20d0.zip
netns: T3829: Ability to configure network namespaces
Diffstat (limited to 'python/vyos/util.py')
-rw-r--r--python/vyos/util.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/python/vyos/util.py b/python/vyos/util.py
index 9aa1f98d2..6c375e1a6 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