简体   繁体   English

杨模型递归搜索的必要条件

[英]Yang Model recursive search for must condition

I have a problem with a restriction on my CLI. 我对CLI的限制存在问题。 I've been investigating yang RFC7950 ( https://tools.ietf.org/html/rfc7950 ) but I've found nothing. 我一直在研究yang RFC7950( https://tools.ietf.org/html/rfc7950 ),但没有发现任何问题。

Here is an example. 这是一个例子。

grouping httpGroup {
  list http-list{
    key "value";
    leaf value {
      status current { yexte:preliminary; }
      description "value to match";
      must "(not(../protocol)) and (not(../network-port)))" {
        error-message "Not compatible with protocol or non-TCP ports";
      }
      type string { length "1..255"; }
    }
  }
}

This group will be included in several groups with the following structure: 该组将包含在具有以下结构的几个组中:

list and {
  leaf-list protocol { ..... }
  uses A;
  list or { 
    leaf-list protocol { ..... }
    uses A;
  }
}
grouping A {
  status{}
  leaf-list protocol { ..... }
  leaf-list X { ..... }
  uses httpGroup;
}

I need this must condition included in httpGroup to verify that protocol value has not been configured in any level of the hierarchy. 我需要这个必须的条件所包含httpGroup验证协议价值尚未在层次结构的任何一级配置。

I've made this be adding more relatives paths to search for this node: 我已经为此添加了更多的亲戚路径来搜索该节点:

// same level
not(../protocol)

// next level
not(../and/protocol)
not(../or/protocol)

// previous level
not(../../protocol)
not(../../protocol)

//recursively down previous level
not(../../and/protocol)
not(../../or/protocol)

// third level
not(../and/or/protocol)
not(../and/and/protocol)

As you can see, this is not a clean solution at all. 如您所见,这根本不是一个干净的解决方案。

Is there any way it can be done for a whole hierarchy like: 有没有办法对整个层次结构进行处理,例如:

if protocol node exists and http-list exists then error.

Thank you in advance. 先感谢您。

Groupings are meant to be reusable. 分组是可重用的。 It is a bad practice to attempt to create a grouping that may only be used in specific contexts. 尝试创建只能在特定上下文中使用的分组是一种不良做法。 This is exactly what happens if you define an XPath expression within a grouping and this expression references nodes that are "outside" this grouping (a not yet known ancestor data node, for example, or even worse - an ancestor with a specific name). 如果您在分组中定义XPath表达式,并且该表达式引用该分组“之外”的节点(例如,尚不知道的祖先数据节点,或更糟糕的是-具有特定名称的祖先),则会发生这种情况。

The proper way for you to handle this situation would be to use a refine statement in each different context where this grouping is used. 处理这种情况的正确方法是在使用此分组的每个不同上下文中使用优化语句。 You target the value leaf with it, then refine it by adding a must statement, the expression of which of course depends on usage context. 您可以用它来定位value叶,然后通过添加must语句对其进行优化,该语句当然取决于使用上下文。 You do not define a must statement within grouping http-list . 没有在分组http-list定义must语句。

Within grouping A : 在分组A

grouping A {
  status{}
  leaf-list protocol { ..... }
  leaf-list X { ..... }
  uses httpGroup {refine "http-list/value" {must "not(../../protocol)";}}
}

As you can see, grouping A is now completely self-sufficient and may be used within any context - the must will not have any problems with it. 如您所见,分组A现在已经完全可以自给自足,可以在任何上下文中使用-必填项不会有任何问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM