03-15-2024 08:46 AM
I'm facing an issue with implementing conditional logic within an XML template. Specifically, I'm trying to build a multi-device template where variables are passed to the XML template from a YANG model using the 'choice' construct. However, when I attempt to use conditional logic in the XML template to handle different device types, the processing instruction '<?if {/device-type=edge-router}?>' seems to be skipped during debugging.
choice device-type {
case edge-router {
case access-router {
<?xml version="1.0"?>
<config-template xmlns="http://tail-f.com/ns/config/1.0">
<devices xmlns="http://tail-f.com/ns/ncs">
<device>
<name>{$device}</name>
<config>
<?if {/device-type=edge-router}?>
<mpls xmlns="urn:ios">
<mpls-ip-conf>
<ip>
<propagate-ttl>
<forwarded>false</forwarded>
</propagate-ttl>
</ip>
</mpls-ip-conf>
</mpls>
<?end?>
processing instruction 'if': skipping (from file "test.template.xml", line 7)
Has anyone encountered a similar issue with implementing conditional logic in XML templates? How did you resolve it? Any suggestions or insights would be greatly appreciated.
Solved! Go to Solution.
03-18-2024 02:02 AM
OK - I had assumed you had a device-type leaf which was of type enumeration.
The choice and case statements are not something stored in the database, they act as a constraint on the schema. What 'choice' says is that the parts of the model under each case are alternatives. Exactly one case exists if you have 'mandatory true' under the choice else it is at most one case exists. If you leave all the different case statements empty the whole constuct becomes pointless. In fact I can't think of any good reason for an empty case statement.
You definitely need to change your yang mode. Try the enumeration maybe.
03-15-2024 10:00 AM
03-15-2024 10:14 AM - edited 03-15-2024 10:16 AM
Yes I did <?if {/device-type= 'edge-router'}?> , still kipping.
description
"service1";
augment "/ncs:services" {
list service1 {
description
"This is an RFS skeleton service";
key "device";
leaf device {
type leafref {
path "/ncs:devices/ncs:device/ncs:name";
}
}
uses ncs:service-data;
ncs:servicepoint "service1-servicepoint";
leaf hostname {
type string;
mandatory true;
}
leaf pop {
type string;
mandatory true;
}
choice device-type {
case edge-router {
case access-router {
checking xpath, i can see the leafs and not the cases:
admin@ncs# show running-config services service1 | display xpath
/services/service1:service1[device='router1']/hostname router_1
/services/service1:service1[device='router1']/ la
03-18-2024 02:02 AM
OK - I had assumed you had a device-type leaf which was of type enumeration.
The choice and case statements are not something stored in the database, they act as a constraint on the schema. What 'choice' says is that the parts of the model under each case are alternatives. Exactly one case exists if you have 'mandatory true' under the choice else it is at most one case exists. If you leave all the different case statements empty the whole constuct becomes pointless. In fact I can't think of any good reason for an empty case statement.
You definitely need to change your yang mode. Try the enumeration maybe.
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