]> xenbits.xensource.com Git - libvirt.git/commitdiff
virsh: Add completer for hypervisor-cpu-baseline --model
authorJiri Denemark <jdenemar@redhat.com>
Thu, 6 Oct 2022 15:12:24 +0000 (17:12 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Mon, 10 Oct 2022 12:31:43 +0000 (14:31 +0200)
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tools/virsh-completer-host.c
tools/virsh-completer-host.h
tools/virsh-host.c

index 05a84a43bb43deea0bd3b7a9aa3d0370a890866a..93b633eb6476140668c7f0c1c353f4c0408295c4 100644 (file)
@@ -205,3 +205,53 @@ virshArchCompleter(vshControl *ctl G_GNUC_UNUSED,
     return virshEnumComplete(VIR_ARCH_LAST,
                              (const char *(*)(int))virArchToString);
 }
+
+
+char **
+virshCPUModelCompleter(vshControl *ctl,
+                       const vshCmd *cmd,
+                       unsigned int flags)
+{
+    virshControl *priv = ctl->privData;
+    const char *virttype = NULL;
+    const char *emulator = NULL;
+    const char *arch = NULL;
+    const char *machine = NULL;
+    g_autofree char *domcaps = NULL;
+    g_autoptr(xmlDoc) xml = NULL;
+    g_autoptr(xmlXPathContext) ctxt = NULL;
+    g_autofree xmlNodePtr *nodes = NULL;
+    g_auto(GStrv) models = NULL;
+    int nmodels = 0;
+    size_t i;
+
+    virCheckFlags(0, NULL);
+
+    if (vshCommandOptStringReq(ctl, cmd, "virttype", &virttype) < 0 ||
+        vshCommandOptStringReq(ctl, cmd, "emulator", &emulator) < 0 ||
+        vshCommandOptStringReq(ctl, cmd, "arch", &arch) < 0 ||
+        vshCommandOptStringReq(ctl, cmd, "machine", &machine) < 0)
+        return NULL;
+
+    if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
+        return NULL;
+
+    if (!(domcaps = virConnectGetDomainCapabilities(priv->conn, emulator, arch,
+                                                    machine, virttype, 0)))
+        return NULL;
+
+    if (!(xml = virXMLParseStringCtxt(domcaps, _("domain capabilities"), &ctxt)))
+        return NULL;
+
+    nmodels = virXPathNodeSet("/domainCapabilities/cpu/mode[@name='custom']/model",
+                              ctxt, &nodes);
+    if (nmodels <= 0)
+        return NULL;
+
+    models = g_new0(char *, nmodels + 1);
+
+    for (i = 0; i < nmodels; i++)
+        models[i] = virXMLNodeContentString(nodes[i]);
+
+    return g_steal_pointer(&models);
+}
index b182661cded1809e1b21104eefe0c42c11bb110a..608ae9e3e72268b7ccaa078f62a86cf335bd6c71 100644 (file)
@@ -51,3 +51,8 @@ char **
 virshArchCompleter(vshControl *ctl,
                    const vshCmd *cmd,
                    unsigned int flags);
+
+char **
+virshCPUModelCompleter(vshControl *ctl,
+                       const vshCmd *cmd,
+                       unsigned int flags);
index 16c3585a1a298fad07fb4e58bb1390ed88caa8e7..21d479fd01622d531287f770a6203536af79bd10 100644 (file)
@@ -1719,6 +1719,7 @@ static const vshCmdOptDef opts_hypervisor_cpu_baseline[] = {
     },
     {.name = "model",
      .type = VSH_OT_STRING,
+     .completer = virshCPUModelCompleter,
      .help = N_("Shortcut for calling the command with a single CPU model "
                 "and no additional features")
     },