How to define different default value for different product

As you know, the default value could be defined in Yang file for each leaf.

But how to define different default values for different product? As these products use the same Yang file and they should have different default value for one same leaf.

One way is to have a YANG annotation file per product that annotate the shared YANG model with different default values depending on product.
See ConfD 6.3-4 UG Chapter 3.7.1. “Using a YANG annotation file” and tailf_yang_extensions(5) man page under “tailf:annotate” and “tailf:annotate-module”.

I am still not very clear for the annotate to implement the case. Could you help to explain more detail?

Which part is not clear?
How to implement an annotation file that add an application specific default value to a base YANG model used by all applications that does not have a default statement?

How to define the annotation file? Then how to use in the Yang module for the annotation file?

Thanks for the clarification, A good starting point is the examples.confd/validate/c/mtest.annot.yang model that annotate the mtest.yang model.
See also the Makefile in that example for how the annotation model, mtest.annot.yang is compiled with confdc to annotate the mtest.yang model.
You can search for “tailf:annotate” in the YANG models provided in the ConfD example set for more variants.

Yang RFC also describes a way to set default value with deviate statement (for different product one can use different deviation file, see confdc --deviation).

When I tried something like this.

tailf:annotate “/if:interfaces/if:interface/if:port” {
when “current()/…/if:protocol = ‘ssh’”{
default 22;

But I am receving an error as
“error: unexpected keyword “default”.”

another way is to use deviation for different product.

deviation /base:system/base:user/base:type {
deviate add {
default “admin”; // new users are ’admin’ by default

I do not think you can add deault value conditionally, as deviation or deviate cannot have when substatement.

Yes, deviation without condition would work.

My requirement is more of having a different default values for a leaf “port” based on the leaf “protocol”.

Any other options available to achieve this ?

You can use tailf:set-hook callpoint, that would be called on every modification of the protocol leaf.
It can modify/update port leaf accordingly.

leaf protocol {
      tailf:callpoint protocol_hook {
           tailf:set-hook node;
        type string;

Unfortunately, you need to write (simple) hook callback handler.
More description is in the ConfD User Guilde, section 10.6 (Hooks)

1 Like

Thanks for your inputs :slight_smile:

I will try this one…