diff options
author | John Estabrook <jestabro@vyos.io> | 2025-06-11 11:50:21 -0500 |
---|---|---|
committer | John Estabrook <jestabro@vyos.io> | 2025-07-08 08:26:11 -0500 |
commit | 5e333ccf4a4ddabbb61042d5b347de54845d60c0 (patch) | |
tree | 76940d4773daef73bad5a24b4cfcf2d6efbb939a /python | |
parent | fd58e0914d5f16d5c635c808834b9e38f6f3ac38 (diff) | |
download | vyos-1x-5e333ccf4a4ddabbb61042d5b347de54845d60c0.tar.gz vyos-1x-5e333ccf4a4ddabbb61042d5b347de54845d60c0.zip |
T7499: add interface for (non-)destructive configtree merge
Diffstat (limited to 'python')
-rw-r--r-- | python/vyos/configtree.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/python/vyos/configtree.py b/python/vyos/configtree.py index 9b3755841..dd7dc5b93 100644 --- a/python/vyos/configtree.py +++ b/python/vyos/configtree.py @@ -499,6 +499,28 @@ def union(left, right, libpath=LIBPATH): return tree +def merge(left, right, destructive=False, libpath=LIBPATH): + if left is None: + left = ConfigTree(config_string='\n') + if right is None: + right = ConfigTree(config_string='\n') + if not (isinstance(left, ConfigTree) and isinstance(right, ConfigTree)): + raise TypeError('Arguments must be instances of ConfigTree') + + __lib = cdll.LoadLibrary(libpath) + __tree_merge = __lib.tree_merge + __tree_merge.argtypes = [c_bool, c_void_p, c_void_p] + __tree_merge.restype = c_void_p + __get_error = __lib.get_error + __get_error.argtypes = [] + __get_error.restype = c_char_p + + res = __tree_merge(destructive, left._get_config(), right._get_config()) + tree = ConfigTree(address=res) + + return tree + + def mask_inclusive(left, right, libpath=LIBPATH): if not (isinstance(left, ConfigTree) and isinstance(right, ConfigTree)): raise TypeError('Arguments must be instances of ConfigTree') |