cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1933
Views
10
Helpful
1
Replies

Using variables set in a template

robert.lee2
Level 1
Level 1

https://community.cisco.com/t5/nso-developer-hub-discussions/xpath-position/td-p/3513828

 

For context please first review the issue described in the link above.  We left this issue at a point where it was determined that moving to 4.6+ was the only possible solution which supports new capabilities in the template such as setting variable values and several new loop constructs.  I have upgraded one of our lab nodes to 4.6.1.3, and where I am still stuck is - within the foreach loop segment - how to increment the value of the counter.  In the 4.6.1.3 development guide, the section on pg.261, only demonstrates the ability to increment a counter when using a for loop construct, but does not show any indication of how this may done in a foreach context, where the value of the counter is preserved across each pass, incremented and subsequently applied in the template.

 

1 Reply 1

robert.lee2
Level 1
Level 1

Solution that I came up with eventually - Hope this will help others as well -  Snippet from my template; mpls-path-hops is a list in my yang.....

 

           <? set i = 0 ?>
            <? foreach {mpls-path-hops} ?>
            <?set i={$i+100}?>
            <hop>
              <hop-number>{$i}</hop-number>
              <ip-address>{hop-id}</ip-address>
              <mode>{hop-id-state}</mode>
            </hop>
            <?end?>

Polls
AI-powered tools for network troubleshooting are likely to be part of everyone’s workflow sooner or later. What is the single biggest challenge or concern you see with adopting these tools in your organization?