diff options
author | Christian Poessinger <christian@poessinger.com> | 2021-02-28 10:50:06 +0100 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2021-03-06 09:28:41 +0100 |
commit | bab4537ae4c64dd622e69b43c97b79e8e6e63863 (patch) | |
tree | 526d8dc0746e15b7e7facfb2991584cccde7fe37 /src | |
parent | f2f60b1d72456d7bb416240a5095bb1bb32bdd0a (diff) | |
download | vyos-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 'src')
-rwxr-xr-x | src/conf_mode/interfaces-tunnel.py | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/src/conf_mode/interfaces-tunnel.py b/src/conf_mode/interfaces-tunnel.py index 748a9d261..d1d3616f6 100755 --- a/src/conf_mode/interfaces-tunnel.py +++ b/src/conf_mode/interfaces-tunnel.py @@ -40,22 +40,12 @@ from vyos.ifconfig import SitIf from vyos.ifconfig import Sit6RDIf from vyos.template import is_ipv4 from vyos.template import is_ipv6 -from vyos.util import cmd +from vyos.util import get_json_iface_options from vyos.util import dict_search from vyos import ConfigError from vyos import airbag airbag.enable() -def get_tunnel_encapsulation(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['linkinfo']['info_kind'] - def get_config(config=None): """ Retrive CLI config as dictionary. Dictionary can never be empty, as at least @@ -135,11 +125,13 @@ def generate(tunnel): return None def apply(tunnel): - # If a gre-bridge tunnel is already existing we can not "simply" change - # local or remote addresses. This returns "Operation not supported" by the - # Kernel. There is no other solution to destroy and recreate the tunnel. interface = tunnel['ifname'] - encap = get_tunnel_encapsulation(interface) + # If a gretap tunnel is already existing we can not "simply" change local or + # remote addresses. This returns "Operation not supported" by the Kernel. + # There is no other solution to destroy and recreate the tunnel. + encap = '' + tmp = get_json_iface_options(interface) + if tmp: encap = dict_search('linkinfo.info_kind', tmp) if 'deleted' in tunnel or 'encapsulation_changed' in tunnel or encap == 'gretap': if interface in interfaces(): |