cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Announcements

Community Helping Community

190
Views
0
Helpful
5
Replies
Beginner

NSO yang leafref device-group

I'm attempting to create my first service template but have issues when referencing device-groups in my yang file.

 

user@ncs(config)# L2-BRIDGE TEST device-group LEAF-SWITCHES vlan 10 vni 10002

 

user@ncs(config-L2-BRIDGE-TEST)# commit dry-run outformat native


Aborted: L2-BRIDGE-template.xml:5 The node '/ncs:devices/device{LEAF-SWITCHES}' was not created. An explicit tag 'merge' or 'create' is needed.

 

The device-group LEAF-SWITCHES exists within NSO and contains some switches.

 

    leaf-list device-group {
      type leafref {
        path "/ncs:devices/ncs:device-group/ncs:name";
      }
    }
 
If I replace 'device-group' with 'device' I am able to run the service against individual nodes.  
 
Any pointers would be appreciated.
 
Thanks
 

 

Everyone's tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
Cisco Employee

Re: NSO yang leafref device-group

Hmm.. Stupid thing ate my xml tags..

Trying again:

-------------------------------

Hello,
Ok, the problem is here:
  <devices xmlns="http://tail-f.com/ns/ncs">
  <device>
    <name>{/device-group}</name> 
If you do "commit dry-run | debug template", you can see that the expression {/device-group} evaluates to the single device-group name, and that is given as the name of the device to the template above. What you need is to get the devices inside that device-group.
In this case, you can use 'deref' to dereference the leafref in your service model. So, you can use something like
  <devices xmlns="http://tail-f.com/ns/ncs">
  <device>
    <name>{deref(/device-group)/../member}</name>
(/devices/device-group/member is the flattened list of all members of a device-group. You need this, instead of devices/device-group/device-name, because device-groups can be nested).
However, the "device-group" in your service is itself a leaf-list - which means there can be multiple device-groups configured in your service model. Then the above deref won't be fully correct, since it only works for the first leaf-list entry. Now you need to iterate through the items in your service model's leaf-list, which you can do like this:
<devices xmlns="http://tail-f.com/ns/ncs">
  <?foreach {/device-group}?>
  <device>
    <name>{deref(.)/../member}</name>
    ...
    ...
  </device>
  <?end?>
</devices>
Try something like this!
 
/Ram
-------------------------------

View solution in original post

5 REPLIES 5
Cisco Employee

Re: NSO yang leafref device-group

Hi,
> Aborted: L2-BRIDGE-template.xml:5 The node '/ncs:devices/device{LEAF-SWITCHES}' was not created. An explicit tag 'merge' or 'create' is needed.

This error message means that you should explicitly use the tag "merge" or "create" in your service template, if you want to create a new device. I'm assuming you are not creating a new device, but trying to refer to an existing device in a device-group. Could you show your yang model and the service template?

Thanks,
Ram
Beginner

Re: NSO yang leafref device-group

Correct, I am not trying to create a new device as they are existing within the device-group.  My goal for this initial test is to deploy the service template to all the devices within the device-group.  

 

<config-template xmlns="http://tail-f.com/ns/config/1.0"
                 servicepoint="L2-BRIDGE">
  <devices xmlns="http://tail-f.com/ns/ncs">
  <device>
    <name>{/device-group}</name>
    <config>
      <vlan xmlns="http://tail-f.com/ned/cisco-nx">
        <vlan-list>
          <id>{/vlan}</id>
          <name>{/customer-name}</name>
          <vn-segment>{/vni}</vn-segment>
        </vlan-list>
      </vlan>
      <evpn xmlns="http://tail-f.com/ned/cisco-nx">
        <vni>
          <id>{/vni}</id>
          <l2/>
          <rd>auto</rd>
          <route-target>
            <method>import</method>
            <rt>auto</rt>
          </route-target>
          <route-target>
            <method>export</method>
            <rt>auto</rt>
          </route-target>
        </vni>
      </evpn>
      <interface xmlns="http://tail-f.com/ned/cisco-nx">
        <nve>
          <name>1</name>
          <member>
            <vni>
              <id>{/vni}</id>
              <suppress-arp/>
              <ingress-replication>
                <protocol>
                  <bgp/>
                </protocol>
              </ingress-replication>
            </vni>
          </member>
        </nve>
        <port-channel>
          <name>200</name>
          <switchport>
            <trunk>
              <allowed>
                <vlan>
                  <ids>{/vlan}</ids>
                </vlan>
              </allowed>
            </trunk>
          </switchport>
        </port-channel>
      </interface>
    </config>
  </device>
 </devices>
</config-template>
module L2-BRIDGE {
  namespace "http://com/example/L2BRIDGE";
  prefix L2-BRIDGE;

  import ietf-inet-types {
    prefix inet;
  }
  import tailf-ncs {
    prefix ncs;
  }

  list L2-BRIDGE {
    key customer-name;

    uses ncs:service-data;
    ncs:servicepoint "L2-BRIDGE";

    leaf customer-name {
      type string;
    }

    leaf-list device-group {
      type leafref {
        path "/ncs:devices/ncs:device-group/ncs:name";
      }
    }
    leaf vlan {
      mandatory true;
      type uint16;
    }
      
    leaf vni {
      mandatory true;
      type uint16;
    }
  }
}

 

Thanks!

 

Cisco Employee

Re: NSO yang leafref device-group

Hello,
Ok, the problem is here:
-----------------------



{/device-group}

-----------------------

If you do "commit dry-run | debug template", you can see that the expression {/device-group} evaluates to the single device-group name, and that is given as the name of the device to the template above. What you need is to get the devices inside that device-group.
In this case, you can use 'deref' to dereference the leafref in your service model. So, you can use something like
-----------------------



{deref(/device-group)/../member}

-----------------------
(/devices/device-group/member is the flattened list of all members of a device-group. You need this, instead of devices/device-group/device-name, because device-groups can be nested).

However, the "device-group" in your service is itself a leaf-list - which means there can be multiple device-groups configured in your service model. Then the above deref won't be fully correct, since it only works for the first leaf-list entry. Now you need to iterate through the items in your service model's leaf-list, which you can do like this:
-----------------------




{deref(.)/../member}
...
...



-----------------------

Try something like this!

/Ram
Cisco Employee

Re: NSO yang leafref device-group

Hmm.. Stupid thing ate my xml tags..

Trying again:

-------------------------------

Hello,
Ok, the problem is here:
  <devices xmlns="http://tail-f.com/ns/ncs">
  <device>
    <name>{/device-group}</name> 
If you do "commit dry-run | debug template", you can see that the expression {/device-group} evaluates to the single device-group name, and that is given as the name of the device to the template above. What you need is to get the devices inside that device-group.
In this case, you can use 'deref' to dereference the leafref in your service model. So, you can use something like
  <devices xmlns="http://tail-f.com/ns/ncs">
  <device>
    <name>{deref(/device-group)/../member}</name>
(/devices/device-group/member is the flattened list of all members of a device-group. You need this, instead of devices/device-group/device-name, because device-groups can be nested).
However, the "device-group" in your service is itself a leaf-list - which means there can be multiple device-groups configured in your service model. Then the above deref won't be fully correct, since it only works for the first leaf-list entry. Now you need to iterate through the items in your service model's leaf-list, which you can do like this:
<devices xmlns="http://tail-f.com/ns/ncs">
  <?foreach {/device-group}?>
  <device>
    <name>{deref(.)/../member}</name>
    ...
    ...
  </device>
  <?end?>
</devices>
Try something like this!
 
/Ram
-------------------------------

View solution in original post

Beginner

Re: NSO yang leafref device-group

Thanks Ram, that worked a charm!