Custom output on cli

Hi all,

My cli command is “show network device router info 2 5” (2,5 are user input).
i want output as “ciscorouter running”
i am sharing my yang and code(ref from arp) please help me.

module dwm {
namespace “http://tail-f.com/ns/example/dwm”;
prefix dwm;

import ietf-inet-types {
prefix inet;
}
import tailf-common {
prefix tailf;
}

container network {
container device {
container router {

list info {
tailf:callpoint pvt;
config false;
key “first_val second_val”;
max-elements 10;

 leaf first_val {
   type uint16 {
   range "0 .. 3";
   }
 }

 leaf second_val {
   type uint16 {
   range "0 .. 3";
   }
 }

}

}
}
}

struct aentry {
int first_val;
int second_val;
struct aentry *next;
};

struct arpdata {
struct aentry *arp_entries;
struct timeval lastparse;
};

static int get_next(struct confd_trans_ctx *tctx,
confd_hkeypath_t *keypath,
long next)
{
struct arpdata *dp = tctx->t_opaque;
struct aentry *curr;
confd_value_t v[2];
if (next == -1) { // first call
if (run_arp(dp) == CONFD_ERR)
return CONFD_ERR;
curr = dp->arp_entries;
next = 0;
} else {
curr = (struct aentry *)next;
}
if (curr == NULL) {
confd_data_reply_next_key(tctx, NULL, -1, -1);
return CONFD_OK;
}

// 2 keys
CONFD_SET_UINT16(&v[0], curr->first_val);
CONFD_SET_UINT16(&v[1], curr->second_val );
confd_data_reply_next_key(tctx, &v[0], 2, (long)curr->next);
return CONFD_OK;

}

static int get_elem(struct confd_trans_ctx *tctx,
confd_hkeypath_t *keypath)
{
confd_value_t v;
int id,id1;

switch (CONFD_GET_XMLTAG(&(keypath->v[0][0]))) {
case dwm_first_val:
id = CONFD_GET_UINT16(&(keypath->v[1][0]));
id1 = CONFD_GET_UINT16(&(keypath->v[1][1]));
printf("\n\t $$$$ params = %d %d \n",id,id1);  // 2 5
return_result = get_module(id, id1, 1);
printf("buf_string = %s \n", buf_string);  //ciscorouter running
CONFD_SET_STR(&v, buf_string);  
default:
return CONFD_ERR;
}
confd_data_reply_value(tctx,&v);
return CONFD_OK;

}

show network device router info 2 5
FIRST SECOND
VAL VAL

2 5

You can use ConfD’s show templates feature to achieve your required output. An example using your YANG model will look something like the following:

container network {
  container device {
    container router {
      list info {
        tailf:callpoint pvt;
        config false;
        key "first_val second_val";
        max-elements 10;
        tailf:cli-suppress-table;
        tailf:cli-show-template-enter "";
        tailf:cli-show-template
          'cisco router running $(first_val) $(second_val)\n';
        leaf first_val {
          type uint16 {
            range "0 .. 3";
          }
        }

        leaf second_val {
          type uint16 {
            range "0 .. 3";
          }
        }
      }
    }
  }
}

With the above annotated YANG model, the show output will look as follows:

localhost# show network device router info 2 3 
cisco router running 2 3
localhost#

Hi,

Here we are hard coding ‘cisco router running $(first_val) $(second_val)’ in yang file which was not my requirement. From my C code i am calling get_module() which internally calls SDK api and updates buf_string(global variable) with “cisco router running”

code:
return_result = get_module(id, id1, 1); //id=2, id1=3, flag=1
printf(“buf_string = %s \n”, buf_string);
CONFD_SET_STR(&v, buf_string);
confd_data_reply_value(tctx,&v);

my requirement is
switch5# show network device router info 2 3
cisco router running

The data provider API allows you to return what is modeled in your YANG model. In order to tailor the show output other than using show templates, you will need to use the clispec to add your own custom show command as described in Chapter 16.21.6, Adding custom show output, of the ConfD User Guide.

Hi Waitai
Let me know is there any example available under the examples.confd folder to demonstrate how to use clispec to tailor the show output ?

You can find the relevant CLI example under examples.confd/cli/cli_command in the premium version of ConfD.