How to use the pyang.plugin function in pyang

To help you get started, we’ve selected a few pyang examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mbj4668 / pyang / test / plugins / yangxml.py View on Github external
# This pyang plugin generates a random XML instance document adhering
# to a YANG module.

from pyang import plugin
from pyang import types
from pyang import statements
import sys
from random import randint, random

def pyang_plugin_init():
    plugin.register_plugin(YANGXMLPlugin())

class YANGXMLPlugin(plugin.PyangPlugin):
    def add_output_format(self, fmts):
        fmts['xml'] = self
    def emit(self, ctx, modules, writef):
        module = modules[0]
        emit_xml(module, writef)
    
def emit_xml(module, fd):
    # pick one top-level child
    if len(module.i_children) == 0:
        return
    c = pick(module.i_children)
    attrs = ' xmlns="%s"' % module.search_one('namespace').arg
    if c.keyword == 'choice':
        sys.stderr.write("Cannot handle choice on top-level")
        sys.exit(1)
    emit_stmt(c, fd, '', attrs, 1)
github mbj4668 / pyang / test / test_transform / add-foo.py View on Github external
from pyang import plugin
from pyang import statements


def pyang_plugin_init():
    plugin.register_plugin(AddFoo())


class AddFoo(plugin.PyangPlugin):
    def add_transform(self, xforms):
        xforms['add-foo'] = self

    def transform(self, ctx, modules):
        for module in modules:
            for stmt in module.substmts:
                if stmt.keyword == 'container':
                    foo = stmt.search_one('foo')
                    if not foo:
                        foo = add_leaf(stmt, 'foo', 'string')


def add_leaf(parent, name, type_name):
    leaf = statements.new_statement(parent.top, parent, parent.pos,
                                    'leaf', name)
    parent.substmts.append(leaf)
github mbj4668 / pyang / test / plugins / yangxml.py View on Github external
def pyang_plugin_init():
    plugin.register_plugin(YANGXMLPlugin())
github mbj4668 / pyang / pyang / translators / yang.py View on Github external
def pyang_plugin_init():
    plugin.register_plugin(YANGPlugin())
github mbj4668 / pyang / pyang / plugins / sid.py View on Github external
def pyang_plugin_init():
    plugin.register_plugin(SidPlugin())
github mbj4668 / pyang / pyang / translators / dsdl.py View on Github external
__docformat__ = "reStructuredText"

import sys
import optparse
import time

import pyang
from pyang import plugin, error, xpath, util, statements, types

from schemanode import SchemaNode

def pyang_plugin_init():
    plugin.register_plugin(DSDLPlugin())

class DSDLPlugin(plugin.PyangPlugin):
    def add_output_format(self, fmts):
        self.multiple_modules = True
        fmts['dsdl'] = self
    def add_opts(self, optparser):
        optlist = [
            optparse.make_option("--dsdl-no-documentation",
                                 dest="dsdl_no_documentation",
                                 action="store_true",
                                 default=False,
                                 help="No output of DTD compatibility"
                                 " documentation annotations"),
            optparse.make_option("--dsdl-no-dublin-core",
                                 dest="dsdl_no_dublin_core",
                                 action="store_true",
                                 default=False,
                                 help="No output of Dublin Core"
github opencord / voltha / experiments / netconf / yang2proto / yang2proto.py View on Github external
def pyang_plugin_init():
    plugin.register_plugin(ProtobufPlugin())
github mbj4668 / pyang / pyang / plugins / jstree.py View on Github external
def pyang_plugin_init():
    plugin.register_plugin(JSTreePlugin())
github mbj4668 / pyang / pyang / plugins / flatten.py View on Github external
def __init__(self):
        plugin.PyangPlugin.__init__(self, "flatten")