Search code examples
ietf-netmod-yang

How to augment list from one module to another and add leafs YANG


Suppose I have two modules, I would like to extend one list with new leafs.

module A {
    list deviceList {
        key name;
        leaf name{

        }
        leaf hostname{

        }
    }
}

and I would like to augment it to another leaf

module B {
    list generalInfo{
        key customerName;
        leaf customerName{
            type string;
        }
        augment moduleA:deviceList {
            leaf ipAddress{
                
            }
        }
}

I have done it using grouping and container and list inside but this completely changes our existing structure, I would like to ommit container and grouping if thats possible.


Solution

  • It seems that you want to reuse a part of the schema definition, put it in another place in the schema tree and add a node to it.

    You cannot do it the way you tried because the augment statement can appear only on the root level or in the uses statement.

    You can do that only with a grouping but you can omit the container. Refactor A: define a grouping that's a list. Refer to it in B and augment it.

    module A {
        grouping devices {
          list deviceList {
            key name;
            leaf name{
            }
            leaf hostname{
            }
          }
        }
        uses devices;
    }
    
    module B {
        list generalInfo{
            key customerName;
            leaf customerName{
                type string;
            }
            uses moduleA:devices {
              augment "deviceList" {
                leaf ipAddress{
                }
              }
            }
        }
    }
    

    Note that if you use the augment statement in the module B then it means that any device implementing module B has to also implement module A and its root-level list deviceList. See RFC 7950 4.2.8:

    When a server implements a module containing an "augment" statement, that implies that the server's implementation of the augmented module contains the additional nodes.

    I am not sure if this is what you want. If not, then move the grouping definition to a module that contains only grouping definitions (without any "data definition statements") and import it from both A and B.