mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-03 12:55:45 +00:00
virsh-domain: Use the virsh wrappers for getting XML to simplify code
Reuse virshDomainGetXML and virshDomainGetXMLFromDom.
This commit is contained in:
parent
6bd2889014
commit
9f5f5bd7d6
@ -2983,13 +2983,13 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd)
|
|||||||
const char *iface;
|
const char *iface;
|
||||||
const char *state;
|
const char *state;
|
||||||
char *value;
|
char *value;
|
||||||
char *desc;
|
|
||||||
virMacAddr macaddr;
|
virMacAddr macaddr;
|
||||||
const char *element;
|
const char *element;
|
||||||
const char *attr;
|
const char *attr;
|
||||||
bool config;
|
bool config;
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
unsigned int flags = 0;
|
unsigned int flags = 0;
|
||||||
|
unsigned int xmlflags = 0;
|
||||||
size_t i;
|
size_t i;
|
||||||
xmlDocPtr xml = NULL;
|
xmlDocPtr xml = NULL;
|
||||||
xmlXPathContextPtr ctxt = NULL;
|
xmlXPathContextPtr ctxt = NULL;
|
||||||
@ -3011,28 +3011,18 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get persistent or live description of network device */
|
if (config) {
|
||||||
desc = virDomainGetXMLDesc(dom, config ? VIR_DOMAIN_XML_INACTIVE : 0);
|
|
||||||
if (desc == NULL) {
|
|
||||||
vshError(ctl, _("Failed to get domain description xml"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config)
|
|
||||||
flags = VIR_DOMAIN_AFFECT_CONFIG;
|
flags = VIR_DOMAIN_AFFECT_CONFIG;
|
||||||
else
|
xmlflags |= VIR_DOMAIN_XML_INACTIVE;
|
||||||
|
} else {
|
||||||
flags = VIR_DOMAIN_AFFECT_LIVE;
|
flags = VIR_DOMAIN_AFFECT_LIVE;
|
||||||
|
}
|
||||||
|
|
||||||
if (virDomainIsActive(dom) == 0)
|
if (virDomainIsActive(dom) == 0)
|
||||||
flags = VIR_DOMAIN_AFFECT_CONFIG;
|
flags = VIR_DOMAIN_AFFECT_CONFIG;
|
||||||
|
|
||||||
/* extract current network device description */
|
if (virshDomainGetXMLFromDom(ctl, dom, xmlflags, &xml, &ctxt) < 0)
|
||||||
xml = virXMLParseStringCtxt(desc, _("(domain_definition)"), &ctxt);
|
|
||||||
VIR_FREE(desc);
|
|
||||||
if (!xml) {
|
|
||||||
vshError(ctl, _("Failed to parse domain description xml"));
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
obj = xmlXPathEval(BAD_CAST "/domain/devices/interface", ctxt);
|
obj = xmlXPathEval(BAD_CAST "/domain/devices/interface", ctxt);
|
||||||
if (obj == NULL || obj->type != XPATH_NODESET ||
|
if (obj == NULL || obj->type != XPATH_NODESET ||
|
||||||
@ -3575,7 +3565,6 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd)
|
|||||||
int nvol_list = 0;
|
int nvol_list = 0;
|
||||||
virshUndefineVolume *vols = NULL; /* info about the volumes to delete*/
|
virshUndefineVolume *vols = NULL; /* info about the volumes to delete*/
|
||||||
size_t nvols = 0;
|
size_t nvols = 0;
|
||||||
char *def = NULL; /* domain def */
|
|
||||||
xmlDocPtr doc = NULL;
|
xmlDocPtr doc = NULL;
|
||||||
xmlXPathContextPtr ctxt = NULL;
|
xmlXPathContextPtr ctxt = NULL;
|
||||||
xmlNodePtr *vol_nodes = NULL; /* XML nodes of volumes of the guest */
|
xmlNodePtr *vol_nodes = NULL; /* XML nodes of volumes of the guest */
|
||||||
@ -3685,14 +3674,8 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(def = virDomainGetXMLDesc(dom, 0))) {
|
if (virshDomainGetXMLFromDom(ctl, dom, 0, &doc, &ctxt) < 0)
|
||||||
vshError(ctl, _("Could not retrieve domain XML description"));
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
if (!(doc = virXMLParseStringCtxt(def, _("(domain_definition)"),
|
|
||||||
&ctxt)))
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
/* tokenize the string from user and save its parts into an array */
|
/* tokenize the string from user and save its parts into an array */
|
||||||
if (vol_string &&
|
if (vol_string &&
|
||||||
@ -3897,7 +3880,6 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd)
|
|||||||
VIR_FREE(vol_list[i]);
|
VIR_FREE(vol_list[i]);
|
||||||
VIR_FREE(vol_list);
|
VIR_FREE(vol_list);
|
||||||
|
|
||||||
VIR_FREE(def);
|
|
||||||
VIR_FREE(vol_nodes);
|
VIR_FREE(vol_nodes);
|
||||||
xmlFreeDoc(doc);
|
xmlFreeDoc(doc);
|
||||||
xmlXPathFreeContext(ctxt);
|
xmlXPathFreeContext(ctxt);
|
||||||
@ -6029,7 +6011,6 @@ virshCPUCountCollect(vshControl *ctl,
|
|||||||
int ret = -2;
|
int ret = -2;
|
||||||
virDomainInfo info;
|
virDomainInfo info;
|
||||||
int count;
|
int count;
|
||||||
char *def = NULL;
|
|
||||||
xmlDocPtr xml = NULL;
|
xmlDocPtr xml = NULL;
|
||||||
xmlXPathContextPtr ctxt = NULL;
|
xmlXPathContextPtr ctxt = NULL;
|
||||||
|
|
||||||
@ -6071,10 +6052,8 @@ virshCPUCountCollect(vshControl *ctl,
|
|||||||
count = info.nrVirtCpu;
|
count = info.nrVirtCpu;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!(def = virDomainGetXMLDesc(dom, VIR_DOMAIN_XML_INACTIVE)))
|
if (virshDomainGetXMLFromDom(ctl, dom, VIR_DOMAIN_XML_INACTIVE,
|
||||||
goto cleanup;
|
&xml, &ctxt) < 0)
|
||||||
|
|
||||||
if (!(xml = virXMLParseStringCtxt(def, _("(domain_definition)"), &ctxt)))
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_VCPU_MAXIMUM) {
|
if (flags & VIR_DOMAIN_VCPU_MAXIMUM) {
|
||||||
@ -6092,7 +6071,6 @@ virshCPUCountCollect(vshControl *ctl,
|
|||||||
|
|
||||||
ret = count;
|
ret = count;
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(def);
|
|
||||||
xmlXPathFreeContext(ctxt);
|
xmlXPathFreeContext(ctxt);
|
||||||
xmlFreeDoc(xml);
|
xmlFreeDoc(xml);
|
||||||
|
|
||||||
@ -6237,7 +6215,6 @@ virshDomainGetVcpuBitmap(vshControl *ctl,
|
|||||||
bool inactive)
|
bool inactive)
|
||||||
{
|
{
|
||||||
unsigned int flags = 0;
|
unsigned int flags = 0;
|
||||||
char *def = NULL;
|
|
||||||
virBitmapPtr ret = NULL;
|
virBitmapPtr ret = NULL;
|
||||||
xmlDocPtr xml = NULL;
|
xmlDocPtr xml = NULL;
|
||||||
xmlXPathContextPtr ctxt = NULL;
|
xmlXPathContextPtr ctxt = NULL;
|
||||||
@ -6253,10 +6230,7 @@ virshDomainGetVcpuBitmap(vshControl *ctl,
|
|||||||
if (inactive)
|
if (inactive)
|
||||||
flags |= VIR_DOMAIN_XML_INACTIVE;
|
flags |= VIR_DOMAIN_XML_INACTIVE;
|
||||||
|
|
||||||
if (!(def = virDomainGetXMLDesc(dom, flags)))
|
if (virshDomainGetXMLFromDom(ctl, dom, flags, &xml, &ctxt) < 0)
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (!(xml = virXMLParseStringCtxt(def, _("(domain_definition)"), &ctxt)))
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virXPathUInt("string(/domain/vcpu)", ctxt, &maxvcpus) < 0) {
|
if (virXPathUInt("string(/domain/vcpu)", ctxt, &maxvcpus) < 0) {
|
||||||
@ -6308,7 +6282,6 @@ virshDomainGetVcpuBitmap(vshControl *ctl,
|
|||||||
VIR_FREE(nodes);
|
VIR_FREE(nodes);
|
||||||
xmlXPathFreeContext(ctxt);
|
xmlXPathFreeContext(ctxt);
|
||||||
xmlFreeDoc(xml);
|
xmlFreeDoc(xml);
|
||||||
VIR_FREE(def);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -10902,7 +10875,6 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
|
|||||||
virDomainPtr dom;
|
virDomainPtr dom;
|
||||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
char *doc = NULL;
|
|
||||||
char *xpath = NULL;
|
char *xpath = NULL;
|
||||||
char *listen_addr = NULL;
|
char *listen_addr = NULL;
|
||||||
int port, tls_port = 0;
|
int port, tls_port = 0;
|
||||||
@ -10932,10 +10904,7 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (vshCommandOptStringReq(ctl, cmd, "type", &type) < 0)
|
if (vshCommandOptStringReq(ctl, cmd, "type", &type) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(doc = virDomainGetXMLDesc(dom, flags)))
|
if (virshDomainGetXMLFromDom(ctl, dom, flags, &xml, &ctxt) < 0)
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (!(xml = virXMLParseStringCtxt(doc, _("(domain_definition)"), &ctxt)))
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
/* Attempt to grab our display info */
|
/* Attempt to grab our display info */
|
||||||
@ -11108,14 +11077,12 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(doc);
|
|
||||||
VIR_FREE(xpath);
|
VIR_FREE(xpath);
|
||||||
VIR_FREE(passwd);
|
VIR_FREE(passwd);
|
||||||
VIR_FREE(listen_addr);
|
VIR_FREE(listen_addr);
|
||||||
VIR_FREE(output);
|
VIR_FREE(output);
|
||||||
xmlXPathFreeContext(ctxt);
|
xmlXPathFreeContext(ctxt);
|
||||||
xmlFreeDoc(xml);
|
xmlFreeDoc(xml);
|
||||||
virshDomainFree(dom);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -11145,7 +11112,6 @@ cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd)
|
|||||||
virDomainPtr dom;
|
virDomainPtr dom;
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
int port = 0;
|
int port = 0;
|
||||||
char *doc = NULL;
|
|
||||||
char *listen_addr = NULL;
|
char *listen_addr = NULL;
|
||||||
|
|
||||||
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
|
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
|
||||||
@ -11157,10 +11123,7 @@ cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(doc = virDomainGetXMLDesc(dom, 0)))
|
if (virshDomainGetXMLFromDom(ctl, dom, 0, &xml, &ctxt) < 0)
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (!(xml = virXMLParseStringCtxt(doc, _("(domain_definition)"), &ctxt)))
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
/* Get the VNC port */
|
/* Get the VNC port */
|
||||||
@ -11192,7 +11155,6 @@ cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd)
|
|||||||
ret = true;
|
ret = true;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(doc);
|
|
||||||
VIR_FREE(listen_addr);
|
VIR_FREE(listen_addr);
|
||||||
xmlXPathFreeContext(ctxt);
|
xmlXPathFreeContext(ctxt);
|
||||||
xmlFreeDoc(xml);
|
xmlFreeDoc(xml);
|
||||||
|
Loading…
Reference in New Issue
Block a user