I have two leafs a and b. I want default of b as 0.8 times configured value of a. Is there any way we can do that.?
leaf a {
description “xx”;
type uint8 { range “0…60”; }
default 5;
}
leaf b {
description “xx”;
type uint8;
default 0.8 * value of a;
}
There is no way to do that in the data model. What you should do is to describe this relation in the description
statement for leaf b
, and then implement it in your instrumentation code. E.g. in a CDB subscriber that is supposed to actually do something with the value for leaf b, if there is no value set, compute the value from leaf a and use that.
There exists a related extension tailf:default-ref
(see the tailf_yang_extensions(5)
man page), but it can not express a computation, only a direct reference. In theory, you could add a leaf, say b-default
, use tailf:hidden full
for that and tailf:default-ref ../b-default
for leaf b
, and implement a set-hook or transaction-hook for leaf a
, that sets b-default
to the desired value. But this is way more complex than the method above, and doesn’t add any significant value.
Thank you @per for your response.
Tried your suggestion of setting value of leaf b at back-end implementation.