I am trying to write must statement to restrict the instance-identifier, if ref is for instance of “/container/foo”, range should be from 1 to 100, if ref is for instance of “/ifs/if”, range should be from 101 to 200.
I am not sure how to write the must statement in container test below.
yang example:
container ifs {
list if {
key “name”;
leaf name {
type string;
}
}
}
container foo {
list bar {
key “name”;
leaf name {
type string;
}
}
}
container test {
/if ref is for instance of “/container/foo”, range should be from 1 to 100./
/if ref is for instance of “/ifs/if”, range should be from 101 to 200./
must “??” {}
error-message;
}
leaf ref {
type instance-identifier;
}
leaf range {
type uint32;
}
}
thanks, it works. thanks for helping on this, with tailf:annotate statement, there is a clear approach to have such validation logic yang model without polluting the original data model.
btw:do we have some typical use cases of using xpath for must statement? I don’t have much more knowledge on it.
The use of must statements in YANG models are very common. For example, it is being used in an IETF standardized YANG model called ietf-system.yang which is part of the linuxcfg example in the ConfD distribution.
if the case is instance-identifier to point to a deep path, which more list data node in that path (e.g. /foo/bar[name=n1]/bar2[name=n2]/bar3[name=n3]), I guess there is no way to use regex function from xpath 1.0 to match that path.
I know we have valdation callpoint can help on this, if it is can be done in yang model it could be better.