YINsolidated is a YIN-like representation of a YANG model, consolidated into a single XML file.
While YIN is easier to programmatically consume than YANG, simply because it's XML, it's still just a one-for-one mapping from YANG, which leaves a significant amount of parsing logic up to the consumer. An application that consumes YIN files needs to resolve uses
statements, augment
statements, typedef
s, identityref
s, leafref
s, and more.
YINsolidated takes care of all of that overhead for you, providing you with a single XML file representing your entire model.
- A
pyang
plugin for generating a YINsolidated model from a YANG model consisting of one or more YANG modules - A Python library for parsing the YINsolidated model into an in-memory XML document with convenient YANG-specific methods and properties layered on top of the elements
pip install yinsolidated
To generate a YINsolidated module, you will need to install pyang
separately:
pip install pyang
The YINsolidated plugin will be automatically recognized by pyang
by way of setuptools
entry points, so you simply need to invoke pyang
with the yinsolidated
format:
pyang -f yinsolidated --yinsolidated-output-format=xml -o yinsolidatedModel.xml main-module.yang other-module.yang ...
pyang -f yinsolidated --yinsolidated-output-format=json -o yinsolidatedModel.json main-module.yang other-module.yang ...
NOTE: The main YANG module (the one that includes other submodules or is augmented by other modules) needs to be passed as the first positional argument.
This version of pyang
does not yet have support for the setuptools
entry point, so the path in which the plugin is installed must be explicitly passed to the pyang
command:
$ export PLUGINDIR=`/usr/bin/env python -c \
'import os; from yinsolidated.plugin import plugin; \
print os.path.dirname(plugin.__file__)'`
$ pyang --plugindir $PLUGINDIR -f yinsolidated -o yinsolidatedModel.xml main-module.yang other-module.yang ...
import yinsolidated
model_tree = yinsolidated.parse('yinsolidatedModel.xml')
import yinsolidated
with open('yinsolidatedModel.xml') as model_file:
model_string = model_file.read()
model_tree = yinsolidated.fromstring(model_string)
import yinsolidated
# generated using --yinsolidated-output-format=json
with open('yinsolidatedModel.json') as model_file:
contents = model_file.read()
model_tree = yinsolidated.parse_json(contents)
The YINsolidated XML Format (generated using --yinsolidated-output-format=xml
)
The YINsolidated JSON Format (generated using --yinsolidated-output-format=json
)