Annotate leaf-list in a action statement

Hi,

I need to annotate leaf-list with when/must to avoid getting a specific interface name based on below yang file:

container reset {
	config false;
	tailf:action counters {
		tailf:actionpoint reset_action;
		input {
			choice target {
				leaf-list interfaces {
					type leafref {
						path "/oc-if:interfaces/oc-if:interface/oc-if:config/oc-if:name";
					}
				}
				leaf all {
				}
			}
		}
	}
}

i tried in multiple ways but failed to make it work

tailf:annotate "/rc-if:reset/rc-if:counters/rc-if:input/rc-if:target/rc-if:interfaces" {
       1) when 'current() != "eth0"';
       2) must "current() != 'eth0'";
       3) must "deref(current())!='eth0'" {
                       tailf:dependency '.';
                       error-message "reset not allowed";
            }
       4) must "count(/oc-if:interfaces/oc-if:interface[oc-if:name = current()]/oc-if:config/oc-if:name = 'eth0')=1" {
                      error-message "reset not allowed";
           }
}

Could you please suggest the right way to annotate so that eth0 is not allowed or does no appear in the list to reset the counters.

The reason is that tailf:annotate can be used only for adding tailf:... statements. If you want to add statements like must or when, you either need to modify the original YANG file, or use a deviation module (see the RFC 7950 and the confdc documentation). The deviation in your case may look like this:

  deviation "/config:reset/config:counters/config:input/config:target/config:interfaces/config:interfaces" {
    deviate add {
      must ". != 'eth0'";
    }
  }

Note the duplication of rc-if:interfaces - this is because there is an implicit case statement.

Thanks @mvf. it worked. Is there any possibility to avoid eth0 appearing in the list? i tried with when but looks like when is not supported in deviations.

error: unexpected keyword ‘when’

Hm, right, when cannot be deviated, not sure why. But when would not help you here, a when statement referencing the current node is troublesome, to say the least (and confdc actually refuses that).

What do you mean by “to avoid eth0 appearing in the list”, do you refer to CLI completion? In that case you might need to implement a custom completion callback.

Ok. Thank you.
One last question.
is it possible to put tailf:cli-completion-actionpoint or tailf:validate as part of some condition in annotate statement? validation or completion should be called only when condition is true.
example:
tailf:annotate “/oc-if:interfaces/oc-if:interface/oc-eth:ethernet/oc-eth:config/oc-eth:port-speed” {
tailf:cli-completion-actionpoint or tailf:validate when /oc-if:interfaces/oc-if:interface/oc-if:config/oc-if:name is “etho”
}

No, I’m afraid nothing like that is possible, you would have to implement the condition in the callback code.

Note that you can use tailf:annotate-module/statement to to annotate an existing statement with ‘must’, ‘min-elements’, ‘max-elements’, ‘mandatory’, ‘unique’, and ‘when’ statements.

Hi @cohult,

Is it possible to add a condition using annotate-statement in this case?
tailf:annotate “/oc-if:interfaces/oc-if:interface/oc-eth:ethernet/oc-eth:config/oc-eth:port-speed” {
tailf:cli-completion-actionpoint port_speed;
}
ethernet is an augmented container in interfaces module. Also at the end i need to refer interface name to restrict to a specific port speed list. Is /oc-if:interfaces/oc-if:interface/oc-if:config/oc-if:name path accessible here?

I gave a try by using annotate-statement but couldn’t succeed.

Thanks,
Karthik