]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Expose new virDomainPMSuspendForDuration API
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 26 Jan 2012 19:20:49 +0000 (20:20 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Sat, 28 Jan 2012 09:20:46 +0000 (10:20 +0100)
under new command "dompmsuspend"

tools/virsh.c
tools/virsh.pod

index ffcd746b367be1f75123fa90ef156028374ec111..3a5974662c3d7a587e3cb6db787f675940addc95 100644 (file)
@@ -2169,6 +2169,77 @@ cmdSuspend(vshControl *ctl, const vshCmd *cmd)
     return ret;
 }
 
+/*
+ * "dompmsuspend" command
+ */
+static const vshCmdInfo info_dom_pm_suspend[] = {
+    {"help", N_("suspend a domain for a given time duration")},
+    {"desc", N_("Suspend a running domain for a given time duration.")},
+    {NULL, NULL}
+};
+
+static const vshCmdOptDef opts_dom_pm_suspend[] = {
+    {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
+    {"duration", VSH_OT_INT, VSH_OFLAG_REQ_OPT, N_("duration in seconds")},
+    {"target", VSH_OT_STRING, VSH_OFLAG_REQ, N_("mem(Suspend-to-RAM), "
+                                                "disk(Suspend-to-Disk), "
+                                                "hybrid(Hybrid-Suspend)")},
+    {NULL, 0, 0, NULL}
+};
+
+static bool
+cmdDomPMSuspend(vshControl *ctl, const vshCmd *cmd)
+{
+    virDomainPtr dom;
+    const char *name;
+    bool ret = false;
+    const char *target = NULL;
+    unsigned int suspendTarget;
+    unsigned long long duration = 0;
+
+    if (!vshConnectionUsability(ctl, ctl->conn))
+        return false;
+
+    if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
+        return false;
+
+    if (vshCommandOptULongLong(cmd, "duration", &duration) < 0) {
+        vshError(ctl, _("Invalid duration argument"));
+        goto cleanup;
+    }
+
+    if (vshCommandOptString(cmd, "target", &target) < 0) {
+        vshError(ctl, _("Invalid target argument"));
+        goto cleanup;
+    }
+
+    if (STREQ(target, "mem"))
+        suspendTarget = VIR_NODE_SUSPEND_TARGET_MEM;
+    else if (STREQ(target, "disk"))
+        suspendTarget = VIR_NODE_SUSPEND_TARGET_DISK;
+    else if (STREQ(target, "hybrid"))
+        suspendTarget = VIR_NODE_SUSPEND_TARGET_HYBRID;
+    else {
+        vshError(ctl, "%s", _("Invalid target"));
+        goto cleanup;
+    }
+
+    if (virDomainPMSuspendForDuration(dom, suspendTarget, duration, 0) < 0) {
+        vshError(ctl, _("Domain %s could not be suspended"),
+                 virDomainGetName(dom));
+        goto cleanup;
+    }
+
+    vshPrint(ctl, _("Domain %s successfully suspended"),
+             virDomainGetName(dom));
+
+    ret = true;
+
+cleanup:
+    virDomainFree(dom);
+    return ret;
+}
+
 /*
  * "create" command
  */
@@ -16109,6 +16180,8 @@ static const vshCmdDef domManagementCmds[] = {
     {"domjobabort", cmdDomjobabort, opts_domjobabort, info_domjobabort, 0},
     {"domjobinfo", cmdDomjobinfo, opts_domjobinfo, info_domjobinfo, 0},
     {"domname", cmdDomname, opts_domname, info_domname, 0},
+    {"dompmsuspend", cmdDomPMSuspend,
+     opts_dom_pm_suspend, info_dom_pm_suspend, 0},
     {"domuuid", cmdDomuuid, opts_domuuid, info_domuuid, 0},
     {"domxml-from-native", cmdDomXMLFromNative, opts_domxmlfromnative,
      info_domxmlfromnative, 0},
index 6622caf3e71da10ff6926ff24bb072509b1524a1..4bc25bf366b656229f24dcd68febdf0e52bee9bc 100644 (file)
@@ -1239,6 +1239,14 @@ Moves a domain out of the suspended state.  This will allow a previously
 suspended domain to now be eligible for scheduling by the underlying
 hypervisor.
 
+=item B<suspend-duration> I<domain-id> I<target>
+
+Suspend a running domain into one of these states (possible I<target>
+values):
+    mem equivallent of S3 ACPI state
+    disk equivallent of S4 ACPI state
+    hybrid RAM is saved to disk but not powered off
+
 =item B<ttyconsole> I<domain-id>
 
 Output the device used for the TTY console of the domain. If the information