提交 98369d31 编写于 作者: E Eric Blake

virsh: add snapshot-parent

Down the road, I want to add virDomainSnapshotGetParent, and use
the new API rather than xml scraping; but this virsh command can
be implemented even without the new API.

* tools/virsh.c (cmdSnapshotParent): New command.
* tools/virsh.pod (snapshot-parent): Document it.
上级 398ce48d
......@@ -12284,6 +12284,82 @@ cleanup:
return ret;
}
/*
* "snapshot-parent" command
*/
static const vshCmdInfo info_snapshot_parent[] = {
{"help", N_("Get the name of the parent of the current snapshot")},
{"desc", N_("Extract the snapshot's parent, if any")},
{NULL, NULL}
};
static const vshCmdOptDef opts_snapshot_parent[] = {
{"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
{"snapshotname", VSH_OT_DATA, VSH_OFLAG_REQ, N_("snapshot name")},
{NULL, 0, 0, NULL}
};
static bool
cmdSnapshotParent(vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom = NULL;
bool ret = false;
const char *name = NULL;
virDomainSnapshotPtr snapshot = NULL;
char *xml = NULL;
char *parent = NULL;
xmlDocPtr xmldoc = NULL;
xmlXPathContextPtr ctxt = NULL;
if (!vshConnectionUsability(ctl, ctl->conn))
goto cleanup;
dom = vshCommandOptDomain(ctl, cmd, NULL);
if (dom == NULL)
goto cleanup;
if (vshCommandOptString(cmd, "snapshotname", &name) <= 0)
goto cleanup;
snapshot = virDomainSnapshotLookupByName(dom, name, 0);
if (snapshot == NULL)
goto cleanup;
xml = virDomainSnapshotGetXMLDesc(snapshot, 0);
if (!xml)
goto cleanup;
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)
goto cleanup;
parent = virXPathString("string(/domainsnapshot/parent/name)", ctxt);
if (!parent)
goto cleanup;
vshPrint(ctl, "%s", parent);
ret = true;
cleanup:
VIR_FREE(parent);
xmlXPathFreeContext(ctxt);
if (xmldoc)
xmlFreeDoc(xmldoc);
VIR_FREE(xml);
if (snapshot)
virDomainSnapshotFree(snapshot);
if (dom)
virDomainFree(dom);
return ret;
}
/*
* "snapshot-revert" command
*/
......@@ -12754,6 +12830,8 @@ static const vshCmdDef snapshotCmds[] = {
info_snapshot_dumpxml, 0},
{"snapshot-list", cmdSnapshotList, opts_snapshot_list,
info_snapshot_list, 0},
{"snapshot-parent", cmdSnapshotParent, opts_snapshot_parent,
info_snapshot_parent, 0},
{"snapshot-revert", cmdDomainSnapshotRevert, opts_snapshot_revert,
info_snapshot_revert, 0},
{NULL, NULL, NULL, NULL, 0}
......
......@@ -1583,6 +1583,10 @@ List all of the available snapshots for the given domain.
Output the snapshot XML for the domain's snapshot named I<snapshot>.
=item B<snapshot-parent> I<domain> I<snapshot>
Output the name of the parent snapshot for the given I<snapshot>, if any.
=item B<snapshot-revert> I<domain> I<snapshot>
Revert the given domain to the snapshot specified by I<snapshot>. Be aware
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册