0

Trying to use one Yang leaf with two different if-types depending on the value given. Currently have:

leaf interface_number {
        when "boolean(string(/payload/interface_type) != 'ae')";
            type isyt:interface_number_value;
        when "boolean(string(/payload/interface_type) == 'ae')";
            type isyt:interface_lag_value;
        description
            "Interface Number. Example value: 1/1/1 or 11 for LAG";
        mandatory "true";
    }

I have also tried:

        leaf interface_number {
        when "boolean(string(/payload/interface_type) != 'ae')" {
            type isyt:interface_number_value;
        }
        when "boolean(string(/payload/interface_type) == 'ae')" {
            type isyt:interface_lag_value;
        }
        description
            "Interface Number. Example value: 1/1/1 or 11 for LAG";
        mandatory "true";
    }

Yang seems to accept the first when they errors on the second when statements' boolean. Is this even possible? or is there a better method to use for this.

1 Answers1

0

That's not how the YANG syntax works; the type statement cannot be conditional upon the when. The when affects the whole enclosing node, so if it evaluates to false, your interface_number would not be valid at all.

What you can do here is to create a choice whose case statements are when-conditional depending on the type of the ../interface_type leaf. This will need a different name for each of the leaf that you define within these case statements.

Jan Kundrát
  • 3,700
  • 1
  • 18
  • 29