summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libvyosconfig/lib/bindings.ml8
-rw-r--r--python/vyos/configtree.py14
2 files changed, 22 insertions, 0 deletions
diff --git a/libvyosconfig/lib/bindings.ml b/libvyosconfig/lib/bindings.ml
index 2b222fb0b..64d22f21e 100644
--- a/libvyosconfig/lib/bindings.ml
+++ b/libvyosconfig/lib/bindings.ml
@@ -179,6 +179,13 @@ let exists c_ptr path =
let path = split_on_whitespace path in
if (Vytree.exists ct path) then 1 else 0
+let value_exists c_ptr path value =
+ let ct = Root.get c_ptr in
+ let path = split_on_whitespace path in
+ try
+ if (CT.value_exists ct path value) then 1 else 0
+ with VT.Empty_path -> 0
+
let list_nodes c_ptr path =
let ct = Root.get c_ptr in
let path = split_on_whitespace path in
@@ -325,6 +332,7 @@ struct
let () = I.internal "is_leaf" ((ptr void) @-> string @-> returning bool) is_leaf
let () = I.internal "get_subtree" ((ptr void) @-> string @-> bool @-> returning (ptr void)) get_subtree
let () = I.internal "exists" ((ptr void) @-> string @-> returning int) exists
+ let () = I.internal "value_exists" ((ptr void) @-> string @-> string @-> returning int) value_exists
let () = I.internal "list_nodes" ((ptr void) @-> string @-> returning string) list_nodes
let () = I.internal "return_value" ((ptr void) @-> string @-> returning string) return_value
let () = I.internal "return_values" ((ptr void) @-> string @-> returning string) return_values
diff --git a/python/vyos/configtree.py b/python/vyos/configtree.py
index aeeb329c5..21b37e638 100644
--- a/python/vyos/configtree.py
+++ b/python/vyos/configtree.py
@@ -145,6 +145,10 @@ class ConfigTree(object):
self.__exists.argtypes = [c_void_p, c_char_p]
self.__exists.restype = c_int
+ self.__value_exists = self.__lib.value_exists
+ self.__value_exists.argtypes = [c_void_p, c_char_p, c_char_p]
+ self.__value_exists.restype = c_int
+
self.__list_nodes = self.__lib.list_nodes
self.__list_nodes.argtypes = [c_void_p, c_char_p]
self.__list_nodes.restype = c_char_p
@@ -361,6 +365,16 @@ class ConfigTree(object):
else:
return True
+ def value_exists(self, path, value):
+ check_path(path)
+ path_str = ' '.join(map(str, path)).encode()
+
+ res = self.__value_exists(self.__config, path_str, value)
+ if res == 0:
+ return False
+ else:
+ return True
+
def list_nodes(self, path, path_must_exist=True):
check_path(path)
path_str = ' '.join(map(str, path)).encode()