简体   繁体   English

如何在杨中导入模块

[英]how to import a module in Yang

I'm trying to build a CLI. 我正在尝试构建一个CLI。 I choose to use 'yang' to do so. 我选择使用“阳”来做。 I'm new to it and can't find out how to import existing moduls. 我是新手,无法找到如何导入现有模块的方法。 As exemple I found a module for ospf on github ( https://github.com/YangModels/yang/blob/master/vendor/cisco/xe/1631/ietf-ospf.yang ) and I would like to import it in my own moduls. 作为示例,我在github( https://github.com/YangModels/yang/blob/master/vendor/cisco/xe/1631/ietf-ospf.yang )上找到了ospf的模块,我想将其导入我的自己的模数。 Can this be done? 能做到吗? how? 怎么样?

EDIT1: 编辑1:

module mininet {

 /* name space */
 namespace "http://tail-f.com/ns/example/mininet";
 prefix mininet;

 import ietf-ospf {
     prefix ospf;
     revision-date 2015-03-09
 }

 leaf area-id-type {
     type yang:area-id-type;
 }
}

So I tried to do it this way using Piotr Babij help. 因此,我尝试使用Piotr Babij帮助进行此操作。 Unfortunately this isn't working. 不幸的是,这不起作用。 What do I need to change? 我需要更改什么? area-id-type is a typedef of ietf-ospf. area-id-type是ietf-ospf的typedef。 The error I have is te following one: 我有以下错误:

mininet.yang:12:3: error: trailing garbage after module
mininet.yang:12:3: error: unterminated statement

You may import other modules in your own modules by using the import statement. 您可以使用import语句在自己的模块中导入其他模块。 It is described in both RFC 7950 for YANG 1.1 and in RFC 6020 for YANG 1.0. 在YANG 1.1的RFC 7950和YANG 1.0的RFC 6020中都有描述。 In YANG 1.1 you may import two different revisions of the same module. 在YANG 1.1中,您可以导入同一模块的两个不同修订版。 Other that that, the import statement works the same in both versions. 除此之外, import语句在两个版本中均相同。

In practice the basic import looks like this: 实际上,基本导入如下所示:

 module acme-system {
     namespace "http://acme.example.com/system";
     prefix "acme";

     import ietf-yang-types {
         prefix "yang";
         revision-date 2013-07-15;
     }

     leaf acme-ip-address {
         type yang:dotted-quad;
     }
 }

If you omit the optional revision-date statement then an undefined module revision is imported. 如果省略可选的revision-date语句,那么将导入未定义的模块修订。 So, in general, it is a good practive to use it. 因此,通常来说,使用它是一个很好的方法。

The mandatory prefix statement lets you to refer to the things in the imported module. 强制prefix语句使您可以引用导入模块中的内容。 In the example the prefix of the imported ietf-yang-types module is yang and, thanks to that, it is clear that yang:dotted-quad refers to a type from that module. 在示例中,导入的ietf-yang-types模块的前缀为yang ,因此,很明显yang:dotted-quad引用了该模块中的类型。 In your case you have set the prefix to ospf , so you should have ospf:area-id-type to refer to a type definition from that module. 在您的情况下,您已将前缀设置为ospf ,因此您应该具有ospf:area-id-type来引用该模块中的类型定义。 If you import multiple modules you need to ensure their prefixes are unique. 如果导入多个模块,则需要确保其前缀是唯一的。

Additionally, you are importing the oldest available revision of the ietf-ospf module. 此外,您正在导入ietf-ospf模块的最旧的可用修订。 I just hope that this is what you really want to do. 我只是希望这是您真正想要做的。

Anyway, once you import a module you are allowed to: 无论如何,一旦导入模块,就可以:

  • use any grouping and typedef defined at the top level in the imported module or its submodules. 使用在导入的模块或其子模块的顶层定义的任何groupingtypedef

  • use any extension , feature , and identity defined in the imported module or its submodules. 使用在导入的模块或其子模块中定义的任何extensionfeatureidentity

  • use any node in the imported module's schema tree in must , path , and when statements, or as the target node in augment and deviation statements. mustpathwhen语句中使用导入的模块的架构树中的任何节点,或在augmentdeviation语句中用作目标节点。

In the above example the typedef dotted-quad from the ietf-yang-types is used in the acme-system module. 在上面的示例中,在acme-system模块中使用了来自ietf-yang-typestypedef dotted-quad ietf-yang-types

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

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