06-19-2018 05:29 AM - edited 03-01-2019 04:11 AM
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.";
}
}
}
}
}
}
Solved! Go to Solution.
06-26-2018 08:10 AM
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";
}
}
}
}
}
06-26-2018 08:10 AM
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";
}
}
}
}
}
06-26-2018 11:50 AM
Boom!
Of course... I didn't know that you could have a "must" statement in a list... Awesome, thanks Håkan!
06-27-2018 12:58 AM
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
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide