I'm trying to define a container in a sub module as below
submodule sub-module {
belongs-to main-module{
prefix "sub";
}
grouping my-container-group {
container my-container {
leaf id {
type string;
}
leaf value {
type string;
}
}
}
}
and use this container in the main-module to create a list as below
module main-module {
namespace "http://example-ns";
prefix "sub";
include sub-module;
list my-list {
key id;
uses my-container-group;
}
}
But, the pyang throws an error as below
test# pyang main-module.yang -f tree
main-module.yang:10: error: the key "id" does not reference an existing leaf
module: main-module
+--rw my-list* [id]
+--rw my-container
+--rw id? string
+--rw value? string
What am I doing wrong here?
List's keys must be children of that list. It is not enough for them to be just descendants. You have a container in between; a relative schema node identifier for leaf "id" in the context of list "my-list" would be "my-container/id".
RFC 6020, Section 7.8.2. The list's key Statement
Additionally, the text above requires a space separated list of identifiers as an argument to this statement, not a list of schema node identifiers (like in case of the "unique" statement).
The same applies with YANG 1.1, RFC 7950.
You can refactor that grouping into two groupings and use the one that defines proper contents: