[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 12/17] virsh: Add vcpu list completion to setvcpu command



Signed-off-by: Lin Ma <lma suse de>
---
 tools/virsh-completer-domain.c | 46 ++++++++++++++++++++++++++++++++++
 tools/virsh-completer-domain.h |  5 ++++
 tools/virsh-domain.c           |  2 ++
 3 files changed, 53 insertions(+)

diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c
index 9b22db2119..218f10e5ba 100644
--- a/tools/virsh-completer-domain.c
+++ b/tools/virsh-completer-domain.c
@@ -518,3 +518,49 @@ virshDomainVcpuCompleter(vshControl *ctl,
     virshDomainFree(dom);
     return ret;
 }
+
+
+char **
+virshDomainVcpulistCompleter(vshControl *ctl,
+                             const vshCmd *cmd,
+                             unsigned int flags)
+{
+    virDomainPtr dom;
+    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 (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);
+
+    if (vshCommandOptStringQuiet(ctl, cmd, "vcpulist", &vcpuid) < 0)
+        goto cleanup;
+
+    ret = virshCommaStringListComplete(vcpuid, (const char **)vcpulist);
+
+ cleanup:
+    xmlXPathFreeContext(ctxt);
+    xmlFreeDoc(xml);
+    virshDomainFree(dom);
+    return ret;
+}
diff --git a/tools/virsh-completer-domain.h b/tools/virsh-completer-domain.h
index 7c3b4c3cc0..84219ab088 100644
--- a/tools/virsh-completer-domain.h
+++ b/tools/virsh-completer-domain.h
@@ -83,3 +83,8 @@ char **
 virshDomainVcpuCompleter(vshControl *ctl,
                          const vshCmd *cmd,
                          unsigned int flags);
+
+char **
+virshDomainVcpulistCompleter(vshControl *ctl,
+                             const vshCmd *cmd,
+                             unsigned int flags);
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 7dd566b573..c3ac28cab0 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -7525,6 +7525,8 @@ static const vshCmdOptDef opts_setvcpu[] = {
     {.name = "vcpulist",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
+     .completer = virshDomainVcpulistCompleter,
+     .completer_flags = 0,
      .help = N_("ids of vcpus to manipulate")
     },
     {.name = "enable",
-- 
2.26.0


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]