0

I am learning netconf and yang. One thing which confuses me is, how to write an XML instance data for a given yang schema. Is there a tool which can create a sample instance data? Where I can just put my own values without worrying about nodes, and it's nesting.

eg for below given yang model

module tubecats {
    namespace "http://plajjan.github.io/ns/yang/tubecats";
    prefix tc;

    revision 2017-03-15 {
        description "First and only version";
    }

    container internet {
        list cat {
            key name;
            leaf name {
                type string;
            }
        }
    }
}

How below sample instance data is generated?

<ns0:data xmlns:ns0="urn:ietf:params:xml:ns:netconf:base:1.0">
    <tc:internet xmlns:tc="http://plajjan.github.io/ns/yang/tubecats">
        <tc:cat>
            <tc:name>jingles</tc:name>
        </tc:cat>
        <tc:cat>
            <tc:name>fluffy</tc:name>
        </tc:cat>
    </tc:internet>
</ns0:data>

I understand there is a tool called yanglint which can validate model again instance data but that is not what I want.

myquest4 sh
  • 371
  • 4
  • 16
  • 1
    Questions like this (asking for tool recommendations) are [not a good fit](https://stackoverflow.com/help/on-topic) for this site. That being said, [pyang](https://github.com/mbj4668/pyang) has a plugin that generates skeleton instance documents if I recall correctly. – predi Aug 25 '22 at 06:42

1 Answers1

0

There's the netconf-cli which has a yang-cli command line utility. With this, you can do something like the following:

$ yang-cli --configonly path/to/your/tubecats.yang
/> create tc:internet/cat[name="Micinka"]

There's tab completion which should get you going, and you can print the datatsore content as JSON:

/> dump json
{
  "tc:internet": {
    "cat": [
      {
        "name": "Micinka"
      }
    ]
  }
}

...or XML:

/> dump xml
<tc xmlns="http://plajjan.github.io/ns/yang/tubecats">
  <cat>
    <name>Micinka</name>
  </cat>
</tc>
Jan Kundrát
  • 3,700
  • 1
  • 18
  • 29