diff options
author | John Estabrook <jestabro@vyos.io> | 2023-06-16 10:38:25 -0500 |
---|---|---|
committer | John Estabrook <jestabro@vyos.io> | 2023-06-16 10:43:39 -0500 |
commit | d35223e670beb0151f7b7235ce686c31c6bb5dec (patch) | |
tree | 233e49a94e70df1d08e42a20b2decf1f2590ac0c /python | |
parent | c67c51e0202d9eafed6a719a49dd6885132c76ec (diff) | |
download | vyos-1x-d35223e670beb0151f7b7235ce686c31c6bb5dec.tar.gz vyos-1x-d35223e670beb0151f7b7235ce686c31c6bb5dec.zip |
config-mgmt: T5297: add check for changes under node between revisions
Diffstat (limited to 'python')
-rw-r--r-- | python/vyos/config_mgmt.py | 23 |
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 |