summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2022-02-23 14:32:02 -0600
committerJohn Estabrook <jestabro@vyos.io>2022-04-21 12:08:03 -0500
commit2d37aa4240447b0ee052fec637fd9a7cd5ec915b (patch)
tree89ab7ce326551e0103d076e57f3ae6eef6152cdb
parent572f5ca5e4d265e4f1e70bbad83972004aa000d7 (diff)
downloadvyos1x-config-2d37aa4240447b0ee052fec637fd9a7cd5ec915b.tar.gz
vyos1x-config-2d37aa4240447b0ee052fec637fd9a7cd5ec915b.zip
T4235: add utility function get_subtree
(cherry picked from commit 23173c6b5d12e5b7990fafe2b43d40f5cbf1a2a5)
-rw-r--r--src/config_tree.ml9
-rw-r--r--src/config_tree.mli2
2 files changed, 11 insertions, 0 deletions
diff --git a/src/config_tree.ml b/src/config_tree.ml
index 6ae7ad2..3e97e80 100644
--- a/src/config_tree.ml
+++ b/src/config_tree.ml
@@ -101,6 +101,15 @@ let is_tag node path =
let data = Vytree.get_data node path in
data.tag
+let get_subtree ?(with_node=false) node path =
+ try
+ let n = Vytree.get node path in
+ if with_node then
+ Vytree.make_full default_data "root" [n]
+ else
+ Vytree.make_full default_data "root" (Vytree.children_of_node n)
+ with Vytree.Nonexistent_path -> make "root"
+
module Renderer =
struct
(* Rendering configs as set commands *)
diff --git a/src/config_tree.mli b/src/config_tree.mli
index cf94af7..5375c23 100644
--- a/src/config_tree.mli
+++ b/src/config_tree.mli
@@ -34,6 +34,8 @@ val set_tag : t -> string list -> bool -> t
val is_tag : t -> string list -> bool
+val get_subtree : ?with_node:bool -> t -> string list -> t
+
val render_commands : ?op:command -> t -> string list -> string
val render_config : t -> string