]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: add function to get the CPU models for an arch
authorGiuseppe Scrivano <gscrivan@redhat.com>
Mon, 23 Sep 2013 09:46:03 +0000 (11:46 +0200)
committerEric Blake <eblake@redhat.com>
Mon, 23 Sep 2013 22:42:10 +0000 (16:42 -0600)
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
tools/virsh-host.c
tools/virsh.pod

index f69ab79ded02cda9d26ec1c6879966dd0a7f01f1..1d1bb97120db736a98d10fee45508d444a220a78 100644 (file)
@@ -664,6 +664,54 @@ cmdURI(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
     return true;
 }
 
+/*
+ * "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)
+{
+    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
  */
@@ -889,6 +937,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,
index 2864f3d55ff6b8870ebada92cd8afcc94d54ae11..e12a800fb9db1b406badeb4b91888831a50bd377 100644 (file)
@@ -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