cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1184
Views
0
Helpful
2
Replies

How to implement a functionality similar to config# load merge ?

Shashank Srivastava
Cisco Employee
Cisco Employee

Hi,

 

I am trying to read a csv file from an OS directory and parse its output to nso config. I wanted to implement on the same lines as that of nso in-built command:

admin@ncs(config)# load merge
Possible completions:
<filename> README.ncs devices.xml logs/ ncs-cdb/ ncs.conf netsim/ packages/ scripts/ state/ storedstate target/

 

When one presses tab in this command, content of ncs-run directory gets listed. I would like to have similar behavior for my service such that when I do: my_service service_name <tab> everything in home directory should get listed.

 

Thanks,

Shashank Srivastava

2 Replies 2

vleijon
Cisco Employee
Cisco Employee
What you probably want to do is modify the cli behavior using clispec (man clispec), you can then either create a custom command and set a param to file or capi to trigger a completion callback that you can write in code. I don’t have a good example at hand unfortunately.

ramkraja
Cisco Employee
Cisco Employee

When one presses tab in this command, content of ncs-run directory gets listed. I would like to have similar behavior for my service such that when I do: my_service service_name <tab> everything in home directory should get listed.

What you need is a completion callback. You can use the extension tailf:cli-completion-actionpoint in your model, and implement a callback to provide the completions. A small snippet is provided in the javadoc for com.tailf.dp.Completion in the NSO documentation. I provide it here for reference:

Having a YANG model snippet like the following:

  container application {
    leaf file-name {
      type string;
      tailf:cli-completion-actionpoint "file-complete" {
        tailf:cli-completion-id "path";
      }
    }
  }

The corresponding completion action is as follows:

  @ActionCallback(callPoint = "file-complete",
                 callType = ActionCBType.COMPLETION)
  public Completion completion(DpActionTrans actx, char cliStyle,
                               String token, char completionChar,
                               ConfObject[] kp, String cmdPath,
                               String cmdParamId, ConfQname simpleType,
                               String extra) throws DpCallbackException {
     ....
     // User processing of the completion
     ....
     CompletionReply reply = Completion.newReply();
     reply.addCompletion("completion-entry1", null);
     ...
     reply.addCompletion("completion-entryN", null);
     reply.setCompletionInfo("my-info");
     reply.setCompletionDesc("my-description");
     return reply;
  }

/Ram