summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2024-07-29 22:29:35 +0200
committerGitHub <noreply@github.com>2024-07-29 22:29:35 +0200
commitad0acad65051a449432f882edb60246cdfeeb8e5 (patch)
tree6fbcb396df88744e539eae75e56bb0835428fa65 /python
parent7724a5f58b515fbc094b4f211d455c1bd5071a74 (diff)
parent30111fa493c72e7182854f295bc88d9eecccf419 (diff)
downloadvyos-1x-ad0acad65051a449432f882edb60246cdfeeb8e5.tar.gz
vyos-1x-ad0acad65051a449432f882edb60246cdfeeb8e5.zip
Merge pull request #3898 from dmbaturin/T6620
vyos.configtree: T6620: allow list_nodes() to work on non-existent paths
Diffstat (limited to 'python')
-rw-r--r--python/vyos/configtree.py9
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