]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh-snapshot: Add ability to print only snapshot names
authorPeter Krempa <pkrempa@redhat.com>
Fri, 1 Mar 2013 14:42:25 +0000 (15:42 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 5 Mar 2013 07:34:48 +0000 (08:34 +0100)
Help script creators by not having to parse the names from the table.

tools/virsh-snapshot.c
tools/virsh.pod

index 3d82276ec21c8223bf15e048de031346398d4c48..ed410147f6884377631cbbdaec4ad99e6e82f182 100644 (file)
@@ -1556,6 +1556,12 @@ static const vshCmdOptDef opts_snapshot_list[] = {
      .flags = 0,
      .help = N_("with --from, list all descendants")
     },
+    {.name = "name",
+     .type = VSH_OT_BOOL,
+     .flags = 0,
+     .help = N_("list snapshot names only")
+    },
+
     {.name = NULL}
 };
 
@@ -1578,10 +1584,17 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
     char timestr[100];
     struct tm time_info;
     bool tree = vshCommandOptBool(cmd, "tree");
+    bool name = vshCommandOptBool(cmd, "name");
     const char *from = NULL;
     virDomainSnapshotPtr start = NULL;
     vshSnapshotListPtr snaplist = NULL;
 
+    if (tree && name) {
+        vshError(ctl, "%s",
+                 _("--tree and --name are mutually exclusive"));
+        return false;
+    }
+
     dom = vshCommandOptDomain(ctl, cmd, NULL);
     if (dom == NULL)
         goto cleanup;
@@ -1660,7 +1673,7 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
                                            tree)) == NULL)
         goto cleanup;
 
-    if (!tree) {
+    if (!tree && !name) {
         if (show_parent)
             vshPrintExtra(ctl, " %-20s %-25s %-15s %s",
                           _("Name"), _("Creation Time"), _("State"),
@@ -1689,7 +1702,7 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
     }
 
     for (i = 0; i < snaplist->nsnaps; i++) {
-        const char *name;
+        const char *snap_name;
 
         /* free up memory from previous iterations of the loop */
         VIR_FREE(parent);
@@ -1699,8 +1712,13 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
         VIR_FREE(doc);
 
         snapshot = snaplist->snaps[i].snap;
-        name = virDomainSnapshotGetName(snapshot);
-        assert(name);
+        snap_name = virDomainSnapshotGetName(snapshot);
+        assert(snap_name);
+
+        if (name) {
+            vshPrint(ctl, "%s\n", snap_name);
+            continue;
+        }
 
         doc = virDomainSnapshotGetXMLDesc(snapshot, 0);
         if (!doc)
@@ -1731,9 +1749,9 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
 
         if (parent)
             vshPrint(ctl, " %-20s %-25s %-15s %s\n",
-                     name, timestr, state, parent);
+                     snap_name, timestr, state, parent);
         else
-            vshPrint(ctl, " %-20s %-25s %s\n", name, timestr, state);
+            vshPrint(ctl, " %-20s %-25s %s\n", snap_name, timestr, state);
     }
 
     ret = true;
index a5d8fe6021592f94693d38e7a524194cf19394e7..7fb89e41ee826014c757f74e8e09260d7d1ccdf7 100644 (file)
@@ -2854,10 +2854,11 @@ accessible only from the original name.
 Output basic information about a named <snapshot>, or the current snapshot
 with I<--current>.
 
-=item B<snapshot-list> I<domain> [{I<--parent> | I<--roots> | I<--tree>}]
+=item B<snapshot-list> I<domain> [I<--metadata>] [I<--no-metadata>]
+[{I<--parent> | I<--roots> | [{I<--tree> | I<--name>}]}]
 [{[I<--from>] B<snapshot> | I<--current>} [I<--descendants>]]
-[I<--metadata>] [I<--no-metadata>] [I<--leaves>] [I<--no-leaves>]
-[I<--inactive>] [I<--active>] [I<--disk-only>] [I<--internal>] [I<--external>]
+[I<--leaves>] [I<--no-leaves>] p[I<--inactive>] [I<--active>]
+[I<--disk-only>] [I<--internal>] [I<--external>]
 
 List all of the available snapshots for the given domain, defaulting
 to show columns for the snapshot name, creation time, and domain state.
@@ -2866,7 +2867,9 @@ If I<--parent> is specified, add a column to the output table giving
 the name of the parent of each snapshot.  If I<--roots> is specified,
 the list will be filtered to just snapshots that have no parents.
 If I<--tree> is specified, the output will be in a tree format, listing
-just snapshot names.  These three options are mutually exclusive.
+just snapshot names.  These three options are mutually exclusive. If
+I<--name> is specified only the snapshot name is printed. This option is
+mutually exclusive with I<--tree>.
 
 If I<--from> is provided, filter the list to snapshots which are
 children of the given B<snapshot>; or if I<--current> is provided,