CLI configurable format: [Default format should be configurable](https://github.com/clicon/clixon-controller/issues/87)
Added option: `CLICON_CLI_OUTPUT_FORMAT` - Default CLI output format
This commit is contained in:
parent
bd3a841103
commit
60a774cbf7
18 changed files with 168 additions and 83 deletions
|
|
@ -15,9 +15,14 @@ Expected: June 2024
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
|
* CLI configurable format: [Default format should be configurable](https://github.com/clicon/clixon-controller/issues/87)
|
||||||
|
|
||||||
* New `clixon-config@2024-04-01.yang` revision
|
* New `clixon-config@2024-04-01.yang` revision
|
||||||
* Added options: `CLICON_NETCONF_DUPLICATE_ALLOW` - Disable duplicate check in NETCONF messages
|
* Added options:
|
||||||
|
- `CLICON_NETCONF_DUPLICATE_ALLOW` - Disable duplicate check in NETCONF messages
|
||||||
|
- `CLICON_CLI_OUTPUT_FORMAT` - Default CLI output format
|
||||||
* New `clixon-lib@2024-04-01.yang` revision
|
* New `clixon-lib@2024-04-01.yang` revision
|
||||||
|
- Added: Default format
|
||||||
|
|
||||||
## 7.0.1
|
## 7.0.1
|
||||||
3 April 2024
|
3 April 2024
|
||||||
|
|
|
||||||
|
|
@ -926,6 +926,7 @@ cli_validate(clixon_handle h,
|
||||||
* @param[in] db2 Name of second datastrore
|
* @param[in] db2 Name of second datastrore
|
||||||
* @retval 0 OK
|
* @retval 0 OK
|
||||||
* @retval -1 Error
|
* @retval -1 Error
|
||||||
|
* @note JSON and CLI are NYI
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
compare_db_names(clixon_handle h,
|
compare_db_names(clixon_handle h,
|
||||||
|
|
@ -975,7 +976,7 @@ compare_db_names(clixon_handle h,
|
||||||
goto done;
|
goto done;
|
||||||
cligen_output(stdout, "%s", cbuf_get(cb));
|
cligen_output(stdout, "%s", cbuf_get(cb));
|
||||||
break;
|
break;
|
||||||
case FORMAT_JSON:
|
case FORMAT_JSON: /* XXX NYI */
|
||||||
case FORMAT_CLI:
|
case FORMAT_CLI:
|
||||||
if (clixon_compare_xmls(xc1, xc2, format) < 0) /* astext? */
|
if (clixon_compare_xmls(xc1, xc2, format) < 0) /* astext? */
|
||||||
goto done;
|
goto done;
|
||||||
|
|
@ -1023,6 +1024,14 @@ compare_dbs(clixon_handle h,
|
||||||
clixon_err(OE_XML, 0, "format not found %s", formatstr);
|
clixon_err(OE_XML, 0, "format not found %s", formatstr);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
/* Special default format handling */
|
||||||
|
if (format == FORMAT_DEFAULT){
|
||||||
|
formatstr = clicon_option_str(h, "CLICON_CLI_OUTPUT_FORMAT");
|
||||||
|
if ((int)(format = format_str2int(formatstr)) < 0){
|
||||||
|
clixon_err(OE_PLUGIN, 0, "Not valid format: %s", formatstr);
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (compare_db_names(h, format, db1, db2) < 0)
|
if (compare_db_names(h, format, db1, db2) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
retval = 0;
|
retval = 0;
|
||||||
|
|
@ -1318,6 +1327,8 @@ save_config_file(clixon_handle h,
|
||||||
goto done;
|
goto done;
|
||||||
fprintf(f, "</edit-config></rpc>]]>]]>\n");
|
fprintf(f, "</edit-config></rpc>]]>]]>\n");
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
} /* switch */
|
} /* switch */
|
||||||
retval = 0;
|
retval = 0;
|
||||||
/* Fall through */
|
/* Fall through */
|
||||||
|
|
|
||||||
|
|
@ -286,7 +286,7 @@ pipe_showas_fn(clixon_handle h,
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
if (cvec_len(argv) > argc){
|
if (cvec_len(argv) > argc){
|
||||||
if (cli_show_option_format(argv, argc++, &format) < 0)
|
if (cli_show_option_format(h, argv, argc++, &format) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
if (cvec_len(argv) > argc){
|
if (cvec_len(argv) > argc){
|
||||||
|
|
|
||||||
|
|
@ -611,13 +611,13 @@ cli_show_common(clixon_handle h,
|
||||||
int skiptop
|
int skiptop
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
cxobj *xt = NULL;
|
cxobj *xt = NULL;
|
||||||
cxobj *xerr;
|
cxobj *xerr;
|
||||||
cxobj **vec = NULL;
|
cxobj **vec = NULL;
|
||||||
size_t veclen;
|
size_t veclen;
|
||||||
cxobj *xp;
|
cxobj *xp;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (state && strcmp(db, "running") != 0){
|
if (state && strcmp(db, "running") != 0){
|
||||||
clixon_err(OE_FATAL, 0, "Show state only for running database, not %s", db);
|
clixon_err(OE_FATAL, 0, "Show state only for running database, not %s", db);
|
||||||
|
|
@ -713,6 +713,7 @@ done:
|
||||||
|
|
||||||
/*! Common internal parse cli show format option
|
/*! Common internal parse cli show format option
|
||||||
*
|
*
|
||||||
|
* @param[in] h Clixon handle
|
||||||
* @param[in] argv String vector: <dbname> <format> <xpath> [<varname>]
|
* @param[in] argv String vector: <dbname> <format> <xpath> [<varname>]
|
||||||
* @param[in] argc Index into argv
|
* @param[in] argc Index into argv
|
||||||
* @param[out] format Output format
|
* @param[out] format Output format
|
||||||
|
|
@ -720,18 +721,29 @@ done:
|
||||||
* @retval -1 Error
|
* @retval -1 Error
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
cli_show_option_format(cvec *argv,
|
cli_show_option_format(clixon_handle h,
|
||||||
|
cvec *argv,
|
||||||
int argc,
|
int argc,
|
||||||
enum format_enum *format)
|
enum format_enum *formatp)
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
char *formatstr;
|
enum format_enum format = FORMAT_XML;
|
||||||
|
char *formatstr;
|
||||||
|
|
||||||
formatstr = cv_string_get(cvec_i(argv, argc));
|
formatstr = cv_string_get(cvec_i(argv, argc));
|
||||||
if ((int)(*format = format_str2int(formatstr)) < 0){
|
if ((int)(format = format_str2int(formatstr)) < 0){
|
||||||
clixon_err(OE_PLUGIN, 0, "Not valid format: %s", formatstr);
|
clixon_err(OE_PLUGIN, 0, "Not valid format: %s", formatstr);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
/* Special default format handling */
|
||||||
|
if (format == FORMAT_DEFAULT){
|
||||||
|
formatstr = clicon_option_str(h, "CLICON_CLI_OUTPUT_FORMAT");
|
||||||
|
if ((int)(format = format_str2int(formatstr)) < 0){
|
||||||
|
clixon_err(OE_PLUGIN, 0, "Not valid format: %s", formatstr);
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*formatp = format;
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
return retval;
|
return retval;
|
||||||
|
|
@ -774,7 +786,7 @@ cli_show_option_bool(cvec *argv,
|
||||||
|
|
||||||
/*! Common internal parse cli show with-default option
|
/*! Common internal parse cli show with-default option
|
||||||
*
|
*
|
||||||
* Ddefault modes accorsing to RFC6243 + three extra modes based on report-all-tagged:
|
* Default modes accorsing to RFC6243 + three extra modes based on report-all-tagged:
|
||||||
* 1) NULL
|
* 1) NULL
|
||||||
* 2) report-all-tagged-default Strip "default" attribute (=report-all)
|
* 2) report-all-tagged-default Strip "default" attribute (=report-all)
|
||||||
* 3) report-all-tagged-strip Strip "default" attribute and all nodes tagged with it (=trim)
|
* 3) report-all-tagged-strip Strip "default" attribute and all nodes tagged with it (=trim)
|
||||||
|
|
@ -878,7 +890,7 @@ cli_show_config(clixon_handle h,
|
||||||
}
|
}
|
||||||
dbname = cv_string_get(cvec_i(argv, argc++));
|
dbname = cv_string_get(cvec_i(argv, argc++));
|
||||||
if (cvec_len(argv) > argc)
|
if (cvec_len(argv) > argc)
|
||||||
if (cli_show_option_format(argv, argc++, &format) < 0)
|
if (cli_show_option_format(h, argv, argc++, &format) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (cvec_len(argv) > argc)
|
if (cvec_len(argv) > argc)
|
||||||
xpath = cv_string_get(cvec_i(argv, argc++));
|
xpath = cv_string_get(cvec_i(argv, argc++));
|
||||||
|
|
@ -1062,7 +1074,7 @@ cli_show_auto(clixon_handle h,
|
||||||
else
|
else
|
||||||
dbname = str;
|
dbname = str;
|
||||||
if (cvec_len(argv) > argc)
|
if (cvec_len(argv) > argc)
|
||||||
if (cli_show_option_format(argv, argc++, &format) < 0)
|
if (cli_show_option_format(h, argv, argc++, &format) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (cvec_len(argv) > argc){
|
if (cvec_len(argv) > argc){
|
||||||
if (cli_show_option_bool(argv, argc++, &pretty) < 0)
|
if (cli_show_option_bool(argv, argc++, &pretty) < 0)
|
||||||
|
|
@ -1194,7 +1206,7 @@ cli_show_auto_mode(clixon_handle h,
|
||||||
}
|
}
|
||||||
dbname = cv_string_get(cvec_i(argv, argc++));
|
dbname = cv_string_get(cvec_i(argv, argc++));
|
||||||
if (cvec_len(argv) > argc)
|
if (cvec_len(argv) > argc)
|
||||||
if (cli_show_option_format(argv, argc++, &format) < 0)
|
if (cli_show_option_format(h, argv, argc++, &format) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (cvec_len(argv) > argc){
|
if (cvec_len(argv) > argc){
|
||||||
if (cli_show_option_bool(argv, argc++, &pretty) < 0)
|
if (cli_show_option_bool(argv, argc++, &pretty) < 0)
|
||||||
|
|
@ -1868,3 +1880,60 @@ cli_show_statistics(clixon_handle h,
|
||||||
cbuf_free(cb);
|
cbuf_free(cb);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! CLI set default output format
|
||||||
|
*
|
||||||
|
* @param[in] h Clixon handle
|
||||||
|
* @param[in] cvv Vector of cli string and instantiated variables, expected: 1: format
|
||||||
|
* @param[in] argv Vector, expected NULL
|
||||||
|
* @retval 0 OK
|
||||||
|
* @retval -1 Error
|
||||||
|
* Format of argv:
|
||||||
|
* <api-path-fmt> Generated
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
cli_format_set(clixon_handle h,
|
||||||
|
cvec *cvv,
|
||||||
|
cvec *argv)
|
||||||
|
{
|
||||||
|
int retval = -1;
|
||||||
|
cg_var *cv;
|
||||||
|
char *str;
|
||||||
|
enum format_enum fmt = FORMAT_XML;
|
||||||
|
|
||||||
|
if ((cv = cvec_find(cvv, "fmt")) == NULL){
|
||||||
|
clixon_err(OE_PLUGIN, EINVAL, "Requires one variable to be <format>");
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
str = cv_string_get(cv);
|
||||||
|
if ((fmt = format_str2int(str)) < 0){
|
||||||
|
clixon_err(OE_PLUGIN, EINVAL, "Invalid format: %s", str);
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
/* Alt make a int option/data */
|
||||||
|
retval = clicon_option_str_set(h, "CLICON_CLI_OUTPUT_FORMAT", str);
|
||||||
|
done:
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! CLI set default output format
|
||||||
|
*
|
||||||
|
* @param[in] h Clixon handle
|
||||||
|
* @param[in] cvv Vector of cli string and instantiated variables, expected: 1: format
|
||||||
|
* @param[in] argv Vector, expected NULL
|
||||||
|
* @retval 0 OK
|
||||||
|
* @retval -1 Error
|
||||||
|
* Format of argv:
|
||||||
|
* <api-path-fmt> Generated
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
cli_format_show(clixon_handle h,
|
||||||
|
cvec *cvv,
|
||||||
|
cvec *argv)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
str = clicon_option_str(h, "CLICON_CLI_OUTPUT_FORMAT");
|
||||||
|
cligen_output(stderr, "%s\n", str);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,7 @@ int cli_show_common(clixon_handle h, char *db, enum format_enum format, int pret
|
||||||
|
|
||||||
int show_yang(clixon_handle h, cvec *vars, cvec *argv);
|
int show_yang(clixon_handle h, cvec *vars, cvec *argv);
|
||||||
int show_conf_xpath(clixon_handle h, cvec *cvv, cvec *argv);
|
int show_conf_xpath(clixon_handle h, cvec *cvv, cvec *argv);
|
||||||
int cli_show_option_format(cvec *argv, int argc, enum format_enum *format);
|
int cli_show_option_format(clixon_handle h, cvec *argv, int argc, enum format_enum *format);
|
||||||
int cli_show_option_bool(cvec *argv, int argc, int *result);
|
int cli_show_option_bool(cvec *argv, int argc, int *result);
|
||||||
int cli_show_option_withdefault(cvec *argv, int argc, char **withdefault, char **extdefault);
|
int cli_show_option_withdefault(cvec *argv, int argc, char **withdefault, char **extdefault);
|
||||||
int cli_show_config(clixon_handle h, cvec *cvv, cvec *argv);
|
int cli_show_config(clixon_handle h, cvec *cvv, cvec *argv);
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ cli> set table parameter a ?
|
||||||
cli> set table parameter a value 42
|
cli> set table parameter a value 42
|
||||||
cli> validate
|
cli> validate
|
||||||
cli> commit
|
cli> commit
|
||||||
cli> show configuration xml
|
cli> show configuration
|
||||||
<table xmlns="urn:example:clixon">
|
<table xmlns="urn:example:clixon">
|
||||||
<parameter>
|
<parameter>
|
||||||
<name>a</name>
|
<name>a</name>
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,9 @@ edit @datamodelmode, cli_auto_edit("basemodel");
|
||||||
up, cli_auto_up("basemodel");
|
up, cli_auto_up("basemodel");
|
||||||
top, cli_auto_top("basemodel");
|
top, cli_auto_top("basemodel");
|
||||||
set @datamodel, cli_auto_set();
|
set @datamodel, cli_auto_set();
|
||||||
|
set default {
|
||||||
|
format("Set default output format") <fmt:string choice:xml|json|text|cli>("CLI output format"), cli_format_set();
|
||||||
|
}
|
||||||
merge @datamodel, cli_auto_merge();
|
merge @datamodel, cli_auto_merge();
|
||||||
create @datamodel, cli_auto_create();
|
create @datamodel, cli_auto_create();
|
||||||
delete("Delete a configuration item") {
|
delete("Delete a configuration item") {
|
||||||
|
|
@ -77,18 +80,17 @@ copy("Copy and create a new object") {
|
||||||
discard("Discard edits (rollback 0)"), discard_changes();
|
discard("Discard edits (rollback 0)"), discard_changes();
|
||||||
|
|
||||||
show("Show a particular state of the system"){
|
show("Show a particular state of the system"){
|
||||||
|
default{
|
||||||
|
format("Show default output format"), cli_format_show();
|
||||||
|
}
|
||||||
auto("Show expand x"){
|
auto("Show expand x"){
|
||||||
xml @datamodelshow, cli_show_auto("candidate", "xml", true, false, "report-all");
|
@datamodelshow, cli_show_auto("candidate", "default", true, false, "report-all");
|
||||||
text @datamodelshow, cli_show_auto("candidate", "text", true, false, "report-all");
|
|
||||||
json @datamodelshow, cli_show_auto("candidate", "json", true, false, "report-all");
|
|
||||||
netconf @datamodelshow, cli_show_auto("candidate", "netconf", true, false, "report-all");
|
|
||||||
cli @datamodelshow, cli_show_auto("candidate", "cli", true, false, "report-all", "set ");
|
|
||||||
}
|
}
|
||||||
xpath("Show configuration") <xpath:string>("XPATH expression")
|
xpath("Show configuration") <xpath:string>("XPATH expression")
|
||||||
[<ns:string>("Namespace")], show_conf_xpath("candidate");
|
[<ns:string>("Namespace")], show_conf_xpath("candidate");
|
||||||
version("Show version"), cli_show_version("candidate", "text", "/");
|
version("Show version"), cli_show_version("candidate", "text", "/");
|
||||||
options("Show clixon options"), cli_show_options();
|
options("Show clixon options"), cli_show_options();
|
||||||
compare("Compare candidate and running databases"), compare_dbs("running", "candidate", "xml");{
|
compare("Compare candidate and running databases"), compare_dbs("running", "candidate", "default");{
|
||||||
xml("Show comparison in xml"), compare_dbs("running", "candidate", "xml");
|
xml("Show comparison in xml"), compare_dbs("running", "candidate", "xml");
|
||||||
text("Show comparison in text"), compare_dbs("running", "candidate", "text");
|
text("Show comparison in text"), compare_dbs("running", "candidate", "text");
|
||||||
}
|
}
|
||||||
|
|
@ -98,32 +100,25 @@ show("Show a particular state of the system"){
|
||||||
text, cli_pagination("use xpath var", "es", "http://example.com/ns/example-social", "text", "10");
|
text, cli_pagination("use xpath var", "es", "http://example.com/ns/example-social", "text", "10");
|
||||||
json, cli_pagination("use xpath var", "es", "http://example.com/ns/example-social", "json", "10");
|
json, cli_pagination("use xpath var", "es", "http://example.com/ns/example-social", "json", "10");
|
||||||
}
|
}
|
||||||
configuration("Show configuration"), cli_show_auto_mode("candidate", "text", true, false);{
|
configuration("Show configuration"), cli_show_auto_mode("candidate", "default", true, false, "explicit", "set ");{
|
||||||
xml("Show configuration as XML"), cli_show_auto_mode("candidate", "xml", true, false);{
|
default("With-default mode"){
|
||||||
default("With-default mode"){
|
report-all, cli_show_auto_mode("candidate", "default", true, false, "report-all");
|
||||||
report-all, cli_show_auto_mode("candidate", "xml", true, false, "report-all");
|
trim, cli_show_auto_mode("candidate", "default", true, false, "trim");
|
||||||
trim, cli_show_auto_mode("candidate", "xml", true, false, "trim");
|
explicit, cli_show_auto_mode("candidate", "default", true, false, "explicit");
|
||||||
explicit, cli_show_auto_mode("candidate", "xml", true, false, "explicit");
|
report-all-tagged, cli_show_auto_mode("candidate", "default", true, false, "report-all-tagged");
|
||||||
report-all-tagged, cli_show_auto_mode("candidate", "xml", true, false, "report-all-tagged");
|
report-all-tagged-default, cli_show_auto_mode("candidate", "default", true, false, "report-all-tagged-default");
|
||||||
report-all-tagged-default, cli_show_auto_mode("candidate", "xml", true, false, "report-all-tagged-default");
|
report-all-tagged-strip, cli_show_auto_mode("candidate", "default", true, false, "report-all-tagged-strip");
|
||||||
report-all-tagged-strip, cli_show_auto_mode("candidate", "xml", true, false, "report-all-tagged-strip");
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
cli("Show configuration as CLI commands"), cli_show_auto_mode("candidate", "cli", true, false, "explicit", "set ");
|
|
||||||
netconf("Show configuration as netconf edit-config operation"), cli_show_auto_mode("candidate", "netconf", true, false);
|
|
||||||
text("Show configuration as text"), cli_show_auto_mode("candidate", "text", true, false);
|
|
||||||
json("Show configuration as JSON"), cli_show_auto_mode("candidate", "json", true, false);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
state("Show configuration and state"), cli_show_auto_mode("running", "text", true, true); {
|
state("Show configuration and state"), cli_show_auto_mode("running", "default", true, true); {
|
||||||
xml("Show configuration and state as XML"), cli_show_auto_mode("running", "xml", true, true);{
|
xml("Show configuration and state as XML"), cli_show_auto_mode("running", "default", true, true);{
|
||||||
default("With-default mode"){
|
default("With-default mode"){
|
||||||
report-all, cli_show_auto_mode("running", "xml", true, true, "report-all");
|
report-all, cli_show_auto_mode("running", "default", true, true, "report-all");
|
||||||
trim, cli_show_auto_mode("running", "xml", true, true, "trim");
|
trim, cli_show_auto_mode("running", "default", true, true, "trim");
|
||||||
explicit, cli_show_auto_mode("running", "xml", true, true, "explicit");
|
explicit, cli_show_auto_mode("running", "default", true, true, "explicit");
|
||||||
report-all-tagged, cli_show_auto_mode("running", "xml", true, true, "report-all-tagged");
|
report-all-tagged, cli_show_auto_mode("running", "default", true, true, "report-all-tagged");
|
||||||
report-all-tagged-default, cli_show_auto_mode("running", "xml", true, true, "report-all-tagged-default");
|
report-all-tagged-default, cli_show_auto_mode("running", "default", true, true, "report-all-tagged-default");
|
||||||
report-all-tagged-strip, cli_show_auto_mode("running", "xml", true, true, "report-all-tagged-strip");
|
report-all-tagged-strip, cli_show_auto_mode("running", "default", true, true, "report-all-tagged-strip");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -182,14 +182,15 @@ typedef int (xml_applyfn_t)(cxobj *x, void *arg);
|
||||||
typedef struct clixon_xml_vec clixon_xvec; /* struct defined in clicon_xml_vec.c */
|
typedef struct clixon_xml_vec clixon_xvec; /* struct defined in clicon_xml_vec.c */
|
||||||
|
|
||||||
/* Alternative tree formats,
|
/* Alternative tree formats,
|
||||||
* @see format_int2str, format_str2int
|
* @see format_int2str, format_str2int, datastore_format in clixon-lib.yang
|
||||||
*/
|
*/
|
||||||
enum format_enum{
|
enum format_enum{
|
||||||
FORMAT_XML,
|
FORMAT_XML,
|
||||||
FORMAT_JSON,
|
FORMAT_JSON,
|
||||||
FORMAT_TEXT,
|
FORMAT_TEXT,
|
||||||
FORMAT_CLI,
|
FORMAT_CLI,
|
||||||
FORMAT_NETCONF
|
FORMAT_NETCONF,
|
||||||
|
FORMAT_DEFAULT
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,7 @@
|
||||||
#include "clixon_queue.h"
|
#include "clixon_queue.h"
|
||||||
#include "clixon_hash.h"
|
#include "clixon_hash.h"
|
||||||
#include "clixon_handle.h"
|
#include "clixon_handle.h"
|
||||||
|
#include "clixon_string.h"
|
||||||
#include "clixon_event.h"
|
#include "clixon_event.h"
|
||||||
#include "clixon_yang.h"
|
#include "clixon_yang.h"
|
||||||
#include "clixon_xml.h"
|
#include "clixon_xml.h"
|
||||||
|
|
@ -83,24 +84,18 @@
|
||||||
|
|
||||||
static int _atomicio_sig = 0;
|
static int _atomicio_sig = 0;
|
||||||
|
|
||||||
/*! Formats (showas) derived from XML
|
|
||||||
*/
|
|
||||||
struct formatvec{
|
|
||||||
char *fv_str;
|
|
||||||
int fv_int;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*! Translate between int and string of tree formats
|
/*! Translate between int and string of tree formats
|
||||||
*
|
*
|
||||||
* @see eum format_enum
|
* @see enum format_enum
|
||||||
*/
|
*/
|
||||||
static struct formatvec _FORMATS[] = {
|
static const map_str2int _FORMATS[] = {
|
||||||
{"xml", FORMAT_XML},
|
{"xml", FORMAT_XML},
|
||||||
{"text", FORMAT_TEXT},
|
{"text", FORMAT_TEXT},
|
||||||
{"json", FORMAT_JSON},
|
{"json", FORMAT_JSON},
|
||||||
{"cli", FORMAT_CLI},
|
{"cli", FORMAT_CLI},
|
||||||
{"netconf", FORMAT_NETCONF},
|
{"netconf", FORMAT_NETCONF},
|
||||||
{NULL, -1}
|
{"default", FORMAT_DEFAULT},
|
||||||
|
{NULL, -1}
|
||||||
};
|
};
|
||||||
|
|
||||||
/*! Translate from numeric format to string representation
|
/*! Translate from numeric format to string representation
|
||||||
|
|
@ -111,12 +106,7 @@ static struct formatvec _FORMATS[] = {
|
||||||
char *
|
char *
|
||||||
format_int2str(enum format_enum showas)
|
format_int2str(enum format_enum showas)
|
||||||
{
|
{
|
||||||
struct formatvec *fv;
|
return (char*)clicon_int2str(_FORMATS, showas);
|
||||||
|
|
||||||
for (fv=_FORMATS; fv->fv_int != -1; fv++)
|
|
||||||
if (fv->fv_int == showas)
|
|
||||||
break;
|
|
||||||
return fv?(fv->fv_str?fv->fv_str:"unknown"):"unknown";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Translate from string to numeric format representation
|
/*! Translate from string to numeric format representation
|
||||||
|
|
@ -127,12 +117,7 @@ format_int2str(enum format_enum showas)
|
||||||
enum format_enum
|
enum format_enum
|
||||||
format_str2int(char *str)
|
format_str2int(char *str)
|
||||||
{
|
{
|
||||||
struct formatvec *fv;
|
return clicon_str2int(_FORMATS, str);
|
||||||
|
|
||||||
for (fv=_FORMATS; fv->fv_int != -1; fv++)
|
|
||||||
if (strcmp(fv->fv_str, str) == 0)
|
|
||||||
break;
|
|
||||||
return fv?fv->fv_int:-1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Given family, addr str, port, return sockaddr and length
|
/*! Given family, addr str, port, return sockaddr and length
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
if [ $(whoami) != root ]; then
|
if [ $(whoami) != root ]; then
|
||||||
EXTRAUSER="<user-name>$(whoami)</user-name>"
|
EXTRAUSER="<user-name>$(whoami)</user-name>"
|
||||||
|
else
|
||||||
|
EXTRAUSER=""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Three groups from RFC8341 A.1 (admin extended with $USER)
|
# Three groups from RFC8341 A.1 (admin extended with $USER)
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ cat <<EOF > $cfg
|
||||||
<CLICON_BACKEND_PIDFILE>/usr/local/var/run/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
|
<CLICON_BACKEND_PIDFILE>/usr/local/var/run/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
|
||||||
<CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
|
<CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
|
||||||
<CLICON_YANG_LIBRARY>true</CLICON_YANG_LIBRARY>
|
<CLICON_YANG_LIBRARY>true</CLICON_YANG_LIBRARY>
|
||||||
|
<CLICON_CLI_OUTPUT_FORMAT>xml</CLICON_CLI_OUTPUT_FORMAT>
|
||||||
</clixon-config>
|
</clixon-config>
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
|
@ -89,19 +90,19 @@ new "wait backend"
|
||||||
wait_backend
|
wait_backend
|
||||||
|
|
||||||
new "cli show config startup"
|
new "cli show config startup"
|
||||||
expectpart "$($clixon_cli -1 -f $cfg -l o show config xml default report-all)" 0 '<table xmlns="urn:example:clixon">' '<map xmlns="urn:example:augment">' '<enable>true</enable>'
|
expectpart "$($clixon_cli -1 -f $cfg -l o show config default report-all)" 0 '<table xmlns="urn:example:clixon">' '<map xmlns="urn:example:augment">' '<enable>true</enable>'
|
||||||
|
|
||||||
new "cli delete map name"
|
new "cli delete map name"
|
||||||
expectpart "$($clixon_cli -1 -f $cfg -l o delete table map name me)" 0 ""
|
expectpart "$($clixon_cli -1 -f $cfg -l o delete table map name me)" 0 ""
|
||||||
|
|
||||||
new "cli show config deleted"
|
new "cli show config deleted"
|
||||||
expectpart "$($clixon_cli -1 -f $cfg -l o show config xml default report-all)" 0 '<table xmlns="urn:example:clixon">' '<map xmlns="urn:example:augment">' '<enable>true</enable>'
|
expectpart "$($clixon_cli -1 -f $cfg -l o show config default report-all)" 0 '<table xmlns="urn:example:clixon">' '<map xmlns="urn:example:augment">' '<enable>true</enable>'
|
||||||
|
|
||||||
new "cli set map name"
|
new "cli set map name"
|
||||||
expectpart "$($clixon_cli -1 -f $cfg -l o set table map name x)" 0 ""
|
expectpart "$($clixon_cli -1 -f $cfg -l o set table map name x)" 0 ""
|
||||||
|
|
||||||
new "cli show config set"
|
new "cli show config set"
|
||||||
expectpart "$($clixon_cli -1 -f $cfg -l o show config xml default report-all)" 0 '<table xmlns="urn:example:clixon">' '<map xmlns="urn:example:augment">' '<enable>true</enable>'
|
expectpart "$($clixon_cli -1 -f $cfg -l o show config default report-all)" 0 '<table xmlns="urn:example:clixon">' '<map xmlns="urn:example:augment">' '<enable>true</enable>'
|
||||||
|
|
||||||
if [ $BE -ne 0 ]; then
|
if [ $BE -ne 0 ]; then
|
||||||
new "Kill backend"
|
new "Kill backend"
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ cat <<EOF > $cfg
|
||||||
<CLICON_SOCK>/usr/local/var/run/$APPNAME.sock</CLICON_SOCK>
|
<CLICON_SOCK>/usr/local/var/run/$APPNAME.sock</CLICON_SOCK>
|
||||||
<CLICON_BACKEND_PIDFILE>/usr/local/var/run/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
|
<CLICON_BACKEND_PIDFILE>/usr/local/var/run/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
|
||||||
<CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
|
<CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
|
||||||
|
<CLICON_CLI_OUTPUT_FORMAT>cli</CLICON_CLI_OUTPUT_FORMAT>
|
||||||
</clixon-config>
|
</clixon-config>
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
|
@ -73,10 +74,10 @@ new "cli set 43 exclude keys"
|
||||||
expectpart "$($clixon_cli -1 -o CLICON_CLI_VARONLY=1 -f $cfg set table parameter 43)" 0 "^$"
|
expectpart "$($clixon_cli -1 -o CLICON_CLI_VARONLY=1 -f $cfg set table parameter 43)" 0 "^$"
|
||||||
|
|
||||||
new "cli show 42 43 include"
|
new "cli show 42 43 include"
|
||||||
expectpart "$($clixon_cli -1 -o CLICON_CLI_VARONLY=0 -f $cfg show conf cli)" 0 "set table parameter 42" "set table parameter 43"
|
expectpart "$($clixon_cli -1 -o CLICON_CLI_VARONLY=0 -f $cfg show conf)" 0 "set table parameter 42" "set table parameter 43"
|
||||||
|
|
||||||
new "cli show 42 43 exclude"
|
new "cli show 42 43 exclude"
|
||||||
expectpart "$($clixon_cli -1 -o CLICON_CLI_VARONLY=1 -f $cfg show conf cli)" 0 "set table parameter 42" "set table parameter 43"
|
expectpart "$($clixon_cli -1 -o CLICON_CLI_VARONLY=1 -f $cfg show conf)" 0 "set table parameter 42" "set table parameter 43"
|
||||||
|
|
||||||
new "cli expand include keys"
|
new "cli expand include keys"
|
||||||
expectpart "$(echo "set table parameter ?" | $clixon_cli -o CLICON_CLI_VARONLY=0 -f $cfg 2>&1)" 0 42 43
|
expectpart "$(echo "set table parameter ?" | $clixon_cli -o CLICON_CLI_VARONLY=0 -f $cfg 2>&1)" 0 42 43
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ cat <<EOF > $cfg
|
||||||
<CLICON_NACM_MODE>external</CLICON_NACM_MODE>
|
<CLICON_NACM_MODE>external</CLICON_NACM_MODE>
|
||||||
<CLICON_NACM_FILE>$nacmfile</CLICON_NACM_FILE>
|
<CLICON_NACM_FILE>$nacmfile</CLICON_NACM_FILE>
|
||||||
<CLICON_NACM_CREDENTIALS>none</CLICON_NACM_CREDENTIALS>
|
<CLICON_NACM_CREDENTIALS>none</CLICON_NACM_CREDENTIALS>
|
||||||
|
<CLICON_CLI_OUTPUT_FORMAT>text</CLICON_CLI_OUTPUT_FORMAT>
|
||||||
$RESTCONFIG
|
$RESTCONFIG
|
||||||
</clixon-config>
|
</clixon-config>
|
||||||
EOF
|
EOF
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ cat <<EOF > $cfg
|
||||||
<CLICON_BACKEND_PIDFILE>/usr/local/var/run/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
|
<CLICON_BACKEND_PIDFILE>/usr/local/var/run/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
|
||||||
<CLICON_XMLDB_DIR>/usr/local/var/$APPNAME</CLICON_XMLDB_DIR>
|
<CLICON_XMLDB_DIR>/usr/local/var/$APPNAME</CLICON_XMLDB_DIR>
|
||||||
<CLICON_VALIDATE_STATE_XML>true</CLICON_VALIDATE_STATE_XML>
|
<CLICON_VALIDATE_STATE_XML>true</CLICON_VALIDATE_STATE_XML>
|
||||||
|
<CLICON_CLI_OUTPUT_FORMAT>cli</CLICON_CLI_OUTPUT_FORMAT>
|
||||||
</clixon-config>
|
</clixon-config>
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
|
@ -301,7 +302,7 @@ new "netconf get replaced config (report-all)"
|
||||||
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS><get-config><source><candidate/></source><with-defaults xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\">report-all</with-defaults></get-config></rpc>" "" "<rpc-reply $DEFAULTNS><data><interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\"><interface><name>eth&</name><type>t<></type><enabled>true</enabled></interface><interface xmlns:ex=\"urn:example:clixon\"><name>eth1</name><type>ex:eth</type><enabled>true</enabled></interface><interface xmlns:ex=\"urn:example:clixon\"><name>eth2</name><type>ex:eth</type><enabled>true</enabled></interface></interfaces></data></rpc-reply>"
|
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS><get-config><source><candidate/></source><with-defaults xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\">report-all</with-defaults></get-config></rpc>" "" "<rpc-reply $DEFAULTNS><data><interfaces xmlns=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\"><interface><name>eth&</name><type>t<></type><enabled>true</enabled></interface><interface xmlns:ex=\"urn:example:clixon\"><name>eth1</name><type>ex:eth</type><enabled>true</enabled></interface><interface xmlns:ex=\"urn:example:clixon\"><name>eth2</name><type>ex:eth</type><enabled>true</enabled></interface></interfaces></data></rpc-reply>"
|
||||||
|
|
||||||
new "cli show configuration eth& - encoding tests"
|
new "cli show configuration eth& - encoding tests"
|
||||||
expectpart "$($clixon_cli -1 -f $cfg show conf cli)" 0 "interfaces interface eth& type t<>
|
expectpart "$($clixon_cli -1 -f $cfg show conf)" 0 "interfaces interface eth& type t<>
|
||||||
interfaces interface eth& enabled true"
|
interfaces interface eth& enabled true"
|
||||||
|
|
||||||
new "netconf edit CDATA"
|
new "netconf edit CDATA"
|
||||||
|
|
|
||||||
|
|
@ -240,6 +240,7 @@ function testrun(){
|
||||||
<CLICON_BACKEND_PIDFILE>/usr/local/var/run/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
|
<CLICON_BACKEND_PIDFILE>/usr/local/var/run/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
|
||||||
<CLICON_XMLDB_DIR>/usr/local/var/$APPNAME</CLICON_XMLDB_DIR>
|
<CLICON_XMLDB_DIR>/usr/local/var/$APPNAME</CLICON_XMLDB_DIR>
|
||||||
<CLICON_XMLDB_FORMAT>$format</CLICON_XMLDB_FORMAT>
|
<CLICON_XMLDB_FORMAT>$format</CLICON_XMLDB_FORMAT>
|
||||||
|
<CLICON_CLI_OUTPUT_FORMAT>text</CLICON_CLI_OUTPUT_FORMAT>
|
||||||
${AUTOCLI}
|
${AUTOCLI}
|
||||||
</clixon-config>
|
</clixon-config>
|
||||||
EOF
|
EOF
|
||||||
|
|
|
||||||
|
|
@ -147,6 +147,7 @@ function testrun()
|
||||||
<CLICON_YANG_UNKNOWN_ANYDATA>$unknown</CLICON_YANG_UNKNOWN_ANYDATA>
|
<CLICON_YANG_UNKNOWN_ANYDATA>$unknown</CLICON_YANG_UNKNOWN_ANYDATA>
|
||||||
<CLICON_STREAM_DISCOVERY_RFC8040>false</CLICON_STREAM_DISCOVERY_RFC8040>
|
<CLICON_STREAM_DISCOVERY_RFC8040>false</CLICON_STREAM_DISCOVERY_RFC8040>
|
||||||
<CLICON_NETCONF_MONITORING>false</CLICON_NETCONF_MONITORING>
|
<CLICON_NETCONF_MONITORING>false</CLICON_NETCONF_MONITORING>
|
||||||
|
<CLICON_CLI_OUTPUT_FORMAT>xml</CLICON_CLI_OUTPUT_FORMAT>
|
||||||
$F
|
$F
|
||||||
$RESTCONFIG
|
$RESTCONFIG
|
||||||
</clixon-config>
|
</clixon-config>
|
||||||
|
|
@ -209,7 +210,7 @@ EOF
|
||||||
|
|
||||||
# Add other functions, (based on previous errors), eg cli show config, cli commit.
|
# Add other functions, (based on previous errors), eg cli show config, cli commit.
|
||||||
new "cli show configuration"
|
new "cli show configuration"
|
||||||
expectpart "$($clixon_cli -1 -f $cfg show conf xml)" 0 "<u31>42</u31>"
|
expectpart "$($clixon_cli -1 -f $cfg show conf)" 0 "<u31>42</u31>"
|
||||||
|
|
||||||
new "cli commit"
|
new "cli commit"
|
||||||
expectpart "$($clixon_cli -1 -f $cfg commit)" 0 "^$"
|
expectpart "$($clixon_cli -1 -f $cfg commit)" 0 "^$"
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,7 @@ module clixon-config {
|
||||||
description
|
description
|
||||||
"Added options:
|
"Added options:
|
||||||
CLICON_NETCONF_DUPLICATE_ALLOW - Disable duplicate check in NETCONF messages.
|
CLICON_NETCONF_DUPLICATE_ALLOW - Disable duplicate check in NETCONF messages.
|
||||||
|
CLICON_CLI_OUTPUT_FORMAT - Default CLI output format
|
||||||
Released in Clixon 7.1";
|
Released in Clixon 7.1";
|
||||||
}
|
}
|
||||||
revision 2024-01-01 {
|
revision 2024-01-01 {
|
||||||
|
|
@ -879,6 +880,12 @@ module clixon-config {
|
||||||
While setting this value makes sense for adding new values, it makes less sense for
|
While setting this value makes sense for adding new values, it makes less sense for
|
||||||
deleting.";
|
deleting.";
|
||||||
}
|
}
|
||||||
|
leaf CLICON_CLI_OUTPUT_FORMAT {
|
||||||
|
type cl:datastore_format;
|
||||||
|
default xml;
|
||||||
|
description
|
||||||
|
"Default CLI output format.";
|
||||||
|
}
|
||||||
leaf CLICON_SOCK_FAMILY {
|
leaf CLICON_SOCK_FAMILY {
|
||||||
type socket_address_family;
|
type socket_address_family;
|
||||||
default UNIX;
|
default UNIX;
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,8 @@ module clixon-lib {
|
||||||
|
|
||||||
revision 2024-04-01 {
|
revision 2024-04-01 {
|
||||||
description
|
description
|
||||||
"Released in Clixon 7.1";
|
"Added: Default format
|
||||||
|
Released in Clixon 7.1";
|
||||||
}
|
}
|
||||||
revision 2024-01-01 {
|
revision 2024-01-01 {
|
||||||
description
|
description
|
||||||
|
|
@ -179,6 +180,9 @@ module clixon-lib {
|
||||||
enum cli{
|
enum cli{
|
||||||
description "CLI format";
|
description "CLI format";
|
||||||
}
|
}
|
||||||
|
enum default{
|
||||||
|
description "Default format";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
identity snmp {
|
identity snmp {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue