Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing YANG Model in java

How do I parse YANG models in java ? I need to convert the yang model into a xml format.

I have already tried pyang. But since it is in python, it does not suite my requirement.

like image 481
Keshava Avatar asked Jul 25 '14 07:07

Keshava


People also ask

How do you convert Yang to JSON?

yang > ietf. xml and then using python xmltodict library the same can be converted to json.

What is Yang data model?

YANG is a data modeling language for the NETCONF configuration management protocol. Together, NETCONF and YANG provide the tools that network administrators need to automate configuration tasks across heterogeneous devices in a software-defined network (SDN).

What is Yang tool?

YANG Tools Overview YANG is a data modeling language used to model configuration & state data. Modeling languages such as SMI (SNMP), UML, XML Schema, and others already existed. However, none of these languages were specifically targeted to the needs of configuration management.


2 Answers

Yes, that's true.

Use yang-parser-impl from Open daylight. It provides a yang parser and returns a set of parsed modules. Which you can further query to get more node objects.

like image 169
Sathya Avatar answered Sep 28 '22 20:09

Sathya


The above API is valid for previous versions. Use the following API for the current version

    YangTextSchemaContextResolver yangContextResolver = YangTextSchemaContextResolver.create("yang-context-resolver");

    yangContextResolver.registerSource(new URL("file:///home/ABA/XXX/Workspaces/ABC/X/config.yang"));
    yangContextResolver.registerSource(new URL("file:///home/ABC/XXX/Workspaces/ABC/X/XXX-YY.yang"));


    Optional<SchemaContext> sc = yangContextResolver.getSchemaContext();
like image 40
Vithun Venugopalan Avatar answered Sep 28 '22 18:09

Vithun Venugopalan