configurationrfcyangnetconf

Yang constraint (unique)


I want to add a constraint in the following way: efg.yang has the following structure:

module efg {
  container deps {
    container my-deps {
      list my-dp {
        key "key-dp";
        leaf key-dp {
          type string;
        }
        
        list high-bw {
          type boolean;
        }
        // ... other leaf definitions ...
      }
    }
  }
}

I want the list 'my-dp' to be able to exist even when 'high-bw' is an empty. But, if at least one 'high-bw' exists, then 'my-dp' instance should not be allowed to be deleted. How do I achieve this?

I tried adding a must constraint: must "(count(high-bw)=>1 and key-dp) or (count(high-bw)=0)". It did not satisfy my requirement.


Solution

  • There's no constraint in YANG that would make a configuration tree become "read only" or "locked for changes" at runtime (based on data node state).

    The best YANG can do is to require a certain number of list entries to always exist (min-elements). It can also define an XPath assertion to fail after list entry removal has already been performed (must).

    Perhaps what you really wanted to do is to define two sibling lists, where the second list's key is a leafref to the first list's key. This way the an instance of a first list entry can exist in its own, but an instance of a second list entry would require an instance of the first list entry.