* Auto-CLI enhancements
* A generated clispec including state (default @datanodestate) also generated along with the config clispec tree (default @datanode) * New mode `GT_HIDE` set by option `CLICON_CLI_GENMODEL_TYPE` to collapse non-presence containers that only contain a single list * Added a prfix for cli_show_config/cli_show_auto so that it can produce parseable output * Thanks dcornejo@netgate.com for trying it out and suggestions
This commit is contained in:
parent
e2d9c046af
commit
e898dda016
16 changed files with 319 additions and 86 deletions
|
|
@ -421,10 +421,12 @@ show_yang(clicon_handle h,
|
|||
* <format> "text"|"xml"|"json"|"cli"|"netconf" (see format_enum)
|
||||
* <xpath> xpath expression, that may contain one %, eg "/sender[name='foo']"
|
||||
* <namespace> If xpath set, the namespace the symbols in xpath belong to (optional)
|
||||
* <prefix> to print before cli syntax output (optional)
|
||||
* @code
|
||||
* show config id <n:string>, cli_show_config("running","xml","iface[name='foo']","urn:example:example");
|
||||
* @endcode
|
||||
* @note if state parameter is set, then db must be running
|
||||
* @see cli_show_auto1
|
||||
*/
|
||||
static int
|
||||
cli_show_config1(clicon_handle h,
|
||||
|
|
@ -446,9 +448,10 @@ cli_show_config1(clicon_handle h,
|
|||
yang_stmt *yspec;
|
||||
char *namespace = NULL;
|
||||
cvec *nsc = NULL;
|
||||
char *prefix = NULL;
|
||||
|
||||
if (cvec_len(argv) != 3 && cvec_len(argv) != 4){
|
||||
clicon_err(OE_PLUGIN, 0, "Got %d arguments. Expected: <dbname>,<format>,<xpath>[,<attr>]", cvec_len(argv));
|
||||
if (cvec_len(argv) < 3 && cvec_len(argv) > 5){
|
||||
clicon_err(OE_PLUGIN, 0, "Got %d arguments. Expected: <dbname>,<format>,<xpath>[,<namespace>, [<prefix>]]", cvec_len(argv));
|
||||
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -474,11 +477,14 @@ cli_show_config1(clicon_handle h,
|
|||
}
|
||||
cprintf(cbxpath, "%s", xpath);
|
||||
/* Fourth argument is namespace */
|
||||
if (cvec_len(argv) == 4){
|
||||
if (cvec_len(argv) > 3){
|
||||
namespace = cv_string_get(cvec_i(argv, 3));
|
||||
if ((nsc = xml_nsctx_init(NULL, namespace)) == NULL)
|
||||
goto done;
|
||||
}
|
||||
if (cvec_len(argv) > 4){
|
||||
prefix = cv_string_get(cvec_i(argv, 4));
|
||||
}
|
||||
if (state == 0){ /* Get configuration-only from database */
|
||||
if (clicon_rpc_get_config(h, NULL, db, cbuf_get(cbxpath), nsc, &xt) < 0)
|
||||
goto done;
|
||||
|
|
@ -516,7 +522,7 @@ cli_show_config1(clicon_handle h,
|
|||
goto done;
|
||||
xc = NULL; /* Dont print xt itself */
|
||||
while ((xc = xml_child_each(xt, xc, CX_ELMNT)) != NULL)
|
||||
xml2cli(stdout, xc, NULL, gt); /* cli syntax */
|
||||
xml2cli(stdout, xc, prefix, gt); /* cli syntax */
|
||||
break;
|
||||
case FORMAT_NETCONF:
|
||||
fprintf(stdout, "<rpc><edit-config><target><candidate/></target><config>\n");
|
||||
|
|
@ -549,6 +555,7 @@ done:
|
|||
* <format> "text"|"xml"|"json"|"cli"|"netconf" (see format_enum)
|
||||
* <xpath> xpath expression, that may contain one %, eg "/sender[name="%s"]"
|
||||
* <namespace> If xpath set, the namespace the symbols in xpath belong to (optional)
|
||||
* <prefix> to print before cli syntax output
|
||||
* @code
|
||||
* show config id <n:string>, cli_show_config("running","xml","iface[name='foo']","urn:example:example");
|
||||
* @endcode
|
||||
|
|
@ -675,8 +682,10 @@ int cli_show_version(clicon_handle h,
|
|||
* <api_path_fmt> Generated API PATH
|
||||
* <dbname> "running"|"candidate"|"startup"
|
||||
* <format> "text"|"xml"|"json"|"cli"|"netconf" (see format_enum)
|
||||
* <prefix> to print before cli syntax output
|
||||
* @note if state parameter is set, then db must be running
|
||||
* @note that first argument is generated by code.
|
||||
* @see cli_show_config1
|
||||
*/
|
||||
static int
|
||||
cli_show_auto1(clicon_handle h,
|
||||
|
|
@ -687,7 +696,6 @@ cli_show_auto1(clicon_handle h,
|
|||
int retval = 1;
|
||||
yang_stmt *yspec;
|
||||
char *api_path_fmt; /* xml key format */
|
||||
// char *api_path = NULL; /* xml key */
|
||||
char *db;
|
||||
char *xpath = NULL;
|
||||
cvec *nsc = NULL;
|
||||
|
|
@ -698,9 +706,10 @@ cli_show_auto1(clicon_handle h,
|
|||
cxobj *xerr;
|
||||
enum genmodel_type gt;
|
||||
char *api_path = NULL;
|
||||
char *prefix = NULL;
|
||||
|
||||
if (cvec_len(argv) != 3){
|
||||
clicon_err(OE_PLUGIN, 0, "Usage: <api-path-fmt>* <database> <format>. (*) generated.");
|
||||
if (cvec_len(argv) < 3 && cvec_len(argv) > 4){
|
||||
clicon_err(OE_PLUGIN, 0, "Usage: <api-path-fmt>* <database> <format> <prefix>. (*) generated.");
|
||||
goto done;
|
||||
}
|
||||
/* First argv argument: API_path format */
|
||||
|
|
@ -709,6 +718,10 @@ cli_show_auto1(clicon_handle h,
|
|||
db = cv_string_get(cvec_i(argv, 1));
|
||||
/* Third format: output format */
|
||||
formatstr = cv_string_get(cvec_i(argv, 2));
|
||||
if (cvec_len(argv) > 3){
|
||||
/* Fourth format: prefix to print before cli syntax */
|
||||
prefix = cv_string_get(cvec_i(argv, 3));
|
||||
}
|
||||
if ((int)(format = format_str2int(formatstr)) < 0){
|
||||
clicon_err(OE_PLUGIN, 0, "Not valid format: %s", formatstr);
|
||||
goto done;
|
||||
|
|
@ -758,7 +771,7 @@ cli_show_auto1(clicon_handle h,
|
|||
case FORMAT_CLI:
|
||||
if ((gt = clicon_cli_genmodel_type(h)) == GT_ERR)
|
||||
goto done;
|
||||
xml2cli(stdout, xp, NULL, gt); /* cli syntax */
|
||||
xml2cli(stdout, xp, prefix, gt); /* cli syntax */
|
||||
break;
|
||||
case FORMAT_NETCONF:
|
||||
fprintf(stdout, "<rpc><edit-config><target><candidate/></target><config>\n");
|
||||
|
|
@ -786,6 +799,7 @@ cli_show_auto1(clicon_handle h,
|
|||
* <api_path_fmt> Generated API PATH
|
||||
* <dbname> "running"|"candidate"|"startup"
|
||||
* <format> "text"|"xml"|"json"|"cli"|"netconf" (see format_enum)
|
||||
* <prefix> to print before cli syntax outptu
|
||||
* @see cli_show_auto_state For config and state
|
||||
*/
|
||||
int
|
||||
|
|
@ -801,7 +815,9 @@ cli_show_auto(clicon_handle h,
|
|||
* <api_path_fmt> Generated API PATH
|
||||
* <dbname> "running"
|
||||
* <format> "text"|"xml"|"json"|"cli"|"netconf" (see format_enum)
|
||||
* <prefix> to print before cli syntax output
|
||||
* @see cli_show_auto For config only
|
||||
* @see cli_show_config_state Not auto-generated
|
||||
*/
|
||||
int
|
||||
cli_show_auto_state(clicon_handle h,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue