want to get clarity on the following:
say, (omitting key for brevity)
list l1 {
leaf lx {
leafref /x/y;
require-instance false;
mandatory false;
}
}
- because mandatory is false, I can have a l1 instance without the leaf lx.
- because require-instance is false, i can have a list instance with lx of any value (of valid type) whether a corresponding /x/y exists or not.
And, suppose the leaf is mandatory;
list l1 {
leaf lx {
leafref /x/y;
require-instance false;
mandatory true;
}
}
now, list instance must carry the leaf lx. And any value (of correct type) is valid because require-instance is false.
correct ?
when should I use this facility ?
If
require-instance
is set tofalse
then the value space of theleafref
node is the same as the value space of the referred node. This may be useful if the value space of the referred node is particulary complex, has lots of restrictions etc. So, basically, module creators can reuse what they have defined earlier.If
require-instance
is set totrue
(or omitted) then when there are no leaf instances that specify the value-space of aleafref
node then it's value space is empty. Thus, you cannot create a valid instance of aleafref
node because there are no possible values for it.Below is the relevant part of the YANG 1.1 RFC 7950:
and a fragment about the
require-instance
statement:IMHO this part of the YANG 1.1 RFC 7950 is a bit misleading. First, it says that the value space of the referring node is the value space of the referred node but later on it says that there is an instance existence restriction by default. This means that, by default, the value space od the referring node is a set of leaf instance values of the referred node and not the complete value space of that node.