Assuming that your list keys are name and grade you can do something like this:
container employees {
must "boolean(employee[name][grade=2])" {
error-message
"Total count of grade 2 employees must not be less than 1 once the list is initialized";
}
list employee {
key "name grade";
leaf name {
type string;
}
leaf grade {
type int32;
}
}
}
I think the must statement above works for blocking deletion of the last grade-2 employee.
But I think the requirement here is to block deletion of any employee (other grades) if there is only one grade-2 employee in the list.
Priyadarshini, Can you confirm this?
If this is the case, then you cannot do this via must statements.
The reason is because what is validated is data and not operations.
Are both valid configurations but you want to control the operation that takes us from configuration 1 to configuration 2 which is not possible in YANG.
Your only option in this case is to use the validation callback and read the new candidate configuration and compare it against the committed configuration. You can then return an error code if you decide something is wrong.