From 0d3e730c9e71748f866573a72951e142b4108a7b Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Thu, 24 Sep 2026 12:01:15 -0500 Subject: T7886: add supporting functions for calculation of reverse dependencies --- python/vyos/dependentverify.py | 62 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 python/vyos/dependentverify.py (limited to 'python') diff --git a/python/vyos/dependentverify.py b/python/vyos/dependentverify.py new file mode 100644 index 000000000..157f99ae3 --- /dev/null +++ b/python/vyos/dependentverify.py @@ -0,0 +1,62 @@ +# Copyright (C) VyOS Inc. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. If not, see . + + +from vyos.configtree import ConfigTree # noqa: I001 +from vyos.configtree import DiffTree +from vyos.configtree import subtree_values_of_path +from vyos.referencetree import ReferenceTree + + +def removed_dependency_value_paths_of_kind( + kind: str, + reference_tree: ReferenceTree, + session_tree: ConfigTree, + diff_tree: DiffTree, +): + paths = reference_tree.get_nodes_of_kind(kind) + value_paths = [] + for path in paths: + path_vals = subtree_values_of_path(diff_tree.sub, path, reference_tree) + path_vals = [t for t in path_vals if t != ([], [])] + for vlst, p in path_vals: + vals = list( + filter( + lambda v, cur_p=p: not session_tree.exists(cur_p + [v]), + vlst, + ) + ) + if vals: + value_paths.append((vals, p)) + + return value_paths + + +def dependent_value_paths_of_kind( + kind: str, + reference_tree: ReferenceTree, + session_tree: ConfigTree, +): + dependent_data = reference_tree.get_rdeps_of_kind_data(kind) + + dependent_value_paths = {} + for p, a in dependent_data: + path_vals = subtree_values_of_path(session_tree, p, reference_tree) + path_vals = [t for t in path_vals if t != ([], [])] + if path_vals: + lst = dependent_value_paths.setdefault(a, []) + lst.extend(path_vals) + + return dependent_value_paths -- cgit v1.2.3