diff options
author | Daniil Baturin <daniil@vyos.io> | 2025-06-26 15:29:43 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-26 15:29:43 +0100 |
commit | 062f7f4e7cd7d71cba56d168f9f99344e9044b59 (patch) | |
tree | f17a96f9726cdffcb2ef2fab10309f4b313ed8cc /scripts/build-command-op-templates | |
parent | 5c2f70ffd82047740a91be949af5098a6ee39c2c (diff) | |
parent | edc64e7fb63757a3779df12945ecefca9c462952 (diff) | |
download | vyos-1x-062f7f4e7cd7d71cba56d168f9f99344e9044b59.tar.gz vyos-1x-062f7f4e7cd7d71cba56d168f9f99344e9044b59.zip |
Merge pull request #4565 from dmbaturin/T7560-op-virtual-tag-nodes
op-mode: T7560: add support for virtual tag nodes
Diffstat (limited to 'scripts/build-command-op-templates')
-rwxr-xr-x | scripts/build-command-op-templates | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/scripts/build-command-op-templates b/scripts/build-command-op-templates index 9eef25a2f..a2b7c9ddc 100755 --- a/scripts/build-command-op-templates +++ b/scripts/build-command-op-templates @@ -3,7 +3,7 @@ # build-command-template: converts new style command definitions in XML # to the old style (bunch of dirs and node.def's) command templates # -# Copyright (C) 2017-2024 VyOS maintainers <maintainers@vyos.net> +# Copyright (C) 2017-2025 VyOS maintainers <maintainers@vyos.net> # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -30,6 +30,8 @@ import functools from lxml import etree as ET from textwrap import fill +debug = True + # Defaults validator_dir = "/opt/vyatta/libexec/validators" default_constraint_err_msg = "Invalid value" @@ -177,7 +179,13 @@ def process_node(n, tmpl_dir): node_type = n.tag - my_tmpl_dir.append(name) + if name: + my_tmpl_dir.append(name) + else: + # Virtual tag nodes have no names, + # that's a normal situation. + # In that case we create subdirs at the current level. + pass if debug: print(f"Name of the node: {name};\n Created directory: ", end="") @@ -234,6 +242,27 @@ def process_node(n, tmpl_dir): inner_nodes = children.iterfind("*") for inner_n in inner_nodes: process_node(inner_n, my_tmpl_dir) + elif node_type == "virtualTagNode": + # The outer structure is already created + + # Create the inner node.tag part + my_tmpl_dir.append("node.tag") + os.makedirs(make_path(my_tmpl_dir), exist_ok=True) + if debug: + print("Created path for the virtualTagNode: {}".format(make_path(my_tmpl_dir)), end="") + + # Not sure if we want partially defined tag nodes, write the file unconditionally + nodedef_path = os.path.join(make_path(my_tmpl_dir), "node.def") + # Only create the "node.def" file if it exists but is empty, or if it + # does not exist at all. + if not os.path.exists(nodedef_path) or os.path.getsize(nodedef_path) == 0: + with open(nodedef_path, "w") as f: + f.write(make_node_def(props, command)) + + if children is not None: + inner_nodes = children.iterfind("*") + for inner_n in inner_nodes: + process_node(inner_n, my_tmpl_dir) elif node_type == "leafNode": # This is a leaf node if debug: |