Unique leaf value per key

Hi All,

I have requirement that one of the attribute(Optional user may choose or ignore this) in list has to be unique per key element.
Once user committed the list and if he wish to change the attribute for same key should get error. So that use has to delete the list entry and add again.

Below mentioned the snippet of list:

list list-test {
tailf:cli-suppress-mode;
tailf:cli-sequence-commands;
tailf:cli-compact-syntax;
key ip;
leaf ip {
type inet:ipv4-address;
}
leaf 2nd-ip {
tailf:cli-optional-in-sequence;
type inet:ipv4-address;
}
leaf value1 {
type string;
}
leaf value2 {
type unit8;
}
}

In above list pair of “ip and 2nd-ip” (2nd-ip can be optional user may select/ignore) once user committed he should not be allowed to change “2nd-ip” for same key element “ip”. Please let me know how we can achieve this?

Thanks
Anil

Hi,

Can anyone help me in this.

Thanks
Anil

I don’t know whether we have a special tailf clause for the same, but you can always do this using tailf:validate callbacks in validation phase.

The idea would be

  • In validation callback you would have a maapi socket and a transaction handle for the current changed cdb (changed in this commit)
  • create another (socket, thandle) as a CONFD_READ transaction towards CDB. This would give you the snapshot of CDB before the commit.
  • Now the check could be as simple as error out if leaf exist both in new cdb and old cdb and they are not same (meaning the leaf has been modified in this commit).

However note that these types of checks are generally discouraged. If A and B both are two valid snapshots of CDB, we should allow A->B transition of CDB (i.e. we should validate the final snapshot of CDB, not how we reached there).

1 Like

I think you can also use two phase subscription. If you detect modification (in first phase), you can still abort transaction. See ConfD User Guide - confd_cdb - cdb_subscribe2.

(two phase subscriber UML diagrams can be generated from this code https://github.com/ConfD-Developer/ConfD-Workshop/tree/master/ConfDUmlScenarios)