[libvirt] [PATCH for 1.2.7 3/8] virsh: expose virConnectGetDomainCapabilities

Michal Privoznik mprivozn at redhat.com
Mon Jun 30 15:31:46 UTC 2014


The API is exposed under 'domcapabilities' command. Currently, with
the variety of drivers that libvirt supports, none of the command
arguments is obligatory, but all are optional instead.

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 tools/virsh-host.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 tools/virsh.pod    | 16 +++++++++++
 2 files changed, 100 insertions(+)

diff --git a/tools/virsh-host.c b/tools/virsh-host.c
index 734f1a8..a1d8465 100644
--- a/tools/virsh-host.c
+++ b/tools/virsh-host.c
@@ -69,6 +69,84 @@ cmdCapabilities(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
 }
 
 /*
+ * "domcapabilities" command
+ */
+static const vshCmdInfo info_domcapabilities[] = {
+    {.name = "help",
+     .data = N_("domain capabilities")
+    },
+    {.name = "desc",
+     .data = N_("Returns capabilities of emulator with respect to host and libvirt.")
+    },
+    {.name = NULL}
+};
+
+static const vshCmdOptDef opts_domcapabilities[] = {
+    {.name = "virttype",
+     .type = VSH_OT_STRING,
+     .help = N_("virtualization type (/domain/@type)"),
+    },
+    {.name = "emulatorbin",
+     .type = VSH_OT_STRING,
+     .help = N_("path to emulator binary (/domain/devices/emulator)"),
+    },
+    {.name = "arch",
+     .type = VSH_OT_STRING,
+     .help = N_("domain architecture (/domain/os/type/@arch)"),
+    },
+    {.name = "machine",
+     .type = VSH_OT_STRING,
+     .help = N_("machine type (/domain/os/type/@machine)"),
+    },
+    {.name = NULL}
+};
+
+static bool
+cmdDomCapabilities(vshControl *ctl, const vshCmd *cmd)
+{
+    bool ret = false;
+    char *caps;
+    const char *virttype = NULL;
+    const char *emulatorbin = NULL;
+    const char *arch = NULL;
+    const char *machine = NULL;
+    const unsigned int flags = 0; /* No flags so far */
+
+    if (vshCommandOptString(cmd, "virttype", &virttype) < 0) {
+        vshError(ctl, "%s", _("ble"));
+        goto cleanup;
+    }
+
+    if (vshCommandOptString(cmd, "emulatorbin", &emulatorbin) < 0) {
+        vshError(ctl, "%s", _("ble"));
+        goto cleanup;
+    }
+
+    if (vshCommandOptString(cmd, "arch", &arch) < 0) {
+        vshError(ctl, "%s", _("ble"));
+        goto cleanup;
+    }
+
+    if (vshCommandOptString(cmd, "machine", &machine) < 0) {
+        vshError(ctl, "%s", _("ble"));
+        goto cleanup;
+    }
+
+    caps = virConnectGetDomainCapabilities(ctl->conn, emulatorbin,
+                                           arch, machine, virttype, flags);
+    if (!caps) {
+        vshError(ctl, "%s", _("failed to get emulator capabilities"));
+        goto cleanup;
+    }
+
+    vshPrint(ctl, "%s\n", caps);
+    ret = true;
+ cleanup:
+    VIR_FREE(caps);
+    return ret;
+}
+
+/*
  * "freecell" command
  */
 static const vshCmdInfo info_freecell[] = {
@@ -1131,6 +1209,12 @@ const vshCmdDef hostAndHypervisorCmds[] = {
      .info = info_cpu_models,
      .flags = 0
     },
+    {.name = "domcapabilities",
+     .handler = cmdDomCapabilities,
+     .opts = opts_domcapabilities,
+     .info = info_domcapabilities,
+     .flags = 0
+    },
     {.name = "freecell",
      .handler = cmdFreecell,
      .opts = opts_freecell,
diff --git a/tools/virsh.pod b/tools/virsh.pod
index b248c9a..b37a2be 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -350,6 +350,22 @@ description see:
   L<http://libvirt.org/formatcaps.html>
 The XML also show the NUMA topology information if available.
 
+=item B<domcapabilities> [I<virttype>] [I<emulatorbin>]
+[I<arch>] [I<machine>]
+
+Print an XML document describing the capabilities of the
+hypervisor we are currently connected to. This may be useful if
+you intend to create a new domain and are curious if for instance
+should use VFIO or legacy KVM device passthrough. The I<virttype>
+specifies the virtualization used (the domain XML counterpart is
+the 'type' attribute of the <domain/> top level element). Then,
+the I<emulatorbin> specifies the path to the emulator (this is
+same as <emulator> element in the domain XML). Then, the I<arch>
+argument sets the domain architecture (exposed under
+/domain/os/type/@arch attribute). Then at last I<machine>
+overrides the default machine for the emulator (can be found in
+domain XML under /domain/os/type).
+
 =item B<inject-nmi> I<domain>
 
 Inject NMI to the guest.
-- 
1.8.5.5




More information about the libvir-list mailing list