$ virsh hypervisor-cpu-models --arch x86_64 Name Alias ---------------------------------------------------- max host base qemu64-v1 qemu64 qemu64-v1 qemu32-v1 qemu32 qemu32-v1 phenom-v1 phenom phenom-v1 (...) Note that this includes alias names and cpu models that currently do not exist in libvirt, e.g. Denverton and Knights Mill. Signed-off-by: Tim Wiederhake <twiederh@xxxxxxxxxx> --- docs/manpages/virsh.rst | 14 +++++++++ tools/virsh-host.c | 67 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 45469f2f35..a55792b0e2 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -955,6 +955,20 @@ If *--validate* is specified, validates the format of the XML document against an internal RNG schema. +hypervisor-cpu-models +--------------------- + +**Syntax:** + +:: + + hypervisor-cpu-models [arch] + +List the names of cpu models known to the hypervisor. A hypervisor may define +alias names for some or all cpu models. Note that the cpu models may differ +from libvirt, even if named identically. + + hypervisor-cpu-baseline ----------------------- diff --git a/tools/virsh-host.c b/tools/virsh-host.c index ead966b500..cb8e1e8c6d 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -32,6 +32,7 @@ #include "virstring.h" #include "virfile.h" #include "virenum.h" +#include "vsh-table.h" /* * "capabilities" command @@ -1674,6 +1675,65 @@ cmdHypervisorCPUCompare(vshControl *ctl, } +/* + * "hypervisor-cpu-models" command + */ +static const vshCmdInfo info_hypervisor_cpu_models[] = { + {.name = "help", + .data = N_("return list of CPU models supported by a specific hypervisor") + }, + {.name = "desc", + .data = N_("Return list of CPU models supported by a specific hypervisor") + }, + {.name = NULL} +}; + +static const vshCmdOptDef opts_hypervisor_cpu_models[] = { + {.name = "arch", + .type = VSH_OT_STRING, + .completer = virshArchCompleter, + .help = N_("CPU architecture (/domain/os/type/@arch)"), + }, + {.name = NULL} +}; + +static bool +cmdHypervisorCPUModels(vshControl *ctl, + const vshCmd *cmd) +{ + virshControl *priv = ctl->privData; + bool ret = false; + const char *arch = NULL; + char **name = NULL; + char **alias = NULL; + int nresults; + g_autoptr(vshTable) table = vshTableNew(_("Name"), _("Alias"), NULL); + + if (!table) + return ret; + + if (vshCommandOptStringReq(ctl, cmd, "arch", &arch) < 0) + return false; + + nresults = virConnectGetHypervisorCPUModelNames(priv->conn, arch, &name, + &alias, 0); + if (nresults >= 0) { + size_t index; + for (index = 0; index < nresults; ++index) { + if (vshTableRowAppend(table, name[index], alias[index], NULL) < 0) + return ret; + g_free(name[index]); + g_free(alias[index]); + } + ret = true; + } + vshTablePrintToStdout(table, ctl); + g_free(name); + g_free(alias); + + return ret; +} + /* * "hypervisor-cpu-baseline" command */ @@ -1819,6 +1879,13 @@ const vshCmdDef hostAndHypervisorCmds[] = { .info = info_hostname, .flags = 0 }, + { + .name = "hypervisor-cpu-models", + .handler = cmdHypervisorCPUModels, + .opts = opts_hypervisor_cpu_models, + .info = info_hypervisor_cpu_models, + .flags = 0 + }, {.name = "hypervisor-cpu-baseline", .handler = cmdHypervisorCPUBaseline, .opts = opts_hypervisor_cpu_baseline, -- 2.31.1