diff options
author | Christian Breunig <christian@breunig.cc> | 2023-03-29 21:12:22 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-29 21:12:22 +0200 |
commit | 623dfc9d87d513bd69e5e6eef9664056dc1a45f1 (patch) | |
tree | 912adf40656c8419c4833983f6a7da636d6c2d42 /python/vyos | |
parent | db0fc992c0f1e3f1ab6f099b07b933bfca07d520 (diff) | |
parent | dccc689e0e666787834f45e6ab6bd972fddabf95 (diff) | |
download | vyos-1x-623dfc9d87d513bd69e5e6eef9664056dc1a45f1.tar.gz vyos-1x-623dfc9d87d513bd69e5e6eef9664056dc1a45f1.zip |
Merge pull request #1900 from jestabro/diff-test
configdiff: T5089: add unit test of config_diff
Diffstat (limited to 'python/vyos')
-rw-r--r-- | python/vyos/configtree.py | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/python/vyos/configtree.py b/python/vyos/configtree.py index c0b3ebd78..9308bdde4 100644 --- a/python/vyos/configtree.py +++ b/python/vyos/configtree.py @@ -60,7 +60,7 @@ class ConfigTree(object): self.__get_error.restype = c_char_p self.__to_string = self.__lib.to_string - self.__to_string.argtypes = [c_void_p] + self.__to_string.argtypes = [c_void_p, c_bool] self.__to_string.restype = c_char_p self.__to_commands = self.__lib.to_commands @@ -160,8 +160,8 @@ class ConfigTree(object): def _get_config(self): return self.__config - def to_string(self): - config_string = self.__to_string(self.__config).decode() + def to_string(self, ordered_values=False): + config_string = self.__to_string(self.__config, ordered_values).decode() config_string = "{0}\n{1}".format(config_string, self.__version) return config_string @@ -352,6 +352,27 @@ def show_diff(left, right, path=[], commands=False, libpath=LIBPATH): return res +def union(left, right, 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_union = __lib.tree_union + __tree_union.argtypes = [c_void_p, c_void_p] + __tree_union.restype = c_void_p + __get_error = __lib.get_error + __get_error.argtypes = [] + __get_error.restype = c_char_p + + res = __tree_union( left._get_config(), right._get_config()) + tree = ConfigTree(address=res) + + return tree + class DiffTree: def __init__(self, left, right, path=[], libpath=LIBPATH): if left is None: |