cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
323
Views
1
Helpful
3
Replies

Service Template XML Variable when using Choice

BasharAziz
Level 1
Level 1

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.

1 Accepted Solution

Accepted Solutions

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.

 

 

View solution in original post

3 Replies 3

snovello
Cisco Employee
Cisco Employee
You are just missing qoutes around ‘edge-router’ .
You can test xpath expressions by turning on devtools in cli and using the xpath command.

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

 

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.