Yang: Force user to input from the list to which the node is referring to

518 views Asked by At

I am new to yang. Below is my yang config.

 container ntp {
 tailf:info "NTP Configuration";
 tailf:cli-oper-info "Display NTP information";
 tailf:cli-incomplete-show-path;

 //ntp server config
 leaf-list server {
  tailf:info "NTP servers";
  ordered-by user;
  tailf:cli-flat-list-syntax {
    tailf:cli-replace-all;
  }
  type gw-types:ipv4-host;
  max-elements 4;
}

 container auth {
   tailf:info "Configure NTP authentication keys";
   list server {
     tailf:info "Configured ip addresses";
     tailf:cli-suppress-mode;
     tailf:cli-sequence-commands;
     tailf:cli-incomplete-command;
     tailf:cli-compact-syntax;

     key "serverip";

     leaf serverip {
       tailf:info "ip address";
       type leafref {
       path "/gw-system:ntp/server";
       }
     }
     leaf key {
       tailf:info "Authentication key ID for this server";
       type uint32 {
       range "1..65535";
       }
     }
     choice authtype {
      tailf:cli-incomplete-command;
      leaf sha256 {
        tailf:info "Value of the sha256 key";
        type tailf:aes-cfb-128-encrypted-string {
        tailf:info "Cleartext or AES encrypted key";
     }
    }
   }
  }
 }
}

I want to achieve the below two requirements. Can someone please help me

  1. I have used type leafrefin node serverip so that a user can input ip address which is present in the leaf-list server. When I tested it, I was able to input some random ip address also which is not present in the leaf-list server to whom my leaf serverip is referring. When I do commit then it gives error Illegal reference but I wanted that user should not be allowed to complete the command if he has given the random ip which is not present in the list. Is there any way to restrict him at run time when he is typing the command instead showing error at commit.

  2. leaf serveripis referring to the leaf-list server. I want that if user try to remove the targeted node i.e. server then automatically all it's dependent should be deleted first. Like first all the dependents should be removed and then main node.
    Or
    it should give error to user that, delete the dependent node first before deleting targeted node. i.e. Before deleting the leaf-list server user should be asked to delete node serverip first. How can I achieve either of them?

1

There are 1 answers

0
Sachin On

As per my understanding in question 1 you want to restrict "leafref". But as per RFC 6020.

"A leafref cannot be restricted." - Refer RFC Section 9.9.1

       leaf serverip {
          tailf:info "ip address";
             type leafref {
                 path "/gw-system:ntp/server";
             }
       }

In this leaf all the server IPs will be available and with tab we can get the same. If still want to apply some logic here then you can try :

choice or when statement to apply some logic here.

For the 2nd Question, You can try to make all mandatory leafs as key. It should work.