mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
virsh: Introduce virshDomainDiskTargetCompleter
Signed-off-by: Lin Ma <lma@suse.com> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
78809398df
commit
14dd3b63e9
@ -143,6 +143,54 @@ virshDomainInterfaceCompleter(vshControl *ctl,
|
||||
}
|
||||
|
||||
|
||||
char **
|
||||
virshDomainDiskTargetCompleter(vshControl *ctl,
|
||||
const vshCmd *cmd,
|
||||
unsigned int flags)
|
||||
{
|
||||
virshControlPtr priv = ctl->privData;
|
||||
xmlDocPtr xmldoc = NULL;
|
||||
xmlXPathContextPtr ctxt = NULL;
|
||||
xmlNodePtr *disks = NULL;
|
||||
int ndisks;
|
||||
size_t i;
|
||||
char **ret = NULL;
|
||||
|
||||
virCheckFlags(0, NULL);
|
||||
|
||||
if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
|
||||
return NULL;
|
||||
|
||||
if (virshDomainGetXML(ctl, cmd, 0, &xmldoc, &ctxt) < 0)
|
||||
goto error;
|
||||
|
||||
ndisks = virXPathNodeSet("./devices/disk", ctxt, &disks);
|
||||
if (ndisks < 0)
|
||||
goto error;
|
||||
|
||||
if (VIR_ALLOC_N(ret, ndisks + 1) < 0)
|
||||
goto error;
|
||||
|
||||
for (i = 0; i < ndisks; i++) {
|
||||
ctxt->node = disks[i];
|
||||
if (!(ret[i] = virXPathString("string(./target/@dev)", ctxt)))
|
||||
goto error;
|
||||
}
|
||||
|
||||
VIR_FREE(disks);
|
||||
xmlFreeDoc(xmldoc);
|
||||
xmlXPathFreeContext(ctxt);
|
||||
return ret;
|
||||
|
||||
error:
|
||||
VIR_FREE(disks);
|
||||
xmlFreeDoc(xmldoc);
|
||||
xmlXPathFreeContext(ctxt);
|
||||
virStringListFree(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
char **
|
||||
virshStoragePoolNameCompleter(vshControl *ctl,
|
||||
const vshCmd *cmd ATTRIBUTE_UNUSED,
|
||||
|
@ -38,6 +38,10 @@ char ** virshDomainInterfaceCompleter(vshControl *ctl,
|
||||
const vshCmd *cmd,
|
||||
unsigned int flags);
|
||||
|
||||
char ** virshDomainDiskTargetCompleter(vshControl *ctl,
|
||||
const vshCmd *cmd,
|
||||
unsigned int flags);
|
||||
|
||||
char ** virshStoragePoolNameCompleter(vshControl *ctl,
|
||||
const vshCmd *cmd,
|
||||
unsigned int flags);
|
||||
|
Loading…
Reference in New Issue
Block a user