[libvirt] [PATCH] virsh: introduce name-uuid for list command

Chen Hanxiao chen_han_xiao at 126.com
Wed Jun 15 09:36:05 UTC 2016


From: Chen Hanxiao <chenhanxiao at gmail.com>

This patch will show both name and UUID of domain:

 Id    Name                           State      UUID
 ---------------------------------------------------------------------------------------
  3     f23                            running    918f1dd6-b19f-412b-ba17-d113bad89af8

Signed-off-by: Chen Hanxiao <chenhanxiao at gmail.com>
---
 tools/virsh-domain-monitor.c | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
index 0a93949..32e4ea4 100644
--- a/tools/virsh-domain-monitor.c
+++ b/tools/virsh-domain-monitor.c
@@ -1793,6 +1793,10 @@ static const vshCmdOptDef opts_list[] = {
      .type = VSH_OT_BOOL,
      .help = N_("show domain title")
     },
+    {.name = "name-uuid",
+     .type = VSH_OT_BOOL,
+     .help = N_("show domain name and uuid")
+    },
     {.name = NULL}
 };
 
@@ -1807,6 +1811,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd)
     bool optTable = vshCommandOptBool(cmd, "table");
     bool optUUID = vshCommandOptBool(cmd, "uuid");
     bool optName = vshCommandOptBool(cmd, "name");
+    bool optNameUuid = vshCommandOptBool(cmd, "name-uuid");
     size_t i;
     char *title;
     char uuid[VIR_UUID_STRING_BUFLEN];
@@ -1844,10 +1849,10 @@ cmdList(vshControl *ctl, const vshCmd *cmd)
     FILTER("state-shutoff", VIR_CONNECT_LIST_DOMAINS_SHUTOFF);
     FILTER("state-other",   VIR_CONNECT_LIST_DOMAINS_OTHER);
 
-    if (optTable + optName + optUUID > 1) {
+    if (optTable + optName + optUUID + optNameUuid > 1) {
         vshError(ctl, "%s",
-                 _("Only one argument from --table, --name and --uuid "
-                   "may be specified."));
+                 _("Only one argument from --table, --name, --uuid "
+                   "and --name-uuid may be specified."));
         return false;
     }
 
@@ -1864,6 +1869,12 @@ cmdList(vshControl *ctl, const vshCmd *cmd)
                           _("Id"), _("Name"), _("State"), _("Title"),
                           "-----------------------------------------"
                           "-----------------------------------------");
+        else if (optNameUuid)
+            vshPrintExtra(ctl, " %-5s %-30s %-10s %-36s\n%s\n",
+                          _("Id"), _("Name"), _("State"), _("UUID"),
+                          "-----------------------------------------"
+                          "-----------------------------------------"
+                          "----");
         else
             vshPrintExtra(ctl, " %-5s %-30s %s\n%s\n",
                           _("Id"), _("Name"), _("State"),
@@ -1901,6 +1912,16 @@ cmdList(vshControl *ctl, const vshCmd *cmd)
                          title);
 
                 VIR_FREE(title);
+            } else if (optNameUuid) {
+                if (virDomainGetUUIDString(dom, uuid) < 0) {
+                    vshError(ctl, "%s", _("Failed to get domain's UUID"));
+                    goto cleanup;
+                }
+                vshPrint(ctl, " %-5s %-30s %-10s %-36s\n", id_buf,
+                         virDomainGetName(dom),
+                         state == -2 ? _("saved")
+                         : virshDomainStateToString(state),
+                         uuid);
             } else {
                 vshPrint(ctl, " %-5s %-30s %s\n", id_buf,
                          virDomainGetName(dom),
-- 
1.8.3.1





More information about the libvir-list mailing list