ConfD User Community

How to create dependency of leaf to another and then allow only those values which are configured on dependent node


#1

Hi Team,

I have one leaf which is dependent on other leaf node(of different grouping) and i want to set its value only if it is configured in dependent leaf node.

ex.

container A{
     leaf x{
         type uint;
     }
}

container B{
    leaf Y{
         type leafref{
           path "../../A/x"
    }

when ,
if x is configured then only allow to set y else y should not set
case 1:

# A  10
# B 10 -> should work

case 2:

#B 10 -> should not work as x do not contain this value

#2

Hello,

if you want to make it conditional - e.g. when you can / cannot create leaf you need a “when” statement in YANG (https://tools.ietf.org/html/rfc6020#section-7.19.5).

YANG snippet:

  container A {
    leaf X { type int32; }
  }

  container B {
    leaf Y {
      when "../../A/X";
      type int32;
    }
  }

CLI behavior on empty database:

  • there’s no leaf X set, Y is not suggested / cannot be configured
dev(config)# B ?
Possible completions:
\<cr>
dev(config)#
dev(config)# B Y 123
---------------^
syntax error: element does not exist
  • let’s add the dependency - X, and now also Y can be configured:
dev(config)# A X 123
dev(config)# B Y ?
Possible completions:
  \<int>
dev(config)# B ?
Possible completions:
  Y
dev(config)# B Y 456

#3

No I wanted whatever value i give to Y it should be acceptable only when X has that value . , This dependency can be achieved via leafref .

Thanks for the support.

One quick question, is there any error message i can put in leafref if not statisfied . Currently it is showing me “syntax error: unknown argument”. I want to change this message