[PATCH v3 6/7] virsh: add function to get the CPU models for an arch

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

 



Signed-off-by: Giuseppe Scrivano <gscrivan@xxxxxxxxxx>
---
 tools/virsh-host.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 tools/virsh.pod    |  5 +++++
 2 files changed, 59 insertions(+)

diff --git a/tools/virsh-host.c b/tools/virsh-host.c
index 880ae4b..5d47428 100644
--- a/tools/virsh-host.c
+++ b/tools/virsh-host.c
@@ -627,6 +627,54 @@ cmdURI(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
 }
 
 /*
+ * "cpu-models" command
+ */
+static const vshCmdInfo info_cpu_models[] = {
+    {.name = "help",
+     .data = N_("CPU models")
+    },
+    {.name = "desc",
+     .data = N_("Get the CPU models for an arch.")
+    },
+    {.name = NULL}
+};
+
+static const vshCmdOptDef opts_cpu_models[] = {
+    {.name = "arch",
+     .type = VSH_OT_DATA,
+     .flags = VSH_OFLAG_REQ,
+     .help = N_("architecture")
+    },
+    {.name = NULL}
+};
+
+static bool
+cmdCPUModelNames(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
+{
+    char **models;
+    size_t i;
+    int nmodels;
+    const char *arch = NULL;
+
+    if (vshCommandOptStringReq(ctl, cmd, "arch", &arch) < 0)
+        return false;
+
+    nmodels = virConnectGetCPUModelNames(ctl->conn, arch, &models, 0);
+    if (nmodels < 0) {
+        vshError(ctl, "%s", _("failed to get CPU model names"));
+        return false;
+    }
+
+    for (i = 0; i < nmodels; i++) {
+        vshPrint(ctl, "%s\n", models[i]);
+        VIR_FREE(models[i]);
+    }
+    VIR_FREE(models);
+
+    return true;
+}
+
+/*
  * "version" command
  */
 static const vshCmdInfo info_version[] = {
@@ -851,6 +899,12 @@ const vshCmdDef hostAndHypervisorCmds[] = {
      .info = info_capabilities,
      .flags = 0
     },
+    {.name = "cpu-models",
+     .handler = cmdCPUModelNames,
+     .opts = opts_cpu_models,
+     .info = info_cpu_models,
+     .flags = 0
+    },
     {.name = "freecell",
      .handler = cmdFreecell,
      .opts = opts_freecell,
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 0ae5178..72555e7 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -163,6 +163,7 @@ group as an option.  For example:
 
   Host and Hypervisor (help keyword 'host'):
      capabilities                   capabilities
+     cpu-models                     show the CPU models for an architecture
      connect                        (re)connect to hypervisor
      freecell                       NUMA free memory
      hostname                       print the hypervisor hostname
@@ -358,6 +359,10 @@ current domain is in.
 
 =over 4
 
+=item B<cpu-models> I<arch>
+
+Print the list of CPU models known for the specified architecture.
+
 =item B<running>
 
 The domain is currently running on a CPU
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[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]