cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Announcements

Cisco Community Designated VIP Class of 2020

169
Views
0
Helpful
4
Replies
Beginner

Help with accessing variables of a service from another service

Hi.

 

I am having trouble filling a service template using the values of variables defined in another service.

Let's say I have defined a service (tlfr3) where I store variables that will be used by other services. For the time being I have added this variable with values:

admin@ncs# show running-config tlfr3 variables global Rango
tlfr3 variables global Rango
value-list [ 1.1.1.1/32 2.2.2.0/26 3.3.3.0/24 ]
!

 

Displaying the xpath of the variable shows:

admin@ncs# show running-config tlfr3 variables global Rango | display xpath
/tlfr3/variables/global[name='Rango']/value-list [ 1.1.1.1/32 2.2.2.0/26 3.3.3.0/24 ]

 

Now I have another service called 'cr-art', which template includes these lines:

<prefix-list>
  <name>SSH</name>
  <prefix-list-item>
    <name>{string(/tlfr3/variables/global[name='Rango']/value-list)}</name>
  </prefix-list-item>
</prefix-list>

 

However, commiting an instance of the cr-art service does not fill the prefix-list SSH with the values of Rango. Commiting with debug shows that the values for Rango are not found:
Fetching literal "SSH" (from file "cr-art-template.xml", line 298)
Operation 'merge' on existing node: /devices/device[name='artfran1-01']/config/junos:configuration/policy-options/prefix-list[name='SSH'] (from file "cr-art-template.xml", line 298)
Evaluating "/tlfr3/variables/global[name='Rango']" (from file "cr-art-template.xml", line 300)
Context node: /cr-art[DEVICE='artfran1-01']
Result: empty node - skipping siblings

I have tried removing the trailing "/value-list" in the template, removing the string() function, ... but nothing seems to make a difference, the node is always empty. I guess my problem is related to the context node, which remains "/cr-art[DEVICE='artfran1-01']", even putting the "/" before "tlfr3" in the template, but I do not know how to change it.

 

Any hint would be greatly appreciated.

Thanks.

4 REPLIES 4
Cisco Employee

Re: Help with accessing variables of a service from another service

Indeed the context is the issue.

 

You have some options:

 

1. You can move upward in the model with you xpath expression until you reach the level you need, and then do as you tried.

It would be something like (depending on the number of levels you need):

 

<name>{string(/../../../tlfr3/variables/global[name='Rango']/value-list)}</name>

 

2. Another approach would be to apply the template with a different context from the start. That might be good only if you don't need the service context.

You do that by putting that context node inside your template object creation:

 

template = ncs.template.Template(my_node)

 

3. Depending on the NSO version you use, you can also force-change the context from within the template. You can have a look at the NSO developer guide for how to do that (search for 'Processing instructions').

Beginner

Re: Help with accessing variables of a service from another service

Thanks for your answer.

 

I have tried with several options:

 

  • Evaluating "string(/../../../tlfr3/variables/global[name='Rango']/value-list)" (from file "cr-art-template.xml", line 300)
    Context node: /cr-art[DEVICE='artfran1-01']
    Result: []

 

  • Evaluating "string(/../../tlfr3/variables/global[name='Rango']/value-list)" (from file "cr-art-template.xml", line 300)
    Context node: /cr-art[DEVICE='artfran1-01']
    Result: []

 

  • Evaluating "string(/../tlfr3/variables/global[name='Rango']/value-list)" (from file "cr-art-template.xml", line 300)
    Context node: /cr-art[DEVICE='artfran1-01']
    Result: []

 

  • Evaluating "string(../tlfr3/variables/global[name='Rango']/value-list)" (from file "cr-art-template.xml", line 300)
    Context node: /cr-art[DEVICE='artfran1-01']
    Result: []

 

  • Evaluating "string(/../../../../../../tlfr3/variables/global[name='Rango']/value-list)" (from file "cr-art-template.xml", line 300)
    Context node: /cr-art[DEVICE='artfran1-01']
    Result: []

No go, Result is always empty.

 

I have also tried:

<prefix-list-item>
<?set-root-node {/}?>

 

But that raises an error:

 

ncs# *** ALARM package-load-failure: [cr-art-template.xml:300 Processing instruction is unexpected here.]
ncs#

 

I am completely lost.

Beginner

Re: Help with accessing variables of a service from another service

Thanks for your answer.


I have tried with several options:


Evaluating "string(/../../../tlfr3/variables/global[name='Rango']/value-list)" (from file "cr-art-template.xml", line 300)
Context node: /cr-art[DEVICE='artfran1-01']
Result: []


Evaluating "string(/../../tlfr3/variables/global[name='Rango_IP_global_gest_CGR']/value-list)" (from file "cr-art-template.xml", line 300)
Context node: /cr-art[DEVICE='artfran1-01']
Result: []


Evaluating "string(/../tlfr3/variables/global[name='Rango']/value-list)" (from file "cr-art-template.xml", line 300)
Context node: /cr-art[DEVICE='artfran1-01']
Result: []


Evaluating "string(../tlfr3/variables/global[name='Rango']/value-list)" (from file "cr-art-template.xml", line 300)
Context node: /cr-art[DEVICE='artfran1-01']
Result: []


Evaluating "string(/../../../../../../tlfr3/variables/global[name='Rango']/value-list)" (from file "cr-art-template.xml", line 300)
Context node: /cr-art[DEVICE='artfran1-01']
Result: []

No go, Result is always empty.


I have also tried:

<prefix-list-item>
<?set-root-node {/}?>


But that raises an error:


ncs# *** ALARM package-load-failure: [cr-art-template.xml:300 Processing instruction is unexpected here.]

 

 

However, it looks like I have found what was not working.

 

tlfr3 does not appear as a service in the web-ui, but as a module named tlfr3-common:tlfr3. So I have tried this:

 

<name>{/../tlfr3-common:tlfr3/variables/global[name='Rango']/value-list}</name>

 

And now it works!!!

 

Thanks for your help.

Highlighted
Cisco Employee

Re: Help with accessing variables of a service from another service

Very good!

 

Yes. When you move to a new namespace, you need to prefix the node name according to the module you're trying to reach.