Is it possible to use range conditionally at schema level

Hi,

I was working on it and got a use case where I want to put range conditionally.

Ex. set user configurable maximum windows devices range from 1-5 and linux devices range from 1-10.

How to display range in confd cli like below :

test(config)#router ABC config platform windows max-devices ?
Description: No of devices can be connected.
Possible completions:
<unsignedShort, 1 … 5>

test(config)#router ABC config platform linux max-devices ?
Description: No of devices can be connected.
Possible completions:
<unsignedShort, 1 … 10>

I tried to use display-when, when and must but seems all works on leaf but here its required to put on type.
So below one is failing.

    leaf max-devices {
        type uint16{
            display-when "../paltform='windows'";
                range "1..5";
        }
        type uint16{
            display-when "../paltform='linux'";
                range "1..10";
        }
    }

One possible solution is to put range from 1 to 10 and validate it in code. But I am curious if above requirement can be solved in confd schema itself.

Any suggestion will be helpful for me.

Thanks.

Not exactly like this. First, you probably intended to write tailf:display-when or when, not display-when; when is a standard YANG statement, display-when is a Tail-f extension and must be used with a prefix. The two statements have similar (though not identical) semantics, but neither of them can be used as a child to type - they can be used only as a child to leaf, list and similar “data definition statements”.

But you can do this, with the same CLI behavior:

      container max-devices {
        choice devices {
          leaf win-devices {
            type uint16 {
              range 1..5;
            }
            tailf:cli-drop-node-name;
            when "../../platform = 'windows'";
          }
          leaf linux-devices {
            type uint16 {
              range 1..10;
            }
            tailf:cli-drop-node-name;
            when "../../platform = 'linux'";
          }
        }
      }
1 Like

Thanks Mvf.
Its really nice way to achieve it.