[libvirt] [PATCH v2 2/2] virsh: enable --table with --name or --uuid

Chen Hanxiao chen_han_xiao at 126.com
Fri Jun 24 16:44:52 UTC 2016


From: Chen Hanxiao <chenhanxiao at gmail.com>

 remove restrictions of --table with --name or --uid.

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

diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
index c712fa5..2596504 100644
--- a/tools/virsh-domain-monitor.c
+++ b/tools/virsh-domain-monitor.c
@@ -1844,22 +1844,33 @@ cmdList(vshControl *ctl, const vshCmd *cmd)
     FILTER("state-shutoff", VIR_CONNECT_LIST_DOMAINS_SHUTOFF);
     FILTER("state-other",   VIR_CONNECT_LIST_DOMAINS_OTHER);
 
-    VSH_EXCLUSIVE_OPTIONS("table", "name");
-    VSH_EXCLUSIVE_OPTIONS("table", "uuid");
-
     if (!optUUID && !optName)
         optTable = true;
+    if (optUUID && optTitle)
+        optTable = true;
 
     if (!(list = virshDomainListCollect(ctl, flags)))
         goto cleanup;
 
     /* print table header in legacy mode */
     if (optTable) {
-        if (optTitle)
+        if (optTitle && optUUID)
+            vshPrintExtra(ctl, " %-5s %-30s %-10s %-36s %-20s\n%s\n",
+                          _("Id"), _("Name"), _("State"), _("UUID"), _("Title"),
+                          "-----------------------------------------"
+                          "-----------------------------------------"
+                          "-----------------------------------------");
+        else if (optTitle)
             vshPrintExtra(ctl, " %-5s %-30s %-10s %-20s\n%s\n",
                           _("Id"), _("Name"), _("State"), _("Title"),
                           "-----------------------------------------"
                           "-----------------------------------------");
+        else if (optUUID)
+            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"),
@@ -1886,7 +1897,22 @@ cmdList(vshControl *ctl, const vshCmd *cmd)
                 virDomainHasManagedSaveImage(dom, 0) > 0)
                 state = -2;
 
-            if (optTitle) {
+            if (optTitle && optUUID) {
+                if (!(title = virshGetDomainDescription(ctl, dom, true, 0)))
+                    goto cleanup;
+                if (virDomainGetUUIDString(dom, uuid) < 0) {
+                    vshError(ctl, "%s", _("Failed to get domain's UUID"));
+                    goto cleanup;
+                }
+                vshPrint(ctl, " %-5s %-30s %-10s %-36s %-20s\n", id_buf,
+                         virDomainGetName(dom),
+                         state == -2 ? _("saved")
+                         : virshDomainStateToString(state),
+                         uuid,
+                         title);
+
+                VIR_FREE(title);
+            } else if (optTitle) {
                 if (!(title = virshGetDomainDescription(ctl, dom, true, 0)))
                     goto cleanup;
 
@@ -1897,6 +1923,16 @@ cmdList(vshControl *ctl, const vshCmd *cmd)
                          title);
 
                 VIR_FREE(title);
+            } else if (optUUID) {
+                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),
-- 
2.5.0





More information about the libvir-list mailing list