summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2023-06-16 21:55:31 +0200
committerGitHub <noreply@github.com>2023-06-16 21:55:31 +0200
commit49e2822e9775c1c38a067bdc2e92ab5fd69eac95 (patch)
tree9661a9dc5e68bc0c801794e2c85f58468185a893
parent962a30c8f0320bc091778f6daedf810e2a1a55d6 (diff)
parentd35223e670beb0151f7b7235ce686c31c6bb5dec (diff)
downloadvyos-1x-49e2822e9775c1c38a067bdc2e92ab5fd69eac95.tar.gz
vyos-1x-49e2822e9775c1c38a067bdc2e92ab5fd69eac95.zip
Merge pull request #2045 from jestabro/is-node-revised
config-mgmt: T5297: add check for changes under node between revisions
-rw-r--r--python/vyos/config_mgmt.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/python/vyos/config_mgmt.py b/python/vyos/config_mgmt.py
index 57563a9c1..26114149f 100644
--- a/python/vyos/config_mgmt.py
+++ b/python/vyos/config_mgmt.py
@@ -72,6 +72,29 @@ def unsaved_commits() -> bool:
os.unlink(tmp_save)
return ret
+def get_file_revision(rev: int):
+ revision = os.path.join(archive_dir, f'config.boot.{rev}.gz')
+ try:
+ with gzip.open(revision) as f:
+ r = f.read().decode()
+ except FileNotFoundError:
+ logger.warning(f'commit revision {rev} not available')
+ return ''
+ return r
+
+def get_config_tree_revision(rev: int):
+ c = get_file_revision(rev)
+ return ConfigTree(c)
+
+def is_node_revised(path: list = [], rev1: int = 1, rev2: int = 0) -> bool:
+ from vyos.configtree import DiffTree
+ left = get_config_tree_revision(rev1)
+ right = get_config_tree_revision(rev2)
+ diff_tree = DiffTree(left, right)
+ if diff_tree.add.exists(path) or diff_tree.sub.exists(path):
+ return True
+ return False
+
class ConfigMgmtError(Exception):
pass