Making leaf node Conditional mandatory in yang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2022 05:23 AM
Hi,
I am trying to make a leaf node as conditional mandatory as explained below.
list top-list {
leaf type {
description "type.";
mandatory true;
type network-type; /// this type has 3 values i.e local/remote/gr-remote
}
leaf node {
description "Node details.";
type leafref {
path /// -- some reference
}
mandatory true;
when "../type = 'local'";
}
}
Now here, the ask is to have node as mandatory when type is local and optional when type is gr-remote and not allowed when type is local.
I am able to make both local & gr-remote as either mandatory or option via using "when" but not able to make leaf "node" as mandatory when type is "local" and optional when type is "gr-remote".
Any leads on this would be helpful.
Thank in advance.
Regards
Nikhil
- Labels:
-
YANG Development Kit (YDK)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2022 01:28 PM
Hi @nikhilagarwal.85,
I see that no YANG experts have commented so I'll make a suggestion. You might want to try the 'refine' statement and/or the 'default' sub-statement as described in these two StackOverflow discussions:
- How to refine the mandatory property of nodes from a grouping in YANG language?
- Conditional assignment of default values in yang
Hope this helps!
