diff options
author | John Estabrook <jestabro@vyos.io> | 2025-04-05 22:17:06 -0500 |
---|---|---|
committer | John Estabrook <jestabro@vyos.io> | 2025-04-11 13:36:10 -0500 |
commit | 29785a8aa9ebbb1f821a858b3d8f0379dbd30798 (patch) | |
tree | 9e69fdc408bc7d68c3e16d3e6aac3aeeb35ee4f5 | |
parent | 992c5a2e8941f27843f112020383115bde076d21 (diff) | |
download | vyos1x-config-29785a8aa9ebbb1f821a858b3d8f0379dbd30798.tar.gz vyos1x-config-29785a8aa9ebbb1f821a858b3d8f0379dbd30798.zip |
T7321: add utility needed for validate_tree in vyconfd load config
-rw-r--r-- | src/config_tree.ml | 22 | ||||
-rw-r--r-- | src/config_tree.mli | 2 |
2 files changed, 24 insertions, 0 deletions
diff --git a/src/config_tree.ml b/src/config_tree.ml index 712db2b..4d0f5df 100644 --- a/src/config_tree.ml +++ b/src/config_tree.ml @@ -135,6 +135,28 @@ let get_subtree ?(with_node=false) node path = Vytree.make_full default_data "" (Vytree.children_of_node n) with Vytree.Nonexistent_path -> make "" +let value_paths_of_tree node = + let func ct (p, a) _t = + match p with + | [] -> (p, a) + | _ -> + let q = List.rev p in + if not (Vytree.is_terminal_path ct q) then + (p, a) + else + let vals = get_values ct q in + match vals with + | [] -> (p, q::a) + | _ as vs -> + let a' = + let f acc v = + let q' = q @ [v] in + q'::acc + in List.fold_left f a vs + in (p, a') + in List.rev (snd (Vytree.fold_tree_with_path (func node) ([], []) node)) + + module Renderer = struct (* Rendering configs as set commands *) diff --git a/src/config_tree.mli b/src/config_tree.mli index f24a906..be746a0 100644 --- a/src/config_tree.mli +++ b/src/config_tree.mli @@ -47,6 +47,8 @@ val is_leaf : t -> string list -> bool val get_subtree : ?with_node:bool -> t -> string list -> t +val value_paths_of_tree : t -> string list list + val render_commands : ?op:command -> t -> string list -> string val render_config : ?ord_val:bool -> t -> string |