cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
610
Views
0
Helpful
4
Replies

How to disable cli commands after a leaf in yang model in nso?

Elvin J
Level 1
Level 1

I have a container and inside there is one action leaf which has 3 enums.   

 

 

 

container container_name {
          
          leaf action {
            type enumeration {
              enum key1;
              enum key2;
              enum key3;
            }
            default key2;
          }
leaf leaf_name {
            when "../action = 'key1'";
            default 10;
          }

 

 


In nso cli, after writing  

 

 

 

 

container_name  key1  ?

 

 

 

 it shows 

 

 

 

Possible completions:
key2
key3
<cr>

 

 

 I want to disable possible combinations after i put container_name key1 10  and nothing should be followed after this cli

 which is wrong , it should only accept one enum at the same time. Is it possible to modify behavior of this autocompletion from my yang models?

4 Replies 4

Ruben Cocheno
Spotlight
Spotlight

@Elvin J 

An example 

leaf my-enum{
        type enumeration {
            enum single{value 1;}
            enum dual{value 2;}            
        }
    }
Tag me to follow up.
Please mark it as Helpful and/or Solution Accepted if that is the case. Thanks for making Engineering easy again.
Connect with me for more on Linkedin https://www.linkedin.com/in/rubencocheno/

I get error: unterminated statement for keyword "value"

I dont think it is what i want.  I want to disable possible combinations after i put container_name key1 10  and nothing should be followed after this cli

tohagber
Cisco Employee
Cisco Employee

That yang snippet you show do render the commands as you show. Where does the action token go in your illustration? Does it have a drop-node-name extension in module?

What you show in the yang module render the commands as:
# container_name ?
Possible completions:
action
# container_name action ?
Possible completions:
key1 key2 key3
# container_name action key1 ?
Possible completions:
leaf_name <cr>
# container_name action key1 leaf_name ?
Possible completions:
<int>[10]

Maybe you simplified the yang snippet when you shared it? Anyhow I don't think the commands that you are illustrating is consistent with the yang snippet.
If you describe how you want each token to render and also show what you expect to see on "show running-config.." for this config i can probably suggest you a way on how the model needs look like.

rogaglia
Cisco Employee
Cisco Employee

Hi,

As it was said by others, your ask is not really clear. What you may be looking for is adding a must statement which would limit the possible completions in the second leaf like this example (you can use any Xpath1.0 expression). There are other NSO features like validation callbacks and policies that could be applied too.

  leaf action {
    type enumeration {
      enum key1;
      enum key2;
    }
    default key2;
  }
  leaf leaf_name {
            when "../action = 'key1'";
            type uint16;
            default 10;
            must "(../action='key1' and current()<20) or (../action='key2' and current()>8)";
  }

which ends up with a result solution:

admin@ncs% set action key1
[ok][2024-02-07 11:29:48]

[edit]
admin@ncs% set leaf_name 14
[ok][2024-02-07 11:29:56]

[edit]
admin@ncs% validate
Validation complete
[ok][2024-02-07 11:29:58]

[edit]
admin@ncs% set leaf_name 35
[ok][2024-02-07 11:30:01]

[edit]
admin@ncs% validate
Failed: 'leaf_name' (value "35"): the 'must' expression "(../action='key1' and current()<20) or (../action='key2' and current()>8)" failed
[error][2024-02-07 11:30:04]

[edit]
admin@ncs%