]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Add vcpu list completion to setvcpu command
authorLin Ma <morecache@gmail.com>
Fri, 11 Sep 2020 07:13:13 +0000 (15:13 +0800)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 14 Sep 2020 13:52:40 +0000 (15:52 +0200)
Signed-off-by: Lin Ma <lma@suse.de>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
tools/virsh-completer-domain.c
tools/virsh-completer-domain.h
tools/virsh-domain.c

index 795210972a3aa200f695515d8bc6d08ec71d97cf..281091c41c3c9727b43acad09f8b976c060bd8c6 100644 (file)
@@ -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;
+}
index a5388d92011268cf6ff6602fc51f4d05e406d9b0..d9ed5b44b3dad9be3d1e26a17e6a059dac05b745 100644 (file)
@@ -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);
index 01e18bdd8b08cc4f9f29d3ba4da5581a5e1820fd..baec00645a9a1083dc514c9512ed744750579bc1 100644 (file)
@@ -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",