How to find uuid of a list with another unique item

Hi folks,

Im trying to set values of a list with maapi_set_elem2. But to able to set a value i have to know its uuid. But unfortunately in my case im not aware of uuid of subnet.

In the below case i know that the subnet2 uuid is available. so i am able to easily set new ‘cidr’ value with the new one.

So ‘cidr’ is unique item here. I would like to find uuid over the cidr item.Because in further details i have set another items under this subnet.

For instance;

Here to set ip-address of the host i need to find its subnet with cidr first.


> (maapi_set_elem2(msock,th,"****","/dhcp/mysubnets/subnets/{%s}/cidr", "**subnet2**")

>   grouping subnet4-list {
>     list subnets {
>       key uuid;
>       unique "net";
>       leaf uuid {
>         type string;
>       }
>       leaf cidr{
>         type inet:ipv4-prefix;
>         mandatory true;
>       }
>    container hosts {
>          list hosts {
>            description "Host grouping.";
>            key uuid;
>           unique "host-label-name";
>           unique "ip-address";
>           unique "host-identifier";
>           leaf uuid {
>             type string;
>           }
>           leaf host-label-name {
>                    etc.....
>            }

Is there any idea for this problem?

Thanks in advance,
Kind regards.

I think you can use maapi_cursor to iterate through list elements and find element with searched cidr.

struct maapi_cursor mc;

Here is sample code form ConfD User Guide (see confd_lib_maapi, search for maapi_init_cursor.

maapi_init_cursor(sock, th, &mc, "/servers/server");
while (mc.n != 0) {
   ... do something

Thanks for the sample, its good one. i thought iterate over the subnets as you said but i will have to many entry(thousands) in every time i need to search over the subnets

In that case you may try maapi_xpath_eval function. Example can be found in examples.confd/intro/12-c_maapi/maapi_example.c.

1 Like