ConfD User Community

How to have a MUST NOT construct

I have a yang model for reading input like this:

    input {
        leaf interface-id {
            type uint16;
        }
        leaf ipv4 {
           type inet:ipv4-address;
        }
        choice direction-choice {
             case ingress-case {
                 leaf ingress {
                     type empty;
                  }
              }
              case egress-case {
                  leaf egress {
                      type empty;
                  }
              }
          }
      }

Now, I want to have a restriction that if an interface is configured then direction should not be listed in possible completions.
Valid: ipv4 and direction, ipv4 only, interface only
Invalid: interface and direction, interface and ipv4 and direction

Please suggest how to build this construct.

if an interface is configured then direction should not be listed in possible completions.

YANG when statement should fit the requirement - try something like:

 ...
 choice direction-choice {
     when "not(../interface-id)";
     case ingress-case {
         ...

edit: typo in when statement above, see further comments below for correct solution

Tried this, but no luck!
I still see the leaf nodes under direction-choice when interface-id is configured.

i tried editing example from ConfD basic 7.3 - examples.confd/intro/7-c_actions:

and added (changed your data type so i don’t have to import inet…)

+++ b/examples.confd/intro/7-c_actions/config.yang
@@ -40,6 +40,17 @@ module config {
       tailf:action reboot {
         tailf:actionpoint reboot-point;
         input {
+          leaf interface-id { type uint16; }
+          leaf ipv4 { type string; }
+          choice direction-choice {
+            when "not(./interface-id)";
+            case ingress-case {
+              leaf ingress { type empty; }
+            }
+            case egress-case {
+              leaf egress { type empty; }
+            }
+          }
         }

and it seems to work correctly, as expected in C style CLI:

dev# config system reboot ?
Possible completions:
  egress  ingress  interface-id  ipv4  |  <cr>
dev# config system reboot interface-id 123 ?
Possible completions:
  ipv4  |  <cr>
dev# config system reboot interface-id 123 ingress
--------------------------------------------------^
syntax error: expecting
  ipv4 -

(please note typo in my previous comment - ./ vs ../, but this should give error/warning when compiling YANG)

1 Like

Thanks much, Joseph!
I somehow missed the warning. Replacing the ../ with ./ did solve the problem!

great! i’m implicitly used to use --fail-on-warnings for confdc, and wrote first comment only from memory…
Fun with the choice/case statements is that they are not reflected into xpath data nodes and this can cause confusion/errors with some paths/api calls etc.