[PATCH 5/7] screenshot: Expose the new API in virsh

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

 



---
 tools/virsh.c   |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 tools/virsh.pod |    4 ++++
 2 files changed, 53 insertions(+), 0 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 19e3449..6f6883d 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -1881,6 +1881,54 @@ cmdDump(vshControl *ctl, const vshCmd *cmd)
 }
 
 /*
+ * "screenshot" command
+ */
+static const vshCmdInfo info_screenshot[] = {
+    {"help", N_("take a screenshot of a current domain console and store it "
+                "into a file")},
+    {"desc", N_("screenshot of a current domain console")},
+    {NULL, NULL}
+};
+
+static const vshCmdOptDef opts_screenshot[] = {
+    {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
+    {"file", VSH_OT_DATA, VSH_OFLAG_REQ, N_("where to store the screenshot")},
+    {NULL, 0, 0, NULL}
+};
+
+static int
+cmdScreenshot(vshControl *ctl, const vshCmd *cmd)
+{
+    virDomainPtr dom;
+    const char *name = NULL;
+    const char *to = NULL;
+    int ret = FALSE;
+    int flags = 0; /* currently unused */
+
+    if (!vshConnectionUsability(ctl, ctl->conn))
+        return FALSE;
+
+    if (vshCommandOptString(cmd, "file", &to) <= 0)
+        return FALSE;
+
+    if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
+        return FALSE;
+
+    if (virDomainScreenshot(dom, to, flags) == 0) {
+        vshPrint(ctl, _("Screenshot saved to %s"), to);
+    } else {
+        vshError(ctl, _("Failed to take a screenshot of %s"), name);
+        goto error;
+    }
+
+    ret = TRUE;
+
+error:
+    virDomainFree(dom);
+    return ret;
+}
+
+/*
  * "resume" command
  */
 static const vshCmdInfo info_resume[] = {
@@ -10691,6 +10739,7 @@ static const vshCmdDef domManagementCmds[] = {
     {"resume", cmdResume, opts_resume, info_resume},
     {"save", cmdSave, opts_save, info_save},
     {"schedinfo", cmdSchedinfo, opts_schedinfo, info_schedinfo},
+    {"screenshot", cmdScreenshot, opts_screenshot, info_screenshot},
     {"setmaxmem", cmdSetmaxmem, opts_setmaxmem, info_setmaxmem},
     {"setmem", cmdSetmem, opts_setmem, info_setmem},
     {"setvcpus", cmdSetvcpus, opts_setvcpus, info_setvcpus},
diff --git a/tools/virsh.pod b/tools/virsh.pod
index f4bd294..e61f501 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -578,6 +578,10 @@ Therefore, -1 is a useful shorthand for 262144.
 B<Note>: The weight and cap parameters are defined only for the
 XEN_CREDIT scheduler and are now I<DEPRECATED>.
 
+=item B<screenshot> I<domain-id> I<imagefilepath>
+
+Takes a screenshot of a current domain console and stores it into a file.
+
 =item B<setmem> I<domain-id> B<kilobytes> optional I<--config> I<--live>
 
 Change the memory allocation for a guest domain.
-- 
1.7.4

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