phani
October 24, 2017, 6:15pm
1
Hi,
I have a model like list a { leafref b {type string } } . Whenever a value is added under one of the list entry a in leafref list, need to check this new value should not present across all list entry’s of a’s leafrefs. Is this possible to achieve through must constraint.
Thanks
Phani
Hi,
this can be done also without must statement - using YANG’ s “unique” statement in list:
list a {
key "something";
unique "b";
leaf b {
type leafref { ... }
}
}
(see e.g. https://tools.ietf.org/html/rfc7950#section-7.8.3 )
If you really need need to use statement, you can do something like this:
list a {
key "something";
leaf b {
must "count(../../a[b=current()]) == 1";
type leafref { ... }
}
}
(number of all the list “a” entries that have value b equal to “b” being validated, must be equal to 1)
phani
October 27, 2017, 11:39am
3
Hi Joseph,
Thanks for the reply. It was small mistake in the above question. leaf b is leaf-list b. model goes as follows.
list a {
key "something";
leaf-list b {
type string; --- This string needs to be unique across all list's leaf list.
}
}
Thanks
Phani