ConfD User Community

How to traverse a list with leaf as a key element

Hi

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]";
          }
          description
           "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;
     maapi_get_next(&mc))
{
     // printf ("Data[%d]: %s\n", i++, CONFD_GET_CBUFPTR(&mc.keys[0])); 
}

maapi_destroy_cursor(&mc);

Your suggestion Helped. Thanks