[PATCH 1/1] virsh: allow both --table and --uuid at the same time

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This will allow to print full domains info:

 Id   Name   State   UUID
---------------------------

Signed-off-by: Nikolai Barybin <nikolai.barybin@xxxxxxxxxxxxx>
---
 docs/manpages/virsh.rst      | 14 +++++++-------
 tools/virsh-domain-monitor.c | 37 ++++++++++++++++++++++++++++++++----
 2 files changed, 40 insertions(+), 11 deletions(-)

diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst
index fa038e4547..f02a28156d 100644
--- a/docs/manpages/virsh.rst
+++ b/docs/manpages/virsh.rst
@@ -648,7 +648,7 @@ list
 
    list [--inactive | --all]
         [--managed-save] [--title]
-        { [--table] | --name | --uuid | --id }
+        { [--table] | --name | --id } [--uuid]
         [--persistent] [--transient]
         [--with-managed-save] [--without-managed-save]
         [--autostart] [--no-autostart]
@@ -791,12 +791,12 @@ are printed instead of names. If *--id* is specified then domain's ID's
 are printed indead of names. However, it is possible to combine
 *--name*, *--uuid* and *--id* to select only desired fields for
 printing. Flag *--table* specifies that the legacy table-formatted
-output should be used, but it is mutually exclusive with *--name*,
-*--uuid* and *--id*. This is the default and will be used if neither of
-*--name*, *--uuid* or *--id* is specified. If neither *--name* nor *--uuid* is
-specified, but *--id* is, then only active domains are listed, even with the
-*--all* parameter as otherwise the output would just contain bunch of lines
-with just *-1*.
+output should be used, but it is mutually exclusive with *--name*, and *--id*.
+This is the default and will be used if neither of *--name*, *--uuid* or *--id*
+is specified. If neither *--name* nor *--uuid* is specified, but *--id* is,
+then only active domains are listed, even with the *--all* parameter as otherwise
+the output would just contain bunch of lines with just *-1*. If *--table* is
+combined with *--uuid*, then domain uuid is printed as an extra column.
 
 If *--title* is specified, then the short domain description (title) is
 printed in an extra column. This flag is usable only with the default
diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
index ef07ace577..74deca2f94 100644
--- a/tools/virsh-domain-monitor.c
+++ b/tools/virsh-domain-monitor.c
@@ -1855,10 +1855,9 @@ cmdList(vshControl *ctl, const vshCmd *cmd)
     FILTER("state-other",   VIR_CONNECT_LIST_DOMAINS_OTHER);
 
     VSH_EXCLUSIVE_OPTIONS("table", "name");
-    VSH_EXCLUSIVE_OPTIONS("table", "uuid");
     VSH_EXCLUSIVE_OPTIONS("table", "id");
 
-    if (!optUUID && !optName && !optID)
+    if (!optName && !optID)
         optTable = true;
 
     if (!(list = virshDomainListCollect(ctl, flags)))
@@ -1866,8 +1865,12 @@ cmdList(vshControl *ctl, const vshCmd *cmd)
 
     /* print table header in legacy mode */
     if (optTable) {
-        if (optTitle)
+        if (optTitle && !optUUID)
             table = vshTableNew(_("Id"), _("Name"), _("State"), _("Title"), NULL);
+        else if (optUUID && !optTitle)
+            table = vshTableNew(_("Id"), _("Name"), _("State"), _("UUID"), NULL);
+        else if (optUUID && optTitle)
+            table = vshTableNew(_("Id"), _("Name"), _("State"), _("Title"), _("UUID"), NULL);
         else
             table = vshTableNew(_("Id"), _("Name"), _("State"), NULL);
 
@@ -1896,7 +1899,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd)
                 virDomainHasManagedSaveImage(dom, 0) > 0)
                 state = -2;
 
-            if (optTitle) {
+            if (optTitle && !optUUID) {
                 g_autofree char *title = NULL;
 
                 if (!(title = virshGetDomainDescription(ctl, dom, true, 0)))
@@ -1907,6 +1910,32 @@ cmdList(vshControl *ctl, const vshCmd *cmd)
                                       : virshDomainStateToString(state),
                                       title, NULL) < 0)
                     goto cleanup;
+            } else if (optUUID && !optTitle) {
+                if (virDomainGetUUIDString(dom, uuid) < 0) {
+                    vshError(ctl, "%s", _("Failed to get domain's UUID"));
+                    goto cleanup;
+                }
+                if (vshTableRowAppend(table, id_buf,
+                                      virDomainGetName(dom),
+                                      state == -2 ? _("saved")
+                                      : virshDomainStateToString(state),
+                                      uuid, NULL) < 0)
+                    goto cleanup;
+            } else if (optUUID && optTitle) {
+                g_autofree char *title = NULL;
+
+                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;
+                }
+                if (vshTableRowAppend(table, id_buf,
+                                      virDomainGetName(dom),
+                                      state == -2 ? _("saved")
+                                      : virshDomainStateToString(state),
+                                      title, uuid, NULL) < 0)
+                    goto cleanup;
             } else {
                 if (vshTableRowAppend(table, id_buf,
                                       virDomainGetName(dom),
-- 
2.43.5



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux