Giter VIP home page Giter VIP logo

pyang-old's Introduction

pyang

Release Build Status

Overview

pyang is a YANG validator, transformator and code generator, written in python. It can be used to validate YANG modules for correctness, to transform YANG modules into other formats, and to write plugins to generate code from the modules.

YANG (RFC 7950) is a data modeling language for NETCONF (RFC 6241), developed by the IETF NETMOD WG.

This fork introduces a new option called --sid-extension which add extra information to the sid file to allow easier conversion between JSON and CBOR formats. If the "Type" key is present, the sid is associated to a YANG leaf and the value indicate the type present in the YANG Data Model. In case of union, the value is an array of all the types.

--sid-extension build also a key-mapping entry containing the sid of a list as the object key and the sids of the list's keys as values. This may be use to find elements without referring to the YANG Data Model.

it will add a "type" key in the leaf SID description (the absence of type indicate that the node is not a leaf). Type is either:

  • the type used in the definition
  • an array of type for union
  • an object mapping enumeration number with enumeration value

a "key-mapping" object. keys are list SIDs and value lists in an array the key SIDs. Testing the presence of "key-mapping" in the JSON structure allows to check if the --sid-extension argument has been specified.

WARNING: This hack has been tested on YANG Data Model used by SCHC. There is no guaranty that it works in all YANG Data Models.

Documentation

See Documentation.

Installation

  • 1 PyPI

Pyang can be installed from PyPI:

# pip install pyang
  • 2 Source
  git clone https://github.com/ltn22/pyang.git
  cd pyang
  python setup.py install
  (this might require root access)

To install in a different location, run:

  python setup.py install --prefix=/usr/local

If you do this, it is recommended to set the environment variable YANG_INSTALL to the prefix directory. This ensures that pyang will find standard YANG modules. In addition, make sure that PYTHONPATH is set to something as follows:

export PYTHONPATH=/usr/local/lib/python2.7/site-packages

or whatever version of python you are running.

Run locally without installing

export PATH=`pwd`/bin:$PATH
export MANPATH=`pwd`/man:$MANPATH
export PYTHONPATH=`pwd`:$PYTHONPATH
export YANG_MODPATH=`pwd`/modules:$YANG_MODPATH
export PYANG_XSLT_DIR=`pwd`/xslt
export PYANG_RNG_LIBDIR=`pwd`/schema

or:

source ./env.sh

Compatibility

pyang is compatible with the following IETF RFCs:

Features

  • Validate YANG modules.
  • Convert YANG modules to YIN, and YIN to YANG.
  • Translate YANG data models to DSDL schemas, which can be used for validating various XML instance documents. See InstanceValidation.
  • Generate UML diagrams from YANG models. See UMLOutput for an example.
  • Generate compact tree representation of YANG models for quick visualization. See TreeOutput for an example.
  • Generate a skeleton XML instance document from the data model.
  • Schema-aware translation of instance documents encoded in XML to JSON and vice-versa. See XmlJson.
  • Plugin framework for simple development of other outputs, such as code generation.

Usage

pyang -h

or

man pyang

Code structure

  • bin/ Executable scripts.

  • pyang/ Contains the pyang library code.

  • pyang/init.py Initialization code for the pyang library.

  • pyang/context.py Defines the Context class, which represents a parsing session

  • pyang/repository.py Defines the Repository class, which is used to access modules.

  • pyang/syntax.py Generic syntax checking for YANG and YIN statements. Defines regular expressions for argument checking of core statements.

  • pyang/grammar.py Generic grammar for YANG and YIN. Defines chk_module_statements() which validates a parse tree according to the grammar.

  • pyang/statements.py Defines the generic Statement class and all validation code.

  • pyang/yang_parser.py YANG tokenizer and parser.

  • pyang/yin_parser.py YIN parser. Uses the expat library for XML parsing.

  • pyang/types.py Contains code for checking built-in types.

  • pyang/plugin.py Plugin API. Defines the class PyangPlugin which all plugins inherits from. All output handlers are written as plugins.

  • pyang/plugins/ Directory where plugins can be installed. All plugins in this directory are automatically initialized when the library is initialized.

  • pyang/translators/ Contains output plugins for YANG, YIN, and DSDL translation.

  • xslt Contains XSLT style sheets for generating RELAX NG, Schematron and DSRL schemas and validating instance documents. Also included is the free implementation of ISO Schematron by Rick Jelliffe from http://www.schematron.com/ (files iso_schematron_skeleton_for_xslt1.xsl, iso_abstract_expand.xsl and iso_svrl_for_xslt1.xsl).

  • schema Contains RELAX NG schemas and pattern libraries.

pyang-old's People

Contributors

ltn22 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.