aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2011-08-18 15:37:14 -0600
committerEric Blake <eblake@redhat.com>2011-08-19 09:13:55 -0600
commitd89dd42d51679cd73932f8dc9472549bb1265ac4 (patch)
treec99271bbb4d5caf92809167853863fa89ab51b86 /tools
parentxml: add another convenience function (diff)
downloadlibvirt-d89dd42d51679cd73932f8dc9472549bb1265ac4.tar.gz
libvirt-d89dd42d51679cd73932f8dc9472549bb1265ac4.tar.bz2
libvirt-d89dd42d51679cd73932f8dc9472549bb1265ac4.zip
maint: simplify lots of libxml2 clients
Repetitive patterns should be factored. The sign of a good factorization is a change that kills 5x more lines than it adds :) * src/conf/domain_conf.c (virDomainDeviceDefParse) (virDomainSnapshotDefParseString): Use new convenience macros. * src/conf/storage_conf.c (virStoragePoolDefParseSourceString): Likewise. * src/cpu/cpu.c (cpuCompareXML, cpuBaselineXML): Likewise. * src/esx/esx_vi.c (esxVI_Context_Execute): Likewise. * src/qemu/qemu_migration.c (qemuMigrationCookieXMLParseStr): Likewise. * src/security/virt-aa-helper.c (caps_mockup): Likewise. * src/test/test_driver.c (testOpenFromFile): Likewise. * tests/cputest.c (cpuTestLoadXML, cpuTestLoadMultiXML): Likewise. * tools/virsh.c (cmdFreecell, makeCloneXML, cmdVNCDisplay) (cmdTTYConsole, cmdDetachInterface, cmdDetachDisk) (cmdSnapshotCreate, cmdSnapshotCreateAs, cmdSnapshotCurrent) (cmdSnapshotList, cmdSnapshotParent): Likewise.
Diffstat (limited to 'tools')
-rw-r--r--tools/virsh.c84
1 files changed, 13 insertions, 71 deletions
diff --git a/tools/virsh.c b/tools/virsh.c
index c43de4c32..1c6715029 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -67,6 +67,8 @@ static char *progname;
#define VSH_PROMPT_RW "virsh # "
#define VSH_PROMPT_RO "virsh > "
+#define VIR_FROM_THIS VIR_FROM_NONE
+
#define GETTIMEOFDAY(T) gettimeofday(T, NULL)
#define DIFF_MSEC(T, U) \
((((int) ((T)->tv_sec - (U)->tv_sec)) * 1000000.0 + \
@@ -2901,16 +2903,11 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
goto cleanup;
}
- xml = xmlReadDoc((const xmlChar *) cap_xml, "node.xml", NULL,
- XML_PARSE_NOENT | XML_PARSE_NONET |
- XML_PARSE_NOWARNING);
-
+ xml = virXMLParseStringCtxt(cap_xml, "node.xml", &ctxt);
if (!xml) {
vshError(ctl, "%s", _("unable to get node capabilities"));
goto cleanup;
}
-
- ctxt = xmlXPathNewContext(xml);
nodes_cnt = virXPathNodeSet("/capabilities/host/topology/cells/cell",
ctxt, &nodes);
@@ -8404,13 +8401,9 @@ makeCloneXML(const char *origxml, const char *newname) {
xmlChar *newxml = NULL;
int size;
- doc = xmlReadDoc((const xmlChar *) origxml, "domain.xml", NULL,
- XML_PARSE_NOENT | XML_PARSE_NONET | XML_PARSE_NOWARNING);
+ doc = virXMLParseStringCtxt(origxml, "domain.xml", &ctxt);
if (!doc)
goto cleanup;
- ctxt = xmlXPathNewContext(doc);
- if (!ctxt)
- goto cleanup;
obj = xmlXPathEval(BAD_CAST "/volume/name", ctxt);
if ((obj == NULL) || (obj->nodesetval == NULL) ||
@@ -10199,15 +10192,10 @@ cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd)
if (!doc)
goto cleanup;
- xml = xmlReadDoc((const xmlChar *) doc, "domain.xml", NULL,
- XML_PARSE_NOENT | XML_PARSE_NONET |
- XML_PARSE_NOWARNING);
+ xml = virXMLParseStringCtxt(doc, "domain.xml", &ctxt);
VIR_FREE(doc);
if (!xml)
goto cleanup;
- ctxt = xmlXPathNewContext(xml);
- if (!ctxt)
- goto cleanup;
obj = xmlXPathEval(BAD_CAST "string(/domain/devices/graphics[@type='vnc']/@port)", ctxt);
if ((obj == NULL) || (obj->type != XPATH_STRING) ||
@@ -10272,15 +10260,10 @@ cmdTTYConsole(vshControl *ctl, const vshCmd *cmd)
if (!doc)
goto cleanup;
- xml = xmlReadDoc((const xmlChar *) doc, "domain.xml", NULL,
- XML_PARSE_NOENT | XML_PARSE_NONET |
- XML_PARSE_NOWARNING);
+ xml = virXMLParseStringCtxt(doc, "domain.xml", &ctxt);
VIR_FREE(doc);
if (!xml)
goto cleanup;
- ctxt = xmlXPathNewContext(xml);
- if (!ctxt)
- goto cleanup;
obj = xmlXPathEval(BAD_CAST "string(/domain/devices/console/@tty)", ctxt);
if ((obj == NULL) || (obj->type != XPATH_STRING) ||
@@ -10664,19 +10647,12 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)
if (!doc)
goto cleanup;
- xml = xmlReadDoc((const xmlChar *) doc, "domain.xml", NULL,
- XML_PARSE_NOENT | XML_PARSE_NONET |
- XML_PARSE_NOWARNING);
+ xml = virXMLParseStringCtxt(doc, "domain.xml", &ctxt);
VIR_FREE(doc);
if (!xml) {
vshError(ctl, "%s", _("Failed to get interface information"));
goto cleanup;
}
- ctxt = xmlXPathNewContext(xml);
- if (!ctxt) {
- vshError(ctl, "%s", _("Failed to get interface information"));
- goto cleanup;
- }
snprintf(buf, sizeof(buf), "/domain/devices/interface[@type='%s']", type);
obj = xmlXPathEval(BAD_CAST buf, ctxt);
@@ -11138,19 +11114,12 @@ cmdDetachDisk(vshControl *ctl, const vshCmd *cmd)
if (!doc)
goto cleanup;
- xml = xmlReadDoc((const xmlChar *) doc, "domain.xml", NULL,
- XML_PARSE_NOENT | XML_PARSE_NONET |
- XML_PARSE_NOWARNING);
+ xml = virXMLParseStringCtxt(doc, "domain.xml", &ctxt);
VIR_FREE(doc);
if (!xml) {
vshError(ctl, "%s", _("Failed to get disk information"));
goto cleanup;
}
- ctxt = xmlXPathNewContext(xml);
- if (!ctxt) {
- vshError(ctl, "%s", _("Failed to get disk information"));
- goto cleanup;
- }
obj = xmlXPathEval(BAD_CAST "/domain/devices/disk", ctxt);
if ((obj == NULL) || (obj->type != XPATH_NODESET) ||
@@ -11865,14 +11834,9 @@ cmdSnapshotCreate(vshControl *ctl, const vshCmd *cmd)
if (!doc)
goto cleanup;
- xml = xmlReadDoc((const xmlChar *) doc, "domainsnapshot.xml", NULL,
- XML_PARSE_NOENT | XML_PARSE_NONET |
- XML_PARSE_NOWARNING);
+ xml = virXMLParseStringCtxt(doc, "domainsnapshot.xml", &ctxt);
if (!xml)
goto cleanup;
- ctxt = xmlXPathNewContext(xml);
- if (!ctxt)
- goto cleanup;
name = virXPathString("string(/domainsnapshot/name)", ctxt);
if (!name) {
@@ -11974,14 +11938,9 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd)
if (!doc)
goto cleanup;
- xml = xmlReadDoc((const xmlChar *) doc, "domainsnapshot.xml", NULL,
- XML_PARSE_NOENT | XML_PARSE_NONET |
- XML_PARSE_NOWARNING);
+ xml = virXMLParseStringCtxt(doc, "domainsnapshot.xml", &ctxt);
if (!xml)
goto cleanup;
- ctxt = xmlXPathNewContext(xml);
- if (!ctxt)
- goto cleanup;
parsed_name = virXPathString("string(/domainsnapshot/name)", ctxt);
if (!parsed_name) {
@@ -12056,16 +12015,9 @@ cmdSnapshotCurrent(vshControl *ctl, const vshCmd *cmd)
xmlDocPtr xmldoc = NULL;
xmlXPathContextPtr ctxt = NULL;
- xmldoc = xmlReadDoc((const xmlChar *) xml, "domainsnapshot.xml",
- NULL, XML_PARSE_NOENT | XML_PARSE_NONET |
- XML_PARSE_NOWARNING);
+ xmldoc = virXMLParseStringCtxt(xml, "domainsnapshot.xml", &ctxt);
if (!xmldoc)
goto cleanup;
- ctxt = xmlXPathNewContext(xmldoc);
- if (!ctxt) {
- xmlFreeDoc(xmldoc);
- goto cleanup;
- }
name = virXPathString("string(/domainsnapshot/name)", ctxt);
xmlXPathFreeContext(ctxt);
@@ -12165,14 +12117,9 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
if (!doc)
continue;
- xml = xmlReadDoc((const xmlChar *) doc, "domainsnapshot.xml", NULL,
- XML_PARSE_NOENT | XML_PARSE_NONET |
- XML_PARSE_NOWARNING);
+ xml = virXMLParseStringCtxt(doc, "domainsnapshot.xml", &ctxt);
if (!xml)
continue;
- ctxt = xmlXPathNewContext(xml);
- if (!ctxt)
- continue;
state = virXPathString("string(/domainsnapshot/state)", ctxt);
if (state == NULL)
@@ -12312,14 +12259,9 @@ cmdSnapshotParent(vshControl *ctl, const vshCmd *cmd)
if (!xml)
goto cleanup;
- xmldoc = xmlReadDoc((const xmlChar *) xml, "domainsnapshot.xml", NULL,
- XML_PARSE_NOENT | XML_PARSE_NONET |
- XML_PARSE_NOWARNING);
+ xmldoc = virXMLParseStringCtxt(xml, "domainsnapshot.xml", &ctxt);
if (!xmldoc)
goto cleanup;
- ctxt = xmlXPathNewContext(xmldoc);
- if (!ctxt)
- goto cleanup;
parent = virXPathString("string(/domainsnapshot/parent/name)", ctxt);
if (!parent)