From e8434e64bada81aabed2cfe614d64cd213110984 Mon Sep 17 00:00:00 2001 From: Christian Breunig Date: Tue, 28 Apr 2026 16:44:28 +0200 Subject: 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 --- python/vyos/utils/config.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'python') 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 -- cgit v1.2.3