pyang is an open source tool. pyang has become the de facto standard for YANG model compilation.
This article does not cover how to use pyang in detail as there are plenty of good tutorials available on the Internet. This article does provide a small number of examples that can be used to compile the Nokia SR OS YANG models and display the information in various formats.
No SR OS device is required.
All examples use the nokia-combined YANG models. For more details about the YANG models delivered with SR OS see the developer portal.
One of the simplest and most useful outputs from pyang is the ASCII tree representation of the YANG model.
From the YANG directory containing the unpacked SR OS YANG modules enter the following command:
pyang -f tree -p ./:./ietf/ nokia-combined/nokia-conf.yang
This provides output similar to the following:
module: nokia-conf
+--rw configure
+--rw aaa
| +--rw apply-groups* -> ../../groups/group/name
| +--rw radius
| | +--rw coa-port? inet:port-number
| | +--rw acct-on-off-group* [name]
| | | +--rw name types-sros:named-item
| | | +--rw description? types-sros:description
| | | +--rw apply-groups* -> ../../../../groups/group/name
| | +--rw server-policy* [name]
| | | +--rw name types-sros:named-item
| | | +--rw description? types-sros:description
| | | +--rw python-policy? -> ../../../../python/python-policy/name
| | | +--rw apply-groups* -> ../../../../groups/group/name
Generating the ASCII tree for any other YANG model is exactly the same. Pyang also allows you to add wildcards and multiple YANG files into the command and generate all described trees.
Probably one of the most useful output formats of pyang is the Javascript Tree (or jstree) because this generates a Javascript driven webpage that can be used to browse through the YANG models, collapsing and expanding branches as required.
To produce this output format, enter the following:
pyang -f jstree -p ./:./ietf/ nokia-combined/nokia-conf.yang > /tmp/nokia-conf.html
This creates the HTML file in /tmp/nokia-conf.html which can be opened in any browser. Pyang also allows you to add wildcards and multiple YANG files into the command and generate all described trees. A useful example of this is to generate the Nokia config and state trees in a single HTML file:
pyang -f jstree -p ./:./ietf/ nokia-combined/nokia-*.yang > /tmp/nokia.html