How to map leafref element type in init.xml

I am trying to create init.xml
One of the leafs is of following format in yang:
leaf pool {
type leafref {
path “/ltm/pool/name”;

What should be the value of this field in the XML?
I tried different options, but I continue to get:
CDB boot error: Init transaction failed to validate: illegal reference /ltm:ltm/virtual{Alex_dns_tcp}/pool

It should be the value of name. Assuming name is a string and it is assigned the value of “test”, then the contents of your init.xml will look like the following:


in which the instance of /ltm/pool/name{test} will need to be present in the init.xml file.

A short cut to creating CDB init files or testing to see what you should put in one is to go into the CLI, set configuration values, and then use the “save” command to save the configuration in XML format to a file. When you save configuration in XML format from the CLI, the resulting saved file can be used as a CDB initialization file.

When doing this to generate an init file, it is best to save at the namespace/YANG module level. For example, in examples.confd/intro/1-2-3-start-query-model, there is the YANG module dhcpd.yang with a top level container called “dhcp”.

admin connected from using console on JLAWITZK-M-R012
JLAWITZK-M-R012# config
Entering configuration mode terminal
JLAWITZK-M-R012(config)# dhcp defaultLeaseTime 1200s
JLAWITZK-M-R012(config)# dhcp maxLeaseTime 6000s
JLAWITZK-M-R012(config)# dhcp logFacility kern
JLAWITZK-M-R012(config)# commit
Commit complete.
JLAWITZK-M-R012(config)# save dhcp_init.xml xml dhcp
Saving parts of the configuration.

$ cat dhcp_init.xml
<config xmlns="">
  <dhcp xmlns="">

What value will I get if I use “cdb_get_str()” on this node?
“test” or “/ltm/pool/name” or “/ltm/pool/name{test}”?

What if leafref points to a path/object (for example “/item/pool” here) instead an end leaf?


Hi bizhu,

The leafref type can only point to a leaf, by definition, the compiler will fail if leafref points to something else.


confdc --fail-on-warnings -c -o test.fxs test.yang
test.yang:197: error: the leafref refers to non-leaf and non-leaf-list node ‘class-map’ at test.yang:836
test.yang:197: error: the leafref refers to non-leaf and non-leaf-list node ‘class-map’ at test.yang:836
make: *** [test.fxs] Error 1

The man page: man confd_lib_cdb gives the information below:

int cdb_get_str(int sock, char *rval, int n, const char *fmt, …);

   Type safe variant of cdb_get() which is used to read string values. If the buffer returned by cdb_get()
   plus a terminating NUL fits into n bytes CONFD_OK is returned and the buffer is copied into *rval (as
   well as a terminating NUL character).

fmt here should point to the leaf of type string that you want to read.
I am assuming “/ltm/pool/name” is of type string, so this should work. It will then return to you the value of name in the 2nd argument (rval).