cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1134
Views
0
Helpful
3
Replies

template - 'when' attribute cannot be used on key elements

rainnomm56
Level 1
Level 1

Natural key would port and vlan combination for service port. My issue is that NSO does not allow key used in template for "when" statement. How can i have 2 different xml lines with out it?

Live device conf:

      <epipe>

        <service-id>3714</service-id>

        <customer>1</customer>

        <description>NSO 2sap test</description>

        <sap>

          <sap-id>1/2/1</sap-id>

        </sap>

        <sap>

          <sap-id>3/1/1:510</sap-id>

        </sap>

      </epipe>

template that gives error on subject line:

        <sap foreach="{sap}">

          <sap-id when="{not(vlan=0)}">{port}:{vlan}</sap-id>

          <sap-id when="{vlan=0}">{port}</sap-id>

        </sap>

service yang for sap:

    list sap {

      key "port vlan";

      min-elements 1;

      max-elements 2;

      leaf port {

        type string;

        mandatory true;

      }

      leaf vlan {

        type uint32 {

          range "0..4096";

        }

      }

    }

1 Accepted Solution

Accepted Solutions

It depends on the NSO version.

Starting with NSO 4.6, a functionality similar to what you illustrated is now supported.

Checkout the developer guide - search for "Template processing instructions" and around the same chapter.

If you need to use an older version of NSO, then maybe you can try and get the foreach one level higher.

If things are getting too hairy, you can also move the iteration to the code that applies the template (if that isn't a template-only service package).

View solution in original post

3 Replies 3

yfherzog
Cisco Employee
Cisco Employee

The key that cannot be used in 'when' statement is the key of the target model (e.g. device model).

Port and vlan from you service model (source model) can be used in when statements, but you cannot have when statements on key elements of your target model.

In this case, assuming that your target model is a ned, you can have a look at the ned YANG model, and you should see that it contains a list called sap, and this list's key is composed out of the sap-id leaf, and having the target model's key in a when statement is not allowed, and this is why you're getting the error.

In short, if you want to implement such block with when statements, you'd need to have the when condition on a higher level in the hierarchy of the target model (e.g. on 'sap' rather than on 'sap-id'), and you'd need to duplicate the block in your xml template, so that you'd have one complete block with <sap-id>{port}:{vlan}</sap-id> and another with <sap-id>{port}</sap-id>.

In short, if you want to implement such block with when statements, you'd need to have the when condition on a higher level in the hierarchy of the target model (e.g. on 'sap' rather than on 'sap-id'), and you'd need to duplicate the block in your xml template, so that you'd have one complete block with <sap-id>{port}:{vlan}</sap-id> and another with <sap-id>{port}</sap-id>.

I suspected that, but how? The upper block is foreach loop.

Can i add dummy wrapper in XML that is removed or not used in XML? I'm pretty sure template below will produce the wrong config, there is no "dummy_wrapper" in config tree.

<dummy_wrapper foreach="{sap}">

        <sap when="{not(vlan=0)}">

          <sap-id >{port}:{vlan}</sap-id>

        </sap>

        <sap when="{vlan=0}">

          <sap-id>{port}</sap-id>

        </sap>

</dummy_wrapper>

It depends on the NSO version.

Starting with NSO 4.6, a functionality similar to what you illustrated is now supported.

Checkout the developer guide - search for "Template processing instructions" and around the same chapter.

If you need to use an older version of NSO, then maybe you can try and get the foreach one level higher.

If things are getting too hairy, you can also move the iteration to the code that applies the template (if that isn't a template-only service package).