简体   繁体   English

杨建模基于另一个场设置一个场

[英]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: 您可以使用whenmust构造: 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.

相关问题 Logstash字段拆分并合并 - Logstash Field split and merge 哪个语句用于关联YANG数据模型中的子模块和父模块? - Which statement is used to associate a submodule and a parent module in a YANG data model? CCNA 问题:IEEE 802.1Q 中字段标识帧中的6 个字节由哪些字段组成? - CCNA Question: What field is consisted of 6 bytes in the field identification frame in IEEE 802.1Q? 带有数字的JSON.NET字段名称? - JSON.NET field names with numbers? 基于 EVE-NG QEMU 的节点未启动 - EVE-NG QEMU based nodes are not starting 请求模块,“发生异常:TypeError 'set' object is not callable” - Requests module, “Exception has occured:TypeError 'set' object is not callable” Netmiko 的 send_config_set() 中的进度条 - Progress bar in Netmiko's send_config_set() 使用Python Exscript需要为cisco开关创建set_prompt()的正则表达式 - Using Python Exscript need to create regular expression for set_prompt() for cisco switch 我们是否可以将QoS(服务质量)的非推荐值(例如61)设置为DSCP值 - Can we set non recommended values like 61 as DSCP value for QoS (Quality of services) 发送 send_config_set() 时,我不断收到与 Netmiko 相关的此错误,但 send_comand() 有效吗? - I keep geting this error related with Netmiko when sending send_config_set(), but send_comand() works?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM