mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-24 05:25:18 +00:00
snapshot: use new API for less work
This has the added benefit of making 'snapshot-create dom --no-metadata' now able to tell you the name of the just-generated snapshot. * tools/virsh.c (vshSnapshotCreate, cmdSnapshotCurrent): Don't get XML just for name.
This commit is contained in:
parent
6c14439e51
commit
a00c37f2f9
@ -12424,7 +12424,7 @@ vshSnapshotCreate(vshControl *ctl, virDomainPtr dom, const char *buffer,
|
|||||||
char *doc = NULL;
|
char *doc = NULL;
|
||||||
xmlDocPtr xml = NULL;
|
xmlDocPtr xml = NULL;
|
||||||
xmlXPathContextPtr ctxt = NULL;
|
xmlXPathContextPtr ctxt = NULL;
|
||||||
char *name = NULL;
|
const char *name = NULL;
|
||||||
|
|
||||||
snapshot = virDomainSnapshotCreateXML(dom, buffer, flags);
|
snapshot = virDomainSnapshotCreateXML(dom, buffer, flags);
|
||||||
|
|
||||||
@ -12459,21 +12459,9 @@ vshSnapshotCreate(vshControl *ctl, virDomainPtr dom, const char *buffer,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA)
|
name = virDomainSnapshotGetName(snapshot);
|
||||||
doc = vshStrdup(ctl, buffer);
|
|
||||||
else
|
|
||||||
doc = virDomainSnapshotGetXMLDesc(snapshot, 0);
|
|
||||||
if (!doc)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
xml = virXMLParseStringCtxt(doc, "domainsnapshot.xml", &ctxt);
|
|
||||||
if (!xml)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
name = virXPathString("string(/domainsnapshot/name)", ctxt);
|
|
||||||
if (!name) {
|
if (!name) {
|
||||||
vshError(ctl, "%s",
|
vshError(ctl, "%s", _("Could not get snapshot name"));
|
||||||
_("Could not find 'name' element in domain snapshot XML"));
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -12485,7 +12473,6 @@ vshSnapshotCreate(vshControl *ctl, virDomainPtr dom, const char *buffer,
|
|||||||
ret = true;
|
ret = true;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(name);
|
|
||||||
xmlXPathFreeContext(ctxt);
|
xmlXPathFreeContext(ctxt);
|
||||||
xmlFreeDoc(xml);
|
xmlFreeDoc(xml);
|
||||||
if (snapshot)
|
if (snapshot)
|
||||||
@ -12891,32 +12878,22 @@ cmdSnapshotCurrent(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (current < 0)
|
if (current < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
else if (current) {
|
else if (current) {
|
||||||
char *name = NULL;
|
const char *name = NULL;
|
||||||
|
|
||||||
if (!(snapshot = virDomainSnapshotCurrent(dom, 0)))
|
if (!(snapshot = virDomainSnapshotCurrent(dom, 0)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
if (vshCommandOptBool(cmd, "name")) {
|
||||||
|
name = virDomainSnapshotGetName(snapshot);
|
||||||
|
if (!name)
|
||||||
|
goto cleanup;
|
||||||
|
} else {
|
||||||
xml = virDomainSnapshotGetXMLDesc(snapshot, flags);
|
xml = virDomainSnapshotGetXMLDesc(snapshot, flags);
|
||||||
if (!xml)
|
if (!xml)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (vshCommandOptBool(cmd, "name")) {
|
|
||||||
xmlDocPtr xmldoc = NULL;
|
|
||||||
xmlXPathContextPtr ctxt = NULL;
|
|
||||||
|
|
||||||
xmldoc = virXMLParseStringCtxt(xml, "domainsnapshot.xml", &ctxt);
|
|
||||||
if (!xmldoc)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
name = virXPathString("string(/domainsnapshot/name)", ctxt);
|
|
||||||
xmlXPathFreeContext(ctxt);
|
|
||||||
xmlFreeDoc(xmldoc);
|
|
||||||
if (!name)
|
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vshPrint(ctl, "%s", name ? name : xml);
|
vshPrint(ctl, "%s", name ? name : xml);
|
||||||
VIR_FREE(name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = true;
|
ret = true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user