How to access list entry using confd_cmd if the key is identityref?

Here is fragment of yang data model (from ietf-routing.yang):

container control-plane-protocols {
list control-plane-protocol {
key “type name”;
leaf type {
type identityref {
base control-plane-protocol;
}
}
leaf name {
type string;
}
. . .

I populated the model using confd_cli and I see there is one element in the list:

$ confd_cmd -c “traverse_list_keys /routing/control-plane-protocols/control-plane-protocol”
path: </routing/control-plane-protocols/control-plane-protocol>
expr: <(null)>
secondary-index: <(null)>
1: idref<1504445999> myProto

Now, how can I access that element using confd_cmd:

$ confd_cmd -c “get /routing/control-plane-protocols/control-plane-protocol{1504445999 myProto}/name”
FAILED: cdb_get(cs, &val, argv[0]), Error: badly formatted or nonexistent path (8): Bad path </routing/control-plane-protocols/control-plane-protocol{1504445999>, in function do_cdb_get, line 334

$ confd_cmd -c “get /routing/control-plane-protocols/control-plane-protocol{1504445999 “myProto”}/name”
FAILED: cdb_get(cs, &val, argv[0]), Error: badly formatted or nonexistent path (8): Bad path </routing/control-plane-protocols/control-plane-protocol{1504445999>, in function do_cdb_get, line 334

Try this (works if your key is the identityref (not the double key): This get command needs a unique leaf node target. If the name is also a key, I don’t think this will work, but if the identifyref is the only key, it will.

$ confd_cmd -c “get /routing/control-plane-protocols/control-plane-protocol{myProto}/name”

Thanks for the answer, but as you can see from yang data model fragment the key of the control-plane-protocol list consists of 2 references to type (which is identityref) and name (which is string). Effectively it’s double key.
So, no, your suggestion does not work.

Hi,
Try something like:

$ confd_cmd -c 'mcreate "/control-plane-protocols/control-plane-protocol{routing-protocol some-name}"'
$ confd_cmd -c 'mget "/control-plane-protocols/control-plane-protocol{routing-protocol some-name}/type"'
rt:routing-protocol
$ confd_cmd -c 'mget "/control-plane-protocols/control-plane-protocol{routing-protocol some-name}/name"'
some-name
$ confd_cmd -c 'get "/control-plane-protocols/control-plane-protocol{routing-protocol some-name}/name"'
some-name
If $ confd_cmd -c 'get "/control-plane-protocols/control-plane-protocol{routing-protocol some-name}/type"'
rt:routing-protocol

I didn’t realize that confd_cmd requires quotes in quotes.
Thank you very much for the help.

It looks like you wanted to know the values of the keys first before you use the “get” commands. This is why you do a “traverse_list_keys” first right?

The “get” command needs to have the string representation of the “identityref” key.

The identityref type is special in that it needs the schema to be loaded by the library if you want to get the string value. Otherwise you will get something like idref, when you issue a “traverse_list_keys”, which can’t be used in the get commands.

I was able to modify the program confd_cmd.c to load the schema, just for this case.
You can do the same, and you will be able to get the two keys as an output when you issue the “traverse_list_keys” command.

You can modify confd_cmd to add the flag that results in loading the schema.

Search and replace:

{
    "traverse_list_keys", {NULL}, do_traverse_list_keys, -1,
    CMD_MAAPI|CMD_WANT_SCHEMA, "<path> [<xpathexpr>]", NULL
},