Skip to content

Commit bcff488

Browse files
committed
T7969: expose boolean test value_exists
1 parent 761968d commit bcff488

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

libvyosconfig/lib/bindings.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,13 @@ let exists c_ptr path =
179179
let path = split_on_whitespace path in
180180
if (Vytree.exists ct path) then 1 else 0
181181

182+
let value_exists c_ptr path value =
183+
let ct = Root.get c_ptr in
184+
let path = split_on_whitespace path in
185+
try
186+
if (CT.value_exists ct path value) then 1 else 0
187+
with VT.Empty_path -> 0
188+
182189
let list_nodes c_ptr path =
183190
let ct = Root.get c_ptr in
184191
let path = split_on_whitespace path in
@@ -325,6 +332,7 @@ struct
325332
let () = I.internal "is_leaf" ((ptr void) @-> string @-> returning bool) is_leaf
326333
let () = I.internal "get_subtree" ((ptr void) @-> string @-> bool @-> returning (ptr void)) get_subtree
327334
let () = I.internal "exists" ((ptr void) @-> string @-> returning int) exists
335+
let () = I.internal "value_exists" ((ptr void) @-> string @-> string @-> returning int) value_exists
328336
let () = I.internal "list_nodes" ((ptr void) @-> string @-> returning string) list_nodes
329337
let () = I.internal "return_value" ((ptr void) @-> string @-> returning string) return_value
330338
let () = I.internal "return_values" ((ptr void) @-> string @-> returning string) return_values

python/vyos/configtree.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ def __init__(
145145
self.__exists.argtypes = [c_void_p, c_char_p]
146146
self.__exists.restype = c_int
147147

148+
self.__value_exists = self.__lib.value_exists
149+
self.__value_exists.argtypes = [c_void_p, c_char_p, c_char_p]
150+
self.__value_exists.restype = c_int
151+
148152
self.__list_nodes = self.__lib.list_nodes
149153
self.__list_nodes.argtypes = [c_void_p, c_char_p]
150154
self.__list_nodes.restype = c_char_p
@@ -361,6 +365,16 @@ def exists(self, path):
361365
else:
362366
return True
363367

368+
def value_exists(self, path, value):
369+
check_path(path)
370+
path_str = ' '.join(map(str, path)).encode()
371+
372+
res = self.__value_exists(self.__config, path_str, value)
373+
if res == 0:
374+
return False
375+
else:
376+
return True
377+
364378
def list_nodes(self, path, path_must_exist=True):
365379
check_path(path)
366380
path_str = ' '.join(map(str, path)).encode()

0 commit comments

Comments
 (0)