Leaf Node 'when' or 'must' statement Usage

asked 2017-04-21 05:25:51 -0700

david.roberts7 gravatar image

updated 2017-04-24 05:30:19 -0700

I am in the process of learning ODL and Yang and can't figure out how to put a constraint on a leaf node. I have a leaf node (vpn-id). When the l3vpn-type node equals 'bgp', I want data for this one to be allowed for vpn-id. If the leaf node does not equal 'bgp' and the vpn-id is entered I want to throw an error.

Also, I am having a hard time finding Yang examples so I can teach myself. Suggestions are welcome.

module DaveTest {
     namespace "urn:aaa:ddd:DaveTest";
     prefix dave-module;

     description "Dave testing file";

     revision "2017-04-17" {
          description "Initial version.";
     }

     container testing-vars {

          list test-list {

               key "vpn-transaction-id l3vpn-type";
               unique "vpn-transaction-id";

               leaf vpn-transaction-id {
                    type string;
               }

               leaf l3vpn-type {
                    type enumeration {
                         enum "bgp";
                         enum "static";
                         enum "gre tunnel";
                    }
                    mandatory true;
               }

               leaf vpn-id {
                    when "../l3vpn-type = 'bgp'";
                    type string;
               }
          }              
     }

}

edit retag flag offensive close merge delete