1
votes

I am writing a YANG module where I want to include a container from another module i.e. I want to define a NEW container in the module that I am writing that references a container from another module. Example of failed attempt:

 module newmodule {
 yang-version 1.1;
 namespace "urn:nist:params:xml:ns:yang:newmodule";
 prefix newmodule;

    import ietf-access-control-list {
      prefix "acl";
    }

    container newprofile {
      uses acl:access-lists;
    }
  }

I have only included the essential parts above. Here acl:access-lists is a container.

Is it possible to compose containers like this? I've tried successfully to build containers from groupings. However, in this case I have no control over the contents of ietf-access-control-list.

2
Depending on what you are trying to achieve, besides groupings, you should also take a look at the augment statement. It allows injection of your schema nodes into an existing schema node hierarchy, which is what that container you tried referencing in the example is.predi

2 Answers

2
votes

You should import the first module in the second one, then augment the first with the second:

Let's say the first module contains:

module first {
  yang-version 1.1;
  namespace "http://first";
  prefix first;

  container first-container {
    description
      "First container";
}

The second module shall have

module second {
  yang-version 1.1;
  namespace "http://second";
  prefix second;

  import first {
    prefix first;
  }

  augment "/first:first-container" {
    container second-container {
      description
        "Second container";
    }
  }
}

YANG 1.1 allows that operation:

YANG allows a module to insert additional nodes into data models, including both the current module (and its submodules) and an external module. This is useful, for example, for vendors to add vendor-specific parameters to standard data models in an interoperable way.

The "augment" statement defines the location in the data model hierarchy where new nodes are inserted, and the "when" statement defines the conditions when the new nodes are valid.

0
votes

This is apparently not possible. You can only use a grouping in this fashion and not a container.