提交 0d00c7a3 编写于 作者: P Peter Krempa

virsh-snapshot: Add ability to print only snapshot names

Help script creators by not having to parse the names from the table.
上级 be1c364d
......@@ -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;
......
......@@ -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,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册