mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-09-09 09:14:57 +00:00
virsh: add virsh snapshot-current --name
Sometimes, full XML is too much; since most snapshot commands operate on a snapshot name, there should be an easy way to get at the current snapshot's name. For example: virsh snapshot-revert dom `virsh snapshot-current dom --name` * tools/virsh.c (cmdSnapshotCurrent): Add an option. * tools/virsh.pod (snapshot-current): Document it.
This commit is contained in:
parent
6927887829
commit
23b4a3f95b
@ -12034,6 +12034,7 @@ static const vshCmdInfo info_snapshot_current[] = {
|
|||||||
|
|
||||||
static const vshCmdOptDef opts_snapshot_current[] = {
|
static const vshCmdOptDef opts_snapshot_current[] = {
|
||||||
{"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
|
{"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
|
||||||
|
{"name", VSH_OT_BOOL, 0, N_("list the name, rather than the full xml")},
|
||||||
{NULL, 0, 0, NULL}
|
{NULL, 0, 0, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -12044,6 +12045,7 @@ cmdSnapshotCurrent(vshControl *ctl, const vshCmd *cmd)
|
|||||||
bool ret = false;
|
bool ret = false;
|
||||||
int current;
|
int current;
|
||||||
virDomainSnapshotPtr snapshot = NULL;
|
virDomainSnapshotPtr snapshot = NULL;
|
||||||
|
char *xml = NULL;
|
||||||
|
|
||||||
if (!vshConnectionUsability(ctl, ctl->conn))
|
if (!vshConnectionUsability(ctl, ctl->conn))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -12056,7 +12058,7 @@ cmdSnapshotCurrent(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (current < 0)
|
if (current < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
else if (current) {
|
else if (current) {
|
||||||
char *xml;
|
char *name = NULL;
|
||||||
|
|
||||||
if (!(snapshot = virDomainSnapshotCurrent(dom, 0)))
|
if (!(snapshot = virDomainSnapshotCurrent(dom, 0)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -12065,13 +12067,36 @@ cmdSnapshotCurrent(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (!xml)
|
if (!xml)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
vshPrint(ctl, "%s", xml);
|
if (vshCommandOptBool(cmd, "name")) {
|
||||||
VIR_FREE(xml);
|
xmlDocPtr xmldoc = NULL;
|
||||||
|
xmlXPathContextPtr ctxt = NULL;
|
||||||
|
|
||||||
|
xmldoc = xmlReadDoc((const xmlChar *) xml, "domainsnapshot.xml",
|
||||||
|
NULL, XML_PARSE_NOENT | XML_PARSE_NONET |
|
||||||
|
XML_PARSE_NOWARNING);
|
||||||
|
if (!xmldoc)
|
||||||
|
goto cleanup;
|
||||||
|
ctxt = xmlXPathNewContext(xmldoc);
|
||||||
|
if (!ctxt) {
|
||||||
|
xmlFreeDoc(xmldoc);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
name = virXPathString("string(/domainsnapshot/name)", ctxt);
|
||||||
|
xmlXPathFreeContext(ctxt);
|
||||||
|
xmlFreeDoc(xmldoc);
|
||||||
|
if (!name)
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
vshPrint(ctl, "%s", name ? name : xml);
|
||||||
|
VIR_FREE(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = true;
|
ret = true;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
VIR_FREE(xml);
|
||||||
if (snapshot)
|
if (snapshot)
|
||||||
virDomainSnapshotFree(snapshot);
|
virDomainSnapshotFree(snapshot);
|
||||||
if (dom)
|
if (dom)
|
||||||
|
@ -1569,9 +1569,11 @@ Create a snapshot for domain I<domain> with the given <name> and
|
|||||||
value. If I<--print-xml> is specified, then XML appropriate for
|
value. If I<--print-xml> is specified, then XML appropriate for
|
||||||
I<snapshot-create> is output, rather than actually creating a snapshot.
|
I<snapshot-create> is output, rather than actually creating a snapshot.
|
||||||
|
|
||||||
=item B<snapshot-current> I<domain>
|
=item B<snapshot-current> I<domain> [I<--name>]
|
||||||
|
|
||||||
Output the snapshot XML for the domain's current snapshot (if any).
|
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>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user