snapshot_conf: Allow parsing an XML node
Similar to how other objects arrange their parse APIs. This will be used by the test driver.
This commit is contained in:
parent
49ecff3eab
commit
302e49f7d2
@ -166,15 +166,13 @@ cleanup:
|
|||||||
* If flags does not include VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE, then
|
* If flags does not include VIR_DOMAIN_SNAPSHOT_PARSE_REDEFINE, then
|
||||||
* caps and expectedVirtTypes are ignored.
|
* caps and expectedVirtTypes are ignored.
|
||||||
*/
|
*/
|
||||||
virDomainSnapshotDefPtr
|
static virDomainSnapshotDefPtr
|
||||||
virDomainSnapshotDefParseString(const char *xmlStr,
|
virDomainSnapshotDefParse(xmlXPathContextPtr ctxt,
|
||||||
virCapsPtr caps,
|
virCapsPtr caps,
|
||||||
virDomainXMLOptionPtr xmlopt,
|
virDomainXMLOptionPtr xmlopt,
|
||||||
unsigned int expectedVirtTypes,
|
unsigned int expectedVirtTypes,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
xmlXPathContextPtr ctxt = NULL;
|
|
||||||
xmlDocPtr xml = NULL;
|
|
||||||
virDomainSnapshotDefPtr def = NULL;
|
virDomainSnapshotDefPtr def = NULL;
|
||||||
virDomainSnapshotDefPtr ret = NULL;
|
virDomainSnapshotDefPtr ret = NULL;
|
||||||
xmlNodePtr *nodes = NULL;
|
xmlNodePtr *nodes = NULL;
|
||||||
@ -184,26 +182,13 @@ virDomainSnapshotDefParseString(const char *xmlStr,
|
|||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
int active;
|
int active;
|
||||||
char *tmp;
|
char *tmp;
|
||||||
int keepBlanksDefault = xmlKeepBlanksDefault(0);
|
|
||||||
char *memorySnapshot = NULL;
|
char *memorySnapshot = NULL;
|
||||||
char *memoryFile = NULL;
|
char *memoryFile = NULL;
|
||||||
bool offline = !!(flags & VIR_DOMAIN_SNAPSHOT_PARSE_OFFLINE);
|
bool offline = !!(flags & VIR_DOMAIN_SNAPSHOT_PARSE_OFFLINE);
|
||||||
|
|
||||||
xml = virXMLParseCtxt(NULL, xmlStr, _("(domain_snapshot)"), &ctxt);
|
|
||||||
if (!xml) {
|
|
||||||
xmlKeepBlanksDefault(keepBlanksDefault);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
xmlKeepBlanksDefault(keepBlanksDefault);
|
|
||||||
|
|
||||||
if (VIR_ALLOC(def) < 0)
|
if (VIR_ALLOC(def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!xmlStrEqual(ctxt->node->name, BAD_CAST "domainsnapshot")) {
|
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s", _("domainsnapshot"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
||||||
|
|
||||||
def->name = virXPathString("string(./name)", ctxt);
|
def->name = virXPathString("string(./name)", ctxt);
|
||||||
@ -261,7 +246,8 @@ virDomainSnapshotDefParseString(const char *xmlStr,
|
|||||||
_("missing domain in snapshot"));
|
_("missing domain in snapshot"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
def->dom = virDomainDefParseNode(xml, domainNode, caps, xmlopt,
|
def->dom = virDomainDefParseNode(ctxt->node->doc, domainNode,
|
||||||
|
caps, xmlopt,
|
||||||
expectedVirtTypes,
|
expectedVirtTypes,
|
||||||
(VIR_DOMAIN_XML_INACTIVE |
|
(VIR_DOMAIN_XML_INACTIVE |
|
||||||
VIR_DOMAIN_XML_SECURE));
|
VIR_DOMAIN_XML_SECURE));
|
||||||
@ -348,10 +334,61 @@ cleanup:
|
|||||||
VIR_FREE(nodes);
|
VIR_FREE(nodes);
|
||||||
VIR_FREE(memorySnapshot);
|
VIR_FREE(memorySnapshot);
|
||||||
VIR_FREE(memoryFile);
|
VIR_FREE(memoryFile);
|
||||||
xmlXPathFreeContext(ctxt);
|
|
||||||
if (ret == NULL)
|
if (ret == NULL)
|
||||||
virDomainSnapshotDefFree(def);
|
virDomainSnapshotDefFree(def);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
virDomainSnapshotDefPtr
|
||||||
|
virDomainSnapshotDefParseNode(xmlDocPtr xml,
|
||||||
|
xmlNodePtr root,
|
||||||
|
virCapsPtr caps,
|
||||||
|
virDomainXMLOptionPtr xmlopt,
|
||||||
|
unsigned int expectedVirtTypes,
|
||||||
|
unsigned int flags)
|
||||||
|
{
|
||||||
|
xmlXPathContextPtr ctxt = NULL;
|
||||||
|
virDomainSnapshotDefPtr def = NULL;
|
||||||
|
|
||||||
|
if (!xmlStrEqual(root->name, BAD_CAST "domainsnapshot")) {
|
||||||
|
virReportError(VIR_ERR_XML_ERROR, "%s", _("domainsnapshot"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctxt = xmlXPathNewContext(xml);
|
||||||
|
if (ctxt == NULL) {
|
||||||
|
virReportOOMError();
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctxt->node = root;
|
||||||
|
def = virDomainSnapshotDefParse(ctxt, caps, xmlopt,
|
||||||
|
expectedVirtTypes, flags);
|
||||||
|
cleanup:
|
||||||
|
xmlXPathFreeContext(ctxt);
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
|
||||||
|
virDomainSnapshotDefPtr
|
||||||
|
virDomainSnapshotDefParseString(const char *xmlStr,
|
||||||
|
virCapsPtr caps,
|
||||||
|
virDomainXMLOptionPtr xmlopt,
|
||||||
|
unsigned int expectedVirtTypes,
|
||||||
|
unsigned int flags)
|
||||||
|
{
|
||||||
|
virDomainSnapshotDefPtr ret = NULL;
|
||||||
|
xmlDocPtr xml;
|
||||||
|
int keepBlanksDefault = xmlKeepBlanksDefault(0);
|
||||||
|
|
||||||
|
if ((xml = virXMLParse(NULL, xmlStr, _("(domain_snapshot)")))) {
|
||||||
|
xmlKeepBlanksDefault(keepBlanksDefault);
|
||||||
|
ret = virDomainSnapshotDefParseNode(xml, xmlDocGetRootElement(xml),
|
||||||
|
caps, xmlopt,
|
||||||
|
expectedVirtTypes, flags);
|
||||||
xmlFreeDoc(xml);
|
xmlFreeDoc(xml);
|
||||||
|
}
|
||||||
|
xmlKeepBlanksDefault(keepBlanksDefault);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -104,6 +104,12 @@ virDomainSnapshotDefPtr virDomainSnapshotDefParseString(const char *xmlStr,
|
|||||||
virDomainXMLOptionPtr xmlopt,
|
virDomainXMLOptionPtr xmlopt,
|
||||||
unsigned int expectedVirtTypes,
|
unsigned int expectedVirtTypes,
|
||||||
unsigned int flags);
|
unsigned int flags);
|
||||||
|
virDomainSnapshotDefPtr virDomainSnapshotDefParseNode(xmlDocPtr xml,
|
||||||
|
xmlNodePtr root,
|
||||||
|
virCapsPtr caps,
|
||||||
|
virDomainXMLOptionPtr xmlopt,
|
||||||
|
unsigned int expectedVirtTypes,
|
||||||
|
unsigned int flags);
|
||||||
void virDomainSnapshotDefFree(virDomainSnapshotDefPtr def);
|
void virDomainSnapshotDefFree(virDomainSnapshotDefPtr def);
|
||||||
char *virDomainSnapshotDefFormat(const char *domain_uuid,
|
char *virDomainSnapshotDefFormat(const char *domain_uuid,
|
||||||
virDomainSnapshotDefPtr def,
|
virDomainSnapshotDefPtr def,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user