YANG "if-feature" statement

It is possible in YANG to “tag” certain nodes with an “if-feature” statement.

The syntax is: if-feature ;

The goal of features in YANG is to achieve a conditional support of data trees based on the hardware capabilities. This is specified during the compilation time of YANG modules.

In order to make use of the “if-feature” capability, developers needs to define the associated feature in YANG.

Example: feature.yang

feature featureA {
}
feature featureB {
}

container foo {
if-feature featureA;
}
container bar {
if-feature featureB;
}

During compilation, if we want to enable feature A and not feature B, we need to specify -F featureA to confdc. “man confdc” has more details on this.

confdc -c -o feature.fxs -F feature:featureA feature.yang

If the -F option is not specified, all of the features defined in the YANG file will be enabled by default.

Hello,

I have a pyang build error with if-feature, always i got “bad value “my expression” (should be if-feature-expr)”
I 'am using 1.15 pyang programm version

Can you please tell me what is the root cause ?

many thanks for your help.

You can try the same pyang command using the pyang version that comes with ConfD so you can debug this further.

I tried the command below and it was successful using the Pyang that comes with ConfD under $CONFD_DIR/bin/

pyang ietf-interfaces.yang -F if-mib -f tree

What is the command you ran?

-Nabil

When working with ConfD, you should only use the version of pyang which comes with your ConfD distribution. You should not use the open source distribution of pyang from github. The pyang in the ConfD distribution includes some extra things for working with ConfD.

Hello,

yes the problem in my pyang path .

Many thanks for your help

Br

We have an issue after upgrading the confd version to 6.3.0.2, In the previous version if-feature works fine without any issue. In the below code “mandatory true;” not worked.
Looks like it is enabled by default. How do we enable specific

    tailf:action turboramtest {
           tailf:actionpoint fosdiagtests;
         input {
            leaf slot {
                if-feature platform_chassis;
                type slotidtype;
                mandatory true;
            }

Please use the latest version of ConfD to reproduce. ConfD-7.8.3 is available for download on Devnet: