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

XPath - Nested deref() ?

alexis_m
Level 1
Level 1

Hello,

Imagine i have two module, "switch" and "port". A switch has a name and i associated with a device (the "parent-device").

A "port" object is the association of a "switch" and an interface number (int-number).

module switch {

  namespace "http://dna.prodinfo.gca/switch";

  prefix switch;

  import ietf-inet-types { prefix inet; }

  import tailf-common { prefix tailf; }

  import tailf-ncs { prefix ncs; }

  import dna { prefix dna; }

  import environment { prefix environment; }

  import tailf-ned-cisco-nx { prefix nx; }

  description

    "Switch Service";

augment /dna:dna {

  list switch {

    description "Abstraction service for Nexus Switchs";

    key name;

    leaf name {

      tailf:info "switch name";

      type string;

    }

    leaf parent-device {

      tailf:info "Parent device (only for FEX)";

      type leafref {

        path "/ncs:devices/ncs:device/ncs:name";

      }

    }

}

module port {

  namespace "http://dna.prodinfo.gca/port";

  prefix port;

  import ietf-inet-types { prefix inet; }

  import tailf-common { prefix tailf; }

  import tailf-ncs { prefix ncs; }

  import dna { prefix dna; }

  import tailf-ned-cisco-nx { prefix nx; }

  import customer { prefix customer; }

  import switch { prefix switch; }

  import vlan { prefix vlan; }

  description

    "Port Service";

  }

augment /dna:dna {

  list port {

    uses ncs:service-data;

    ncs:servicepoint port-servicepoint;

    description "Port Service";

    key "device int-number";

    leaf device {

      tailf:info "Device Name";

      type leafref {

        path "/ncs:devices/ncs:device/ncs:name";

        //path "/dna:dna/switch:switch/switch:name";

      }

    }

    leaf int-number {

      tailf:info "Interface number";

      type leafref {

        //Neither of the 3 following line is working.

        //path "deref(deref(../switch)/../switch:parent-device)/../ncs:config/nx:interface/nx:Ethernet/nx:name";   => NOT WORKING

        //path "/ncs:devices/ncs:device[ncs:name=current()/../switch]/ncs:config/nx:interface/nx:Ethernet/nx:name"; => NOT WORKING

        //path "/ncs:devices/ncs:device[ncs:name=deref(../switch)/../switch:parent-device)]/ncs:config/nx:interface/nx:Ethernet/nx:name"; => NOT WORKING

      }

    }

}

I would like to be able to autocomplete the "int-number" field using the list of interfaces available on the "parent-device" associated to the "switch". But so far i didn't succeed to it.

Could someone explain me how to do it please ?

Regards,

Alexis

3 Replies 3

yfherzog
Cisco Employee
Cisco Employee

Hi,

I did a bit of exercise out of this, and this is what I found:

It's possible to make the leaf-refs in the way that you specified in your question.

However, it seems as NSO CLI has some difficulties with performing the autocomplete in the case where both device and int-numbers are keys for the port list.

If I only use device as key, then it works as expected, while if I use both as keys the cli crashes.

I'm not sure if it should be possible to achieve this when the two leafs are acting as keys, but the crash is probably a bug.

To workaround this, you can have the device as key, and out a unique statement on the int-number.

See the module I created below (I put both lists on the same module and used ios NED, but you should be able to use nexus NED and split the code into two modules).

Yftach

module switch-port {

  namespace "http://com/example/switchport";

  prefix switch-port;

  import ietf-inet-types {

    prefix inet;

  }

  import tailf-ncs {

    prefix ncs;

  }

  import tailf-ned-cisco-ios {

    prefix ios;

  }

  container switch-port {

    list switch {

      key name;

      leaf name {

        type string;

      }

      leaf parent-device {

        type leafref {

          path "/ncs:devices/ncs:device/ncs:name";

        }

      }

    }

    list port {

      //key "device int-number";

      key device;

      leaf device {

        type leafref {

          //path "/ncs:devices/ncs:device/ncs:name";

          path "/switch-port:switch-port/switch-port:switch/switch-port:name";

        }

      }

      leaf int-number {

        type leafref {

          path "/ncs:devices/ncs:device/ncs:config/ios:interface/ios:Ethernet/ios:name";

        }

        must "current() = deref(deref(current()/../device)/../parent-device)/../ncs:config/ios:interface/ios:Ethernet/ios:name";

      }

    }

  }

}

Has the nested deref CLI crash been filed as a bug? I ask as I recently ran into this as well and am hoping that it will be fixed.

Hi All,

You could use multiple keys with an autocomplete if you use deref in your key. Before NSOv4.5.2, multiple keys with deref might crash the NSO CLI if you don't use proper values but it is fixed now. You could find the CHANGE information below.

- CLI: CLI restarts when set list multiple key leafs with leafref and must expression. This has now been fixed. (ENG-230, RT:30638, PS-10170)


list switch {

      key name;

      uses ncs:service-data;

      ncs:servicepoint "switch";

      leaf name {

        type string;

      }

      leaf parentdevice {

        type leafref {

          path "/ncs:devices/ncs:device/ncs:name";

        }

      }

    }


list port {

      key "switch int-number";

      uses ncs:service-data;

      ncs:servicepoint "port";

      leaf switch {

        type leafref {

          path "/switch:switch/switch:name";

        }

      }

   leaf int-number {

        type leafref {

          path "/ncs:devices/ncs:device/ncs:port";

      }

        must "current() = /ncs:devices/ncs:device[ncs:name = deref(current()/../switch)/../switch:parentdevice]/ncs:port";

    }

}


admin@ncs(config)# port test1 10022

admin@ncs(config-port-test1/10022)# top

admin@ncs(config)# commit dry-run

cli {

    local-node {

        data +switch test1 {

             +    parentdevice d1;

             +}

             +port test1 10022 {

             +}

    }

}


admin@ncs(config)# port test1 12

admin@ncs(config-port-test1/12)# top

admin@ncs(config)# commit dry-run

Aborted: illegal reference 'port test1 12 int-number'

Thanks,

Bilgehan.

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the NSO Developer community: