Presence container in YANG mode

Hi,
We have the following containers:

augment "/if:interfaces/if:interface" {
    container test {
        when "../if:type = 'test'";

        description "test containter";

}

augment "/if:interfaces/if:interface" {
    container value {
        when "../if:type = 'value'";

        description "value containter";
        presence  "";

}

augment "/if:interfaces/if:interface" {
    container sample {
        when "../if:type = 'sample'";

        description "sample containter";
        presence  "";

}

the interface name is defined as <container_name>-
Ex: sample-1, test-2, value-3

In operational mode, when I do show with interface name say,

show interfaces interface sample-1 => getting leaf nodes of sample-1 interface
show interfaces interface value-1 => getting leaf nodes of value-1 interface

show interfaces interface sample => this list all sample interfaces only (because of the presence statement)

In value container, presence statement is not added.
so when I give “show interfaces interface value” => list all value interfaces along with other interfaces (sample and test)

test container is shared between 2 code.
One code doesn’t want presence statement to be added and other code wants.

Is there a way to deviate/refine presence statement?

Thanks in advance!

Regards,
Bala

You can add “presence” statements with refine. Obviously the container must be part of a grouping for this to work.

Hi, Can you please give me an example?

Hi,
See RFC7950 “The YANG 1.1 Data Modeling Language”
https://tools.ietf.org/html/rfc7950#section-7.13.2
https://tools.ietf.org/html/rfc7950#section-4.2.6

It is not standard yang way, but if you can use Java and Groovy in your build environment, you can also generate different versions of the yang file with https://bitbucket.org/novakmi/yangbuilder (note, this is something I have written, so may view is influenced).

This is often useful with larger models, when sometimes yang reuse and condition statements cannot be used (e.g. if-feature cannot be used under import statement), or if you want to bring reuse to another level and mix yang like syntax with the programming language (loops, conditions, functions, etc.)
The output is yang file, which is processed in regular way (confdc, pyang, etc.).

The code would look like (syntax is similar to yang):

   // augment defined as closure, so we do not repeat it 
   def augment = { type, pres = true ->
       augment "/if:interfaces/if:interface", {
           container type, {
                when "../if:type = '${type}'";
                description "${type} containter";
                if (pres) {
                    presence '""'
                }
            }
        }
        yngbuild '' //for new line
    }

    augment "test", true // or false for non presence variant
    augment "value"
    augment "sample"    

Full source code:
https://cisco.box.com/v/containergroovy

(install groovy first, e.g.: apt-get install groovy2 or look at groovy-lang.org/install.html)
run:
groovy container.groovy

Two versions of the yang data model should be generated, one with presence under test, the other without presence)