summaryrefslogtreecommitdiff
path: root/python/vyos/util.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2021-02-28 10:50:06 +0100
committerChristian Poessinger <christian@poessinger.com>2021-03-06 09:28:41 +0100
commitbab4537ae4c64dd622e69b43c97b79e8e6e63863 (patch)
tree526d8dc0746e15b7e7facfb2991584cccde7fe37 /python/vyos/util.py
parentf2f60b1d72456d7bb416240a5095bb1bb32bdd0a (diff)
downloadvyos-1x-bab4537ae4c64dd622e69b43c97b79e8e6e63863.tar.gz
vyos-1x-bab4537ae4c64dd622e69b43c97b79e8e6e63863.zip
vyos.util: provide single implementation for get_json_iface_options()
There had been four implementations of "ip -d -j link show interface" scattered accross the codebase. Those implementations have now been combined into a new helper: vyos.util.get_json_iface_options() (cherry picked from commit f13cc56d665a91ff3fac47df260301afefb1a3a5)
Diffstat (limited to 'python/vyos/util.py')
-rw-r--r--python/vyos/util.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/python/vyos/util.py b/python/vyos/util.py
index ab5029c92..17a7dda91 100644
--- a/python/vyos/util.py
+++ b/python/vyos/util.py
@@ -645,3 +645,13 @@ def dict_search(path, dict):
for p in parts[:-1]:
c = c.get(p, {})
return c.get(parts[-1], None)
+
+def get_json_iface_options(interface):
+ """ Returns the used encapsulation protocol for given interface.
+ If interface does not exist, None is returned.
+ """
+ if not os.path.exists(f'/sys/class/net/{interface}'):
+ return None
+ from json import loads
+ tmp = loads(cmd(f'ip -d -j link show {interface}'))[0]
+ return tmp