diff options
author | sarthurdev <965089+sarthurdev@users.noreply.github.com> | 2021-07-28 12:03:21 +0200 |
---|---|---|
committer | sarthurdev <965089+sarthurdev@users.noreply.github.com> | 2021-12-06 21:20:49 +0100 |
commit | fdeba8da3e99256fe449e331d0b833a941315226 (patch) | |
tree | c6181ec7b84796a52a72d61e7d89ad6974f6f5f6 /python/vyos/configdiff.py | |
parent | 025f0609cea8591e93b8cb4a7d0256e43e23323b (diff) | |
download | vyos-1x-fdeba8da3e99256fe449e331d0b833a941315226.tar.gz vyos-1x-fdeba8da3e99256fe449e331d0b833a941315226.zip |
firewall: T2199: Migrate firewall to XML/Python
Diffstat (limited to 'python/vyos/configdiff.py')
-rw-r--r-- | python/vyos/configdiff.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/python/vyos/configdiff.py b/python/vyos/configdiff.py index 0e41fbe27..4ad7443d7 100644 --- a/python/vyos/configdiff.py +++ b/python/vyos/configdiff.py @@ -17,7 +17,9 @@ from enum import IntFlag, auto from vyos.config import Config from vyos.configdict import dict_merge +from vyos.configdict import list_diff from vyos.util import get_sub_dict, mangle_dict_keys +from vyos.util import dict_search_args from vyos.xml import defaults class ConfigDiffError(Exception): @@ -134,6 +136,34 @@ class ConfigDiff(object): self._key_mangling[1]) return config_dict + def get_child_nodes_diff_str(self, path=[]): + ret = {'add': {}, 'change': {}, 'delete': {}} + + diff = self.get_child_nodes_diff(path, + expand_nodes=Diff.ADD | Diff.DELETE | Diff.MERGE | Diff.STABLE, + no_defaults=True) + + def parse_dict(diff_dict, diff_type, prefix=[]): + for k, v in diff_dict.items(): + if isinstance(v, dict): + parse_dict(v, diff_type, prefix + [k]) + else: + path_str = ' '.join(prefix + [k]) + if diff_type == 'add' or diff_type == 'delete': + if isinstance(v, list): + v = ', '.join(v) + ret[diff_type][path_str] = v + elif diff_type == 'merge': + old_value = dict_search_args(diff['stable'], *prefix, k) + if old_value and old_value != v: + ret['change'][path_str] = [old_value, v] + + parse_dict(diff['merge'], 'merge') + parse_dict(diff['add'], 'add') + parse_dict(diff['delete'], 'delete') + + return ret + def get_child_nodes_diff(self, path=[], expand_nodes=Diff(0), no_defaults=False): """ Args: |