diff options
author | Daniil Baturin <daniil@baturin.org> | 2024-07-29 19:16:43 +0100 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2024-07-29 19:16:43 +0100 |
commit | 30111fa493c72e7182854f295bc88d9eecccf419 (patch) | |
tree | 6fbcb396df88744e539eae75e56bb0835428fa65 /python/vyos/configtree.py | |
parent | 7724a5f58b515fbc094b4f211d455c1bd5071a74 (diff) | |
download | vyos-1x-30111fa493c72e7182854f295bc88d9eecccf419.tar.gz vyos-1x-30111fa493c72e7182854f295bc88d9eecccf419.zip |
vyos.configtree: T6620: allow list_nodes() to work on non-existent paths
and return an empty list in that case
(handy for migration scripts and the like)
Diffstat (limited to 'python/vyos/configtree.py')
-rw-r--r-- | python/vyos/configtree.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/python/vyos/configtree.py b/python/vyos/configtree.py index 5775070e2..bd77ab899 100644 --- a/python/vyos/configtree.py +++ b/python/vyos/configtree.py @@ -1,5 +1,5 @@ # configtree -- a standalone VyOS config file manipulation library (Python bindings) -# Copyright (C) 2018-2022 VyOS maintainers and contributors +# Copyright (C) 2018-2024 VyOS maintainers and contributors # # This library is free software; you can redistribute it and/or modify it under the terms of # the GNU Lesser General Public License as published by the Free Software Foundation; @@ -290,7 +290,7 @@ class ConfigTree(object): else: return True - def list_nodes(self, path): + def list_nodes(self, path, path_must_exist=True): check_path(path) path_str = " ".join(map(str, path)).encode() @@ -298,7 +298,10 @@ class ConfigTree(object): res = json.loads(res_json) if res is None: - raise ConfigTreeError("Path [{}] doesn't exist".format(path_str)) + if path_must_exist: + raise ConfigTreeError("Path [{}] doesn't exist".format(path_str)) + else: + return [] else: return res |