summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2023-08-04 10:49:37 -0500
committerJohn Estabrook <jestabro@vyos.io>2023-08-07 00:48:31 -0500
commitecc00da8c5e303af006052a00f904d187c90bb4b (patch)
tree4f8bb4775a74758be7c7a8f7bccfd06b11b949be /python
parent710dac553fac93d8a205c9bc7e6b116753ac0b34 (diff)
downloadvyos-1x-ecc00da8c5e303af006052a00f904d187c90bb4b.tar.gz
vyos-1x-ecc00da8c5e303af006052a00f904d187c90bb4b.zip
xml: T5435: utility function for default value at path
Diffstat (limited to 'python')
-rw-r--r--python/vyos/xml_ref/__init__.py4
-rw-r--r--python/vyos/xml_ref/definition.py9
2 files changed, 13 insertions, 0 deletions
diff --git a/python/vyos/xml_ref/__init__.py b/python/vyos/xml_ref/__init__.py
index ad2130dca..9f7a31e2c 100644
--- a/python/vyos/xml_ref/__init__.py
+++ b/python/vyos/xml_ref/__init__.py
@@ -13,6 +13,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this library. If not, see <http://www.gnu.org/licenses/>.
+from typing import Optional, Union
from vyos.xml_ref import definition
def load_reference(cache=[]):
@@ -54,6 +55,9 @@ def from_source(d: dict, path: list) -> bool:
def component_version() -> dict:
return load_reference().component_version()
+def default_value(path: list) -> Optional[Union[str, list]]:
+ return load_reference().default_value(path)
+
def multi_to_list(rpath: list, conf: dict) -> dict:
return load_reference().multi_to_list(rpath, conf)
diff --git a/python/vyos/xml_ref/definition.py b/python/vyos/xml_ref/definition.py
index d95d580e2..b0b8a2605 100644
--- a/python/vyos/xml_ref/definition.py
+++ b/python/vyos/xml_ref/definition.py
@@ -153,6 +153,15 @@ class Xml:
return default.split()
return default
+ def default_value(self, path: list) -> Optional[Union[str, list]]:
+ d = self._get_ref_path(path)
+ default = self._get_default_value(d)
+ if default is None:
+ return None
+ if self._is_multi_node(d) or self._is_tag_node(d):
+ return default.split()
+ return default
+
def get_defaults(self, path: list, get_first_key=False, recursive=False) -> dict:
"""Return dict containing default values below path