Manipulating YANG

Introduction to pyang for SR OS


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.

Tutorial requirements

  • Access to a Linux server/workstation with pyang installed 
  • The Nokia SR OS YANG models (these can be downloaded, please see the resources page)

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.

ASCII tree representation

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 . nokia-combined/nokia-conf-combined.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.

Navigable Javascript Tree

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 . nokia-combined/nokia-conf-combined.yang > /tmp/nokia-conf-combined.html

This creates the HTML file in /tmp/nokia-conf-combined.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 . nokia-combined/nokia-*-combined.yang > /tmp/nokia-combined.html