cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1739
Views
10
Helpful
6
Replies

[Help with template]

Carlos A. Silva
Level 3
Level 3

hi, I'm trying to create a template that allows me to configure several L3VPN wan interfaces in different devices inside of one service instance called 'bgpl3vpn'. If I only configure one link one a single device, the template works as I want it to. When I start adding a 2nd link I run in to the following problem in which values expected to configure different wan links get merged into a single one that NSO can't use to configure my routers, for example:

Evaluating "/link/ce-asn" (from file "bgpl3vpn-template.xml", line 137)

Context node: /services/bgpl3vpn:bgpl3vpn[name='chapi']/link[linkname='IOS-0']

Result:

For /services/bgpl3vpn:bgpl3vpn[name='chapi']/link[linkname='IOS-0'], it evaluates to "65016"

For /services/bgpl3vpn:bgpl3vpn[name='chapi']/link[linkname='XR-1'], it evaluates to "65016"

Aborted: bgpl3vpn-template.xml:137 Expression '{/link/ce-asn}' resulted in an incompatible value '6501665016' for /ncs:devices/device{XR-1}/config/cisco-ios-xr:router/bgp/bgp-no-instance{1}/vrf{chapi}/neighbor{172.16.1.2}/remote-as

admin@ncs(config-link-XR-1)#


As you can see, each link has a separate name, but NSO ends up merging the customer equipment ASN for each wan link (they get merged into ASN 6501665016, instead of just 65016 for each link) and trying to apply it to a single router. The same happens for other variables like my wan-ip-address.

I'm hoping that this is something very simple to fix for the more experienced eye.

I'm attaching both my template and yang model.

Thanks!

c.

1 Accepted Solution

Accepted Solutions

Have a look at the attached XML for reference.

Yftach

View solution in original post

6 Replies 6

yfherzog
Cisco Employee
Cisco Employee

Hi,

One of the most important things to keep in mind when using XML templates in NSO is the execution context.

Whenever you try to configure a list on the device data model (e.g. vrf, bgp-vfr, interface, etc.), the context is changing (and you should see it as well on the debug template output.

Whenever your template includes the root node (path that starts with '/...') you're effectively resetting the context, and that's what doesn't allow your template to "iterate" the different instances, and instead outputs the content from all instances on the path.

To avoid that, two things:

1. suppose that you have a service models such as:

list a {

     leaf a-1;

     leaf a-2;

}

and you want to use it to configure device model such as:

list x {

     leaf x-1; //key

     leaf x-2;

}

Your xml template should be something like this:

<x>

     <x-1>{/a/a-1}</x-1>

     <x-2>{a-2}</x-2>

...

In the debug template output, you will notice that the context is changing once you provided the key to the list on the target (device) model, and at this point you should provide a relative path, rather than an absolute one (not to reset the context).

2. While accessing entries on a list on the target model (as before), suppose that you want to use an element from outside of the current context, but without losing the context, you can make use of the xpath string() method, which will evaluate a given path without changing the context. For example:

<x>

     <x-1>{/a/a-1}</x-1>

     <x-2>{a-2}</x-2>

     <x-3>{string(/some/far/away/path)}</x-3>

...

Notice on the debug output that the context will not change when using the string method.

Hope that helps!

Yftach

Have a look at the attached XML for reference.

Yftach

Thank you very much, Yftach! I was able to figure it out from your comments by using the "foreach" expression, everything is filling out properly now.


Now I have a new problem: since I have a template to configure both IOS and IOS XR, when I configure more than one link one in IOS and one in XR, the template tries to configure each with both it's own and the other OS information at the same time.


That is, for example, the router with the XR vpn link has both the interface configuration for the IOS link (different router) AND the interface configuration for the IOS XR link, when they should be in completely separate devices (see debug). Will keep working on this during the day.




Hi, Yftach:

Tried your corrected template and worked exactly as I wanted. Can't thank you enough for taking the time.

Regards,

c.

Glad I was able to help!

Note that you don't need the foreach statement in this case.

In some cases, where iteration gets a bit more complex (in terms of context), foreach might be needed, but in this case, no need for using it, just keeping an eye on how the context is changing each time you access a node through the XML.

Yftach

Exactly, the "foreach" was actually causing the problem. When I removed it and used your suggested string technique, everything started working immediately.

Thank you very much!

c.

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the NSO Developer community: