cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
987
Views
0
Helpful
6
Replies

Structure of yang submodules with python and template

Hi,

I want to develop a number of services which are part of a larger service family. For this reason I would like to use a yang submodule structure to separate the services. But I am unclear what this means exactly for the Python and XML code. The Python code I guess could be structured using the __init__,py file and using different callbackpoints. But for the XML I am lost, how are the templates structured when using yang submodules?

Cheers,

Florian

1 Accepted Solution

Accepted Solutions

frjansso
Cisco Employee
Cisco Employee

NSO reads all the templates in the template directory.

Your code will then apply each template, let's say the two templates in the example above were names address.xml and mask.xml, to apply those from python, you'd do something like this:


template.apply('address', vm_group_vars)

template.apply('mask', vm_group_vars)

View solution in original post

6 Replies 6

frjansso
Cisco Employee
Cisco Employee

To your question, submodules don't affect the XML nor the code, a submodule have the same namespace as its parent. So from XML/code point of view, there is no difference between a large YANG model or a model broken up into sub-modules.

Hi Frederik,

Thank you for the quick response. So there is no mechanism in NSO to split the XML code into multiple files?

Cheers,

Florian

Yes, you can always split XML over several files. How you split them doesn't not have to correspond to submodules in the YANG models.

A simple example:

<config-template xmlns="http://tail-f.com/ns/config/1.0">

  <devices xmlns="http://tail-f.com/ns/ncs">

    <device tags="nocreate">

      <name>{/device}</name>

      <config>

        <interface xmlns="urn:ios" tags="merge">

          <GigabitEthernet>

            <name>{/interface}</name>

            <ip>

              <address>

                <primary>

                  <address>{/address}</address>

                  <mask>{/mask}</mask>

                </primary>

              </address>

            </ip>

...

If you split this in two, see below, and apply both templates from the code, will have the exact same effect as applying the template above.

In many cases it helps breaking templates up into many files, usually because you want to apply some template many times and others just once.

Does that make sense?

<config-template xmlns="http://tail-f.com/ns/config/1.0">

  <devices xmlns="http://tail-f.com/ns/ncs">

    <device tags="nocreate">

      <name>{/device}</name>

      <config>

        <interface xmlns="urn:ios" tags="merge">

          <GigabitEthernet>

            <name>{/interface}</name>

            <ip>

              <address>

                <primary>

                  <address>{/address}</address>

                </primary>

              </address>

            </ip>

...

<config-template xmlns="http://tail-f.com/ns/config/1.0">

  <devices xmlns="http://tail-f.com/ns/ncs">

    <device tags="nocreate">

      <name>{/device}</name>

      <config>

        <interface xmlns="urn:ios" tags="merge">

          <GigabitEthernet>

            <name>{/interface}</name>

            <ip>

              <address>

                <primary>

                  <mask>{/mask}</mask>

                </primary>

              </address>

            </ip>

...

Hi Frederik,

OK, I think the XML mechanic in this case is clear to me, but how does NSO know which files to read? Does it just read all the xml files in the template folder? I am asking because for Python there is specific file (__init__,py) which tells NSO where to find the split files, but afaik there is no such mechanism for XML.

Cheers,

Florian

frjansso
Cisco Employee
Cisco Employee

NSO reads all the templates in the template directory.

Your code will then apply each template, let's say the two templates in the example above were names address.xml and mask.xml, to apply those from python, you'd do something like this:


template.apply('address', vm_group_vars)

template.apply('mask', vm_group_vars)

Hi Frederik,

Thanx, that was of great help!

Cheers,

Florian