* Added cligen variable translation.

* See FAQ and example
This commit is contained in:
Olof hagsand 2018-05-28 22:50:22 +02:00
parent b230215eaf
commit cfe4702069
6 changed files with 65 additions and 1 deletions

View file

@ -11,6 +11,12 @@ module example {
}
description
"Example code that includes ietf-ip and ietf-routing";
/* Translation function example - See also example_cli */
list translate{
leaf value{
type string;
}
}
rpc client-rpc {
description "Example local client-side RPC that is processed by the
the netconf/restconf and not sent to the backend.

View file

@ -137,3 +137,21 @@ clixon_plugin_init(clicon_handle h)
return &api;
}
/*! Translate function from an original value to a new.
* In this case, assume string and increment characters, eg HAL->IBM
*/
int
incstr(cligen_handle h,
cg_var *cv)
{
char *str;
int i;
if (cv_type_get(cv) != CGV_STRING)
return 0;
str = cv_string_get(cv);
for (i=0; i<strlen(str); i++)
str[i]++;
return 0;
}

View file

@ -3,6 +3,11 @@ CLICON_MODE="example";
CLICON_PROMPT="%U@%H> ";
CLICON_PLUGIN="example_cli";
# Translate variable "value" by incrementing its characters
translate value (<value:string translate:incstr()>),cli_set("/translate/value");
# Note, when switching to PT, change datamodel to only @datamodel
set @datamodel:example, cli_set();
merge @datamodel:example, cli_merge();