Use Juniper Networks YANG Modules
Juniper Networks provides YANG modules that define the configuration hierarchies and operational commands, as well as YANG extensions, for devices running Junos OS. The following sections detail how to obtain Juniper Networks YANG modules and how to import them into another module:
Obtaining Juniper Networks YANG Modules
To obtain the Junos OS YANG modules, you can:
Download the modules from the Juniper Networks website
Download the modules from the Juniper Networks GitHub repository for YANG
Generate the modules on a device running Junos OS
In Junos OS Release 17.1 and earlier, the YANG modules for the Junos OS configuration and command hierarchies that are posted on the Juniper Networks website define the schema for all devices running that Junos OS release. Starting in Junos OS Release 17.2, Junos OS YANG modules are specific to a device family. The YANG modules download file includes a separate directory for each device family as well as a common directory. Each family-specific directory contains the configuration and operational command modules that are supported on the platforms in that family, and the common directory contains the modules that are common to all device families. For more information about the device families, see Understanding Junos YANG Modules.
When generated on the local device, the YANG modules include both native Junos OS modules as well as any standard or custom modules that have been added to the device. Starting in Junos OS Release 17.4R1, the native YANG modules generated on a local device contain family-specific schemas, which are identical across all devices in the given device family. In Junos OS Release 17.3 and earlier, the native YANG modules generated on the local device contain device-specific schemas.
To download the Juniper Networks YANG modules:
- Access the downloads page at https://www.juniper.net/support/downloads/junos.html.
- Select your product.
- In the drop-down menus, select the appropriate release type and version.
- In the Tools section, click the YANG module link.
To generate the YANG modules from the CLI on a device running Junos OS:
Log in to the device running Junos OS.
Execute the
show system schema
operational mode command and specify the module name, the YANG format, and optionally, include any desired command options.The module names and command options depend on the Junos OS release running on the device.
In Junos OS Release 15.1 and earlier, to save the output to a specific file, include the
output-file-name
option, and specify an absolute or relative path for the output file.user@host> show system schema module module-name format yang output-file-name path
Starting in Junos OS Release 16.1, you can save a module in a specific directory by including the
output-directory
option.user@host> show system schema module module-name format yang output-directory path
Note:Starting in Junos OS Release 19.1R2 and 19.2R1, the
show system schema
command must include theoutput-directory
option to specify the directory in which to generate the output files. In earlier releases, you can omit theoutput-directory
option when requesting a single module to display the module in standard output.In Junos OS Release 16.1 through 17.3, you can specify an alternate name for the module and the filename by including the
module-name
option.user@host> show system schema module module-name format yang output-directory path module-name module-name
Note:In Junos OS Release 17.3 and earlier, you can filter for specific sections of the
configuration
module by including thefilter
command option and specifying which hierarchies to return.
For a detailed list of command options, see show system schema.
To generate the modules from a remote session:
Connect to the device running Junos OS. For example:
user@server$ ssh user@host.example.net -p 830 -s netconf
Execute the
<get-yang-schema>
RPC, and specify the module or collection name, the YANG format, and the output directory.The module names and command options depend on the Junos OS release running on the device.
<rpc> <get-yang-schema> <format>yang</format> <identifier>all-rpc</identifier> <output-directory>/var/home/user</output-directory> </get-yang-schema> </rpc>
Note:Starting in Junos OS Release 19.1R2 and 19.2R1, the
<get-yang-schema>
RPC must include the<output-directory>
element to specify the directory in which to generate the output files. In earlier releases, you can omit theoutput-directory
element when requesting a single module to display the module in standard output.Note:You can also use the
<get-schema>
Network Configuration Protocol (NETCONF) operation to retrieve a YANG module from the device.
Importing Juniper Networks YANG Modules
You can use YANG-based tools to leverage the Juniper Networks YANG modules. If you are developing custom YANG modules, you can reference definitions in the Juniper Networks YANG modules by importing the modules into your custom module.
To import a Juniper Networks YANG module into an existing module: