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

YANG, unique-selector

sumo89
Level 1
Level 1

Hi!

I have a YANG question. I should only be allowed to configure one "kebab" on each interface on a device. Below does not work, should I do external verification or is it possible in YANG?

augment /base:base {  

  // This does not work...

  tailf:unique-selector "kebabs" {

    tailf:unique-leaf "devices/device";

    tailf:unique-leaf "devices/interfaces/type";

    tailf:unique-leaf "devices/interfaces/number";

    tailf:unique-leaf "devices/interfaces/vid";

  }

  list kebabs {

    key kebab;

    leaf kebab {

      type string;

    }

   

    list devices {        

      key device;

      leaf device {

        type leafref {

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

        }        

      }

  

      list interfaces {

        // Interface is combined key, "type, number, vid"

        key "type number vid";

       

        leaf type {

          type enumeration {

            enum '10G';

            enum 'Eth-Trunk';

            enum '100G';

          }

        }

        leaf number {

          type string;

        }

        leaf vid {

          type uint32 {

            range "1..4094";

          }

          // This does not work either...

          must "count(../../../../kebabs/devices[device=current()]/interfaces[type=current()][number=current()][vid=current()]) = 1" {

            error-message "Only one kebab per interface on a device.";

          }           

        }

      }

    }

  }

}

1 Accepted Solution

Accepted Solutions

hniska
Cisco Employee
Cisco Employee

Maybe this

list kebabs {

    key kebab;

    leaf kebab {

       type string;

    }

  list devices {

    key device;

    leaf device {

     type string;

    }

    list interfaces {

      must "count(../../../kebabs/devices[device=current()/../device]/interfaces[type=current()/type][number=current()/number][vid=current()/vid]) = 1" {

        error-message "Only one kebab per interface on a device.";

      }

     key "type number vid";

     leaf type {

       type enumeration {

         enum '10G';

         enum 'Eth-Trunk';

         enum '100G';

       }

     }

     leaf number {

       type string;

     }

     leaf vid {

       type uint32 {

         range "1..4094";

        }

     }

    }

   }

  }

View solution in original post

3 Replies 3

hniska
Cisco Employee
Cisco Employee

Maybe this

list kebabs {

    key kebab;

    leaf kebab {

       type string;

    }

  list devices {

    key device;

    leaf device {

     type string;

    }

    list interfaces {

      must "count(../../../kebabs/devices[device=current()/../device]/interfaces[type=current()/type][number=current()/number][vid=current()/vid]) = 1" {

        error-message "Only one kebab per interface on a device.";

      }

     key "type number vid";

     leaf type {

       type enumeration {

         enum '10G';

         enum 'Eth-Trunk';

         enum '100G';

       }

     }

     leaf number {

       type string;

     }

     leaf vid {

       type uint32 {

         range "1..4094";

        }

     }

    }

   }

  }

Boom!

Of course... I didn't know that you could have a "must" statement in a list... Awesome, thanks Håkan!

hniska
Cisco Employee
Cisco Employee

Your main problem was your use of current(). For example you said device=current() but in the leaf vid that means the leaf vid. What you meant was the device selected in the parent parent something e.g device=current()/../../device