I have below yang models
container PORT {
description "PORT part of config_db.json";
list PORT_LIST {
key "name";
leaf name {
type string {
length 1..128;
}
}
leaf-list lanes {
type string {
length 1..128;
}
}
}
}
And below config
PORT": {
"PORT_LIST": [
{
"name": "Ethernet8",
"lanes": ["65", "66"]
},
{
"name": "Ethernet9",
"lanes": ["65", "67"]
}
]
}
How to add a constraint, 'must' or 'unique' such that elements of leaf-list 'lanes' are unique across all nodes in PORT_LIST. In above example value '65' in 'lanes' field should be allowed only in one node.
The
unique
statement may only refer to one or moreleaf
statements, so that is not an option.You should be able to achieve a similar result with a
must
statement and a condition like this:The condition says something along the lines of: if there are any lanes for this PORT_LIST entry, none of them should have the same value as the lanes in any of the PORT_LIST entries that come before this one.
This is just a quick example, there may be more efficient ways to define the condition.