# Annotate leaf-list in a action statement

**URL:** https://dmap-community.ductus.global/t/annotate-leaf-list-in-a-action-statement/3502
**Category:** YANG
**Created:** [February 10, 2021, 11:19am UTC](https://dmap-community.ductus.global/t/annotate-leaf-list-in-a-action-statement/3502 "2021-02-10T11:19:05Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![linga.kartheek](https://avatars.discourse-cdn.com/v4/letter/l/e9a140/32.png) [@linga.kartheek](https://dmap-community.ductus.global/u/linga.kartheek)
#### Post date: [February 10, 2021, 11:19am UTC](https://dmap-community.ductus.global/t/annotate-leaf-list-in-a-action-statement/3502/1 "2021-02-10T11:19:05Z")

</div>

Hi,

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

```auto
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

```auto
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.

---

<div class="post-metadata">

### Author: ![mvf](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/mvf/32/182_2.png) [@mvf](https://dmap-community.ductus.global/u/mvf)
#### Post date: [February 10, 2021, 2:37pm UTC](https://dmap-community.ductus.global/t/annotate-leaf-list-in-a-action-statement/3502/2 "2021-02-10T14:37:45Z")

</div>

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:

```auto
  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.

---

<div class="post-metadata">

### Author: ![linga.kartheek](https://avatars.discourse-cdn.com/v4/letter/l/e9a140/32.png) [@linga.kartheek](https://dmap-community.ductus.global/u/linga.kartheek)
#### Post date: [February 10, 2021, 4:29pm UTC](https://dmap-community.ductus.global/t/annotate-leaf-list-in-a-action-statement/3502/3 "2021-02-10T16:29:22Z")

</div>

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’

---

<div class="post-metadata">

### Author: ![mvf](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/mvf/32/182_2.png) [@mvf](https://dmap-community.ductus.global/u/mvf)
#### Post date: [February 11, 2021, 9:40am UTC](https://dmap-community.ductus.global/t/annotate-leaf-list-in-a-action-statement/3502/4 "2021-02-11T09:40:49Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![linga.kartheek](https://avatars.discourse-cdn.com/v4/letter/l/e9a140/32.png) [@linga.kartheek](https://dmap-community.ductus.global/u/linga.kartheek)
#### Post date: [February 11, 2021, 9:50am UTC](https://dmap-community.ductus.global/t/annotate-leaf-list-in-a-action-statement/3502/5 "2021-02-11T09:50:22Z")

</div>

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”  
}

---

<div class="post-metadata">

### Author: ![mvf](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/mvf/32/182_2.png) [@mvf](https://dmap-community.ductus.global/u/mvf)
#### Post date: [February 11, 2021, 10:22am UTC](https://dmap-community.ductus.global/t/annotate-leaf-list-in-a-action-statement/3502/6 "2021-02-11T10:22:37Z")

</div>

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

---

<div class="post-metadata">

### Author: ![cohult](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/cohult/32/221_2.png) [@cohult](https://dmap-community.ductus.global/u/cohult)
#### Post date: [February 11, 2021, 11:15am UTC](https://dmap-community.ductus.global/t/annotate-leaf-list-in-a-action-statement/3502/7 "2021-02-11T11:15:52Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![linga.kartheek](https://avatars.discourse-cdn.com/v4/letter/l/e9a140/32.png) [@linga.kartheek](https://dmap-community.ductus.global/u/linga.kartheek)
#### Post date: [February 11, 2021, 12:51pm UTC](https://dmap-community.ductus.global/t/annotate-leaf-list-in-a-action-statement/3502/8 "2021-02-11T12:51:57Z")

</div>

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
