how to define a list that has one leaf and this leaf is of leafref type to one of two
different leafs. Apparantly union is not supported with leafrefs. any other suggestions ?
A leafref can only point to a single leaf or leaf-list node as described in the YANG RFC:
The “path” statement, which is a substatement to the “type” statement, MUST be present if the type is “leafref”. It takes as an argument a string that MUST refer to a leaf or leaf-list node.
Hi Waitai,
at a time leaf will be pointing to either element in fruits list or flowers list.
union on leafref is not possible. is there any other way i can achieve this.
I want to create a list ‘fruitsORflowers’ each element in this list will be
pointing to a leaf either in list ‘flowers’ or ‘fruits’. since union on leaferefs
is not allowed. is there a way i can remodel my yang to achieve this.
list fruits {
key “name”;
leaf name {
type string;
}
}
list flowers {
key “name”;
leaf name {
type string;
}
}
list fruitsORflowers {
key “name”;
leaf name {
type union {
type leafref {
path “…/…/flowers/name”;
}
type leafref {
path “…/…/fruits/name”;
}
}
}
}
Not sure if this is possible.
Use of a choice helps, but it will be either Fruits or Flowers and separate type of it ?
choice myChoice {
description "Fruit or Flowers";
case fruit {
leaf fruit-name {
description "Fruit name";
type leafref {
path "../../fruits/name";
}
}
}
case flower {
leaf flower-name {
description "Flower name";·
type leafref {
path "../../flowers/name";
}
}
}
}