10-10-2017 10:21 AM - edited 03-01-2019 04:01 AM
We are hitting an error when we try to convert yang file to xml in one of NSO setup but works fine in another setup.
Can anyone share more information about pyang, Is there any packages we need to install for it to work.
We are kind of stuck in this step
Solved! Go to Solution.
10-11-2017 02:12 AM
Hard to say exactly what you are doing based on the above. But I can tell you are not using the latest pyang version. First step I'd recommend is to upgrade: https://github.com/mbj4668/pyang
10-11-2017 02:12 AM
Hard to say exactly what you are doing based on the above. But I can tell you are not using the latest pyang version. First step I'd recommend is to upgrade: https://github.com/mbj4668/pyang
10-11-2017 02:32 AM
I am running the below command to convert yang to XML file
pyang -f sample-xml-skeleton -o router.xml router.yang (this command should get me router.xml file out of router.yang file)
Above command should give me XML file of that yang model.
Reason, why I am converting yang to XML and to JSON, is to prepare a request body using that JSON to activate service in NSO by making REST call.
10-11-2017 06:26 AM
Thank you Jan Lindbald, it worked but we are facing one more issue
sample-xml-skeleton plugin needs a valid module
Any information you have about this.
12-11-2017 09:49 PM
Hi Mithun,
May I know for which version of pyang, yang to xml conversion is working. I have 1.5, I see issues while using pyang.
Were you able to generate xml out of yang?
Please share the information if you are able to convert,
Thanks,
Sujani.
12-13-2017 12:52 AM
When you say "generate xml out of yang", what is it that you're trying to accomplish exactly?
12-13-2017 01:01 AM
Hi,
I would like to create service instance xml by traversing through the yang. I do not want to create service instance from cli and then take out format as xml.
Thanks.
12-13-2017 01:21 AM
Maybe not terribly useful, but if you want to generate something like that, you can use the pyang -f sample-xml-skeleton command:
pyang -f sample-xml-skeleton --sample-xml-skeleton-doctype=config ~/nso/4.5.1/examples.ncs/getting-started/developing-with-ncs/17-mpls-vpn-python/packages/l3vpn/src/yang/l3vpn.yang
12-13-2017 01:30 AM
Hi Jan,
Thanks for the response.
I was trying with sample-xml-skeleton option with data and config. But its just giving as below. Were you able to generate?
I have nso-4.4.2.1.
- pyang -f sample-xml-skeleton --sample-xml-skeleton-doctype=config l3vpn/src/yang/l3vpn.yang
<?xml version='1.0' encoding='utf-8'?>
<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" />
01-13-2021 10:36 PM
Was searching for a document on how to convert yang model to xml, came across this document.
Following is what I have done hope others find it useful.
pyang -f tree ietf-interfaces.yang
this is documented in `pyang --help`
-f FORMAT, --format=FORMAT Convert to FORMAT. Supported formats are: yang, yin, dsdl, jsonxsl, capability, depend, identifiers, tree, jstree, sample-xml-skeleton, omni, uml, jtox, name
The sample-xml-skeleton require few more options, infact the error log doenst give you what exactly is missing, use the following code to convert to xml
pyang -f sample-xml-skeleton --sample-xml-skeleton-doctype=config ietf-interfaces.yang <?xml version='1.0' encoding='UTF-8'?> <config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"> <interface> <name/> <description/> <type/> <link-up-down-trap-enable/> </interface> </interfaces> </config>
we can also use --sample-xml-skeleton-defaults or --sample-xml-skeleton-annotations arguments, they do what they specifies
These options are also specified in pyang --help
Sample-xml-skeleton output specific options: --sample-xml-skeleton-doctype=DOCTYPE Type of sample XML document (data or config). --sample-xml-skeleton-defaults Insert leafs with defaults values. --sample-xml-skeleton-annotations Add annotations as XML comments. --sample-xml-skeleton-path=SAMPLE_PATH Subtree to print
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide