ConfD User Community

How to traverse a list with leaf as a key element


I would like to traverse a list and print the key values using index like
management_interfaces [0] = “abc”
management_interfaces [1] = “def”’

  list management_interface_list {
        key "management_interfaces";
        description "Management Interfaces.";
        leaf management_interfaces {
          type string{
            pattern "ip-(1|200)/(0|COM)/0/LCN[1-2]";
           "Incoming interface for address translation,
            Can be of either LCN1 or LCN2 interface.";

How shall i do it.?
example using confd_cmd maapi_get also fine
can anyone help here

Assuming you already have a maapi socket and transaction handle, you can use combination of maapi_init_cursor() and maapi_get_next()

Something like

struct maapi_cursor mc;

maapi_init_cursor(ms, thandle, &mc, "/path/to/list");
int i;

for (maapi_get_next(&mc), i = 0; 
     mc.n > 0;
     // printf ("Data[%d]: %s\n", i++, CONFD_GET_CBUFPTR(&mc.keys[0])); 


Your suggestion Helped. Thanks