cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
809
Views
0
Helpful
1
Replies

foreach counter

BasharAziz
Level 1
Level 1

Two services: service_01 and service_02 ,service_01 which stores the values in cdb and service_02 iterate over a list in service_01. The problem is I need to control how many  loopbacks should be created, used counter in xml template but is not really working.

 

 

--YANG----

module service_01 {
namespace "http://com/example/service_01";
prefix service_01;

 

list loopback {
key loopback_id;
leaf loopback_id {
type uint16{
range "1000..10000";
}
mandatory true;
}
leaf loopback_ip {
type inet:ipv4-address;
mandatory true;
}

 

 

 

-----XML-----

service_02

 

<interface xmlns="urn:ios">
<?set counter={0}?>
<?foreach {/../service_01:service_01[service_01_name]/loopback}?>
<Loopback>
<name>{loopback_id}</name>
<ip-vrf>
<ip>
<vrf>
<forwarding>{/vrf_id}</forwarding>
</vrf>
</ip>
</ip-vrf>
<ip>
<address>
<primary>
<address>{loopback_ip}</address>
<mask>255.255.255.255</mask>
</primary>
</address>
</ip>
</Loopback>
<?end?>


</interface>

1 Reply 1

kiran kotari
Cisco Employee
Cisco Employee

Validate the xpath `/../service_01:service_01[service_01_name]/loopback` as follows

Step 1:
in the ncs_cli #devtools true (config)# xpath eval <ur-xpath> # need to return all possibilities
(config)#

 Is there any special use case to keep `service_01_name` in template xpath? same goes for the counter `<?set counter={0}?>` 

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?