summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2026-04-28 16:44:28 +0200
committerChristian Breunig <christian@breunig.cc>2026-04-28 16:46:41 +0200
commite8434e64bada81aabed2cfe614d64cd213110984 (patch)
treef3f8c160e3a6c691ac82fb94bff733e1f6459816 /python
parente5c61bdfef7a060120625ff50e302923753b2ef3 (diff)
downloadvyos-1x-e8434e64bada81aabed2cfe614d64cd213110984.tar.gz
vyos-1x-e8434e64bada81aabed2cfe614d64cd213110984.zip
T8541: add vyos.utils.config.set_leaf() helper
Improve config formatting for valueless leaf nodes with a new helper. Otherwise the rendered-to-string configuration would become device ttyS0 { kernel { } } Whereas this would be the preferred representation: device ttyS0 { kernel } Co-authored-by: John Estabrook <jestabro@vyos.io>
Diffstat (limited to 'python')
-rw-r--r--python/vyos/utils/config.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/python/vyos/utils/config.py b/python/vyos/utils/config.py
index 5bba69a61..1032e22dc 100644
--- a/python/vyos/utils/config.py
+++ b/python/vyos/utils/config.py
@@ -71,6 +71,8 @@ def write_saved_value(path: list, value=None, config_path: str=config_file):
set_tags(ct, path)
ct.set(path, value=value, replace=True)
+ set_leaf(ct, path)
+
write_file(config_path, ct.to_string())
def flag(l: list) -> list:
@@ -92,6 +94,11 @@ def set_tags(ct: 'ConfigTree', path: list) -> None:
if condition:
ct.set_tag(target)
+def set_leaf(ct: 'ConfigTree', path: list) -> None:
+ from vyos.xml_ref import is_leaf
+ if is_leaf(path):
+ ct.set_leaf(path, True)
+
def parse_commands(cmds: str) -> dict:
from re import split as re_split
from shlex import split as shlex_split