Starting from the sysrepo example yang model, I added a simple representation of a wifi scan which I'd like to write to the operational datastore.
container scan {
config false;
list bss {
key "bssid";
leaf ssid { type string; }
leaf bssid { type string; }
leaf channel { type uint32; }
leaf frequency { type uint32; }
leaf chan_width { type int16; }
leaf signal_strength { type int16; }
}
}
The sysrepo example callback uses libyang calls to set simple single valued fields. Using libyang, how do I create the keyed list nodes?
I have tried using lyd_new_path() as in the example.
const char *s = "{\"bss\":[{\"bssid\":\"00:40:68:aa:bb:cc\",\"chan_width\":0,\"channel\":48,\"frequency\":5240,\"signal_strength\":0,\"ssid\":\"Hello World\"}]}";
err = lyd_new_path(NULL, ly_ctx, "/examples:scan/bss[bssid='00:40:68:aa:bb:cc']", s, 0, parent);
printf("err=%d msg=%s parent=%p\n", err, ly_errmsg(ly_ctx), (void*)*parent);
// no data as a test to see if succeeds (does)
err = lyd_new_path(*parent, ly_ctx, "/examples:scan/bss[bssid='00:40:68:11:22:33']", NULL, 0, NULL);
printf("err=%d msg=%s parent=%p\n", err, ly_errmsg(ly_ctx), (void*)*parent);
lyd_print_path("/tmp/test.json", *parent, LYD_JSON, 0);
The node will be created (err==0) but the resulting node has no additional fields.
{
"examples:scan": {
"bss": [
{
"bssid": "00:40:68:aa:bb:cc"
},
{
"bssid": "00:40:68:11:22:33"
}
]
}
}
If I do not specify the [bssid='...'], I get an error libyang[0]: Predicate missing for list "bss" in path "/examples:scan/bss". (path: Schema location "/examples:scan/bss".)