10-01-2018 05:20 AM
Hi,
for a PoC I am currently working on a VPN rollout service.
Currently the template is getting bigger and bigger. We have discussed with the customer how we could break up the massive big template and have smaller more specific templates.
The idea was to have like a template file for each "role" (e.g. PE, CE, CR) and in those then have seperate bits for different vendors/OS types.
How can that be achieved? Is there some sort of naming convention mechanism which will ensure that all templates underneath the templates folder of my service will be considered? So far I have only ever used one big template file but often wondered if it can be broken up into smaller, more specific template files.
Some general info on the template mechanism will also be welcomed (e.g. order, what happens when etc.).
Tahnks in advance for help.
Solved! Go to Solution.
10-04-2018 12:40 AM
Not possible today but sounds like a good feature. I would suggest you send it in as feature request.
10-01-2018 08:31 AM
If your service is a template-only service, you'll have to live with a single template file. It would be difficult for the system to know when and how to apply them otherwise.
For service packages with code, the python or java code can invoke any number of templates any number of times with the same or different variable bindings each time. You could have a look at examples.ncs/getting-started/developing-with-ncs/17-mpls-vpn-python/packages/l3vpn/templates
10-02-2018 01:05 AM
Thanks for the reply.
I am aware that I can call any template anytime from the python/java code.
I think the customer just wants to break up the template file into smaller units as he finds that more manageable for some reason.
Is there any reason why I cannot use the normal XML include mechanisms like XInclude or XML external entities in order to break up the big "all-in-one" template file into smaller chunks?
I believe XInclude is generally the preferred mechanism in XML but any processing engine needs to be capable of understanding XInclude. Is NSO fine with XInclude?
10-02-2018 04:02 AM
OK I tried XInclude as well as the external entity variant. Both do not seem to work in NSO
In my main tmeplate file I did the following:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE config-template [ <!ENTITY pe_backbone SYSTEM "./chunks/pe_backbone.xml"> <!ENTITY pe_access SYSTEM "./chunks/pe_access.xml"> <!ENTITY ce_vpn SYSTEM "./chunks/ce_vpn.xml"> <!ENTITY ce_usernet SYSTEM "./chunks/ce_usernet.xml"> ]> <config-template xmlns="http://tail-f.com/ns/config/1.0"> <devices xmlns="http://tail-f.com/ns/ncs"> &pe_backbone; &pe_access; &ce_vpn; &ce_usernet; </devices> </config-template>
And then the files (e.g. pe_backbone.xml) have the format:
<device> ... </device>
On "packages reload" this yields the following Error:
reload-result { package DBS_VPN result false info [DBS_VPN-template.xml:11: Invalid entity: &pe_backbone;] }
In my main template file I did the following:
<config-template xmlns="http://tail-f.com/ns/config/1.0"> <devices xmlns="http://tail-f.com/ns/ncs">
<include href="chunks/pe_backbone.xml"/>
<include href="chunks/pe_access.xml"/>
<include href="chunks/ce_vpn.xml"/>
<include href="chunks/ce_usernet.xml"/> </devices> </config-template>
The files in "chunks" directory are identical to the way I have them in the External entity example above.
This results in the following error on packages reload:
reload-result { package DBS_VPN result false info [DBS_VPN-template.xml:4 Unknown element: 'include'] }
So...is it really impossible to use any of these two mechanisms (for including xml from some other file into an XML file) in NSO? Or am I just missing something?
10-04-2018 12:40 AM
Not possible today but sounds like a good feature. I would suggest you send it in as feature request.
10-04-2018 01:00 AM
10-04-2018 03:25 AM
Hi.
Thanks so far.
I have decided to create multiple templates and call them from my code.
Where before I had:
template.apply('DBS_VPN-template.xml', vars)
I now have:
template.apply('DBS_VPN-pe_access.xml', vars) template.apply('DBS_VPN-pe_backbone.xml', vars) template.apply('DBS_VPN-ce_vpn.xml', vars) template.apply('DBS_VPN-ce_usernet.xml', vars)
For some reason I now get the following error message:
Python cb_create error. item does not exist (1): The template file DBS_VPN-pe_access.xml has not been loaded.
Here is the content of my packages/packagename/templates folder:
-rw-rw-r--. 1 redhat redhat 2531 4. Okt 11:22 DBS_VPN-ce_usernet.xml -rw-rw-r--. 1 redhat redhat 6458 4. Okt 11:21 DBS_VPN-ce_vpn.xml -rw-rw-r--. 1 redhat redhat 3663 4. Okt 11:18 DBS_VPN-pe_access.xml -rw-rw-r--. 1 redhat redhat 7596 4. Okt 11:16 DBS_VPN-pe_backbone.xml -rw-rw-r--. 1 redhat redhat 19846 4. Okt 11:48 DBS_VPN-template.xml drwxrwxr-x. 2 redhat redhat 90 2. Okt 11:40 originals [redhat@localhost templates]$ pwd /home/redhat/ncs-run/packages/DBS_VPN/templates [redhat@localhost templates]$
The file is present. Why am I getting this message?
I tried packages reload and restart (ncs --stop...ncs) of NSO. Always the same message.
Frustrated with this I tried to change things back to call the "all in one template" (
template.apply('DBS_VPN-template.xml', vars)
)
Now I get the error message above but with the old "all in one" template. So my attempt has somehow broken my service entirely? How can I fix this?
10-04-2018 04:08 AM
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