ConfD User Community

Get count for each type in leaf-list

Hi Team, I have a requirement to limit the count of address types like ipv4: ipv6 and DNS: .

      leaf-list host {
          "Match the Host portion of the URI";
        when "../type = 'sip'";
        must "not (../pattern)" {
          error-message "Please remove pattern before proceeding";
        max-elements 13;
        type union {
          type string {
            length "1..32";
            pattern '([0-9,A-Z,a-z-]*T?)';
          type inet:ipv4-address;
          type inet:ipv6-address;

Is it possible to get the count of ipv4 ipv6 addresses? (count(ipv4 )+count(ipv46)) < 10 ;
Thank you for helping here.

You can use string XPath functions; IP addresses would be converted to their canonical string representation in which they must contain either ':' or '.', so you can do something like this:

  leaf-list host {
  must "count(host[contains(., ':') or contains(., '.')]) < 10";

Note that it might have some performance impact, especially if the leaf-list appears in a large list.

(Btw. you may want to use inet:ip-address instead of the two IP variants in a union.)

1 Like

You have “max-elements 13”. Can you change that to 9 ( that is < 10 ) and test? I think this should do exactly what you want.

Hi Team,
thank you for the reply.

@ltrinh, the requirement is to limit the IP addresses to 10 but allow alphanumeric.
had to change model and used must statement as mentioned.

1 Like

Sorry I didn’t realize this requirement in the original post.

1 Like