You can use when
and must
constructs: YANG 1.1, Section 7.5.3 says:
The must statement, which is optional, takes as an argument a string that contains an XPath expression (see Section 6.4). It is used to formally declare a constraint on valid data. The constraintis enforced according to the rules in Section 8.
And Section 7.5.4.3 lays it out:
container interface {
leaf ifType {
type enumeration {
enum ethernet;
enum atm;
}
}
leaf ifMTU {
type uint32;
}
must 'ifType != "ethernet" or ifMTU = 1500' {
error-message "An Ethernet MTU must be 1500";
}
must 'ifType != "atm" or'
+ ' (ifMTU <= 17966 and ifMTU >= 64)' {
error-message "An ATM MTU must be 64 .. 17966";
}
}
On when
, Section 7.21.5 reads,
The when statement makes its parent data definition statement conditional. The node defined by the parent data definition statement is only valid when the condition specified by the when statement is satisfied. The statement's argument is an XPath expression (see Section 6.4), which is used to formally specify this condition.
ConfD provides a tutorial on XPath in NETCONF and YANG; this examples comes out of it:
augment /system/login/user {
when “class != ’wheel’”;
leaf uid {
type uint16 {
range “1000 .. 30000”;
}
}
}