03-08-2019 02:22 PM
Hi all,
A quick YANG question; Consider a list of sites. These sites can be one of three types; hub, branch or transit. Only one hub can exist, but multiple branches and transits are allowed. How would I create this constraint within my YANG model?
list sites {
key site-id;
leaf site-id {
mandatory true;
type uint16;
}
leaf site-type {
type enumeration {
enum hub;
enum transit;
enum branch;
}
}
}
Solved! Go to Solution.
03-12-2019 09:00 AM
You use a must expression. So it looks something like
must "count(/sites[site-type='hub']) < 2";
03-12-2019 04:02 PM
Apparent I had an issue with the path. Solved it by using this syntax instead:
must "count(current()/../../sites[site-type='hub']) < 2"
The sites were in a list of WANs, but the path {/wan/sites[site-type]} didn't work for me either. Probably since I would have to reference the key of the WAN list (name). I dunno, but the above works.. :)
03-12-2019 09:00 AM
You use a must expression. So it looks something like
must "count(/sites[site-type='hub']) < 2";
03-12-2019 03:26 PM
Thanks :)
I get this error;
warning: The 'must' expression will fail: the node 'sites' from module 'wan' (in node 'site-type' in module 'wan' from 'wan') is not found.
I've added this to the module;
list sites {
key site-id;
leaf site-id {
mandatory true;
type uint16;
}
leaf site-type {
type enumeration {
enum hub;
enum transit;
enum branch;
}
must "count(/sites[site-type='hub']) < 2" {
error-message "Only one HUB can be present";
}
}
}
03-12-2019 04:02 PM
Apparent I had an issue with the path. Solved it by using this syntax instead:
must "count(current()/../../sites[site-type='hub']) < 2"
The sites were in a list of WANs, but the path {/wan/sites[site-type]} didn't work for me either. Probably since I would have to reference the key of the WAN list (name). I dunno, but the above works.. :)
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