cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2247
Views
5
Helpful
1
Replies

Making leaf node Conditional mandatory in yang

Hi,

I am trying to make a leaf node as conditional mandatory as explained below.

 

list top-list {

   leaf type {

     description "type.";
     mandatory true;
     type network-type; /// this type has 3 values i.e local/remote/gr-remote

    }

   leaf node {

     description "Node details.";

     type leafref { 

      path /// -- some reference 

     }

     mandatory true; 

     when "../type = 'local'";

   }

}

 

Now here, the ask is to have node as mandatory when type is local and optional when type is gr-remote and not allowed when type is local. 

I am able to make both local & gr-remote as either mandatory or option via using "when" but not able to make leaf "node" as mandatory when type  is "local" and optional when type is "gr-remote". 

 

Any leads on this would be helpful. 

Thank in advance.

 

Regards

Nikhil

1 Reply 1

Alexander Stevenson
Cisco Employee
Cisco Employee

 

Hi @nikhilagarwal.85,

I see that no YANG experts have commented so I'll make a suggestion. You might want to try the 'refine' statement and/or the 'default' sub-statement as described in these two StackOverflow discussions:

 

 

Hope this helps!