From f13cc56d665a91ff3fac47df260301afefb1a3a5 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sun, 28 Feb 2021 10:50:06 +0100 Subject: 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() --- python/vyos/util.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'python') 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 -- cgit v1.2.3