[PATCHv4 10/51] snapshot: add snapshot-list --parent to virsh

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

 



Even though I recently added 'virsh snapshot-parent', doing it one
snapshot at a time is painful, so make it possible to expand the
snapshot-list table at once.

* tools/virsh.c (cmdSnapshotList): Add --parent.
* tools/virsh.pod (snapshot-list): Document it.
---
 tools/virsh.c   |   39 +++++++++++++++++++++++++++++++++------
 tools/virsh.pod |    5 ++++-
 2 files changed, 37 insertions(+), 7 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 2e41b45..b0f4319 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -12184,6 +12184,7 @@ static const vshCmdInfo info_snapshot_list[] = {

 static const vshCmdOptDef opts_snapshot_list[] = {
     {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
+    {"parent", VSH_OT_BOOL, 0, N_("add a column showing parent snapshot")},
     {NULL, 0, 0, NULL}
 };

@@ -12192,6 +12193,9 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
 {
     virDomainPtr dom = NULL;
     bool ret = false;
+    unsigned int flags = 0;
+    int parent_filter = 0; /* 0 for no parent information needed,
+                              1 for parent column */
     int numsnaps;
     char **names = NULL;
     int actual = 0;
@@ -12201,11 +12205,16 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
     char *doc = NULL;
     virDomainSnapshotPtr snapshot = NULL;
     char *state = NULL;
+    char *parent = NULL;
     long long creation_longlong;
     time_t creation_time_t;
     char timestr[100];
     struct tm time_info;

+    if (vshCommandOptBool(cmd, "parent")) {
+        parent_filter = 1;
+    }
+
     if (!vshConnectionUsability(ctl, ctl->conn))
         goto cleanup;

@@ -12213,19 +12222,25 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
     if (dom == NULL)
         goto cleanup;

-    numsnaps = virDomainSnapshotNum(dom, 0);
+    numsnaps = virDomainSnapshotNum(dom, flags);

     if (numsnaps < 0)
         goto cleanup;

-    vshPrintExtra(ctl, " %-20s %-25s %s\n", _("Name"), _("Creation Time"), _("State"));
-    vshPrintExtra(ctl, "---------------------------------------------------\n");
+    if (parent_filter > 0)
+        vshPrintExtra(ctl, " %-20s %-25s %-15s %s",
+                      _("Name"), _("Creation Time"), _("State"), _("Parent"));
+    else
+        vshPrintExtra(ctl, " %-20s %-25s %s",
+                      _("Name"), _("Creation Time"), _("State"));
+    vshPrintExtra(ctl, "\n\
+------------------------------------------------------------\n");

     if (numsnaps) {
         if (VIR_ALLOC_N(names, numsnaps) < 0)
             goto cleanup;

-        actual = virDomainSnapshotListNames(dom, names, numsnaps, 0);
+        actual = virDomainSnapshotListNames(dom, names, numsnaps, flags);
         if (actual < 0)
             goto cleanup;

@@ -12233,6 +12248,7 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)

         for (i = 0; i < actual; i++) {
             /* free up memory from previous iterations of the loop */
+            VIR_FREE(parent);
             VIR_FREE(state);
             if (snapshot)
                 virDomainSnapshotFree(snapshot);
@@ -12252,6 +12268,11 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
             if (!xml)
                 continue;

+            if (parent_filter) {
+                parent = virXPathString("string(/domainsnapshot/parent/name)",
+                                        ctxt);
+            }
+
             state = virXPathString("string(/domainsnapshot/state)", ctxt);
             if (state == NULL)
                 continue;
@@ -12264,9 +12285,14 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
                 continue;
             }
             localtime_r(&creation_time_t, &time_info);
-            strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S %z", &time_info);
+            strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S %z",
+                     &time_info);

-            vshPrint(ctl, " %-20s %-25s %s\n", names[i], timestr, state);
+            if (parent)
+                vshPrint(ctl, " %-20s %-25s %-15s %s\n",
+                         names[i], timestr, state, parent);
+            else
+                vshPrint(ctl, " %-20s %-25s %s\n", names[i], timestr, state);
         }
     }

@@ -12274,6 +12300,7 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)

 cleanup:
     /* this frees up memory from the last iteration of the loop */
+    VIR_FREE(parent);
     VIR_FREE(state);
     if (snapshot)
         virDomainSnapshotFree(snapshot);
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 30ab5ca..7d8e435 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -1697,10 +1697,13 @@ Output the snapshot XML for the domain's current snapshot (if any).
 If I<--name> is specified, just list the snapshot name instead of the
 full xml.

-=item B<snapshot-list> I<domain>
+=item B<snapshot-list> I<domain> [I<--parent>]

 List all of the available snapshots for the given domain.

+If I<--parent> is specified, add a column to the output table giving
+the name of the parent of each snapshot.
+
 =item B<snapshot-dumpxml> I<domain> I<snapshot>

 Output the snapshot XML for the domain's snapshot named I<snapshot>.
-- 
1.7.4.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[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]