[PATCH v1 3/4] virsh: Introduce new hypervisor-cpu-models command

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

 



This command is a virsh wrapper for virConnectGetHypervisorCPUNames.

Signed-off-by: Collin Walling <walling@xxxxxxxxxxxxx>
Reviewed-by: Boris Fiuczynski <fiuczy@xxxxxxxxxxxxx>
---
 docs/manpages/virsh.rst | 20 ++++++++++++
 tools/virsh-host.c      | 70 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 90 insertions(+)

diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst
index 26c328d390..c156e60d6e 100644
--- a/docs/manpages/virsh.rst
+++ b/docs/manpages/virsh.rst
@@ -1004,6 +1004,26 @@ listed in the XML description. If *--migratable* is specified, features that
 block migration will not be included in the resulting CPU.
 
 
+hypervisor-cpu-models
+---------------------
+
+**Syntax:**
+
+::
+
+   hypervisor-cpu-models [virttype] [emulator] [arch] [machine]
+
+Print the list of CPU models known by the hypervisor for the specified architecture.
+It is not guaranteed that a listed CPU will run on the host. To determine CPU
+model compatibility with the host, see ``virsh hypervisor-cpu-baseline`` and
+``virsh hypervisor-cpu-compare``.
+
+The *virttype* option specifies the virtualization type (usable in the 'type'
+attribute of the <domain> top level element from the domain XML). *emulator*
+specifies the path to the emulator, *arch* specifies the CPU architecture, and
+*machine* specifies the machine type.
+
+
 DOMAIN COMMANDS
 ===============
 
diff --git a/tools/virsh-host.c b/tools/virsh-host.c
index 21d479fd01..2eedc1517b 100644
--- a/tools/virsh-host.c
+++ b/tools/virsh-host.c
@@ -1779,6 +1779,70 @@ cmdHypervisorCPUBaseline(vshControl *ctl,
     return ret;
 }
 
+/*
+ * "hypervisor-cpu-models" command
+ */
+static const vshCmdInfo info_hypervisor_cpu_models[] = {
+    {.name = "help",
+     .data = N_("Hypervisor reported CPU models")
+    },
+    {.name = "desc",
+     .data = N_("Get the CPU models reported by the hypervisor.")
+    },
+    {.name = NULL}
+};
+
+static const vshCmdOptDef opts_hypervisor_cpu_models[] = {
+    {.name = "virttype",
+     .type = VSH_OT_STRING,
+     .completer = virshDomainVirtTypeCompleter,
+     .help = N_("virtualization type (/domain/@type)"),
+    },
+    {.name = "emulator",
+     .type = VSH_OT_STRING,
+     .help = N_("path to emulator binary (/domain/devices/emulator)"),
+    },
+    {.name = "arch",
+     .type = VSH_OT_STRING,
+     .completer = virshArchCompleter,
+     .help = N_("CPU architecture (/domain/os/type/@arch)"),
+    },
+    {.name = "machine",
+     .type = VSH_OT_STRING,
+     .help = N_("machine type (/domain/os/type/@machine)"),
+    },
+    {.name = NULL}
+};
+
+static bool
+cmdHypervisorCPUModelNames(vshControl *ctl,
+                           const vshCmd *cmd)
+{
+    const char *virttype = NULL;
+    const char *emulator = NULL;
+    const char *arch = NULL;
+    const char *machine = NULL;
+    g_autofree char *result = NULL;
+    virshControl *priv = ctl->privData;
+
+    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 false;
+
+    result = virConnectGetHypervisorCPUModelNames(priv->conn, emulator, arch,
+                                                  machine, virttype, 0);
+
+    if (!result) {
+        vshError(ctl, "%s", _("failed to get CPU model names"));
+        return false;
+    }
+
+    vshPrint(ctl, "%s\n", result);
+    return true;
+}
+
 
 const vshCmdDef hostAndHypervisorCmds[] = {
     {.name = "allocpages",
@@ -1847,6 +1911,12 @@ const vshCmdDef hostAndHypervisorCmds[] = {
      .info = info_hypervisor_cpu_compare,
      .flags = 0
     },
+    {.name = "hypervisor-cpu-models",
+     .handler = cmdHypervisorCPUModelNames,
+     .opts = opts_hypervisor_cpu_models,
+     .info = info_hypervisor_cpu_models,
+     .flags = 0
+    },
     {.name = "maxvcpus",
      .handler = cmdMaxvcpus,
      .opts = opts_maxvcpus,
-- 
2.39.0




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux