Add mount-point aware code to cli_auto_show
Revert patch in xpath2canonical for mountpoints
This commit is contained in:
parent
5cb41c8d8a
commit
05da8ef3c1
4 changed files with 47 additions and 14 deletions
|
|
@ -109,7 +109,12 @@ You can see which CLISPEC it generates via clixon_cli -D 2:
|
||||||
/* variable expand function */
|
/* variable expand function */
|
||||||
#define GENERATE_EXPAND_XMLDB "expand_dbvar"
|
#define GENERATE_EXPAND_XMLDB "expand_dbvar"
|
||||||
|
|
||||||
/*! Create cligen variable expand entry with xmlkey format string as argument
|
/*! Create cligen variable expand entry with api-pathfmt format string as argument
|
||||||
|
*
|
||||||
|
* Add api-fmt as first argument to callback, eg:
|
||||||
|
* /ex:table
|
||||||
|
* Then if mountpoint add special entry:
|
||||||
|
* /ctrl:dev/ctrl:config
|
||||||
* @param[in] h Clixon handle
|
* @param[in] h Clixon handle
|
||||||
* @param[in] ys yang_stmt of the node at hand
|
* @param[in] ys yang_stmt of the node at hand
|
||||||
* @param[in] cvtype Type of the cligen variable
|
* @param[in] cvtype Type of the cligen variable
|
||||||
|
|
@ -1353,6 +1358,8 @@ yang2cli_post(clicon_handle h,
|
||||||
|
|
||||||
/*! Generate clispec for all modules in yspec (except excluded)
|
/*! Generate clispec for all modules in yspec (except excluded)
|
||||||
*
|
*
|
||||||
|
* Called in cli main function for top-level yangs. But may also be called dynamically for
|
||||||
|
* mountpoints.
|
||||||
* @param[in] h Clixon handle
|
* @param[in] h Clixon handle
|
||||||
* @param[in] yspec Top-level Yang statement of type Y_SPEC
|
* @param[in] yspec Top-level Yang statement of type Y_SPEC
|
||||||
* @param[in] treename Name of tree
|
* @param[in] treename Name of tree
|
||||||
|
|
|
||||||
|
|
@ -839,6 +839,7 @@ int cli_show_version(clicon_handle h,
|
||||||
* @param[in] cvv Vector of variables from CLIgen command-line
|
* @param[in] cvv Vector of variables from CLIgen command-line
|
||||||
* @param[in] argv String vector of show options, format:
|
* @param[in] argv String vector of show options, format:
|
||||||
* <api_path_fmt> Generated API PATH (this is added implicitly, not actually given in the cvv)
|
* <api_path_fmt> Generated API PATH (this is added implicitly, not actually given in the cvv)
|
||||||
|
* [<api-path-fmt>] Extra api-path from mount-point
|
||||||
* <dbname> Name of datastore, such as "running"
|
* <dbname> Name of datastore, such as "running"
|
||||||
* -- from here optional:
|
* -- from here optional:
|
||||||
* <format> "text"|"xml"|"json"|"cli"|"netconf" (see format_enum), default: xml
|
* <format> "text"|"xml"|"json"|"cli"|"netconf" (see format_enum), default: xml
|
||||||
|
|
@ -879,17 +880,26 @@ cli_show_auto(clicon_handle h,
|
||||||
char *extdefault = NULL; /* with extended tagged modes */
|
char *extdefault = NULL; /* with extended tagged modes */
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
char *xpath = NULL;
|
char *xpath = NULL;
|
||||||
yang_stmt *yspec;
|
yang_stmt *yspec0;
|
||||||
char *api_path = NULL;
|
char *api_path = NULL;
|
||||||
int cvvi = 0;
|
int cvvi = 0;
|
||||||
char *api_path_fmt; /* xml key format */
|
char *api_path_fmt; /* xml key format */
|
||||||
|
char *api_path_fmt01 = NULL;
|
||||||
|
char *str;
|
||||||
|
char *mtpoint = NULL;
|
||||||
|
|
||||||
if (cvec_len(argv) < 2 || cvec_len(argv) > 7){
|
if (cvec_len(argv) < 2 || cvec_len(argv) > 7){
|
||||||
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected:: <api-path-fmt>* <database> [<format> <pretty> <state> <default> <prepend>]", cvec_len(argv));
|
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected:: <api-path-fmt>* <database> [<format> <pretty> <state> <default> <prepend>]", cvec_len(argv));
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
api_path_fmt = cv_string_get(cvec_i(argv, argc++));
|
api_path_fmt = cv_string_get(cvec_i(argv, argc++));
|
||||||
dbname = cv_string_get(cvec_i(argv, argc++));
|
str = cv_string_get(cvec_i(argv, argc++));
|
||||||
|
if (str && str[0] == '/'){ /* ad-hoc to see if 2nd arg is mountpoint */
|
||||||
|
mtpoint = str;
|
||||||
|
dbname = cv_string_get(cvec_i(argv, argc++));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
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(argv, argc++, &format) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
@ -910,13 +920,22 @@ cli_show_auto(clicon_handle h,
|
||||||
if (cvec_len(argv) > argc){
|
if (cvec_len(argv) > argc){
|
||||||
prepend = cv_string_get(cvec_i(argv, argc++));
|
prepend = cv_string_get(cvec_i(argv, argc++));
|
||||||
}
|
}
|
||||||
if ((yspec = clicon_dbspec_yang(h)) == NULL){
|
if ((yspec0 = clicon_dbspec_yang(h)) == NULL){
|
||||||
clicon_err(OE_FATAL, 0, "No DB_SPEC");
|
clicon_err(OE_FATAL, 0, "No DB_SPEC");
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
if (api_path_fmt2api_path(api_path_fmt, cvv, &api_path, &cvvi) < 0)
|
if (mtpoint){
|
||||||
goto done;
|
/* Get and combined api-path01 */
|
||||||
if (api_path2xpath(api_path, yspec, &xpath, &nsc, NULL) < 0)
|
if (mtpoint_paths(yspec0, mtpoint, api_path_fmt, &api_path_fmt01) < 0)
|
||||||
|
goto done;
|
||||||
|
if (api_path_fmt2api_path(api_path_fmt01, cvv, &api_path, &cvvi) < 0)
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if (api_path_fmt2api_path(api_path_fmt, cvv, &api_path, &cvvi) < 0)
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
if (api_path2xpath(api_path, yspec0, &xpath, &nsc, NULL) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (xpath == NULL){
|
if (xpath == NULL){
|
||||||
clicon_err(OE_FATAL, 0, "Invalid api-path-fmt: %s", api_path_fmt);
|
clicon_err(OE_FATAL, 0, "Invalid api-path-fmt: %s", api_path_fmt);
|
||||||
|
|
@ -928,6 +947,8 @@ cli_show_auto(clicon_handle h,
|
||||||
goto done;
|
goto done;
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
if (api_path_fmt01)
|
||||||
|
free(api_path_fmt01);
|
||||||
if (nsc)
|
if (nsc)
|
||||||
xml_nsctx_free(nsc);
|
xml_nsctx_free(nsc);
|
||||||
if (xpath)
|
if (xpath)
|
||||||
|
|
|
||||||
|
|
@ -969,7 +969,6 @@ xpath_vec_bool(cxobj *xcur,
|
||||||
* @retval 1 OK with nsc1 containing the transformed nsc
|
* @retval 1 OK with nsc1 containing the transformed nsc
|
||||||
* @retval 0 XPath failure with reason set to why
|
* @retval 0 XPath failure with reason set to why
|
||||||
* @retval -1 Fatal Error
|
* @retval -1 Fatal Error
|
||||||
* XXX Detects mountpoint but is not mountpoint aware, just copies prefixes
|
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
xpath_traverse_canonical(xpath_tree *xs,
|
xpath_traverse_canonical(xpath_tree *xs,
|
||||||
|
|
@ -1005,6 +1004,7 @@ xpath_traverse_canonical(xpath_tree *xs,
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
if ((ymod = yang_find_module_by_namespace(yspec, namespace)) == NULL){
|
if ((ymod = yang_find_module_by_namespace(yspec, namespace)) == NULL){
|
||||||
|
#if 0 /* Just accept it, see note in xpath2canonical */
|
||||||
if ((cb = cbuf_new()) == NULL){
|
if ((cb = cbuf_new()) == NULL){
|
||||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||||
goto done;
|
goto done;
|
||||||
|
|
@ -1013,12 +1013,11 @@ xpath_traverse_canonical(xpath_tree *xs,
|
||||||
if (reason)
|
if (reason)
|
||||||
*reason = cb;
|
*reason = cb;
|
||||||
goto fail;
|
goto fail;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#if 0 /* safe-catch if previous check is not considered as an error */
|
|
||||||
if (ymod == NULL)
|
if (ymod == NULL)
|
||||||
prefix1 = prefix0;
|
prefix1 = prefix0;
|
||||||
else
|
else
|
||||||
#endif
|
|
||||||
if ((prefix1 = yang_find_myprefix(ymod)) == NULL){
|
if ((prefix1 = yang_find_myprefix(ymod)) == NULL){
|
||||||
if ((cb = cbuf_new()) == NULL){
|
if ((cb = cbuf_new()) == NULL){
|
||||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||||
|
|
@ -1093,6 +1092,10 @@ xpath_traverse_canonical(xpath_tree *xs,
|
||||||
* if (xpath1) free(xpath1);
|
* if (xpath1) free(xpath1);
|
||||||
* if (nsc1) xml_nsctx_free(nsc1);
|
* if (nsc1) xml_nsctx_free(nsc1);
|
||||||
* @endcode
|
* @endcode
|
||||||
|
* @note Unsolvable issue of mountpoints, eg an xpath of //x:foo where foo is under one or several
|
||||||
|
* mointpoints: a well-defined namespace cannot be determined. Therefore just allow
|
||||||
|
* inconsistencies and hope that it will be covered by other code
|
||||||
|
* @see xpath2xml
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
xpath2canonical(const char *xpath0,
|
xpath2canonical(const char *xpath0,
|
||||||
|
|
|
||||||
|
|
@ -56,9 +56,11 @@ expectpart "$($clixon_util_xpath -c -y $ydir -p "/i:x[.='42']" -n i:urn:example:
|
||||||
new "xpath canonical form descendants"
|
new "xpath canonical form descendants"
|
||||||
expectpart "$($clixon_util_xpath -c -y $ydir -p "//x[.='42']" -n null:urn:example:a -n j:urn:example:b)" 0 "//a:x\[.='42'\]" '0 : a = "urn:example:a"'
|
expectpart "$($clixon_util_xpath -c -y $ydir -p "//x[.='42']" -n null:urn:example:a -n j:urn:example:b)" 0 "//a:x\[.='42'\]" '0 : a = "urn:example:a"'
|
||||||
|
|
||||||
new "xpath canonical form (no default should fail)"
|
if false; then
|
||||||
expectpart "$($clixon_util_xpath -c -y $ydir -p /x/j:y -n i:urn:example:a -n j:urn:example:b 2>&1)" 0 "/x/j:y: No namespace found for prefix"
|
# No, with mointpoints I cant fail unknown prefix, see comment in xpath2canonical
|
||||||
|
new "xpath canonical form (no default should fail)"
|
||||||
|
expectpart "$($clixon_util_xpath -c -y $ydir -p /x/j:y -n i:urn:example:a -n j:urn:example:b 2>&1)" 0 "/x/j:y: No namespace found for prefix"
|
||||||
|
fi
|
||||||
new "xpath canonical form (wrong namespace should fail)"
|
new "xpath canonical form (wrong namespace should fail)"
|
||||||
expectpart "$($clixon_util_xpath -c -y $ydir -p /i:x/j:y -n i:urn:example:c -n j:urn:example:b 2>&1)" 0 "/i:x/j:y: No yang found for namespace"
|
expectpart "$($clixon_util_xpath -c -y $ydir -p /i:x/j:y -n i:urn:example:c -n j:urn:example:b 2>&1)" 0 "/i:x/j:y: No yang found for namespace"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue