03-13-2018 10:42 AM - edited 03-01-2019 04:06 AM
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
Solved! Go to Solution.
03-13-2018 12:01 PM
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)
03-13-2018 11:08 AM
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.
03-13-2018 11:36 AM
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
03-13-2018 11:45 AM
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>
...
03-13-2018 11:50 AM
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
03-13-2018 12:01 PM
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)
03-13-2018 12:06 PM
Hi Frederik,
Thanx, that was of great help!
Cheers,
Florian
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