From 6f4ce1ed5cd57d9b42617871389f68771f0e69e0 Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Tue, 23 Sep 2025 08:27:26 -0500 Subject: T7850: add util list_strip to remove initial or final sub-list --- python/vyos/utils/list.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'python') diff --git a/python/vyos/utils/list.py b/python/vyos/utils/list.py index 931084e7c..ea4bcd3ba 100644 --- a/python/vyos/utils/list.py +++ b/python/vyos/utils/list.py @@ -18,3 +18,26 @@ def is_list_equal(first: list, second: list) -> bool: if len(first) != len(second) or len(first) == 0: return False return sorted(first) == sorted(second) + + +def list_strip(lst: list, sub: list, right: bool = False) -> list: + """Remove list 'sub' from beginning (right=False), resp., end of list 'lst'""" + + if not right: + while sub: + if lst[:1] == sub[:1]: + lst = lst[1:] + sub = sub[1:] + else: + lst = [] + sub = [] + else: + while sub: + if lst[-1:] == sub[-1:]: + lst = lst[:-1] + sub = sub[:-1] + else: + lst = [] + sub = [] + + return lst -- cgit v1.2.3 From bb5797b834151aab46909b7a7cb45060687e70f2 Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Tue, 23 Sep 2025 08:29:27 -0500 Subject: T7850: make op_mode_config_dict edit level aware --- python/vyos/configquery.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'python') diff --git a/python/vyos/configquery.py b/python/vyos/configquery.py index b661b1a9e..3f385d97b 100644 --- a/python/vyos/configquery.py +++ b/python/vyos/configquery.py @@ -39,6 +39,7 @@ from vyos.xml_ref import is_tag from vyos.base import Warning from vyos.utils.backend import vyconf_backend from vyos.configsource import ConfigSourceVyconfSession +from vyos.utils.list import list_strip config_file = os.path.join(directories['config'], 'config.boot') @@ -199,9 +200,19 @@ def op_mode_config_dict( ): if path is None: path = [] + command = ['/bin/cli-shell-api', '--show-active-only', 'showConfig'] - rc, out = op_mode_run(command + path) + edit_level = os.environ.get('VYATTA_EDIT_LEVEL', '') + if edit_level: + tmp = edit_level.split('/') + edit_path = [el for el in tmp if el] + relative_path = list_strip(path, edit_path) + else: + relative_path = path + + rc, out = op_mode_run(command + relative_path) + if rc == cli_shell_api_err.VYOS_EMPTY_CONFIG: out = '' if rc == cli_shell_api_err.VYOS_INVALID_PATH: -- cgit v1.2.3