# How to map leafref element type in init.xml

**URL:** <https://dmap-community.ductus.global/t/how-to-map-leafref-element-type-in-init-xml/106>\
**Category:** CDB and CDB API\
**Created:** [June 5, 2015, 1:04am UTC](https://dmap-community.ductus.global/t/how-to-map-leafref-element-type-in-init-xml/106 "2015-06-05T01:04:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alext](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@alext](https://dmap-community.ductus.global/u/alext)\
**Post date:** [June 5, 2015, 1:04am UTC](https://dmap-community.ductus.global/t/how-to-map-leafref-element-type-in-init-xml/106/1 "2015-06-05T01:04:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![waitai](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/waitai/32/436_2.png) [@waitai](https://dmap-community.ductus.global/u/waitai)\
**Post date:** [June 5, 2015, 6:40am UTC](https://dmap-community.ductus.global/t/how-to-map-leafref-element-type-in-init-xml/106/2 "2015-06-05T06:40:52Z")

</div>

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:

```
<pool>test</pool>

```

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

---

<div class="post-metadata">

**Author:** ![jlawitzke](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/jlawitzke/32/54_2.png) [@jlawitzke](https://dmap-community.ductus.global/u/jlawitzke)\
**Post date:** [June 5, 2015, 1:50pm UTC](https://dmap-community.ductus.global/t/how-to-map-leafref-element-type-in-init-xml/106/3 "2015-06-05T13:50:30Z")

</div>

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 127.0.0.1 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="http://tail-f.com/ns/config/1.0">
  <dhcp xmlns="http://tail-f.com/ns/example/dhcpd">
    <defaultLeaseTime>PT1200S</defaultLeaseTime>
    <maxLeaseTime>PT6000S</maxLeaseTime>
    <logFacility>kern</logFacility>
  </dhcp>
</config>
```

---

<div class="post-metadata">

**Author:** ![bizhu](https://avatars.discourse-cdn.com/v4/letter/b/3da27b/32.png) [@bizhu](https://dmap-community.ductus.global/u/bizhu)\
**Post date:** [July 10, 2015, 3:28pm UTC](https://dmap-community.ductus.global/t/how-to-map-leafref-element-type-in-init-xml/106/4 "2015-07-10T15:28:38Z")

</div>

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?

Thanks!

---

<div class="post-metadata">

**Author:** ![nabil](https://avatars.discourse-cdn.com/v4/letter/n/e79b87/32.png) [@nabil](https://dmap-community.ductus.global/u/nabil)\
**Post date:** [July 10, 2015, 6:55pm UTC](https://dmap-community.ductus.global/t/how-to-map-leafref-element-type-in-init-xml/106/5 "2015-07-10T18:55:00Z")

</div>

Hi bizhu,

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

Ex:

> 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).
