了解定义 Junos OS 配置的 YANG 模块
瞻博网络使用 YANG 模型发布 Junos OS 配置方案。在 Junos OS 17.3 及更低版本中,Junos OS 配置方案在单个 YANG 模块中发布。从 Junos OS 17.4R1 版开始,Junos OS 配置方案将使用根配置模块发布,该模块由多个较小的模块增强。这使得方案使用者能够仅导入任务所需的模块。
从 Junos OS 17.4R1 版开始,Junos OS YANG 模块对模块的名称、文件名和命名空间使用新的命名约定。有关更多信息,请参阅 了解 Junos YANG 模块。
root 配置模块包括顶级配置节点和未作为单独模块发出的任何节点。针对不同的配置语句层次结构,单独的小型模块扩充根配置模块。增强根模块的配置模块包含配置语句层次结构级别的方案,如模块的名称、文件名和命名空间所示。
以下示例显示了模块的一部分,其中包含层次结构的 [edit interfaces] YANG 模型:
/*
* Copyright (c) 2017 Juniper Networks, Inc.
* All rights reserved.
*/
module junos-conf-interfaces {
namespace "http://yang.juniper.net/junos/conf/interfaces";
prefix jc-interfaces;
import junos-common-types {
prefix jt;
}
import junos-conf-root {
prefix jc;
}
organization "Juniper Networks, Inc.";
contact "yang-support@juniper.net";
description "Junos interfaces configuration module";
revision 2017-01-01 {
description "Junos: 17.4R1.17";
}
augment /jc:configuration {
uses interfaces-group;
}
augment /jc:configuration/jc:groups {
uses interfaces-group;
}
...
YANG 公用事业只需导入手头特定配置任务所需的模块。因此,与导入单个大型模块相比,使用配置模块的工具在模块上编译、验证或执行其他功能所需的时间更少。
要确定与配置特定区域对应的配置 YANG 模块,请show | display detail发出配置模式命令。在以下示例中,junos-conf-protocols@2017-01-01.yang 模块中包含层次结构级别的方案[edit protocols ospf]。
user@host# show protocols ospf | display detail ## ## ospf: OSPF configuration ## YANG module: junos-conf-protocols@2017-01-01.yang ## lsa-refresh-interval: LSA refresh interval (minutes) ## range: 25 .. 50 ## ## default: 50 ## ...
您可以从瞻博网络下载站点或瞻博网络 YANG GitHub 存储库中下载 Junos OS YANG 模块,也可以在本地设备上生成这些模块。要在本地设备上生成配置模块,请发出 show system schema format yang module module 命令。Junos OS 版本决定了可用的命令选项。
-
在 Junos OS 17.3 及更低版本中,指定
configuration模块。user@host> show system schema format yang module configuration
-
在 Junos OS 17.4 及更高版本中,指定单个模块名称以返回单个配置模块,或指定
all-conf以返回所有配置模块。user@host> show system schema format yang module all-conf output-directory /var/tmp/yang
从 Junos OS 19.1R2 和 19.2R1 版开始,
show system schema命令必须包含output-directory命令选项并指定生成一个或多个文件的目录。在早期版本中,当请求单个模块以标准输出显示模块时,可以省略output-directory选项。
要通过远程会话生成模块,请使用适当的选项执行 <get-yang-schema> Junos OS RPC 或 <get-schema> 网络配置协议 (NETCONF) 操作。
如果指定 module configuration 或 module all-conf,则输出文件既包括本机 Junos OS 配置模块,也包括已添加到设备中的任何标准或自定义配置模块。
从 Junos OS 17.4R1 版开始,本地设备上生成的本机 YANG 模块包含特定于家族的模式,这些模式在给定设备系列中的所有设备上都是相同的。在早期版本中,生成的模块包含特定于设备的方案。要生成 Junos OS 17.4R1 及更高版本的设备特定模块,请在device-specific[edit system services netconf yang-modules]层次结构级别配置配置语句。
show system schema 命令必须包含
output-directory 命令选项并指定生成一个或多个文件的目录。