简体   繁体   English

如何将列表从一个模块增加到另一个模块并添加叶子 YANG

[英]How to augment list from one module to another and add leafs YANG

Suppose I have two modules, I would like to extend one list with new leafs.假设我有两个模块,我想用新的叶子扩展一个列表。

module A {
    list deviceList {
        key name;
        leaf name{

        }
        leaf hostname{

        }
    }
}

and I would like to augment it to another leaf我想把它增加到另一片叶子上

module B {
    list generalInfo{
        key customerName;
        leaf customerName{
            type string;
        }
        augment moduleA:deviceList {
            leaf ipAddress{
                
            }
        }
}

I have done it using grouping and container and list inside but this completely changes our existing structure, I would like to ommit container and grouping if thats possible.我已经使用分组和容器和列表完成了它,但这完全改变了我们现有的结构,如果可能的话,我想省略容器和分组。

It seems that you want to reuse a part of the schema definition, put it in another place in the schema tree and add a node to it.似乎您想重用架构定义的一部分,将其放在架构树中的另一个位置并向其添加一个节点。

You cannot do it the way you tried because the augment statement can appear only on the root level or in the uses statement.您不能按照您尝试的方式进行操作,因为augment语句只能出现在根级别或uses语句中。

You can do that only with a grouping but you can omit the container .您只能使用grouping来做到这一点,但您可以省略container Refactor A: define a grouping that's a list .重构 A:定义一个listgrouping Refer to it in B and augment it.在 B 中引用它并对其进行扩充。

module A {
    grouping devices {
      list deviceList {
        key name;
        leaf name{
        }
        leaf hostname{
        }
      }
    }
    uses devices;
}

module B {
    list generalInfo{
        key customerName;
        leaf customerName{
            type string;
        }
        uses moduleA:devices {
          augment "deviceList" {
            leaf ipAddress{
            }
          }
        }
    }
}

Note that if you use the augment statement in the module B then it means that any device implementing module B has to also implement module A and its root-level list deviceList .请注意,如果您在模块 B 中使用augment语句,则意味着实现模块 B 的任何设备还必须实现模块 A 及其根级list deviceList See RFC 7950 4.2.8 :请参阅RFC 7950 4.2.8

When a server implements a module containing an "augment" statement, that implies that the server's implementation of the augmented module contains the additional nodes.当服务器实现包含“增强”语句的模块时,这意味着服务器对增强模块的实现包含附加节点。

I am not sure if this is what you want.我不确定这是否是您想要的。 If not, then move the grouping definition to a module that contains only grouping definitions (without any "data definition statements") and import it from both A and B.如果没有,则将分组定义移动到仅包含分组定义(没有任何“数据定义语句”)的模块,并从 A 和 B 中导入它。

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

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