summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2026-09-24 12:01:15 -0500
committerJohn Estabrook <jestabro@vyos.io>2026-10-08 07:41:04 -0500
commit0d3e730c9e71748f866573a72951e142b4108a7b (patch)
tree70c0d7b1b7feeedd77a2f889b2d77d4a065666ff /python
parentca01ca14ca49f73a3924cd693d06e546152190db (diff)
downloadvyos-1x-0d3e730c9e71748f866573a72951e142b4108a7b.tar.gz
vyos-1x-0d3e730c9e71748f866573a72951e142b4108a7b.zip
T7886: add supporting functions for calculation of reverse dependencies
Diffstat (limited to 'python')
-rw-r--r--python/vyos/dependentverify.py62
1 files changed, 62 insertions, 0 deletions
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 <http://www.gnu.org/licenses/>.
+
+
+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