]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib,vtysh: show operational data with config
authorRafael Zalamena <rzalamena@opensourcerouting.org>
Thu, 10 Feb 2022 19:20:42 +0000 (16:20 -0300)
committerRafael F. Zalamena <rzalamena@opensourcerouting.org>
Wed, 2 Mar 2022 19:37:43 +0000 (16:37 -0300)
Add option to merge configuration data in the operational data show
command.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
lib/northbound_cli.c
vtysh/vtysh.c

index 3644e23425249092876f7611e78fd024d90e3c7e..56eac9dc32a30071f2a4d49929bfa72c752ff4fc 100644 (file)
@@ -1464,6 +1464,7 @@ DEFPY (show_yang_operational_data,
          [{\
           format <json$json|xml$xml>\
           |translate WORD$translator_family\
+          |with-config$with_config\
         }]",
        SHOW_STR
        "YANG information\n"
@@ -1473,13 +1474,15 @@ DEFPY (show_yang_operational_data,
        "JavaScript Object Notation\n"
        "Extensible Markup Language\n"
        "Translate operational data\n"
-       "YANG module translator\n")
+       "YANG module translator\n"
+       "Merge configuration data\n")
 {
        LYD_FORMAT format;
        struct yang_translator *translator = NULL;
        struct ly_ctx *ly_ctx;
        struct lyd_node *dnode;
        char *strp;
+       uint32_t print_options = LYD_PRINT_WITHSIBLINGS;
 
        if (xml)
                format = LYD_XML;
@@ -1507,11 +1510,21 @@ DEFPY (show_yang_operational_data,
                yang_dnode_free(dnode);
                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);
 
        /* Display the data. */
-       if (lyd_print_mem(&strp, dnode, format, LYD_PRINT_WITHSIBLINGS) != 0
-           || !strp) {
+       if (lyd_print_mem(&strp, dnode, format, print_options) != 0 || !strp) {
                vty_out(vty, "%% Failed to display operational data.\n");
                yang_dnode_free(dnode);
                return CMD_WARNING;
index f8c6a1fc1d4427b08f1ca5ce8b56468a55459fd4..ffef2606362552868a4e05cc838db377cae79fce 100644 (file)
@@ -2954,6 +2954,7 @@ DEFUN (show_yang_operational_data,
          [{\
           format <json|xml>\
           |translate WORD\
+          |with-config\
         }]" DAEMONS_LIST,
        SHOW_STR
        "YANG information\n"
@@ -2964,6 +2965,7 @@ DEFUN (show_yang_operational_data,
        "Extensible Markup Language\n"
        "Translate operational data\n"
        "YANG module translator\n"
+       "Merge configuration data\n"
        DAEMONS_STR)
 {
        return show_one_daemon(vty, argv, argc - 1, argv[argc - 1]->text);