Using maapi in callback function for show commands

Continuing the discussion from How to implement command which will appear in config and show?:

I don’t understand how to implement maapi callback function. What are rules to build callback function name from cmdpoint name and yang list ? Where I can find example ?

If I have yang model:

	grouping my_feature_session_brief
{
          list brief
        {
            tailf:info "Show my_feature session brief format";
            tailf:cli-show-template-enter "";
            tailf:cli-show-template-footer "\n";
            tailf:cli-table-legend "Flags: Legend information\n" ;    
            tailf:cli-full-show-path { tailf:cli-max-keys 1; }
            tailf:cli-enforce-table;
            tailf:sort-order unsorted;
            leaf type           { type session_type; }
            leaf owner          { type string; }
        }
}
grouping my_feature_session_detail
{
     list detail
     {
        tailf:info "Show my_feature session detail format";
        tailf:cli-full-show-path { tailf:cli-max-keys 1; }
        tailf:cli-suppress-table;
        tailf:cli-show-template-enter "";
        tailf:cli-show-template-footer "\n";
        tailf:cli-show-template-legend "Flags: Legend information\n";
        tailf:cli-show-template  "\n"
    + "Interface                           $(interface)\n"
    + "Source address:                     $(src_address)\n"
    + "Destination address:                $(dst_address)\n"
    + "State:                              $(state)\n"
    + "...........AND SO ON..........................";
        tailf:sort-order unsorted;
        leaf state          { type session_type; }
        /*.............AND SO ON................*/
     }
} 
grouping my_feature_show_session {
    container session {
        tailf:info "Show my_feature session information";
        config false;   
        list  check  {
            key "interface destination source";
            leaf interface      { type string; }
            leaf destination    { type inet:ipv4-address; }   
            leaf source         { type inet:ipv4-address; }
        } 
        uses my_feature_session_brief;
        uses my_feature_session_detail;
    }
}

And Cli model:

<?xml version="1.0" encoding="UTF-8"?><clispec xmlns="http://tail-f.com/ns/clispec/1.0" style="c">
  <operationalMode>
    <cmd name="my_feature" mount="show">   
         <info>Show my_feature command</info>
         <help>Show my_feature command</help>
      <cmd name="session"> 
        <info>Show my_feature session</info>
        <help>Show my_feature session</help>       
        <cmd name="brief"> 
        <info>Show my_feature session brief</info>
        <help>Show my_feature session brief</help>       
	<callback>
          <capi>
             <cmdpoint>show_my_feature_session</cmdpoint>                        
	  </capi>
	</callback>
      </cmd>
     <cmd name="detail"> 
        <info>Show my_feature session detail</info>
        <help>Show my_feature session detail</help>       
	<callback>
          <capi>
             <cmdpoint>show_my_feature_session_detail</cmdpoint>                        
	  </capi>
	</callback>
      </cmd>
   </cmd>
   </cmd>
 </operationalMode>
</clispec>

I don’t know how to implement maapi_cli_cmd() callback function on C .

See example examples.confd/cli/c_cli/confd.cli to see how to implement clispec call point.

From your latest code it seems to me you are trying to model in clispec same command structure like you get from YNAG data model. This is not suggested (in original post).
The suggestion was to use clispec if you need command (command alias) that would behave same like some other command. E.g.:

show session (implemented as clispec) would be alias to show session brief - command would call in callpoint show session brief with use of maapi_cli_cmd function.

If I got you right model clispec is gonna be as follows:

    <?xml version="1.0" encoding="UTF-8"?><clispec xmlns="http://tail-f.com/ns/clispec/1.0" style="c">
      <operationalMode>
    <cmd name="my_feature" mount="show">   
         <info>Show my_feature command</info>
         <help>Show my_feature command</help>
    	<callback>
          <capi>
             <cmdpoint>show_my_feature_summary</cmdpoint>                        
    	  </capi>
    	</callback> 
      <cmd name="session"> 
        <info>Show my_feature session</info>
        <help>Show my_feature session</help>          
    	<callback>
          <capi>
             <cmdpoint>show_my_feature_session_brief</cmdpoint>                        
    	  </capi>
    	</callback>     
       </cmd>
       </cmd>
     </operationalMode>
    </clispec>

I look through example /cli/c_cli/. I didn’t find function maapi_cli_cmd.

So, i need help to understand why I do command “show my_feature” container is making it iterate through all the existing my_feature enties How to fix this issue?For example in container my_feature have other container session, where as we are concerned about list inside a particular “brief” entry. I create function path_parse in which call particular handler.

Yes, /cli/c_cli/ shows how to implement callpoint (show_my_feature_session_brief in your case), but does not use maapi_cli_cmd. Currently there is no example using maapi_cli_cmd. intro/12-c_maapi show how to use MAAPI from callpoint (but not maapi_cli_cmd). You need to look at MAAPI man page or into User guide section.

By

Do you mean that data provider iterates through all sublists?
This is how it works. The command tries to show everything under my_feature.
If you want to to do anything, just implement show_my_feature_summary callpoint and do nothing here. But note, all this (clispec) relates only to CLI, not other northbound interfaces.

1 Like

Hi Michal, I tried do it, and if I call this command, confD display this error : Error: application error.
Now I has 2 socket control and work. Do I need create maapi socket?

Can you verify (e.g. with some pritnf logging) that callpoint was called by ConfD. My guess is something wrong went in the application (callpoint). The error should be also visible in devel.log.

If you call maapi_... API from the callpoint, then you need maapi socket. Also note that you should not call anything that can invoke another event on control socket as your ConfD (poll) loop is blocked (worker socket event for this event) - e.g. validatiion (maapi_commit.., dataprovider (maapi_get_....), etc. . If you need this, you need another workersocket and poll loop in different thread.