1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-20 06:50:22 +03:00

virsh: Add vcpu IDs completion to vcpupin 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:
Lin Ma 2020-09-11 15:13:12 +08:00 committed by Michal Privoznik
parent ab4ef5de67
commit 6c74a2e23a
3 changed files with 47 additions and 0 deletions

View File

@ -476,3 +476,45 @@ virshDomainIOThreadIdCompleter(vshControl *ctl,
virshDomainFree(dom);
return ret;
}
char **
virshDomainVcpuCompleter(vshControl *ctl,
const vshCmd *cmd,
unsigned int flags)
{
virDomainPtr dom = NULL;
xmlDocPtr xml = NULL;
xmlXPathContextPtr ctxt = NULL;
int nvcpus = 0;
unsigned int id;
char **ret = NULL;
VIR_AUTOSTRINGLIST tmp = NULL;
virCheckFlags(0, NULL);
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
return NULL;
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(tmp, nvcpus + 1) < 0)
goto cleanup;
for (id = 0; id < nvcpus; id++)
tmp[id] = g_strdup_printf("%u", id);
ret = g_steal_pointer(&tmp);
cleanup:
xmlXPathFreeContext(ctxt);
xmlFreeDoc(xml);
virshDomainFree(dom);
return ret;
}

View File

@ -78,3 +78,7 @@ char ** virshDomainUUIDCompleter(vshControl *ctl,
char ** virshDomainIOThreadIdCompleter(vshControl *ctl,
const vshCmd *cmd,
unsigned int flags);
char ** virshDomainVcpuCompleter(vshControl *ctl,
const vshCmd *cmd,
unsigned int flags);

View File

@ -7002,6 +7002,7 @@ static const vshCmdOptDef opts_vcpupin[] = {
VIRSH_COMMON_OPT_DOMAIN_FULL(0),
{.name = "vcpu",
.type = VSH_OT_INT,
.completer = virshDomainVcpuCompleter,
.help = N_("vcpu number")
},
{.name = "cpulist",