mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 06:50:22 +03:00
virsh: Add vcpu list completion to setvcpu command
Signed-off-by: Lin Ma <lma@suse.de> Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
6c74a2e23a
commit
b3198b95d6
@ -518,3 +518,49 @@ virshDomainVcpuCompleter(vshControl *ctl,
|
||||
virshDomainFree(dom);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
char **
|
||||
virshDomainVcpulistCompleter(vshControl *ctl,
|
||||
const vshCmd *cmd,
|
||||
unsigned int flags)
|
||||
{
|
||||
virDomainPtr dom = NULL;
|
||||
xmlDocPtr xml = NULL;
|
||||
xmlXPathContextPtr ctxt = NULL;
|
||||
int nvcpus = 0;
|
||||
unsigned int id;
|
||||
VIR_AUTOSTRINGLIST vcpulist = NULL;
|
||||
const char *vcpuid = NULL;
|
||||
char **ret = NULL;
|
||||
|
||||
virCheckFlags(0, NULL);
|
||||
|
||||
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
|
||||
return NULL;
|
||||
|
||||
if (vshCommandOptStringQuiet(ctl, cmd, "vcpulist", &vcpuid) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virshDomainGetXMLFromDom(ctl, dom, VIR_DOMAIN_XML_INACTIVE,
|
||||
&xml, &ctxt) < 0)
|
||||
goto cleanup;
|
||||
|
||||
/* Query the max rather than the current vcpu count */
|
||||
if (virXPathInt("string(/domain/vcpu)", ctxt, &nvcpus) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (VIR_ALLOC_N(vcpulist, nvcpus + 1) < 0)
|
||||
goto cleanup;
|
||||
|
||||
for (id = 0; id < nvcpus; id++)
|
||||
vcpulist[id] = g_strdup_printf("%u", id);
|
||||
|
||||
ret = virshCommaStringListComplete(vcpuid, (const char **)vcpulist);
|
||||
|
||||
cleanup:
|
||||
xmlXPathFreeContext(ctxt);
|
||||
xmlFreeDoc(xml);
|
||||
virshDomainFree(dom);
|
||||
return ret;
|
||||
}
|
||||
|
@ -82,3 +82,7 @@ char ** virshDomainIOThreadIdCompleter(vshControl *ctl,
|
||||
char ** virshDomainVcpuCompleter(vshControl *ctl,
|
||||
const vshCmd *cmd,
|
||||
unsigned int flags);
|
||||
|
||||
char ** virshDomainVcpulistCompleter(vshControl *ctl,
|
||||
const vshCmd *cmd,
|
||||
unsigned int flags);
|
||||
|
@ -7522,6 +7522,7 @@ static const vshCmdOptDef opts_setvcpu[] = {
|
||||
{.name = "vcpulist",
|
||||
.type = VSH_OT_DATA,
|
||||
.flags = VSH_OFLAG_REQ,
|
||||
.completer = virshDomainVcpulistCompleter,
|
||||
.help = N_("ids of vcpus to manipulate")
|
||||
},
|
||||
{.name = "enable",
|
||||
|
Loading…
x
Reference in New Issue
Block a user