[PATCH 4/5] virsh: Expose virConnectGetEmulatorCapabilities

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

 



The API is exposed under emulatorcaps command.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 tools/virsh-host.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 tools/virsh.pod    | 13 ++++++++++
 2 files changed, 87 insertions(+)

diff --git a/tools/virsh-host.c b/tools/virsh-host.c
index 13d4c5c..1f9dd0d 100644
--- a/tools/virsh-host.c
+++ b/tools/virsh-host.c
@@ -69,6 +69,74 @@ cmdCapabilities(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
 }
 
 /*
+ * "emulatorcaps" command
+ */
+static const vshCmdInfo info_emulatorcaps[] = {
+    {.name = "help",
+     .data = N_("emulator capabilities")
+    },
+    {.name = "desc",
+     .data = N_("Returns capabilities of emulator with respect to host and libvirt.")
+    },
+    {.name = NULL}
+};
+
+static const vshCmdOptDef opts_emulatorcaps[] = {
+    {.name = "emulatorbin",
+     .type = VSH_OT_STRING,
+     .help = N_("path to emulator binary"),
+    },
+    {.name = "virttype",
+     .type = VSH_OT_STRING,
+     .help = N_("virtualization type (/domain/@type)"),
+    },
+    {.name = "machine",
+     .type = VSH_OT_STRING,
+     .help = N_("machine type (/domain/os/type/@machine)"),
+    },
+    {.name = NULL}
+};
+
+static bool
+cmdEmulatorCaps(vshControl *ctl, const vshCmd *cmd)
+{
+    bool ret = false;
+    char *caps;
+    const char *emulatorbin = NULL;
+    const char *machine = NULL;
+    const char *virttype = NULL;
+    const unsigned int flags = 0; /* No flags so far */
+
+    if (vshCommandOptString(cmd, "emulatorbin", &emulatorbin) < 0) {
+        vshError(ctl, "%s", _("ble"));
+        goto cleanup;
+    }
+
+    if (vshCommandOptString(cmd, "virttype", &virttype) < 0) {
+        vshError(ctl, "%s", _("ble"));
+        goto cleanup;
+    }
+
+    if (vshCommandOptString(cmd, "machine", &machine) < 0) {
+        vshError(ctl, "%s", _("ble"));
+        goto cleanup;
+    }
+
+    caps = virConnectGetEmulatorCapabilities(ctl->conn, emulatorbin,
+                                             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 +1199,12 @@ const vshCmdDef hostAndHypervisorCmds[] = {
      .info = info_cpu_models,
      .flags = 0
     },
+    {.name = "emulatorcaps",
+     .handler = cmdEmulatorCaps,
+     .opts = opts_emulatorcaps,
+     .info = info_emulatorcaps,
+     .flags = 0
+    },
     {.name = "freecell",
      .handler = cmdFreecell,
      .opts = opts_freecell,
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 2c0f18a..155568f 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -505,6 +505,19 @@ B<virsh> list --title
   0     Domain-0                       running    Mailserver 1
   2     fedora                         paused
 
+=item B<emulatorcaps> I<emulatorbin> I<virttype> [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<emulatorbin> specifies the path to the emulator (this is same
+as <emulator> element in the domain XML). Then, I<virttype>
+specifies the virtualization used (the domain XML counterpart is
+the 'type' attribute of the <domain/> top level element). The
+last, optional argument overrides the default machine for the
+emulator (can be found in domain XML under /domain/os/type).
+
 =item B<freecell> [{ [I<--cellno>] B<cellno> | I<--all> }]
 
 Prints the available amount of memory on the machine or within a NUMA
-- 
1.8.5.5

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