* Added cvv_i output parameter to api_path_fmt2api_path() to see how many cvv entries were used
* CLIspec dbxml API: Ability to specify deletion of _any_ vs _specific_ entry.
This commit is contained in:
parent
906d8bc63c
commit
96ab7292b9
7 changed files with 55 additions and 20 deletions
|
|
@ -172,7 +172,7 @@ cli_auto_edit(clicon_handle h,
|
|||
goto done;
|
||||
}
|
||||
/* get api-path and xpath */
|
||||
if (api_path_fmt2api_path(api_path_fmt, cvv2, &api_path) < 0)
|
||||
if (api_path_fmt2api_path(api_path_fmt, cvv2, &api_path, NULL) < 0)
|
||||
goto done;
|
||||
/* Store this as edit-mode */
|
||||
if (clicon_data_set(h, "cli-edit-mode", api_path) < 0)
|
||||
|
|
@ -250,7 +250,7 @@ cli_auto_up(clicon_handle h,
|
|||
cvec_append_var(cvv1, cv);
|
||||
}
|
||||
/* get api-path and xpath */
|
||||
if (api_path_fmt2api_path(api_path_fmt1, cvv1, &api_path) < 0)
|
||||
if (api_path_fmt2api_path(api_path_fmt1, cvv1, &api_path, NULL) < 0)
|
||||
goto done;
|
||||
/* Store this as edit-mode */
|
||||
clicon_data_set(h, "cli-edit-mode", api_path);
|
||||
|
|
@ -660,7 +660,7 @@ cli_auto_sub_enter(clicon_handle h,
|
|||
if (cvec_append_var(cvv1, cvec_i(cvv, i)) < 0)
|
||||
goto done;
|
||||
}
|
||||
if (api_path_fmt2api_path(api_path_fmt, cvv1, &api_path) < 0)
|
||||
if (api_path_fmt2api_path(api_path_fmt, cvv1, &api_path, NULL) < 0)
|
||||
goto done;
|
||||
/* Assign the variables */
|
||||
if ((cvv2 = cvec_append(clicon_data_cvec_get(h, "cli-edit-cvv"), cvv1)) == NULL)
|
||||
|
|
|
|||
|
|
@ -251,6 +251,7 @@ cli_dbxml(clicon_handle h,
|
|||
cxobj *xerr = NULL;
|
||||
int ret;
|
||||
cg_var *cv;
|
||||
int cvv_i = 0;
|
||||
|
||||
if (cvec_len(argv) != 1){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "Requires one element to be xml key format string");
|
||||
|
|
@ -262,7 +263,10 @@ cli_dbxml(clicon_handle h,
|
|||
}
|
||||
arg = cvec_i(argv, 0);
|
||||
api_path_fmt = cv_string_get(arg);
|
||||
if (api_path_fmt2api_path(api_path_fmt, cvv, &api_path) < 0)
|
||||
/* Transform template format string + cvv to actual api-path
|
||||
* cvv_i indicates if all cvv entries were used
|
||||
*/
|
||||
if (api_path_fmt2api_path(api_path_fmt, cvv, &api_path, &cvv_i) < 0)
|
||||
goto done;
|
||||
/* Create config top-of-tree */
|
||||
if ((xtop = xml_new("config", NULL, CX_ELMNT)) == NULL)
|
||||
|
|
@ -292,9 +296,17 @@ cli_dbxml(clicon_handle h,
|
|||
/* Add body last in case of leaf */
|
||||
if (cvec_len(cvv) > 1 &&
|
||||
(yang_keyword_get(y) == Y_LEAF)){
|
||||
/* Add the body last */
|
||||
if (dbxml_body(xbot, cvv) < 0)
|
||||
goto done;
|
||||
/* Add the body last if there is remaining element that was not used in the
|
||||
* earlier api-path transformation.
|
||||
* This is to handle differences between:
|
||||
* DELETE <foo>bar</foo> and DELETE <foo/>
|
||||
* i.e., (1) deletion of a specific leaf entry vs (2) deletion of any entry
|
||||
* Discussion: one can claim (1) is "bad" usage but one could see cases where
|
||||
* you would want to delete a value if it has a specific value but not otherwise
|
||||
*/
|
||||
if (cvv_i != cvec_len(cvv))
|
||||
if (dbxml_body(xbot, cvv) < 0)
|
||||
goto done;
|
||||
/* Loop over namespace context and add them to this leaf node */
|
||||
cv = NULL;
|
||||
while ((cv = cvec_each(nsctx, cv)) != NULL){
|
||||
|
|
|
|||
|
|
@ -121,6 +121,7 @@ expand_dbvar(void *h,
|
|||
char *reason = NULL;
|
||||
cvec *nsc = NULL;
|
||||
int ret;
|
||||
int cvvi = 0;
|
||||
|
||||
if (argv == NULL || cvec_len(argv) != 2){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "requires arguments: <db> <xmlkeyfmt>");
|
||||
|
|
@ -150,7 +151,7 @@ expand_dbvar(void *h,
|
|||
* api_path: --> /interface/eth0/address/.*
|
||||
* xpath: --> /interface/[name="eth0"]/address
|
||||
*/
|
||||
if (api_path_fmt2api_path(api_path_fmt, cvv, &api_path) < 0)
|
||||
if (api_path_fmt2api_path(api_path_fmt, cvv, &api_path, &cvvi) < 0)
|
||||
goto done;
|
||||
if (api_path2xpath(api_path, yspec, &xpath, &nsc, NULL) < 0)
|
||||
goto done;
|
||||
|
|
@ -711,6 +712,7 @@ cli_show_auto1(clicon_handle h,
|
|||
char *prefix = NULL;
|
||||
enum rfc_6020 ys_keyword;
|
||||
int i = 0;
|
||||
int cvvi = 0;
|
||||
|
||||
if (cvec_len(argv) < 3 || cvec_len(argv) > 4){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "Usage: <api-path-fmt>* <database> <format> <prefix>. (*) generated.");
|
||||
|
|
@ -734,7 +736,7 @@ cli_show_auto1(clicon_handle h,
|
|||
clicon_err(OE_FATAL, 0, "No DB_SPEC");
|
||||
goto done;
|
||||
}
|
||||
if (api_path_fmt2api_path(api_path_fmt, cvv, &api_path) < 0)
|
||||
if (api_path_fmt2api_path(api_path_fmt, cvv, &api_path, &cvvi) < 0)
|
||||
goto done;
|
||||
if (api_path2xpath(api_path, yspec, &xpath, &nsc, NULL) < 0)
|
||||
goto done;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue