Table of Contents
YANG is a data-model language defined by the IETF to model:
- The device configuration known as configuration data (writable data)
- The operational state known as state data (read-only status)
YANG determines the structure and syntax of the data.
The data model written in YANG are defined in YANG modules.
YANG modules can be categorized as:
- IETF defined YANG modules. Example: https://tools.ietf.org/html/draft-ietf-ospf-yang-29
- OpenConfig defined YANG modules. Published on https://github.com/openconfig/public/tree/master/release/models
- Network vendor defined YANG modules. Example: EOS data models https://github.com/aristanetworks/yang
YANG RFCs:
- https://tools.ietf.org/html/rfc6020 (YANG)
- https://tools.ietf.org/html/rfc7950 (YANG 1.1)
Before to use Pyang or gNMIc, let's get some YANG modules.
The YANG modules defined by OpenConfig are published on this repository https://github.com/openconfig/public/tree/master/release/models
Let's copy all the YANG files from the OpenConfig repository to a local directory
mkdir yang_modules
git clone https://github.com/openconfig/public.git
cp public/release/models/*.yang yang_modules/.
cp -R public/release/models/*/*.yang yang_modules/.
cp public/third_party/ietf/*.yang yang_modules/.
cd yang_modules/
ls
We can use Pyang to generate a tree representation of YANG models for quick visualization.
Install Pyang on your automation setup
pip install pyang
pip list
ls -l /home/arista/.local/bin/
echo $PATH
echo $HOME
export PATH="$HOME/.local/bin:$PATH"
echo $PATH
pyang source code https://github.com/mbj4668/pyang
pyang openconfig-interfaces.yang -f tree
pyang openconfig-interfaces.yang -f tree --tree-path=/interfaces/interface/state
pyang openconfig-interfaces.yang -f tree --tree-depth=4
gNMIc is a gNMI client.
It can also be used to generate paths and tree representation from YANG modules.
Install gNMIc on your automation setup
bash -c "$(curl -sL https://get-gnmic.kmrd.dev)"
gnmic version
gnmic help
gNMIc documentation https://gnmic.kmrd.dev/
gNMIc source code https://github.com/karimra/gnmic
gnmic generate path --file openconfig-interfaces.yang --state-only
gnmic generate path --file openconfig-interfaces.yang --types
gnmic generate --file openconfig-interfaces.yang
gnmic generate --file openconfig-interfaces.yang --json