* Added cligen variable translation.
* See FAQ and example
This commit is contained in:
parent
b230215eaf
commit
cfe4702069
6 changed files with 65 additions and 1 deletions
|
|
@ -3,8 +3,10 @@
|
|||
## 3.7.0 (Upcoming)
|
||||
### Major changes:
|
||||
### Minor changes:
|
||||
* Added cligen variable translation.
|
||||
* See FAQ and example
|
||||
### Corrected Bugs
|
||||
- Fixed JSON unbalanced braces resultin assert.
|
||||
* Fixed JSON unbalanced braces resultin assert.
|
||||
|
||||
## 3.6.0 (30 April 2018)
|
||||
|
||||
|
|
|
|||
|
|
@ -277,6 +277,9 @@ cli_load_syntax(clicon_handle h,
|
|||
}
|
||||
if (cligen_expandv_str2fn(pt, (expandv_str2fn_t*)clixon_str2fn, handle) < 0)
|
||||
goto done;
|
||||
/* Variable translation functions */
|
||||
if (cligen_translate_str2fn(pt, (translate_str2fn_t*)clixon_str2fn, handle) < 0)
|
||||
goto done;
|
||||
|
||||
/* Make sure we have a syntax mode specified */
|
||||
if (mode == NULL || strlen(mode) < 1) { /* may be null if not given in file */
|
||||
|
|
|
|||
30
doc/FAQ.md
30
doc/FAQ.md
|
|
@ -344,3 +344,33 @@ To authenticate, the callback needs to return the value 1 and supply a username.
|
|||
|
||||
See [../apps/example/example_restconf.c] plugin_credentials() for
|
||||
an example of HTTP basic auth.
|
||||
|
||||
## How do I write a CLI translator function
|
||||
|
||||
The CLI can perform variable translation. This is useful if you want to
|
||||
prcess the input, such as hashing, encrypting or in other way
|
||||
translate the input.
|
||||
|
||||
Yang example:
|
||||
```
|
||||
list translate{
|
||||
leaf value{
|
||||
type string;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
CLI specification:
|
||||
```
|
||||
translate value (<value:string translate:incstr()>),cli_set("/translate/value");
|
||||
```
|
||||
|
||||
If you run this example using the `incstr()` function which increments the characters in the input, you get this result:
|
||||
```
|
||||
cli> translate value HAL
|
||||
cli> show configuration
|
||||
translate {
|
||||
value IBM;
|
||||
}
|
||||
```
|
||||
You can perform translation on any type, not only strings.
|
||||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue