[英]Yang Modeling Set a Field Based on Another Field
I am writing a Yang model. 我正在写一个杨模型。 Is there away to set a leaf (string or enumeration) with a value based on another field. 是否可以使用基于另一个字段的值设置叶子(字符串或枚举)。 So for example, I want to say if x then field a value is b, if z then field a value is c. 因此,例如,我想说如果x则字段值是b,如果z则字段值是c。
Edit: I am new to yang and still trying to learn it, if there are any other ideas or operators I can use to solve this issue please do not hesitate to share. 编辑:我是杨新手,仍在尝试学习它,如果有任何其他想法或操作员可以用来解决此问题,请随时分享。 :D Thank you very much. :D非常感谢你。
You can use when
and must
constructs: YANG 1.1, Section 7.5.3 says: 您可以使用when
且must
构造: YANG 1.1,第7.5.3节说:
The must statement, which is optional, takes as an argument a string that contains an XPath expression (see Section 6.4). must语句(是可选的)将包含XPath表达式的字符串作为参数(请参见6.4节)。 It is used to formally declare a constraint on valid data. 它用于正式声明对有效数据的约束。 The constraintis enforced according to the rules in Section 8. 该约束是根据第8节中的规则执行的。
And Section 7.5.4.3 lays it out: 7.5.4.3节列出了这一点:
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, 关于when
, 第7.21.5节显示为:
The when statement makes its parent data definition statement conditional. when语句使它的父数据定义语句成为条件语句。 The node defined by the parent data definition statement is only valid when the condition specified by the when statement is satisfied. 仅当满足when语句指定的条件时,父数据定义语句定义的节点才有效。 The statement's argument is an XPath expression (see Section 6.4), which is used to formally specify this condition. 该语句的参数是XPath表达式(请参见6.4节),用于正式指定此条件。
ConfD provides a tutorial on XPath in NETCONF and YANG ; ConfD 在NETCONF和YANG中提供了关于XPath的教程; this examples comes out of it: 这个例子出来了:
augment /system/login/user {
when “class != ’wheel’”;
leaf uid {
type uint16 {
range “1000 .. 30000”;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.