Subject: [yang-doctors] Checking for parent path in grouping

From: "Acee Lindem (acee)" <[email-masked]>
Date: Tue, 2 Apr 2019 19:33:25 +0000

Is there a way to check for particular parent path so that a container or leaf in a grouping would be present ONLY when it  is “used” from a particular path? For example:

grouping foo {
  container foo {
    container red {
         when “../../red-parent”;
    }
    container blue {
          when “../../blue-parent”;
     }
   }
}

container red-parent {
  uses foo;
}
 container blue-parent {
   uses foo;
}

It compiled fine using pyang but the check didn’t exclude the container with the non-matching parent from the path in the formatted tree (pyang -f tree output).

Thanks,
Acee

---

From: Martin Bjorklund <[email-masked]>
Date: Wed, 03 Apr 2019 08:03:38 +0200 (CEST)

"Acee Lindem (acee)" <[email-masked]> wrote:
> Is there a way to check for particular parent path so that a container
> or leaf in a grouping would be present ONLY when it is “used” from a
> particular path? For example:
> 
> grouping foo {
>   container foo {
>     container red {
>          when “../../red-parent”;
>     }
>     container blue {
> It compiled fine using pyang but the check didn’t exclude the
> container with the non-matching parent from the path in the formatted
> tree (pyang -f tree output).

As you noted it works, but since the "when" expressions are evaluated
at runtime, you'll see both "red" and "blue" in both parents in the
tree output - they are present in the schema, but their when
expressions will always be false.

/martin