virsh: add list --managed-save

Knowing whether 'virsh start' will resume a saved image or do
a fresh boot is useful enough to expose via 'virsh list'.

Also, translate the state column.

* tools/virsh.c (cmdList): add --managed-save flag
* tools/virsh.pod (list): Document it.
Based on a suggestion by Miklos Vajna.
This commit is contained in:
Eric Blake
2011-08-18 18:09:14 -06:00
parent 6aa57af3e4
commit 131540277e
2 changed files with 17 additions and 3 deletions

View File

@@ -851,6 +851,8 @@ static const vshCmdInfo info_list[] = {
static const vshCmdOptDef opts_list[] = { static const vshCmdOptDef opts_list[] = {
{"inactive", VSH_OT_BOOL, 0, N_("list inactive domains")}, {"inactive", VSH_OT_BOOL, 0, N_("list inactive domains")},
{"all", VSH_OT_BOOL, 0, N_("list inactive & active domains")}, {"all", VSH_OT_BOOL, 0, N_("list inactive & active domains")},
{"managed-save", VSH_OT_BOOL, 0,
N_("mark domains with managed save state")},
{NULL, 0, 0, NULL} {NULL, 0, 0, NULL}
}; };
@@ -864,6 +866,9 @@ cmdList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
int *ids = NULL, maxid = 0, i; int *ids = NULL, maxid = 0, i;
char **names = NULL; char **names = NULL;
int maxname = 0; int maxname = 0;
bool managed = vshCommandOptBool(cmd, "managed-save");
int state;
inactive |= all; inactive |= all;
if (!vshConnectionUsability(ctl, ctl->conn)) if (!vshConnectionUsability(ctl, ctl->conn))
@@ -920,7 +925,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
vshPrint(ctl, "%3d %-20s %s\n", vshPrint(ctl, "%3d %-20s %s\n",
virDomainGetID(dom), virDomainGetID(dom),
virDomainGetName(dom), virDomainGetName(dom),
vshDomainStateToString(vshDomainState(ctl, dom, NULL))); _(vshDomainStateToString(vshDomainState(ctl, dom, NULL))));
virDomainFree(dom); virDomainFree(dom);
} }
for (i = 0; i < maxname; i++) { for (i = 0; i < maxname; i++) {
@@ -932,10 +937,15 @@ cmdList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
continue; continue;
} }
state = vshDomainState(ctl, dom, NULL);
if (managed && state == VIR_DOMAIN_SHUTOFF &&
virDomainHasManagedSaveImage(dom, 0) > 0)
state = -2;
vshPrint(ctl, "%3s %-20s %s\n", vshPrint(ctl, "%3s %-20s %s\n",
"-", "-",
names[i], names[i],
vshDomainStateToString(vshDomainState(ctl, dom, NULL))); state == -2 ? _("saved") : _(vshDomainStateToString(state)));
virDomainFree(dom); virDomainFree(dom);
VIR_FREE(names[i]); VIR_FREE(names[i]);

View File

@@ -266,7 +266,7 @@ The XML also show the NUMA topology information if available.
Inject NMI to the guest. Inject NMI to the guest.
=item B<list> [I<--inactive> | I<--all>] =item B<list> [I<--inactive> | I<--all>] [I<--managed-save>]
Prints information about existing domains. If no options are Prints information about existing domains. If no options are
specified it prints out information about running domains. specified it prints out information about running domains.
@@ -337,6 +337,10 @@ crashed.
=back =back
If I<--managed-save> is specified, then domains that have managed save
state (only possible if they are in the B<shut off> state) will
instead show as B<saved> in the listing.
=item B<freecell> [B<cellno> | I<--all>] =item B<freecell> [B<cellno> | I<--all>]
Prints the available amount of memory on the machine or within a Prints the available amount of memory on the machine or within a