This wraps the virDomainPMWakeup libvirt function available since
version 0.9.11.
Signed-off-by: Claudio Bley <cbley(a)av-test.de>
---
src/main/java/org/libvirt/Domain.java | 27 ++++++++++++++++++++++++++
src/main/java/org/libvirt/SuspendTarget.java | 15 ++++++++++++++
src/main/java/org/libvirt/jna/Libvirt.java | 2 ++
3 files changed, 44 insertions(+)
create mode 100644 src/main/java/org/libvirt/SuspendTarget.java
diff --git a/src/main/java/org/libvirt/Domain.java
b/src/main/java/org/libvirt/Domain.java
index 89bc659..e0dba46 100644
--- a/src/main/java/org/libvirt/Domain.java
+++ b/src/main/java/org/libvirt/Domain.java
@@ -1,6 +1,7 @@
package org.libvirt;
import java.nio.ByteBuffer;
+import java.util.concurrent.TimeUnit;
import org.libvirt.event.IOErrorListener;
import org.libvirt.jna.DomainPointer;
@@ -1091,6 +1092,32 @@ public class Domain {
}
/**
+ * Enter the given power management suspension target level.
+ */
+ public void PMsuspend(SuspendTarget target) throws LibvirtException {
+ PMsuspendFor(target, 0, TimeUnit.SECONDS);
+ }
+
+ /**
+ * Enter the given power management suspension target level for the given duration.
+ */
+ public void PMsuspendFor(SuspendTarget target, long duration, TimeUnit unit) throws
LibvirtException {
+ processError(libvirt.virDomainPMSuspendForDuration(this.VDP, target.ordinal(),
unit.toSeconds(duration), 0));
+ }
+
+ /**
+ * Immediately wake up a guest using power management.
+ * <p>
+ * Injects a <em>wakeup<em> into the guest that previously used
+ * {@link #PMsuspend} or {@link #PMsuspendFor}, rather than
+ * waiting for the previously requested duration (if any) to
+ * elapse.
+ */
+ public void PMwakeup() throws LibvirtException {
+ processError(libvirt.virDomainPMWakeup(this.VDP, 0));
+ }
+
+ /**
* Dynamically changes the real CPUs which can be allocated to a virtual
* CPU. This function requires priviledged access to the hypervisor.
*
diff --git a/src/main/java/org/libvirt/SuspendTarget.java
b/src/main/java/org/libvirt/SuspendTarget.java
new file mode 100644
index 0000000..456c980
--- /dev/null
+++ b/src/main/java/org/libvirt/SuspendTarget.java
@@ -0,0 +1,15 @@
+package org.libvirt;
+
+/**
+ * Power management suspension target levels
+ */
+public enum SuspendTarget {
+ /** Suspend-to-RAM */
+ MEMORY,
+
+ /** Suspend-to-Disk */
+ DISK,
+
+ /** Hybrid-Suspend */
+ HYBRID;
+}
diff --git a/src/main/java/org/libvirt/jna/Libvirt.java
b/src/main/java/org/libvirt/jna/Libvirt.java
index 7183d5b..a6d3b1d 100644
--- a/src/main/java/org/libvirt/jna/Libvirt.java
+++ b/src/main/java/org/libvirt/jna/Libvirt.java
@@ -295,6 +295,8 @@ public interface Libvirt extends Library {
String dxml, NativeLong flags, String dname, NativeLong bandwidth);
int virDomainMemoryStats(DomainPointer virDomainPtr, virDomainMemoryStats[] stats,
int nr_stats, int flags);
int virDomainPinVcpu(DomainPointer virDomainPtr, int vcpu, byte[] cpumap, int
maplen);
+ int virDomainPMSuspendForDuration(DomainPointer virDomainPtr, int target, long
duration, int flags);
+ int virDomainPMWakeup(DomainPointer virDomainPtr, int flags);
int virDomainReboot(DomainPointer virDomainPtr, int flags);
int virDomainRef(DomainPointer virDomainPtr);
int virDomainReset(DomainPointer virDomainPtr, int flags);
--
1.7.9.5