mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-07 06:03:10 +00:00
Merge pull request #10719 from opensourcerouting/nb-show-fixes
lib: fix and improve yang operational data display
This commit is contained in:
commit
dcaba5ae1a
@ -678,6 +678,20 @@ Terminal Mode Commands
|
|||||||
This command displays FRR's timer data for timers that will pop in
|
This command displays FRR's timer data for timers that will pop in
|
||||||
the future.
|
the future.
|
||||||
|
|
||||||
|
.. clicmd:: show yang operational-data XPATH [{format <json|xml>|translate TRANSLATOR|with-config}] DAEMON
|
||||||
|
|
||||||
|
Display the YANG operational data starting from XPATH. The default
|
||||||
|
format is JSON, but can be displayed in XML as well.
|
||||||
|
|
||||||
|
Normally YANG operational data are located inside containers marked
|
||||||
|
as `read-only`.
|
||||||
|
|
||||||
|
Optionally it is also possible to display configuration leaves in
|
||||||
|
addition to operational data with the option `with-config`. This
|
||||||
|
option enables the display of configuration leaves with their
|
||||||
|
currently configured value (if the leaf is optional it will only show
|
||||||
|
if it was created or has a default value).
|
||||||
|
|
||||||
.. _common-invocation-options:
|
.. _common-invocation-options:
|
||||||
|
|
||||||
Common Invocation Options
|
Common Invocation Options
|
||||||
|
@ -1649,10 +1649,12 @@ static int nb_oper_data_iter_container(const struct nb_node *nb_node,
|
|||||||
uint32_t flags, nb_oper_data_cb cb,
|
uint32_t flags, nb_oper_data_cb cb,
|
||||||
void *arg)
|
void *arg)
|
||||||
{
|
{
|
||||||
|
const struct lysc_node *snode = nb_node->snode;
|
||||||
|
|
||||||
if (CHECK_FLAG(nb_node->flags, F_NB_NODE_CONFIG_ONLY))
|
if (CHECK_FLAG(nb_node->flags, F_NB_NODE_CONFIG_ONLY))
|
||||||
return NB_OK;
|
return NB_OK;
|
||||||
|
|
||||||
/* Presence containers. */
|
/* Read-only presence containers. */
|
||||||
if (nb_node->cbs.get_elem) {
|
if (nb_node->cbs.get_elem) {
|
||||||
struct yang_data *data;
|
struct yang_data *data;
|
||||||
int ret;
|
int ret;
|
||||||
@ -1662,15 +1664,24 @@ static int nb_oper_data_iter_container(const struct nb_node *nb_node,
|
|||||||
/* Presence container is not present. */
|
/* Presence container is not present. */
|
||||||
return NB_OK;
|
return NB_OK;
|
||||||
|
|
||||||
ret = (*cb)(nb_node->snode, translator, data, arg);
|
ret = (*cb)(snode, translator, data, arg);
|
||||||
if (ret != NB_OK)
|
if (ret != NB_OK)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Read-write presence containers. */
|
||||||
|
if (CHECK_FLAG(snode->flags, LYS_CONFIG_W)) {
|
||||||
|
struct lysc_node_container *scontainer;
|
||||||
|
|
||||||
|
scontainer = (struct lysc_node_container *)snode;
|
||||||
|
if (CHECK_FLAG(scontainer->flags, LYS_PRESENCE)
|
||||||
|
&& !yang_dnode_get(running_config->dnode, xpath))
|
||||||
|
return NB_OK;
|
||||||
|
}
|
||||||
|
|
||||||
/* Iterate over the child nodes. */
|
/* Iterate over the child nodes. */
|
||||||
return nb_oper_data_iter_children(nb_node->snode, xpath, list_entry,
|
return nb_oper_data_iter_children(snode, xpath, list_entry, list_keys,
|
||||||
list_keys, translator, false, flags,
|
translator, false, flags, cb, arg);
|
||||||
cb, arg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -1464,6 +1464,7 @@ DEFPY (show_yang_operational_data,
|
|||||||
[{\
|
[{\
|
||||||
format <json$json|xml$xml>\
|
format <json$json|xml$xml>\
|
||||||
|translate WORD$translator_family\
|
|translate WORD$translator_family\
|
||||||
|
|with-config$with_config\
|
||||||
}]",
|
}]",
|
||||||
SHOW_STR
|
SHOW_STR
|
||||||
"YANG information\n"
|
"YANG information\n"
|
||||||
@ -1473,13 +1474,15 @@ DEFPY (show_yang_operational_data,
|
|||||||
"JavaScript Object Notation\n"
|
"JavaScript Object Notation\n"
|
||||||
"Extensible Markup Language\n"
|
"Extensible Markup Language\n"
|
||||||
"Translate operational data\n"
|
"Translate operational data\n"
|
||||||
"YANG module translator\n")
|
"YANG module translator\n"
|
||||||
|
"Merge configuration data\n")
|
||||||
{
|
{
|
||||||
LYD_FORMAT format;
|
LYD_FORMAT format;
|
||||||
struct yang_translator *translator = NULL;
|
struct yang_translator *translator = NULL;
|
||||||
struct ly_ctx *ly_ctx;
|
struct ly_ctx *ly_ctx;
|
||||||
struct lyd_node *dnode;
|
struct lyd_node *dnode;
|
||||||
char *strp;
|
char *strp;
|
||||||
|
uint32_t print_options = LYD_PRINT_WITHSIBLINGS;
|
||||||
|
|
||||||
if (xml)
|
if (xml)
|
||||||
format = LYD_XML;
|
format = LYD_XML;
|
||||||
@ -1507,13 +1510,21 @@ DEFPY (show_yang_operational_data,
|
|||||||
yang_dnode_free(dnode);
|
yang_dnode_free(dnode);
|
||||||
return CMD_WARNING;
|
return CMD_WARNING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (with_config && yang_dnode_exists(running_config->dnode, xpath)) {
|
||||||
|
struct lyd_node *config_dnode =
|
||||||
|
yang_dnode_get(running_config->dnode, xpath);
|
||||||
|
if (config_dnode != NULL) {
|
||||||
|
lyd_merge_tree(&dnode, yang_dnode_dup(config_dnode),
|
||||||
|
LYD_MERGE_DESTRUCT);
|
||||||
|
print_options |= LYD_PRINT_WD_ALL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
(void)lyd_validate_all(&dnode, ly_ctx, 0, NULL);
|
(void)lyd_validate_all(&dnode, ly_ctx, 0, NULL);
|
||||||
|
|
||||||
/* Display the data. */
|
/* Display the data. */
|
||||||
if (lyd_print_mem(&strp, dnode, format,
|
if (lyd_print_mem(&strp, dnode, format, print_options) != 0 || !strp) {
|
||||||
LYD_PRINT_WITHSIBLINGS | LYD_PRINT_WD_ALL)
|
|
||||||
!= 0
|
|
||||||
|| !strp) {
|
|
||||||
vty_out(vty, "%% Failed to display operational data.\n");
|
vty_out(vty, "%% Failed to display operational data.\n");
|
||||||
yang_dnode_free(dnode);
|
yang_dnode_free(dnode);
|
||||||
return CMD_WARNING;
|
return CMD_WARNING;
|
||||||
|
@ -2955,6 +2955,7 @@ DEFUN (show_yang_operational_data,
|
|||||||
[{\
|
[{\
|
||||||
format <json|xml>\
|
format <json|xml>\
|
||||||
|translate WORD\
|
|translate WORD\
|
||||||
|
|with-config\
|
||||||
}]" DAEMONS_LIST,
|
}]" DAEMONS_LIST,
|
||||||
SHOW_STR
|
SHOW_STR
|
||||||
"YANG information\n"
|
"YANG information\n"
|
||||||
@ -2965,6 +2966,7 @@ DEFUN (show_yang_operational_data,
|
|||||||
"Extensible Markup Language\n"
|
"Extensible Markup Language\n"
|
||||||
"Translate operational data\n"
|
"Translate operational data\n"
|
||||||
"YANG module translator\n"
|
"YANG module translator\n"
|
||||||
|
"Merge configuration data\n"
|
||||||
DAEMONS_STR)
|
DAEMONS_STR)
|
||||||
{
|
{
|
||||||
return show_one_daemon(vty, argv, argc - 1, argv[argc - 1]->text);
|
return show_one_daemon(vty, argv, argc - 1, argv[argc - 1]->text);
|
||||||
|
Loading…
Reference in New Issue
Block a user