How to implement command which will appear in config and show?

I want to add my feature, which will should include both config and show commands. I think that you need to create the main container “my_feature” which consist of 2 containers: the first container “conf_feature” and the second “show_feature”. For example:

  container my_feature {
        container conf_feature {
         tailf:cli-drop-node-name;
         tailf:info commands my_feature;
         tailf:cli-add-mode;
         leaf something_conf_1 {}
         leaf something_conf_2{}
         }
         container show_feature {
         config false;
          tailf:info show my_feature information;
          tailf:cli-drop-node-name;
          tailf:callpoint show_feature;
               container interface {
                      list brief {}
                      list detail {}
               }
               container other_info {}
          }
 }

I want to enter command $ show my_feature, and invoke callback function for display my_feature summary information. I don`t understand how to implement.
Also I enter command $ show my_feature interface, Confd makes a call to a function callback for 2 branches of the brief and details at once, what do you need to specify so that by default it does only for the brief?

In case you need specializedoutpu in CLI, you can use custom clispec comand for operational mode. In callback of this clispec you can call regular CLI via maapi. E.g. clispec command show my_feature interface would call in callback maapi_cli_cmd with string parameter "show my_feature interface brief". See clispec section in ConfD User guide and confd_lib_maapi - command maapi_cli_cmd.

Hi mnovak, thnx for this answer. I read user guide Confd to chapters cli and maapi. I don’t need specializedoutput in CLI. I tried create 2 sub-modules. The first submodule consist of config parameters and it have main container “my_feature”. I create the second submodule which import the first submodule also augment “/my_feature” and consist of operational data. It’s working. I have problem. Custom help texts is shown both in config and show modes because it add in container “my_feature” in tailf:info Config commands my_feature. How to implement other text in show mode?

Hello,

OK, from description:

Confd makes a call to a function callback for 2 branches of the brief and details at once, what do you need to specify so that by default it does only for the brief?

U thought you need special CLI behavior (i.e. make show my_feature interface behave as show my_feature interface brief), which could be achieved with clispec.

By “2 sub-modules” , do you mean YANG submodules (submodule statment) or something elese? I’m not fully sure what kid of reuse do you try to achieve. maybe grouping statement can help here. Please, paste example.

submodule my_feature_conf 
{

	belong-to main_yang { prefix main_yang; }
	import tailf-common { prefix tailf; }

grouping MyFeatureGlobalCommands{
    	leaf Set1{
        	type Set1;
        	tailf:info "Set 1";
    	}
    	leaf  Set2{
        	type Set2;
        	tailf:info "Set 2;
    	}
        }
        uses MyFeatureCommonCommands;
    }
}

	container my_feature{
    	tailf:info "My_feature commands";
    	tailf:cli-add-mode;
    	uses MyFeatureGlobalCommands;
	}
}

/*******************  my_feature-show-command ************************************/

submodule my_feature_show
{
	belong-to main_yang { prefix main_yang; }
	import tailf-common { prefix tailf; }	
	import ietf-inet-types { prefix inet; }

	include my_feature_conf; 	


	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;
            key "interface destination source";
            leaf interface      { type string; }
            leaf destination    { type inet:ipv4-address; }   
            leaf source         { type inet:ipv4-address; }
            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;
        key "interface src_address dst_address";
        leaf interface      { type string; }
        leaf src_address    { type inet:ipv4-address; }
        leaf dst_address    { type inet:ipv4-address; }
        leaf state          { type session_type; }
        /*.............AND SO ON................*/
     }
} 
grouping my_feature_show_session {
    container session {
        tailf:info "Show my_feature session information";
        config false;        
        uses my_feature_session_brief;
        uses my_feature_session_detail;
    }
}

	grouping MyFeatureShowData {

    container my_feature_show{
        tailf:cli-drop-node-name;
        tailf:info "Show my_feature information";
        tailf:callpoint MyFeatureShow {}
        config false;
        list client {
            tailf:info "Show my_feature client information";
                tailf:sort-order unsorted;
                key "name state";
                leaf name           { type string; }
                leaf state          { type string; }
                leaf num-sessions   { type uint32; }
                uses my_feature_show_summary;
                uses my_feature_show_session;
                uses my_feature_show_neighbor;
                uses my_feature_show_counters;
                uses my_feature_show_interface;
        }
        uses my_feature_show_summary;
        uses my_feature_show_session;
        uses my_feature_show_neighbor;
        uses my_feature_show_counters;
        uses my_feature_show_interface;
    }
}
augment "/my_feature" { uses MyFeatureShowData;}
}

I pasted example.

If I got it right, I need do this command move src=“my_feature interface” dest=“my_feature interface brief”

I have question in my example. In grouping session has 2 list brief and detail. How to describe lists, that I could to will request both list with check key? For example:

$ show my_feature session brief

Confd check key “interface src_address dst_address”, and call get_object list brief.

$show my_feature session detail

Confd check key “interface src_address dst_address”, and call get_object list brief and list detail.

I meant something like this:

<?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">            
      <cmd name="interface">                
	<callback>
          <capi>
             <cmdpoint>show_my_feature_interface</cmdpoint>                        
	  </capi>
	</callback>
      </cmd>
   </cmd>
 </operationalMode>
</clispec>

Then in callpoint (in C application) you can call maapi_cli_cmd("show my_feature interface brief"), so everytime you issue show my_feature interface it will be redirected to show my_feature interface brief.

Do you mean tailf:info "My_feature commands"; under my_feature container? In case you mix operational and config data (commands), I think you need to choose info statement that can be applied to both modes (as you datamodel is part of both modes). This info seems applicable for both modes.

What would be the purpose of calling get_object for brief if you are in detail list? Do you have some reuse in mind? If so, in C callback you can implement reuse in C (just extract common parts to some function). E.g. reuse to get key element values (as they are same for both - brief and detail).

1 Like