]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: allow both --table and --uuid at the same time
authorNikolai Barybin via Devel <devel@lists.libvirt.org>
Wed, 14 Aug 2024 11:30:02 +0000 (14:30 +0300)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 19 Aug 2024 07:42:06 +0000 (09:42 +0200)
This will allow to print full domains info:

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

Signed-off-by: Nikolai Barybin <nikolai.barybin@virtuozzo.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
docs/manpages/virsh.rst
tools/virsh-domain-monitor.c

index fa038e4547fd83477f330109909128ebbdccac17..f02a28156d9e7d6195ef35090ae6a8eea969cd77 100644 (file)
@@ -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
index ef07ace5777ab2167b3a043647c6bb4e4d12a84a..74deca2f94928257b9b1ae09945e922c400e0fe5 100644 (file)
@@ -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),