1

I need to implement a yang mode for CLI: "member instance [template <name> | <instance-id>]" . The CLI has 3 prototypes: "member instance", "member instance template <name>", "member instance <id>". "member instance" means using the default template which equals "member instance template default".

Like below:

container member {
    list instance {
        key "instance-id";
        leaf instance-id {
            type uint16;
        }
    }
}

container member {
    container instance {
        list template {
            key "template-name"
            leaf template-name {
                type string;
            }
        }
    }
}

container member {
    leaf instance {
        type empty;
    }
}

But I want to merge them under the same member container node. I am blocked because the list does not support empty key, how would I be able to do it? I tried 2 list keys using mandatory false, but it does not work.

Lian Fu
  • 11
  • 2

1 Answers1

1

In YANG, all data nodes that appear the same level of data node tree hierarchy must be unique. This includes data nodes that appear within choices and cases, which do not get to be instantiated directly. All data nodes belong to the same namespace, meaning that it does not matter if a node is a container, list or leaf - there can never be two "siblings" with the same identifier and a different YANG keyword in a valid model if those keywords represent data nodes.

Since your requirement is essentially to violate this rule, it cannot be expressed with YANG. My suggestion would be to apply the KISS principle here, and just do:

module d {
  yang-version 1.1;
  namespace "d:uri";
  prefix "d";
  
  container member {
    choice by-id-or-by-name {
      mandatory true;
      list instance-by-id {
        key "instance-id";
        leaf instance-id {
          type uint16;
        }
      }
      container instance {
        presence "Represents a named instance template.";
        description "A missing 'template' list implies a default template.";
        list template {
          key "template-name";
          leaf template-name {
            type string;
          }
        }
      }
    }
  }

}

The presence statement is important in this case, since that container has special meaning to you in a config.

predi
  • 5,528
  • 32
  • 60