Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expand_dbvar usage in clispec #553

Open
EvgeniiVR opened this issue Sep 11, 2024 · 1 comment
Open

expand_dbvar usage in clispec #553

EvgeniiVR opened this issue Sep 11, 2024 · 1 comment
Labels

Comments

@EvgeniiVR
Copy link
Contributor

EvgeniiVR commented Sep 11, 2024

Hello team,
Have some issue with expand_dbvar usage in clispec file.
Does it support nested expansion when one list is located inside another?
If so what is the correct syntax for the path?

let's say we have the following simple yang

container C1 {
  list L1 {
    key name;
    leaf name {
       type string;
     }
     container C2{
        list L2 {
          key name;
          leaf name {
             type string;
          }
        }
     }
  }
}

And in the cli I'd like to get the second list name expansion and completion to work.
I've tried the following spec:

show {
  container {
    (<list1:string>("Show list1 name.")|<list1:string> expand_dbvar("running","/C1/L1=%s/name)>){
      (<list2:string>("Show list2 name.")|<list2:string> expand_dbvar("running","/C1/L1[name='%s']/C2/L2=%s/name)>), some_callbak();
    }
  }
}

Also tried the following paths:

(<list2:string>("Show list2 name.")|<list2:string> expand_dbvar("running","/C1/L1=%s/name/C2/L2=%s/name)>)
and
(<list2:string>("Show list2 name.")|<list2:string> expand_dbvar("running","/C1/L1=%k/name/C2/L2=%s/name)>)

but no luck.

@EvgeniiVR EvgeniiVR changed the title expand_dbvar use in clispec expand_dbvar usage in clispec Sep 11, 2024
@olofhagsand
Copy link
Member

Why dont you use the autocli where these rules are already generated?

I put your YANG in clixon-example.yang, installed and started a backend and cli

# sudo clixon_backend -f /usr/local/etc/clixon/example.xml
# clixon_cli -f  /usr/local/etc/clixon/example.xml
cli/> set C1 L1 a C2 L2 b 
cli/> show auto C1 L1 ?     
  <cr>
  a                    
  <name>                        
cli/> show auto C1 L1 a C2 L2 ?
  <cr>
  b                    
  <name>               
cli /> 

If you want your own callback, you can add that in the clispec declaration:

show container  {
       @datamodelshow, some_callback();
    }

where some_callback() needs to have the following argument list:

 * @param[in]  h     Clixon handle
 * @param[in]  cvv   Vector of variables from CLIgen command-line
 * @param[in]  argv  String vector of show options, format:
 *   <api_path_fmt>  Generated API PATH (this is added implicitly, not actually given in argv)
 *  [<mt-point>]     Optional YANG path-arg/xpath from mount-point

If you really want to make manual rules, you can look at the generated rule with the -G option:

# clixon_cli -G1 -f /usr/local/etc/clixon/example.xml
   C1,overwrite_me("/clixon-example:C1"), act-container;{
      L1,overwrite_me("/clixon-example:C1/L1=%s"),act-list;
{
         (<name:string>|<name:string expand_dbvar("candidate","/clixon-example:C1/L1=%s/name")>),overwrite_me("/clixon-example:C1/L1=%s/"), act-lastkey;{
         C2,overwrite_me("/clixon-example:C1/L1=%s/C2"), act-container;{
            L2,overwrite_me("/clixon-example:C1/L1=%s/C2/L2=%s"),act-list;{
               (<name:string>|<name:string expand_dbvar("candidate","/clixon-example:C1/L1=%s/C2/L2=%s/name")>),overwrite_me("/clixon-example:C1/L1=%s/C2/L2=%s/"), act-lastkey;{
            }
            }
         }
      }
      }
   }

Then edit that to something you like, eg:

show container {
         (<name:string>|<name:string expand_dbvar("candidate","/clixon-example:C1/L1=%s/name")>),cli_show_auto("/clixon-example:C1/L1=%s/", "running", "default", true, false, "report-all"){
               (<name:string>|<name:string expand_dbvar("candidate","/clixon-example:C1/L1=%s/C2/L2=%s/name")>),overwrite_me("/clixon-example:C1/L1=%s/C2/L2=%s/"),cli_show_auto("/clixon-example:C1/L1=%s/", "running", "default", true, false, "report-all");
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants