Skip to content
This repository has been archived by the owner on Dec 31, 2021. It is now read-only.
/ yanger Public archive
forked from mbj4668/yanger

Extensible YANG validator

License

Notifications You must be signed in to change notification settings

yarisx/yanger

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

yanger

Extensible YANG validator.

Prerequisites

erlang libxml2-dev

Installation of Yanger on OS X Example

Tested on OS X 10.13.5 (High Sierra)

  1. Install brew package manager (if not present)

  2. Install erlang and coreutils using brew

brew install erlang coreutils

  1. (optional) install lux to verify test cases
##deps
brew update
brew upgrade
brew install erlang coreutils

##make local env
mkdir ~/local
cd ~/local
git clone https://github.com/hawk/lux.git

##export path
export PATH=$PATH:~/local/lux/bin
(put the above in .bash_profile or .profile)

##rebuild to use brew erlang
cd ~/local/lux
./bin/lux --make

##test
./bin/lux examples/intro.lux
  1. git clone yanger and build it, and source the env bash
git clone https://github.com/mbj4668/yanger.git
cd yanger
source env.sh
make

Installation of Yanger using Docker

Checkout this repository (described above) and build the image:

docker build -t mbj4668/yanger .

Execute the images as below:

$ docker run -it mbj4668/yanger
Usage: yanger [-h] [-v] [--print-error-code] [-p <path>]
              [-P <plugindir>] [-c] [--strict] [-e] [-W <warning>]
              [-w <no_warning>] [-E <error>] [-f <format>]
              [-t <transform>] [--max-status <max_status>]
              [--deviation-module <deviation_module>] [-F <features>]
              [-C <conformance>] [-o <outfile>] [--no-deviation-apply]
              [--print] [--print-all] <file>...

Execute the example below:

docker run -it -v ${PWD}:/workdir mbj4668/yanger -t expand -f swagger test_leaf.yang -o test_leaf_now_swagger.json

Sample Usage

To create a Swagger JSON file from a yang file, you must first have a yang file, for example, create the following test_leaf.yang file in your current working directory:

module test_leaf {
  namespace "http://example.com/ns/example/test_leaf";
  prefix ns;

container test_vars{
    leaf single_value
    {
      type string;
    }
   }
}

Next you must tell yanger which format to output the yang into, in this example, it is the swagger JSON format, giving the new file output name test_leaf_now_swagger.json:

yanger -t expand -f swagger test_leaf.yang -o test_leaf_now_swagger.json

You will now have a JSON file created from the yang file:

$ more test_leaf_now_swagger.json
{
  "swagger": "2.0",
  "info": {
    "title": "test_leaf",
    "description": "",
    "version": "2018-10-15"
  },
  "basePath": "/restconf",
  "tags": [
    {
      "name": "root",
.....

You can for example take the Swagger file to the Swaggerhub and auto create an SDK from it in a python flask format or other languages. The Swaggerhub requires free registration.

For running tests

lux (https://github.com/hawk/lux)

Contributing

Code style

Do not introduce trailing whitespace.

Do not introduce lines longer than 80 characters.

Do not use tabs for indentation.

Hint for emacs users:

(setq whitespace-style (quote (face trailing tabs lines)))

and use whitespace-mode.

Debugging

If you wanted to use the erl-shell in order to debug you could:

erl -pa ./ebin
yanger:main(["-p","<<YANG_PATH>>","-f","swagger","<<YANG_PATH>>/tailf-ncs.yang","-o","tailf-ncs.json"]).

About

Extensible YANG validator

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Erlang 81.9%
  • C 16.3%
  • Makefile 1.4%
  • Other 0.4%