Change imported leaf to mandatory?

I’m “using” a container from another module, and without modifying the original module, I would like to make certain leafs within it mandatory in the current module.

Is this possible?

ex:

module A {
    grouping A-group {
        container A-container {
            leaf A-leaf {
                type uint8;
            }
            leaf B-leaf {
                type uint8;
            }
        }
    }
}

module B {
    import A;
    container B {
        uses A-group;
        // make A-leaf mandatory, but not B-leaf?
    }
}

I believe you want to use the “refine” statement. For example:

    uses A-group {
      refine "A-container/A-leaf" {
        mandatory true;
      }
    }

As you probably are aware of you need to add prefixes when using groupings from another YANG module.
See the YANG RFC for details on the “refine” statement RFC 7950 - The YANG 1.1 Data Modeling Language

1 Like