07-25-2019 10:15 PM
Hi Guys,
I'm wondering if foreach can be used for leaf-list, I haven't find such an example, has anyone ever used it workable?
Thanks
Solved! Go to Solution.
11-20-2019 11:42 PM
Thanks so much for clear explaination. It now working with wrap pw-id with string :)
07-28-2019 07:56 PM - edited 07-28-2019 07:58 PM
I am able to use the leaf-list items using for each loop.
In the below example my leaf-list type is leaf-ref as I m referring to an other leaf to select only those entires.
Ex:
leaf-list DMZ_Tunnels{
type leafref {
path "../../../Interfaces/Tunnel_Name";
}
}
You can refer to it as below in ur python code.
for tunnel in DMZ_Tunnels:
self.log.info(tunnel)
11-20-2019 11:16 AM
Hi,
Is it possible to use each element in leaf-list from plain xml template without python-template ?
For example
I have yang like this
leaf-list neighbors { type inet:ipv4-address; }
and xml template like this
<vfi> <name>{./vfi-name}</name> <neighbor> <address>{./neighbors}</address> <pw-id>{./pw-id}</pw-id> </neighbor> </vfi>
when exeute this service from command line maybe like:
myservice neightbor [ 1.1.1.1 2.2.2.2 ]
How to use this neighbors variable in xml template ?
11-20-2019 10:55 PM
Yes.
Assuming here that pw-id is the same for all neighbors, your template should look something like this:
<vfi> <name>{/vfi-name}</name> <neighbor> <address>{/neighbors}</address> <pw-id>{string(/pw-id)}</pw-id> </neighbor> </vfi>
admin@ncs(config-foo-bar)# commit dry-run outformat native native { device { name xr-00 data l2vpn bridge group 12 bridge-domain 23 vfi ttt neighbor 1.1.1.1 pw-id 4444 exit neighbor 2.2.2.2 pw-id 4444 exit exit exit exit exit } }
I assumed that everything is directly under the service so I didn't add the dots you've added, but depending on the context you'd have, you might need to change that.
But anyhow, the context in a service XML template is a bit tricky, but the bottom line is that if you have some properties taken from a list or leaf-list in your service model, and you assign those to another list in your device model, and you also need to fetch inputs from outside the source list (in this example, pw-id), you'd usually wrap those (and only those) in the xpath string() method, as it doesn't affect the context.
You can usually use 'commit dry-run | debug template' to track the context, but in the case of a leaf-list it won't be as helpful as in the case of a proper list - but still something to keep in mind...
11-20-2019 11:42 PM
Thanks so much for clear explaination. It now working with wrap pw-id with string :)
06-23-2021 06:29 AM
Hi,
what if pw-id needs to be different, it is not a valid for this case. but with ipaddress and subnet configuration
<secondary>
<address>12.1.1.1</address>
<netmask>255.255.255.128</netmask>
</secondary>
<secondary>
<address>13.1.1.1</address>
<netmask>255.255.255.0</netmask>
</secondary>
Tried with list
list test {
key "secondary-ip-address";
leaf secondary-ip-address {
type inet:ipv4-address;
}
leaf secondary-netmask {
type inet:ipv4-address;
}
}
also with leaf-list something like this
leaf-list secondary-ip-address {
type inet:ipv4-address;
}
leaf-list secondary-netmask {
type inet:ipv4-address;
}
but getting this error
_ncs.error.Error: Unknown error (66): leaf-list-test-template.xml:24 Expression '{/test/secondary-netmask}' resulted in an incompatible value '255.255.255.0255.255.255.128' for /ncs:devices/device{ar19.BLB}/config/ifmgr-cfg:interface-con
figurations/interface-configuration{act TenGigE0/0/0/30}/ipv4-io-cfg:ipv4-network/addresses/secondaries/secondary{12.1.1.1}/netmask
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