From: pasquale <pasquale@pasquale-VPCEB1A4E>
-Added the following bindings:
--virDomainGetCpuStats
--virNodeGetCpuStats
--virDomainShutdownFlags
--virDomainDestroyFlags
-Added following classes
--org/libvirt/CPUStatistic giving cpu stats in user friendly form
--org/libvirt/jna/VirUnion binding
--org/libvirt/jna/virDomainCPUStats type
--org/libvirt/jna/virNodeCPUStats type
--org/libvirt/jna/virTypedParameter biding
---
src/main/java/org/libvirt/CPUStatistic.java | 61 +++
src/main/java/org/libvirt/Connect.java | 137 +++++-
src/main/java/org/libvirt/Device.java | 57 ++-
src/main/java/org/libvirt/Domain.java | 501 +++++++++++++++------
.../java/org/libvirt/DomainInterfaceStats.java | 2 +-
src/main/java/org/libvirt/DomainSnapshot.java | 31 +-
src/main/java/org/libvirt/Error.java | 409 ++++++-----------
src/main/java/org/libvirt/ErrorHandler.java | 54 +--
src/main/java/org/libvirt/Interface.java | 65 +--
src/main/java/org/libvirt/Library.java | 4 +-
src/main/java/org/libvirt/Network.java | 61 ++-
src/main/java/org/libvirt/NetworkFilter.java | 43 +-
src/main/java/org/libvirt/Secret.java | 67 ++-
src/main/java/org/libvirt/StoragePool.java | 106 +++--
src/main/java/org/libvirt/StorageVol.java | 68 +--
src/main/java/org/libvirt/Stream.java | 71 ++-
src/main/java/org/libvirt/jna/Libvirt.java | 42 +-
src/main/java/org/libvirt/jna/VirUnion.java | 14 +
src/main/java/org/libvirt/jna/virConnectAuth.java | 4 +-
.../java/org/libvirt/jna/virConnectCredential.java | 4 +-
.../java/org/libvirt/jna/virDomainBlockInfo.java | 4 +-
.../java/org/libvirt/jna/virDomainBlockStats.java | 4 +-
.../java/org/libvirt/jna/virDomainCPUStats.java | 21 +
src/main/java/org/libvirt/jna/virDomainInfo.java | 4 +-
.../org/libvirt/jna/virDomainInterfaceStats.java | 4 +-
.../java/org/libvirt/jna/virDomainJobInfo.java | 4 +-
.../java/org/libvirt/jna/virDomainMemoryStats.java | 4 +-
src/main/java/org/libvirt/jna/virError.java | 4 +-
src/main/java/org/libvirt/jna/virNodeCPUStats.java | 19 +
src/main/java/org/libvirt/jna/virNodeInfo.java | 4 +-
.../java/org/libvirt/jna/virSchedParameter.java | 4 +-
.../java/org/libvirt/jna/virStoragePoolInfo.java | 4 +-
.../java/org/libvirt/jna/virStorageVolInfo.java | 4 +-
.../java/org/libvirt/jna/virTypedParameter.java | 22 +
src/main/java/org/libvirt/jna/virVcpuInfo.java | 4 +-
35 files changed, 1194 insertions(+), 717 deletions(-)
create mode 100644 src/main/java/org/libvirt/CPUStatistic.java
create mode 100644 src/main/java/org/libvirt/jna/VirUnion.java
create mode 100644 src/main/java/org/libvirt/jna/virDomainCPUStats.java
create mode 100644 src/main/java/org/libvirt/jna/virNodeCPUStats.java
create mode 100644 src/main/java/org/libvirt/jna/virTypedParameter.java
diff --git a/src/main/java/org/libvirt/CPUStatistic.java
b/src/main/java/org/libvirt/CPUStatistic.java
new file mode 100644
index 0000000..4cd6f09
--- /dev/null
+++ b/src/main/java/org/libvirt/CPUStatistic.java
@@ -0,0 +1,61 @@
+package org.libvirt;
+
+import java.nio.charset.Charset;
+import org.libvirt.jna.virNodeCPUStats;
+import org.libvirt.jna.virTypedParameter;
+
+public class CPUStatistic {
+ public String tag;
+ public long val;
+
+ //valid for host cpu stats
+ public static final int KERNEL_H = 0;
+ public static final int USER_H = 1;
+ public static final int IDLE_H = 2;
+ public static final int IOWAIT_H = 3;
+
+ //valid for guest cpu stats
+ public static final int CPU_D = 0;
+ public static final int USER_D = 1;
+ public static final int SYSTEM_D = 2;
+
+ private String createStringFromBytes(byte[] b){
+ Charset ch = Charset.forName("UTF-8");
+ int i = 0;
+ while ((i<b.length) && (b[i]!=0))
+ i++;
+
+ return new String(b,0,i,ch);
+ }
+
+ public CPUStatistic(virNodeCPUStats stat){
+ tag = createStringFromBytes(stat.tag);
+ val = stat.val;
+ }
+
+ public CPUStatistic(virTypedParameter stat){
+ tag = createStringFromBytes(stat.field);
+ val = stat.value.l;
+ }
+
+ public String getTag() {
+ return tag;
+ }
+
+ public long getValue() {
+ return val;
+ }
+
+ public void setTag(String tag) {
+ this.tag = tag;
+ }
+
+ public void setValue(long val) {
+ this.val = val;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("tag:%s%nval:%d%n", tag, val);
+ }
+}
diff --git a/src/main/java/org/libvirt/Connect.java
b/src/main/java/org/libvirt/Connect.java
index fedc60e..07285f9 100644
--- a/src/main/java/org/libvirt/Connect.java
+++ b/src/main/java/org/libvirt/Connect.java
@@ -14,15 +14,15 @@ import org.libvirt.jna.StoragePoolPointer;
import org.libvirt.jna.StorageVolPointer;
import org.libvirt.jna.StreamPointer;
import org.libvirt.jna.virConnectAuth;
+import org.libvirt.jna.virNodeCPUStats;
import org.libvirt.jna.virNodeInfo;
import static org.libvirt.Library.libvirt;
-import static org.libvirt.ErrorHandler.processError;
-import static org.libvirt.ErrorHandler.processErrorIfZero;
import com.sun.jna.Memory;
import com.sun.jna.NativeLong;
import com.sun.jna.Pointer;
+import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.LongByReference;
/**
@@ -31,7 +31,7 @@ import com.sun.jna.ptr.LongByReference;
*
* @author stoty
*/
-public class Connect {
+public class Connect implements AutoCloseable{
/**
* Get the version of a connection.
@@ -82,6 +82,7 @@ public class Connect {
*/
public static void setErrorCallback(Libvirt.VirErrorCallback callback) throws
LibvirtException {
Libvirt.INSTANCE.virSetErrorFunc(null, callback);
+ ErrorHandler.processError(Libvirt.INSTANCE);
}
/**
@@ -121,6 +122,7 @@ public class Connect {
VCP = libvirt.virConnectOpen(uri);
// Check for an error
processError(VCP);
+ ErrorHandler.processError(Libvirt.INSTANCE);
}
/**
@@ -141,6 +143,7 @@ public class Connect {
}
// Check for an error
processError(VCP);
+ ErrorHandler.processError(Libvirt.INSTANCE);
}
/**
@@ -173,6 +176,7 @@ public class Connect {
VCP = libvirt.virConnectOpenAuth(uri, vAuth, flags);
// Check for an error
processError(VCP);
+ ErrorHandler.processError(Libvirt.INSTANCE);
}
/**
@@ -195,7 +199,7 @@ public class Connect {
* @throws LibvirtException
* @return number of remaining references (>= 0)
*/
- public int close() throws LibvirtException {
+ public void close() throws LibvirtException {
int success = 0;
if (VCP != null) {
success = libvirt.virConnectClose(VCP);
@@ -205,7 +209,8 @@ public class Connect {
// it's called with a null virConnectPointer
VCP = null;
}
- return processError(success);
+
+ processError(success);
}
/**
@@ -219,7 +224,8 @@ public class Connect {
* @throws LibvirtException
*/
public CPUCompareResult compareCPU(String xmlDesc) throws LibvirtException {
- int rawResult = processError(libvirt.virConnectCompareCPU(VCP, xmlDesc, 0));
+ int rawResult = libvirt.virConnectCompareCPU(VCP, xmlDesc, 0);
+ processError();
return CPUCompareResult.get(rawResult);
}
@@ -306,11 +312,13 @@ public class Connect {
* Documentation</a>
* @param callbackID
* the callback to deregister
- * @return <em>ignore</em> (always 0)
+ * @return 0 on success, -1 on failure
* @throws LibvirtException
*/
public int domainEventDeregisterAny(int callbackID) throws LibvirtException {
- return processError(libvirt.virConnectDomainEventDeregisterAny(VCP,
callbackID));
+ int returnValue = libvirt.virConnectDomainEventDeregisterAny(VCP, callbackID);
+ processError();
+ return returnValue;
}
/**
@@ -475,6 +483,41 @@ public class Connect {
Library.free(ptr);
}
}
+
+ /**
+ * This functions gives a % of the load on the host cpu system.
+ * In the case of a multicore processor it gives a load average.
+ * In order to do so it makes two sequential measurements, according
+ * to the interval parameter.
+ *
+ *
+ * @param interval the interval,in ms, between the two measurations.
+ * @return
+ * @throws LibvirtException
+ */
+ public float getCPUOverallUsage(long interval) throws LibvirtException{
+ float result = 0;
+ CPUStatistic[] st1 = getCPUStats(-1, 0);
+ try {
+ Thread.sleep(interval);
+ CPUStatistic[] st2 = getCPUStats(-1, 0);
+
+ for(int i=0;i<st2.length;i++)
+ st2[i].val -= st1[i].val;
+
+ long sum = 0;
+ for(int i=0;i<st2.length;i++)
+ sum +=st2[i].val;
+
+ result = 100.0f - (st2[CPUStatistic.IDLE_H].val*100.0f/sum);
+
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return result;
+ }
/**
* NUMA Support
@@ -492,7 +535,10 @@ public class Connect {
* Returns the free memory for the connection
*/
public long getFreeMemory() throws LibvirtException {
- return processErrorIfZero(libvirt.virNodeGetFreeMemory(VCP));
+ long returnValue = 0;
+ returnValue = libvirt.virNodeGetFreeMemory(VCP);
+ if (returnValue == 0) processError();
+ return returnValue;
}
/**
@@ -632,11 +678,13 @@ public class Connect {
* @see <a
*
href="http://www.libvirt.org/html/libvirt-libvirt.html#virConnectIsE...
* Documentation</a>
- * @return 1 if encrypted, 0 if not encrypted
+ * @return 1 if encrypted, 0 if not encrypted, -1 on error
* @throws LibvirtException
*/
public int isEncrypted() throws LibvirtException {
- return processError(libvirt.virConnectIsEncrypted(VCP));
+ int returnValue = libvirt.virConnectIsEncrypted(VCP);
+ processError();
+ return returnValue;
}
/**
@@ -645,11 +693,13 @@ public class Connect {
* @see <a
*
href="http://www.libvirt.org/html/libvirt-libvirt.html#virConnectIsS...
* Documentation</a>
- * @return 1 if secure, 0 if not secure
+ * @return 1 if secure, 0 if not secure, -1 on error
* @throws LibvirtException
*/
public int isSecure() throws LibvirtException {
- return processError(libvirt.virConnectIsSecure(VCP));
+ int returnValue = libvirt.virConnectIsSecure(VCP);
+ processError();
+ return returnValue;
}
/**
@@ -1019,6 +1069,7 @@ public class Connect {
processError(libvirt.virNodeGetInfo(VCP, vInfo));
return new NodeInfo(vInfo);
}
+
/**
* Provides the number of inactive domains.
@@ -1130,6 +1181,65 @@ public class Connect {
}
/**
+ * call the error handling logic. Should be called after every libvirt call
+ *
+ * @throws LibvirtException
+ */
+ protected void processError() throws LibvirtException {
+ ErrorHandler.processError(libvirt);
+ }
+
+ public CPUStatistic[] getCPUStats(int number,long flags) throws LibvirtException{
+ CPUStatistic[] stats = null;
+
+ IntByReference nParams = new IntByReference();
+
+ int result = libvirt.virNodeGetCPUStats(
+ VCP, number, null, nParams, flags);
+ processError();
+
+ if(result == 0){
+ virNodeCPUStats[] params = new virNodeCPUStats[nParams.getValue()];
+ result = libvirt.virNodeGetCPUStats(VCP, number , params, nParams, flags);
+ processError();
+
+ if(result >= 0){
+ stats = new CPUStatistic[params.length];
+ for(int i=0;i<params.length;i++)
+ stats[i] = new CPUStatistic(params[i]);
+ }
+ }
+
+ return stats;
+ }
+
+ /**
+ * Calls {@link #processError()} when the given libvirt return code
+ * indicates an error.
+ *
+ * @param ret libvirt return code, indicating error if negative.
+ * @return {@code ret}
+ * @throws LibvirtException
+ */
+ protected final int processError(int ret) throws LibvirtException {
+ if (ret < 0) processError();
+ return ret;
+ }
+
+ /**
+ * Calls {@link #processError()} if {@code arg} is null.
+ *
+ * @param arg An arbitrary object returned by libvirt.
+ * @return {@code arg}
+ * @throws LibvirtException
+ */
+ protected final <T> T processError(T arg) throws LibvirtException {
+ if (arg == null) processError();
+ return arg;
+ }
+
+
+ /**
* Restores a domain saved to disk by Domain.save().
*
* @param from
@@ -1200,6 +1310,7 @@ public class Connect {
public void setConnectionErrorCallback(Libvirt.VirErrorCallback callback) throws
LibvirtException {
libvirt.virConnSetErrorFunc(VCP, null, callback);
+ processError();
}
/**
diff --git a/src/main/java/org/libvirt/Device.java
b/src/main/java/org/libvirt/Device.java
index a3b20b8..fe49ce9 100644
--- a/src/main/java/org/libvirt/Device.java
+++ b/src/main/java/org/libvirt/Device.java
@@ -2,11 +2,6 @@ package org.libvirt;
import org.libvirt.jna.DevicePointer;
import static org.libvirt.Library.libvirt;
-import static org.libvirt.ErrorHandler.processError;
-
-import com.sun.jna.Pointer;
-
-import com.sun.jna.Pointer;
/**
* A device which is attached to a node
@@ -46,7 +41,8 @@ public class Device {
public int destroy() throws LibvirtException {
int success = 0;
if (VDP != null) {
- success = processError(libvirt.virNodeDeviceDestroy(VDP));
+ success = libvirt.virNodeDeviceDestroy(VDP);
+ processError();
VDP = null;
}
@@ -60,7 +56,9 @@ public class Device {
* @throws LibvirtException
*/
public int detach() throws LibvirtException {
- return processError(libvirt.virNodeDeviceDettach(VDP));
+ int num = libvirt.virNodeDeviceDettach(VDP);
+ processError();
+ return num;
}
@Override
@@ -78,7 +76,8 @@ public class Device {
public int free() throws LibvirtException {
int success = 0;
if (VDP != null) {
- success = processError(libvirt.virNodeDeviceFree(VDP));
+ success = libvirt.virNodeDeviceFree(VDP);
+ processError();
VDP = null;
}
@@ -91,7 +90,9 @@ public class Device {
* @throws LibvirtException
*/
public String getName() throws LibvirtException {
- return processError(libvirt.virNodeDeviceGetName(VDP));
+ String name = libvirt.virNodeDeviceGetName(VDP);
+ processError();
+ return name;
}
/**
@@ -100,7 +101,9 @@ public class Device {
* @throws LibvirtException
*/
public int getNumberOfCapabilities() throws LibvirtException {
- return processError(libvirt.virNodeDeviceNumOfCaps(VDP));
+ int num = libvirt.virNodeDeviceNumOfCaps(VDP);
+ processError();
+ return num;
}
/**
@@ -109,7 +112,9 @@ public class Device {
* @throws LibvirtException
*/
public String getParent() throws LibvirtException {
- return processError(libvirt.virNodeDeviceGetParent(VDP));
+ String parent = libvirt.virNodeDeviceGetParent(VDP);
+ processError();
+ return parent;
}
/**
@@ -118,7 +123,9 @@ public class Device {
* @throws LibvirtException
*/
public String getXMLDescription() throws LibvirtException {
- return processError(libvirt.virNodeDeviceGetXMLDesc(VDP));
+ String desc = libvirt.virNodeDeviceGetXMLDesc(VDP);
+ processError();
+ return desc;
}
/**
@@ -128,15 +135,21 @@ public class Device {
*/
public String[] listCapabilities() throws LibvirtException {
int maxCaps = getNumberOfCapabilities();
+ String[] names = new String[maxCaps];
if (maxCaps > 0) {
- Pointer[] ptrs = new Pointer[maxCaps];
- int got = processError(libvirt.virNodeDeviceListCaps(VDP, ptrs, maxCaps));
-
- return Library.toStringArray(ptrs, got);
- } else {
- return Library.NO_STRINGS;
+ libvirt.virNodeDeviceListCaps(VDP, names, maxCaps);
+ processError();
}
+ return names;
+ }
+
+ /**
+ * Error handling logic to throw errors. Must be called after every libvirt
+ * call.
+ */
+ protected void processError() throws LibvirtException {
+ virConnect.processError();
}
/**
@@ -145,7 +158,9 @@ public class Device {
* @throws LibvirtException
*/
public int reAttach() throws LibvirtException {
- return processError(libvirt.virNodeDeviceReAttach(VDP));
+ int num = libvirt.virNodeDeviceReAttach(VDP);
+ processError();
+ return num;
}
/**
@@ -155,6 +170,8 @@ public class Device {
* @throws LibvirtException
*/
public int reset() throws LibvirtException {
- return processError(libvirt.virNodeDeviceReset(VDP));
+ int num = libvirt.virNodeDeviceReset(VDP);
+ processError();
+ return num;
}
}
diff --git a/src/main/java/org/libvirt/Domain.java
b/src/main/java/org/libvirt/Domain.java
index a217733..b515b4b 100644
--- a/src/main/java/org/libvirt/Domain.java
+++ b/src/main/java/org/libvirt/Domain.java
@@ -3,7 +3,6 @@ package org.libvirt;
import org.libvirt.jna.DomainPointer;
import org.libvirt.jna.DomainSnapshotPointer;
import org.libvirt.jna.Libvirt;
-import org.libvirt.jna.SizeT;
import org.libvirt.jna.virDomainBlockInfo;
import org.libvirt.jna.virDomainBlockStats;
import org.libvirt.jna.virDomainInfo;
@@ -11,10 +10,10 @@ import org.libvirt.jna.virDomainInterfaceStats;
import org.libvirt.jna.virDomainJobInfo;
import org.libvirt.jna.virDomainMemoryStats;
import org.libvirt.jna.virSchedParameter;
+import org.libvirt.jna.virTypedParameter;
import org.libvirt.jna.virVcpuInfo;
+
import static org.libvirt.Library.libvirt;
-import static org.libvirt.ErrorHandler.processError;
-import static org.libvirt.ErrorHandler.processErrorIfZero;
import com.sun.jna.Native;
import com.sun.jna.NativeLong;
@@ -33,25 +32,25 @@ public class Domain {
public static final int BYTES = 1;
}
- static final class CreateFlags {
- static final int VIR_DOMAIN_NONE = 0;
- static final int VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE = (1 << 0); /*
Restore or alter
+ public static final class CreateFlags {
+ public static final int VIR_DOMAIN_NONE = 0;
+ public static final int VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE = (1 << 0);
/* Restore or alter
metadata
*/
- static final int VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT = (1 << 1); /* With
redefine, make
+ public static final int VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT = (1 << 1);
/* With redefine, make
snapshot
current */
- static final int VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA = (1 << 2); /* Make
snapshot without
+ public static final int VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA = (1 << 2);
/* Make snapshot without
remembering it */
- static final int VIR_DOMAIN_SNAPSHOT_CREATE_HALT = (1 << 3); /* Stop
running guest
+ public static final int VIR_DOMAIN_SNAPSHOT_CREATE_HALT = (1 << 3);
/* Stop running guest
after
snapshot */
- static final int VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY = (1 << 4); /* disk
snapshot, not
+ public static final int VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY = (1 << 4);
/* disk snapshot, not
system
checkpoint */
- static final int VIR_DOMAIN_SNAPSHOT_CREATE_REUSE_EXT = (1 << 5); /*
reuse any existing
+ public static final int VIR_DOMAIN_SNAPSHOT_CREATE_REUSE_EXT = (1 << 5);
/* reuse any existing
external
files */
- static final int VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE = (1 << 6); /* use
guest agent to
+ public static final int VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE = (1 << 6);
/* use guest agent to
quiesce
all mounted
file
systems within
the domain
*/
- static final int VIR_DOMAIN_SNAPSHOT_CREATE_ATOMIC = (1 << 7); /*
atomically avoid
+ public static final int VIR_DOMAIN_SNAPSHOT_CREATE_ATOMIC = (1 << 7);
/* atomically avoid
partial
changes */
}
@@ -72,6 +71,19 @@ public class Domain {
* when supported */
static final int VIR_MIGRATE_UNSAFE = (1 << 9); /* force
migration even if it is considered unsafe */
}
+
+ public static final class ShutdownFlags{
+ static final long SHUTDOWN_DEFAULT = 0; //hypervisor choice
+ static final long SHUTDOWN_ACPI_POWER_BTN = 1; //send acpi api event
+ static final long SHUTDOWN_GUEST_AGENT = 2; //use guest agent
+ static final long SHUTDOWN_INITCTL = 4; //use init ctl
+ static final long DOMAIN_SHUTDOWN_SIGNAL = 8; //send a signal
+ }
+
+ public static final class DestroyFlags{
+ public static final long DESTROY_DEFAULT = 0; //Default behavior - could lead to
data loss!!
+ public static final long DESTROY_GRACEFUL = 1; //only SIGTERM, no SIGKILL
+ }
static final class XMLFlags {
/**
@@ -162,11 +174,13 @@ public class Domain {
* @see <a
*
href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainAbor...
* Documentation</a>
- * @return <em>ignore</em> (always 0)
+ * @return 0 in case of success and -1 in case of failure.
* @throws LibvirtException
*/
public int abortJob() throws LibvirtException {
- return processError(libvirt.virDomainAbortJob(VDP));
+ int returnValue = libvirt.virDomainAbortJob(VDP);
+ processError();
+ return returnValue;
}
/**
@@ -180,7 +194,8 @@ public class Domain {
* @throws LibvirtException
*/
public void attachDevice(String xmlDesc) throws LibvirtException {
- processError(libvirt.virDomainAttachDevice(VDP, xmlDesc));
+ libvirt.virDomainAttachDevice(VDP, xmlDesc);
+ processError();
}
/**
@@ -196,7 +211,8 @@ public class Domain {
* @throws LibvirtException
*/
public void attachDeviceFlags(String xmlDesc, int flags) throws LibvirtException {
- processError(libvirt.virDomainAttachDeviceFlags(VDP, xmlDesc, flags));
+ libvirt.virDomainAttachDeviceFlags(VDP, xmlDesc, flags);
+ processError();
}
/**
@@ -205,13 +221,14 @@ public class Domain {
*
* @param path
* the path to the block device
- * @return the info
+ * @return the info, or null if an error
* @throws LibvirtException
*/
public DomainBlockInfo blockInfo(String path) throws LibvirtException {
virDomainBlockInfo info = new virDomainBlockInfo();
- processError(libvirt.virDomainGetBlockInfo(VDP, path, info, 0));
- return new DomainBlockInfo(info);
+ int success = libvirt.virDomainGetBlockInfo(VDP, path, info, 0);
+ processError();
+ return success == 0 ? new DomainBlockInfo(info) : null;
}
/**
@@ -231,8 +248,9 @@ public class Domain {
*/
public DomainBlockStats blockStats(String path) throws LibvirtException {
virDomainBlockStats stats = new virDomainBlockStats();
- processError(libvirt.virDomainBlockStats(VDP, path, stats, new
SizeT(stats.size())));
- return new DomainBlockStats(stats);
+ int success = libvirt.virDomainBlockStats(VDP, path, stats, stats.size());
+ processError();
+ return success == 0 ? new DomainBlockStats(stats) : null;
}
/**
@@ -247,7 +265,8 @@ public class Domain {
* @throws LibvirtException
*/
public void blockResize(String disk, long size, int flags) throws LibvirtException {
- processError(libvirt.virDomainBlockResize(VDP, disk, size, flags));
+ int returnValue = libvirt.virDomainBlockResize(VDP, disk, size, flags);
+ processError();
}
@@ -262,7 +281,8 @@ public class Domain {
* @throws LibvirtException
*/
public void coreDump(String to, int flags) throws LibvirtException {
- processError(libvirt.virDomainCoreDump(VDP, to, flags));
+ libvirt.virDomainCoreDump(VDP, to, flags);
+ processError();
}
/**
@@ -277,11 +297,12 @@ public class Domain {
* Launches this defined domain. If the call succeed the domain moves from
* the defined to the running domains pools.
*
- * @return <em>ignore</em> (always 0)
* @throws LibvirtException
*/
public int create() throws LibvirtException {
- return processError(libvirt.virDomainCreate(VDP));
+ int returnValue = libvirt.virDomainCreate(VDP);
+ processError();
+ return returnValue;
}
/**
@@ -289,11 +310,12 @@ public class Domain {
* If the call succeed the domain moves from
* the defined to the running domains pools.
*
- * @return <em>ignore</em> (always 0)
* @throws LibvirtException
*/
public int create(int flags) throws LibvirtException {
- return processError(libvirt.virDomainCreateWithFlags(VDP, flags));
+ int returnValue = libvirt.virDomainCreateWithFlags(VDP, flags);
+ processError();
+ return returnValue;
}
/**
@@ -305,7 +327,13 @@ public class Domain {
* @throws LibvirtException
*/
public void destroy() throws LibvirtException {
- processError(libvirt.virDomainDestroy(VDP));
+ libvirt.virDomainDestroy(VDP);
+ processError();
+ }
+
+ public void destroyWithFlags(long flags) throws LibvirtException{
+ libvirt.virDomainDestroyFlags(VDP, flags);
+ processError();
}
/**
@@ -319,7 +347,8 @@ public class Domain {
* @throws LibvirtException
*/
public void detachDevice(String xmlDesc) throws LibvirtException {
- processError(libvirt.virDomainDetachDevice(VDP, xmlDesc));
+ libvirt.virDomainDetachDevice(VDP, xmlDesc);
+ processError();
}
/**
@@ -333,12 +362,13 @@ public class Domain {
* @throws LibvirtException
*/
public void detachDeviceFlags(String xmlDesc, int flags) throws LibvirtException {
- processError(libvirt.virDomainDetachDeviceFlags(VDP, xmlDesc, flags));
+ libvirt.virDomainDetachDeviceFlags(VDP, xmlDesc, flags);
+ processError();
}
@Override
protected void finalize() throws LibvirtException {
- free();
+ close();
}
/**
@@ -346,12 +376,13 @@ public class Domain {
* structure is freed and should not be used thereafter.
*
* @throws LibvirtException
- * @return number of references left (>= 0)
+ * @return number of references left (>= 0) for success, -1 for failure.
*/
- public int free() throws LibvirtException {
+ public int close() throws LibvirtException {
int success = 0;
if (VDP != null) {
- success = processError(libvirt.virDomainFree(VDP));
+ success = libvirt.virDomainFree(VDP);
+ processError();
VDP = null;
}
@@ -359,7 +390,7 @@ public class Domain {
}
/**
- * Provides a boolean value indicating whether the domain is configured to
+ * Provides a boolean value indicating whether the network is configured to
* be automatically started when the host machine boots.
*
* @return the result
@@ -367,7 +398,8 @@ public class Domain {
*/
public boolean getAutostart() throws LibvirtException {
IntByReference autoStart = new IntByReference();
- processError(libvirt.virDomainGetAutostart(VDP, autoStart));
+ libvirt.virDomainGetAutostart(VDP, autoStart);
+ processError();
return autoStart.getValue() != 0 ? true : false;
}
@@ -379,6 +411,47 @@ public class Domain {
public Connect getConnect() {
return virConnect;
}
+
+ /**
+ * This functions gives a % of the load on the host cpu system.
+ * In the case of a multicore processor it gives a load average.
+ * In order to do so it makes two sequential measurements, according
+ * to the interval parameter.
+ *
+ *
+ * @param interval the interval,in ms, between the two measurations.
+ * @return
+ * @throws LibvirtException
+ */
+ public float getCPUOverallUsage(long interval) throws LibvirtException{
+ float result = 0;
+ CPUStatistic[] h1 = getConnect().getCPUStats(-1, 0);
+ CPUStatistic[] d1 = getCPUStats(-1, 0);
+ try {
+ Thread.sleep(interval);
+ CPUStatistic[] h2 = getConnect().getCPUStats(-1, 0);
+ CPUStatistic[] d2 = getCPUStats(-1, 0);
+
+ for(int i=0;i<h2.length;i++)
+ h2[i].val -= h1[i].val;
+
+ for(int i=0;i<d2.length;i++)
+ d2[i].val -= d1[i].val;
+
+ long sum = 0;
+ for(int i=0;i<h2.length;i++)
+ sum +=h2[i].val;
+
+
+ result = d2[CPUStatistic.CPU_D].val*100.0f/sum;
+
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return result;
+ }
/**
* Gets the hypervisor ID number for the domain
@@ -387,7 +460,9 @@ public class Domain {
* @throws LibvirtException
*/
public int getID() throws LibvirtException {
- return processError(libvirt.virDomainGetID(VDP));
+ int returnValue = libvirt.virDomainGetID(VDP);
+ processError();
+ return returnValue;
}
/**
@@ -403,9 +478,14 @@ public class Domain {
* @throws LibvirtException
*/
public DomainInfo getInfo() throws LibvirtException {
+ DomainInfo returnValue = null;
virDomainInfo vInfo = new virDomainInfo();
- processError(libvirt.virDomainGetInfo(VDP, vInfo));
- return new DomainInfo(vInfo);
+ int success = libvirt.virDomainGetInfo(VDP, vInfo);
+ processError();
+ if (success == 0) {
+ returnValue = new DomainInfo(vInfo);
+ }
+ return returnValue;
}
/**
@@ -419,9 +499,14 @@ public class Domain {
* @throws LibvirtException
*/
public DomainJobInfo getJobInfo() throws LibvirtException {
+ DomainJobInfo returnValue = null;
virDomainJobInfo vInfo = new virDomainJobInfo();
- processError(libvirt.virDomainGetJobInfo(VDP, vInfo));
- return new DomainJobInfo(vInfo);
+ int success = libvirt.virDomainGetJobInfo(VDP, vInfo);
+ processError();
+ if (success == 0) {
+ returnValue = new DomainJobInfo(vInfo);
+ }
+ return returnValue;
}
/**
@@ -431,9 +516,9 @@ public class Domain {
* @throws LibvirtException
*/
public long getMaxMemory() throws LibvirtException {
- // the memory size in kibibytes (blocks of 1024 bytes), or 0 in case of error.
NativeLong returnValue = libvirt.virDomainGetMaxMemory(VDP);
- return processErrorIfZero(returnValue.longValue());
+ processError();
+ return returnValue.longValue();
}
/**
@@ -446,17 +531,21 @@ public class Domain {
* @throws LibvirtException
*/
public int getMaxVcpus() throws LibvirtException {
- return processError(libvirt.virDomainGetMaxVcpus(VDP));
+ int returnValue = libvirt.virDomainGetMaxVcpus(VDP);
+ processError();
+ return returnValue;
}
/**
* Gets the public name for this domain
*
- * @return the name, null if there is no name
- * @throws LibvirtException <em>never</em>
+ * @return the name
+ * @throws LibvirtException
*/
public String getName() throws LibvirtException {
- return libvirt.virDomainGetName(VDP);
+ String returnValue = libvirt.virDomainGetName(VDP);
+ processError();
+ return returnValue;
}
/**
@@ -466,7 +555,8 @@ public class Domain {
* @throws LibvirtException
*/
public String getOSType() throws LibvirtException {
- Pointer ptr = processError(libvirt.virDomainGetOSType(VDP));
+ Pointer ptr = libvirt.virDomainGetOSType(VDP);
+ processError();
try {
return Library.getString(ptr);
} finally {
@@ -482,25 +572,22 @@ public class Domain {
*/
public SchedParameter[] getSchedulerParameters() throws LibvirtException {
IntByReference nParams = new IntByReference();
- Library.free(processError(libvirt.virDomainGetSchedulerType(VDP, nParams)));
-
- int n = nParams.getValue();
-
- if (n > 0) {
- virSchedParameter[] nativeParams = new virSchedParameter[n];
-
- processError(libvirt.virDomainGetSchedulerParameters(VDP, nativeParams,
nParams));
- n = nParams.getValue();
-
- SchedParameter[] returnValue = new SchedParameter[n];
-
- for (int x = 0; x < n; x++) {
+ SchedParameter[] returnValue = new SchedParameter[0];
+ Pointer pScheduler = libvirt.virDomainGetSchedulerType(VDP, nParams);
+ processError();
+ if (pScheduler != null) {
+ String scheduler = Library.getString(pScheduler);
+ Library.free(pScheduler);
+ virSchedParameter[] nativeParams = new
virSchedParameter[nParams.getValue()];
+ returnValue = new SchedParameter[nParams.getValue()];
+ libvirt.virDomainGetSchedulerParameters(VDP, nativeParams, nParams);
+ processError();
+ for (int x = 0; x < nParams.getValue(); x++) {
returnValue[x] = SchedParameter.create(nativeParams[x]);
}
- return returnValue;
- } else {
- return new SchedParameter[] {};
}
+
+ return returnValue;
}
// getSchedulerType
@@ -513,13 +600,14 @@ public class Domain {
* @return the type of the scheduler
* @throws LibvirtException
*/
- public String getSchedulerType() throws LibvirtException {
- Pointer pScheduler = processError(libvirt.virDomainGetSchedulerType(VDP, null));
- try {
- return Library.getString(pScheduler);
- } finally {
- Library.free(pScheduler);
- }
+ public String[] getSchedulerType() throws LibvirtException {
+ IntByReference nParams = new IntByReference();
+ Pointer pScheduler = libvirt.virDomainGetSchedulerType(VDP, nParams);
+ processError();
+ String[] array = new String[1];
+ array[0] = Library.getString(pScheduler);
+ Library.free(pScheduler);
+ return array;
}
/**
@@ -531,8 +619,13 @@ public class Domain {
*/
public int[] getUUID() throws LibvirtException {
byte[] bytes = new byte[Libvirt.VIR_UUID_BUFLEN];
- processError(libvirt.virDomainGetUUID(VDP, bytes));
- return Connect.convertUUIDBytes(bytes);
+ int success = libvirt.virDomainGetUUID(VDP, bytes);
+ processError();
+ int[] returnValue = new int[0];
+ if (success == 0) {
+ returnValue = Connect.convertUUIDBytes(bytes);
+ }
+ return returnValue;
}
/**
@@ -544,8 +637,13 @@ public class Domain {
*/
public String getUUIDString() throws LibvirtException {
byte[] bytes = new byte[Libvirt.VIR_UUID_STRING_BUFLEN];
- processError(libvirt.virDomainGetUUIDString(VDP, bytes));
- return Native.toString(bytes);
+ int success = libvirt.virDomainGetUUIDString(VDP, bytes);
+ processError();
+ String returnValue = null;
+ if (success == 0) {
+ returnValue = Native.toString(bytes);
+ }
+ return returnValue;
}
/**
@@ -565,7 +663,8 @@ public class Domain {
virVcpuInfo[] infos = new virVcpuInfo[cpuCount];
returnValue = new int[cpuCount * maplength];
byte[] cpumaps = new byte[cpuCount * maplength];
- processError(libvirt.virDomainGetVcpus(VDP, infos, cpuCount, cpumaps,
maplength));
+ libvirt.virDomainGetVcpus(VDP, infos, cpuCount, cpumaps, maplength);
+ processError();
for (int x = 0; x < cpuCount * maplength; x++) {
returnValue[x] = cpumaps[x];
}
@@ -583,12 +682,37 @@ public class Domain {
int cpuCount = getMaxVcpus();
VcpuInfo[] returnValue = new VcpuInfo[cpuCount];
virVcpuInfo[] infos = new virVcpuInfo[cpuCount];
- processError(libvirt.virDomainGetVcpus(VDP, infos, cpuCount, null, 0));
+ libvirt.virDomainGetVcpus(VDP, infos, cpuCount, null, 0);
+ processError();
for (int x = 0; x < cpuCount; x++) {
returnValue[x] = new VcpuInfo(infos[x]);
}
return returnValue;
}
+
+ public CPUStatistic[] getCPUStats(int number, long flags) throws LibvirtException{
+
+ CPUStatistic[] stats = null;
+
+ int result = libvirt.virDomainGetCPUStats(VDP,
+ null, 0, -1, 1, 0);
+ processError();
+
+ if(result >0){
+
+ virTypedParameter[] params = new virTypedParameter[result];
+ result = libvirt.virDomainGetCPUStats(VDP, params, result,
+ number, 1, flags);
+ processError();
+ if(result > 0){
+ stats = new CPUStatistic[params.length];
+ for(int i=0;i<params.length;i++)
+ stats[i] = new CPUStatistic(params[i]);
+ }
+ }
+
+ return stats;
+ }
/**
* Provides an XML description of the domain. The description may be reused
@@ -602,7 +726,8 @@ public class Domain {
* Description format </a>
*/
public String getXMLDesc(int flags) throws LibvirtException {
- Pointer ptr = processError(libvirt.virDomainGetXMLDesc(VDP, flags));
+ Pointer ptr = libvirt.virDomainGetXMLDesc(VDP, flags);
+ processError();
try {
return Library.getString(ptr);
} finally {
@@ -615,11 +740,13 @@ public class Domain {
*
* @see <a
href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainHasC...
* r t Documentation</a>
- * @return 1 if running, 0 if inactive
+ * @return 1 if running, 0 if inactive, -1 on error
* @throws LibvirtException
*/
public int hasCurrentSnapshot() throws LibvirtException {
- return processError(libvirt.virDomainHasCurrentSnapshot(VDP, 0));
+ int returnValue = libvirt.virDomainHasCurrentSnapshot(VDP, 0);
+ processError();
+ return returnValue;
}
/**
@@ -632,7 +759,9 @@ public class Domain {
* @throws LibvirtException
*/
public int hasManagedSaveImage() throws LibvirtException {
- return processError(libvirt.virDomainHasManagedSaveImage(VDP, 0));
+ int returnValue = libvirt.virDomainHasManagedSaveImage(VDP, 0);
+ processError();
+ return returnValue;
}
/**
@@ -650,7 +779,8 @@ public class Domain {
*/
public DomainInterfaceStats interfaceStats(String path) throws LibvirtException {
virDomainInterfaceStats stats = new virDomainInterfaceStats();
- processError(libvirt.virDomainInterfaceStats(VDP, path, stats, new
SizeT(stats.size())));
+ libvirt.virDomainInterfaceStats(VDP, path, stats, stats.size());
+ processError();
return new DomainInterfaceStats(stats);
}
@@ -660,11 +790,13 @@ public class Domain {
* @see <a
*
href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainIsAc...
* Documentation</a>
- * @return 1 if running, 0 if inactive
+ * @return 1 if running, 0 if inactive, -1 on error
* @throws LibvirtException
*/
public int isActive() throws LibvirtException {
- return processError(libvirt.virDomainIsActive(VDP));
+ int returnValue = libvirt.virDomainIsActive(VDP);
+ processError();
+ return returnValue;
}
/**
@@ -674,11 +806,13 @@ public class Domain {
* @see <a
*
href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainIsPe...
* Documentation</a>
- * @return 1 if persistent, 0 if transient
+ * @return 1 if persistent, 0 if transient, -1 on error
* @throws LibvirtException
*/
public int isPersistent() throws LibvirtException {
- return processError(libvirt.virDomainIsPersistent(VDP));
+ int returnValue = libvirt.virDomainIsPersistent(VDP);
+ processError();
+ return returnValue;
}
/**
@@ -687,11 +821,13 @@ public class Domain {
* @see <a
*
href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainMana...
* Documentation</a>
- * @return always 0
+ * @return 0 in case of success or -1 in case of failure
* @throws LibvirtException
*/
public int managedSave() throws LibvirtException {
- return processError(libvirt.virDomainManagedSave(VDP, 0));
+ int returnValue = libvirt.virDomainManagedSave(VDP, 0);
+ processError();
+ return returnValue;
}
/**
@@ -700,11 +836,13 @@ public class Domain {
* @see <a
*
href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainMana...
* Documentation</a>
- * @return always 0
+ * @return 0 in case of success, and -1 in case of error
* @throws LibvirtException
*/
public int managedSaveRemove() throws LibvirtException {
- return processError(libvirt.virDomainManagedSaveRemove(VDP, 0));
+ int returnValue = libvirt.virDomainManagedSaveRemove(VDP, 0);
+ processError();
+ return returnValue;
}
/**
@@ -712,19 +850,37 @@ public class Domain {
*
* @param number
* the number of stats to retrieve
- * @return the collection of stats
+ * @return the collection of stats, or null if an error occurs.
* @throws LibvirtException
*/
public MemoryStatistic[] memoryStats(int number) throws LibvirtException {
virDomainMemoryStats[] stats = new virDomainMemoryStats[number];
MemoryStatistic[] returnStats = null;
- int result = processError(libvirt.virDomainMemoryStats(VDP, stats, number, 0));
- returnStats = new MemoryStatistic[result];
- for (int x = 0; x < result; x++) {
- returnStats[x] = new MemoryStatistic(stats[x]);
+ int result = libvirt.virDomainMemoryStats(VDP, stats, number, 0);
+ processError();
+ if (result >= 0) {
+ returnStats = new MemoryStatistic[result];
+ for (int x = 0; x < result; x++) {
+ returnStats[x] = new MemoryStatistic(stats[x]);
+ }
}
return returnStats;
}
+
+ //TODO
+ /*public CPUStatistic[] cpuStats(int number) throws LibvirtException{
+ virDomainCPUStats[] stats = new virDomainCPUStats[number];
+ CPUStatistic[] returnStats = null;
+ int result = libvirt.virDomainGetVcpus(VDP, stats, number,null, 0);
+ processError();
+ if (result >= 0) {
+ returnStats = new CPUStatistic[result];
+ for (int x = 0; x < result; x++) {
+ returnStats[x] = new CPUStatistic(stats[x]);
+ }
+ }
+ return returnStats;
+ }*/
/**
* Migrate this domain object from its current host to the destination host
@@ -795,8 +951,8 @@ public class Domain {
* @throws LibvirtException if the migration fails
*/
public Domain migrate(Connect dconn, long flags, String dxml, String dname, String
uri, long bandwidth) throws LibvirtException {
- DomainPointer newPtr =
- processError(libvirt.virDomainMigrate2(VDP, dconn.VCP, dxml, new
NativeLong(flags), dname, uri, new NativeLong(bandwidth)));
+ DomainPointer newPtr = libvirt.virDomainMigrate2(VDP, dconn.VCP, dxml, new
NativeLong(flags), dname, uri, new NativeLong(bandwidth));
+ processError();
return new Domain(dconn, newPtr);
}
@@ -839,13 +995,14 @@ public class Domain {
* (optional) dest hostname/URI as seen from the source host
* @param bandwidth
* optional) specify migration bandwidth limit in Mbps
- * @return the new domain object if the migration was successful. Note that
- * the new domain object exists in the scope of the destination
- * connection (dconn).
+ * @return the new domain object if the migration was successful, or NULL in
+ * case of error. Note that the new domain object exists in the
+ * scope of the destination connection (dconn).
* @throws LibvirtException
*/
public Domain migrate(Connect dconn, long flags, String dname, String uri, long
bandwidth) throws LibvirtException {
- DomainPointer newPtr = processError(libvirt.virDomainMigrate(VDP, dconn.VCP, new
NativeLong(flags), dname, uri, new NativeLong(bandwidth)));
+ DomainPointer newPtr = libvirt.virDomainMigrate(VDP, dconn.VCP, new
NativeLong(flags), dname, uri, new NativeLong(bandwidth));
+ processError();
return new Domain(dconn, newPtr);
}
@@ -858,11 +1015,13 @@ public class Domain {
* Documentation</a>
* @param downtime
* the time to be down
- * @return always 0
+ * @return 0 in case of success, -1 otherwise.
* @throws LibvirtException
*/
public int migrateSetMaxDowntime(long downtime) throws LibvirtException {
- return processError(libvirt.virDomainMigrateSetMaxDowntime(VDP, downtime, 0));
+ int returnValue = libvirt.virDomainMigrateSetMaxDowntime(VDP, downtime, 0);
+ processError();
+ return returnValue;
}
/**
@@ -896,9 +1055,9 @@ public class Domain {
* @throws LibvirtException
*/
public int migrateToURI(String dconnuri, String miguri, String dxml, long flags,
String dname, long bandwidth) throws LibvirtException {
- return processError(libvirt.virDomainMigrateToURI2(VDP, dconnuri, miguri,
- dxml, new NativeLong(flags),
- dname, new
NativeLong(bandwidth)));
+ int returnValue = libvirt.virDomainMigrateToURI2(VDP, dconnuri, miguri, dxml, new
NativeLong(flags), dname, new NativeLong(bandwidth));
+ processError();
+ return returnValue;
}
/**
@@ -921,7 +1080,9 @@ public class Domain {
* @throws LibvirtException
*/
public int migrateToURI(String uri, long flags, String dname, long bandwidth) throws
LibvirtException {
- return processError(libvirt.virDomainMigrateToURI(VDP, uri, new
NativeLong(flags), dname, new NativeLong(bandwidth)));
+ int returnValue = libvirt.virDomainMigrateToURI(VDP, uri, new NativeLong(flags),
dname, new NativeLong(bandwidth));
+ processError();
+ return returnValue;
}
/**
@@ -943,7 +1104,16 @@ public class Domain {
for (int x = 0; x < cpumap.length; x++) {
packedMap[x] = (byte) cpumap[x];
}
- processError(libvirt.virDomainPinVcpu(VDP, vcpu, packedMap, cpumap.length));
+ libvirt.virDomainPinVcpu(VDP, vcpu, packedMap, cpumap.length);
+ processError();
+ }
+
+ /**
+ * Error handling logic to throw errors. Must be called after every libvirt
+ * call.
+ */
+ protected void processError() throws LibvirtException {
+ virConnect.processError();
}
/**
@@ -956,7 +1126,8 @@ public class Domain {
* @throws LibvirtException
*/
public void reboot(int flags) throws LibvirtException {
- processError(libvirt.virDomainReboot(VDP, flags));
+ libvirt.virDomainReboot(VDP, flags);
+ processError();
}
/**
@@ -967,7 +1138,8 @@ public class Domain {
* @throws LibvirtException
*/
public void resume() throws LibvirtException {
- processError(libvirt.virDomainResume(VDP));
+ libvirt.virDomainResume(VDP);
+ processError();
}
/**
@@ -978,11 +1150,13 @@ public class Domain {
* >Libvirt Documentation</>
* @param snapshot
* the snapshot to revert to
- * @return 0 if the creation is successful
+ * @return 0 if the creation is successful, -1 on error.
* @throws LibvirtException
*/
public int revertToSnapshot(DomainSnapshot snapshot) throws LibvirtException {
- return processError(libvirt.virDomainRevertToSnapshot(snapshot.VDSP, 0));
+ int returnCode = libvirt.virDomainRevertToSnapshot(snapshot.VDSP, 0);
+ processError();
+ return returnCode;
}
/**
@@ -996,7 +1170,8 @@ public class Domain {
* @throws LibvirtException
*/
public void save(String to) throws LibvirtException {
- processError(libvirt.virDomainSave(VDP, to));
+ libvirt.virDomainSave(VDP, to);
+ processError();
}
/**
@@ -1008,7 +1183,8 @@ public class Domain {
*/
public void setAutostart(boolean autostart) throws LibvirtException {
int autoValue = autostart ? 1 : 0;
- processError(libvirt.virDomainSetAutostart(VDP, autoValue));
+ libvirt.virDomainSetAutostart(VDP, autoValue);
+ processError();
}
/**
@@ -1020,7 +1196,8 @@ public class Domain {
* @throws LibvirtException
*/
public void setMaxMemory(long memory) throws LibvirtException {
- processError(libvirt.virDomainSetMaxMemory(VDP, new NativeLong(memory)));
+ libvirt.virDomainSetMaxMemory(VDP, new NativeLong(memory));
+ processError();
}
/**
@@ -1033,7 +1210,8 @@ public class Domain {
* @throws LibvirtException
*/
public void setMemory(long memory) throws LibvirtException {
- processError(libvirt.virDomainSetMemory(VDP, new NativeLong(memory)));
+ libvirt.virDomainSetMemory(VDP, new NativeLong(memory));
+ processError();
}
/**
@@ -1048,7 +1226,8 @@ public class Domain {
for (int x = 0; x < params.length; x++) {
input[x] = SchedParameter.toNative(params[x]);
}
- processError(libvirt.virDomainSetSchedulerParameters(VDP, input,
params.length));
+ libvirt.virDomainSetSchedulerParameters(VDP, input, params.length);
+ processError();
}
/**
@@ -1062,7 +1241,8 @@ public class Domain {
* @throws LibvirtException
*/
public void setVcpus(int nvcpus) throws LibvirtException {
- processError(libvirt.virDomainSetVcpus(VDP, nvcpus));
+ libvirt.virDomainSetVcpus(VDP, nvcpus);
+ processError();
}
/**
@@ -1074,7 +1254,19 @@ public class Domain {
* @throws LibvirtException
*/
public void shutdown() throws LibvirtException {
- processError(libvirt.virDomainShutdown(VDP));
+ libvirt.virDomainShutdown(VDP);
+ processError();
+ }
+
+ /**
+ * Shuts down this domain with selected shutdown flag.
+ * Please use Domain static flags under the inner class SHUTDOWNFlags
+ * @param flag
+ * @throws LibvirtException
+ */
+ public void shutdown(long flag) throws LibvirtException{
+ libvirt.virDomainShutdownFlags(VDP, flag);
+ processError();
}
/**
@@ -1088,12 +1280,17 @@ public class Domain {
* string containing an XML description of the domain
* @param flags
* flags for creating the snapshot, see the virDomainSnapshotCreateFlags
for the flag options
- * @return the snapshot
+ * @return the snapshot, or null on Error
* @throws LibvirtException
*/
public DomainSnapshot snapshotCreateXML(String xmlDesc, int flags) throws
LibvirtException {
- DomainSnapshotPointer ptr = processError(libvirt.virDomainSnapshotCreateXML(VDP,
xmlDesc, flags));
- return new DomainSnapshot(virConnect, ptr);
+ DomainSnapshotPointer ptr = libvirt.virDomainSnapshotCreateXML(VDP, xmlDesc,
flags);
+ processError();
+ DomainSnapshot returnValue = null;
+ if (ptr != null) {
+ returnValue = new DomainSnapshot(virConnect, ptr);
+ }
+ return returnValue;
}
/**
@@ -1103,7 +1300,7 @@ public class Domain {
* This is just a convenience method, it has the same effect
* as calling {@code snapshotCreateXML(xmlDesc, 0);}.
*
- * @see #snapshotCreateXML(String, int)
+ * @see #snapshotCreateXML(int)
* @see <a
*
href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSnap...
* Documentation</a>
@@ -1122,12 +1319,17 @@ public class Domain {
* @see <a
*
href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSnap...
* Documentation</a>
- * @return the snapshot
+ * @return the snapshot, or null on Error
* @throws LibvirtException
*/
public DomainSnapshot snapshotCurrent() throws LibvirtException {
- DomainSnapshotPointer ptr = processError(libvirt.virDomainSnapshotCurrent(VDP,
0));
- return new DomainSnapshot(virConnect, ptr);
+ DomainSnapshotPointer ptr = libvirt.virDomainSnapshotCurrent(VDP, 0);
+ processError();
+ DomainSnapshot returnValue = null;
+ if (ptr != null) {
+ returnValue = new DomainSnapshot(virConnect, ptr);
+ }
+ return returnValue;
}
/**
@@ -1140,15 +1342,16 @@ public class Domain {
* @throws LibvirtException
*/
public String[] snapshotListNames(int flags) throws LibvirtException {
+ String[] returnValue = null;
int num = snapshotNum();
- if (num > 0) {
- Pointer[] ptrs = new Pointer[num];
- int got = processError(libvirt.virDomainSnapshotListNames(VDP, ptrs, num,
flags));
-
- return Library.toStringArray(ptrs, got);
- } else {
- return Library.NO_STRINGS;
+ if (num >= 0) {
+ returnValue = new String[num];
+ if (num > 0) {
+ libvirt.virDomainSnapshotListNames(VDP, returnValue, num, flags);
+ processError();
+ }
}
+ return returnValue;
}
/**
@@ -1176,12 +1379,17 @@ public class Domain {
* Documentation</a>
* @param name
* the name
- * @return The located snapshot
+ * @return The located snapshot, or null if an error
* @throws LibvirtException
*/
public DomainSnapshot snapshotLookupByName(String name) throws LibvirtException {
- DomainSnapshotPointer ptr =
processError(libvirt.virDomainSnapshotLookupByName(VDP, name, 0));
- return new DomainSnapshot(virConnect, ptr);
+ DomainSnapshotPointer ptr = libvirt.virDomainSnapshotLookupByName(VDP, name, 0);
+ processError();
+ DomainSnapshot returnValue = null;
+ if (ptr != null) {
+ returnValue = new DomainSnapshot(virConnect, ptr);
+ }
+ return returnValue;
}
/**
@@ -1192,7 +1400,9 @@ public class Domain {
* Documentation</a>
*/
public int snapshotNum() throws LibvirtException {
- return processError(libvirt.virDomainSnapshotNum(VDP, 0));
+ int returnValue = libvirt.virDomainSnapshotNum(VDP, 0);
+ processError();
+ return returnValue;
}
/**
@@ -1204,7 +1414,8 @@ public class Domain {
* @throws LibvirtException
*/
public void suspend() throws LibvirtException {
- processError(libvirt.virDomainSuspend(VDP));
+ libvirt.virDomainSuspend(VDP);
+ processError();
}
/**
@@ -1213,7 +1424,8 @@ public class Domain {
* @throws LibvirtException
*/
public void undefine() throws LibvirtException {
- processError(libvirt.virDomainUndefine(VDP));
+ libvirt.virDomainUndefine(VDP);
+ processError();
}
/**
@@ -1225,7 +1437,8 @@ public class Domain {
* @throws LibvirtException
*/
public void undefine(int flags) throws LibvirtException {
- processError(libvirt.virDomainUndefineFlags(VDP, flags));
+ libvirt.virDomainUndefineFlags(VDP, flags);
+ processError();
}
/**
@@ -1236,11 +1449,13 @@ public class Domain {
* the xml to update with
* @param flags
* controls the update
- * @return always 0
+ * @return 0 in case of success, -1 in case of failure.
* @throws LibvirtException
*/
public int updateDeviceFlags(String xml, int flags) throws LibvirtException {
- return processError(libvirt.virDomainUpdateDeviceFlags(VDP, xml, flags));
+ int returnValue = libvirt.virDomainUpdateDeviceFlags(VDP, xml, flags);
+ processError();
+ return returnValue;
}
}
diff --git a/src/main/java/org/libvirt/DomainInterfaceStats.java
b/src/main/java/org/libvirt/DomainInterfaceStats.java
index eab5c44..0e948d5 100644
--- a/src/main/java/org/libvirt/DomainInterfaceStats.java
+++ b/src/main/java/org/libvirt/DomainInterfaceStats.java
@@ -3,7 +3,7 @@ package org.libvirt;
import org.libvirt.jna.virDomainInterfaceStats;
/**
- * The Domain.interfaceStats method returns the network counters in this object.
+ * The Domain.interfaceStats method returns th network counters in this object
*
* @author stoty
*
diff --git a/src/main/java/org/libvirt/DomainSnapshot.java
b/src/main/java/org/libvirt/DomainSnapshot.java
index 3013117..b58fd20 100644
--- a/src/main/java/org/libvirt/DomainSnapshot.java
+++ b/src/main/java/org/libvirt/DomainSnapshot.java
@@ -2,9 +2,6 @@ package org.libvirt;
import org.libvirt.jna.DomainSnapshotPointer;
import static org.libvirt.Library.libvirt;
-import static org.libvirt.ErrorHandler.processError;
-
-import com.sun.jna.Pointer;
public class DomainSnapshot {
@@ -30,14 +27,15 @@ public class DomainSnapshot {
*
href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSnap...
* Documentation</a>
* @param flags
- * controls the deletion
- * @return <em>ignore</em> (always 0)
+ * controls teh deletion
+ * @return 0 if the selected snapshot(s) were successfully deleted, -1 on error.
* @throws LibvirtException
*/
public int delete(int flags) throws LibvirtException {
int success = 0;
if (VDSP != null) {
- success = processError(libvirt.virDomainSnapshotDelete(VDSP, flags));
+ success = libvirt.virDomainSnapshotDelete(VDSP, flags);
+ processError();
VDSP = null;
}
@@ -54,12 +52,13 @@ public class DomainSnapshot {
* exist.
*
* @throws LibvirtException
- * @return 0 on success
+ * @return 0 on success, or -1 on error.
*/
public int free() throws LibvirtException {
int success = 0;
if (VDSP != null) {
- success = processError(libvirt.virDomainSnapshotFree(VDSP));
+ success = libvirt.virDomainSnapshotFree(VDSP);
+ processError();
VDSP = null;
}
@@ -73,12 +72,16 @@ public class DomainSnapshot {
* @return the XML document
*/
public String getXMLDesc() throws LibvirtException {
- Pointer p = processError(libvirt.virDomainSnapshotGetXMLDesc(VDSP, 0));
+ String returnValue = libvirt.virDomainSnapshotGetXMLDesc(VDSP, 0);
+ processError();
+ return returnValue;
+ }
- try {
- return Library.getString(p);
- } finally {
- Library.free(p);
- }
+ /**
+ * Error handling logic to throw errors. Must be called after every libvirt
+ * call.
+ */
+ protected void processError() throws LibvirtException {
+ virConnect.processError();
}
}
diff --git a/src/main/java/org/libvirt/Error.java b/src/main/java/org/libvirt/Error.java
index 15dd870..114e758 100644
--- a/src/main/java/org/libvirt/Error.java
+++ b/src/main/java/org/libvirt/Error.java
@@ -28,104 +28,54 @@ public class Error implements Serializable {
}
public static enum ErrorDomain {
- VIR_FROM_NONE,
- /** Error at Xen hypervisor layer */
- VIR_FROM_XEN,
- /** Error at connection with xend daemon */
- VIR_FROM_XEND,
- /** Error at connection with xen store */
- VIR_FROM_XENSTORE,
- /** Error in the S-Expression code */
- VIR_FROM_SEXPR,
- /** Error in the XML code */
- VIR_FROM_XML,
- /** Error when operating on a domain */
- VIR_FROM_DOM,
- /** Error in the XML-RPC code */
- VIR_FROM_RPC,
- /** Error in the proxy code */
- VIR_FROM_PROXY,
- /** Error in the configuration file handling */
- VIR_FROM_CONF,
- /** Error at the QEMU daemon */
- VIR_FROM_QEMU,
- /** Error when operating on a network */
- VIR_FROM_NET,
- /** Error from test driver */
- VIR_FROM_TEST,
- /** Error from remote driver */
- VIR_FROM_REMOTE,
- /** Error from OpenVZ driver */
- VIR_FROM_OPENVZ,
- /** Error at Xen XM layer */
- VIR_FROM_XENXM,
- /** Error in the Linux Stats code */
- VIR_FROM_STATS_LINUX,
- /** Error from Linux Container driver */
- VIR_FROM_LXC,
- /** Error from storage driver */
- VIR_FROM_STORAGE,
- /** Error from network config */
- VIR_FROM_NETWORK,
- /** Error from domain config */
- VIR_FROM_DOMAIN,
- /** Error at the UML driver */
- VIR_FROM_UML,
- /** Error from node device monitor */
- VIR_FROM_NODEDEV,
- /** Error from xen inotify layer */
- VIR_FROM_XEN_INOTIFY,
- /** Error from security framework */
- VIR_FROM_SECURITY,
- /** Error from VirtualBox driver */
- VIR_FROM_VBOX,
- /** Error when operating on an interface */
- VIR_FROM_INTERFACE,
- /** Error from OpenNebula driver */
- VIR_FROM_ONE,
- /** Error from ESX driver */
- VIR_FROM_ESX,
- /** Error from IBM power hypervisor */
- VIR_FROM_PHYP,
- /** Error from secret storage */
- VIR_FROM_SECRET,
- /** Error from CPU driver */
- VIR_FROM_CPU,
- /** Error from XenAPI */
- VIR_FROM_XENAPI,
- /** Error from network filter driver */
- VIR_FROM_NWFILTER,
- /** Error from Synchronous hooks */
- VIR_FROM_HOOK,
- /** Error from domain snapshot */
- VIR_FROM_DOMAIN_SNAPSHOT,
- /** Error from auditing subsystem */
- VIR_FROM_AUDIT,
- /** Error from sysinfo/SMBIOS */
- VIR_FROM_SYSINFO,
- /** Error from I/O streams */
- VIR_FROM_STREAMS,
- /** Error from VMware driver */
- VIR_FROM_VMWARE,
- /** Error from event loop impl */
- VIR_FROM_EVENT,
- /** Error from libxenlight driver */
- VIR_FROM_LIBXL,
- /** Error from lock manager */
- VIR_FROM_LOCKING,
- /** Error from Hyper-V driver */
- VIR_FROM_HYPERV,
- /** Error from capabilities */
- VIR_FROM_CAPABILITIES,
- /** Error from URI handling */
- VIR_FROM_URI,
- /** Error from auth handling */
- VIR_FROM_AUTH,
- /** Error from DBus */
- VIR_FROM_DBUS,
-
- /** unknown error domain */
- VIR_FROM_UNKNOWN; // must be the last entry!
+ VIR_FROM_NONE, VIR_FROM_XEN, /* Error at Xen hypervisor layer */
+ VIR_FROM_XEND, /* Error at connection with xend daemon */
+ VIR_FROM_XENSTORE, /* Error at connection with xen store */
+ VIR_FROM_SEXPR, /* Error in the S-Expression code */
+ VIR_FROM_XML, /* Error in the XML code */
+ VIR_FROM_DOM, /* Error when operating on a domain */
+ VIR_FROM_RPC, /* Error in the XML-RPC code */
+ VIR_FROM_PROXY, /* Error in the proxy code */
+ VIR_FROM_CONF, /* Error in the configuration file handling */
+ VIR_FROM_QEMU, /* Error at the QEMU daemon */
+ VIR_FROM_NET, /* Error when operating on a network */
+ VIR_FROM_TEST, /* Error from test driver */
+ VIR_FROM_REMOTE, /* Error from remote driver */
+ VIR_FROM_OPENVZ, /* Error from OpenVZ driver */
+ VIR_FROM_XENXM, /* Error at Xen XM layer */
+ VIR_FROM_STATS_LINUX, /* Error in the Linux Stats code */
+ VIR_FROM_LXC, /* Error from Linux Container driver */
+ VIR_FROM_STORAGE, /* Error from storage driver */
+ VIR_FROM_NETWORK, /* Error from network config */
+ VIR_FROM_DOMAIN, /* Error from domain config */
+ VIR_FROM_UML, /* Error at the UML driver */
+ VIR_FROM_NODEDEV, /* Error from node device monitor */
+ VIR_FROM_XEN_INOTIFY, /* Error from xen inotify layer */
+ VIR_FROM_SECURITY, /* Error from security framework */
+ VIR_FROM_VBOX, /* Error from VirtualBox driver */
+ VIR_FROM_INTERFACE, /* Error when operating on an interface */
+ VIR_FROM_ONE, /* Error from OpenNebula driver */
+ VIR_FROM_ESX, /* Error from ESX driver */
+ VIR_FROM_PHYP, /* Error from IBM power hypervisor */
+ VIR_FROM_SECRET, /* Error from secret storage */
+ VIR_FROM_CPU, /* Error from CPU driver */
+ VIR_FROM_XENAPI, /* Error from XenAPI */
+ VIR_FROM_NWFILTER, /* Error from network filter driver */
+ VIR_FROM_HOOK, /* Error from Synchronous hooks */
+ VIR_FROM_DOMAIN_SNAPSHOT, /* Error from domain snapshot */
+ VIR_FROM_AUDIT, /* Error from auditing subsystem */
+ VIR_FROM_SYSINFO, /* Error from sysinfo/SMBIOS */
+ VIR_FROM_STREAMS, /* Error from I/O streams */
+ VIR_FROM_VMWARE, /* Error from VMware driver */
+ VIR_FROM_EVENT, /* Error from event loop impl */
+ VIR_FROM_LIBXL, /* Error from libxenlight driver */
+ VIR_FROM_LOCKING, /* Error from lock manager */
+ VIR_FROM_HYPERV, /* Error from Hyper-V driver */
+ VIR_FROM_CAPABILITIES, /* Error from capabilities */
+ VIR_FROM_URI, /* Error from URI handling */
+ VIR_FROM_AUTH, /* Error from auth handling */
+ VIR_FROM_DBUS, /* Error from DBus */
+ VIR_FROM_UNKNOWN; /* unknown error domain (must be the last entry!) */
protected static final ErrorDomain wrap(int value) {
return safeElementAt(value, values());
@@ -151,170 +101,93 @@ public class Error implements Serializable {
}
public static enum ErrorNumber {
- VIR_ERR_OK,
- /** internal error */
- VIR_ERR_INTERNAL_ERROR,
- /** memory allocation failure */
- VIR_ERR_NO_MEMORY,
- /** no support for this function */
- VIR_ERR_NO_SUPPORT,
- /** could not resolve hostname */
- VIR_ERR_UNKNOWN_HOST,
- /** can't connect to hypervisor */
- VIR_ERR_NO_CONNECT,
- /** invalid connection object */
- VIR_ERR_INVALID_CONN,
- /** invalid domain object */
- VIR_ERR_INVALID_DOMAIN,
- /** invalid function argument */
- VIR_ERR_INVALID_ARG,
- /** a command to hypervisor failed */
- VIR_ERR_OPERATION_FAILED,
- /** a HTTP GET command to failed */
- VIR_ERR_GET_FAILED,
- /** a HTTP POST command to failed */
- VIR_ERR_POST_FAILED,
- /** unexpected HTTP error code */
- VIR_ERR_HTTP_ERROR,
- /** failure to serialize an S-Expr */
- VIR_ERR_SEXPR_SERIAL,
- /** could not open Xen hypervisor control */
- VIR_ERR_NO_XEN,
- /** failure doing an hypervisor call */
- VIR_ERR_XEN_CALL,
- /** unknown OS type */
- VIR_ERR_OS_TYPE,
- /** missing kernel information */
- VIR_ERR_NO_KERNEL,
- /** missing root device information */
- VIR_ERR_NO_ROOT,
- /** missing source device information */
- VIR_ERR_NO_SOURCE,
- /** missing target device information */
- VIR_ERR_NO_TARGET,
- /** missing domain name information */
- VIR_ERR_NO_NAME,
- /** missing domain OS information */
- VIR_ERR_NO_OS,
- /** missing domain devices information */
- VIR_ERR_NO_DEVICE,
- /** could not open Xen Store control */
- VIR_ERR_NO_XENSTORE,
- /** too many drivers registered */
- VIR_ERR_DRIVER_FULL,
- /** not supported by the drivers (DEPRECATED) */
- VIR_ERR_CALL_FAILED,
- /** an XML description is not well formed or broken */
- VIR_ERR_XML_ERROR,
- /** the domain already exist */
- VIR_ERR_DOM_EXIST,
- /** operation forbidden on read-only connections */
- VIR_ERR_OPERATION_DENIED,
- /** failed to open a conf file */
- VIR_ERR_OPEN_FAILED,
- /** failed to read a conf file */
- VIR_ERR_READ_FAILED,
- /** failed to parse a conf file */
- VIR_ERR_PARSE_FAILED,
- /** failed to parse the syntax of a conf file */
- VIR_ERR_CONF_SYNTAX,
- /** failed to write a conf file */
- VIR_ERR_WRITE_FAILED,
- /** detail of an XML error */
- VIR_ERR_XML_DETAIL,
- /** invalid network object */
- VIR_ERR_INVALID_NETWORK,
- /** the network already exist */
- VIR_ERR_NETWORK_EXIST,
- /** general system call failure */
- VIR_ERR_SYSTEM_ERROR,
- /** some sort of RPC error */
- VIR_ERR_RPC,
- /** error from a GNUTLS call */
- VIR_ERR_GNUTLS_ERROR,
- /** failed to start network */
- VIR_WAR_NO_NETWORK,
- /** domain not found or unexpectedly disappeared */
- VIR_ERR_NO_DOMAIN,
- /** network not found */
- VIR_ERR_NO_NETWORK,
- /** invalid MAC address */
- VIR_ERR_INVALID_MAC,
- /** authentication failed */
- VIR_ERR_AUTH_FAILED,
- /** invalid storage pool object */
- VIR_ERR_INVALID_STORAGE_POOL,
- /** invalid storage vol object */
- VIR_ERR_INVALID_STORAGE_VOL,
- /** failed to start storage */
- VIR_WAR_NO_STORAGE,
- /** storage pool not found */
- VIR_ERR_NO_STORAGE_POOL,
- /** storage pool not found */
- VIR_ERR_NO_STORAGE_VOL,
- /** failed to start node driver */
- VIR_WAR_NO_NODE,
- /** invalid node device object */
- VIR_ERR_INVALID_NODE_DEVICE,
- /** node device not found */
- VIR_ERR_NO_NODE_DEVICE,
- /** security model not found */
- VIR_ERR_NO_SECURITY_MODEL,
- /** operation is not applicable at this time */
- VIR_ERR_OPERATION_INVALID,
- /** failed to start interface driver */
- VIR_WAR_NO_INTERFACE,
- /** interface driver not running */
- VIR_ERR_NO_INTERFACE,
- /** invalid interface object */
- VIR_ERR_INVALID_INTERFACE,
- /** more than one matching interface found */
- VIR_ERR_MULTIPLE_INTERFACES,
- /** failed to start secret storage */
- VIR_WAR_NO_SECRET,
- /** invalid secret */
- VIR_ERR_INVALID_SECRET,
- /** secret not found */
- VIR_ERR_NO_SECRET,
- /** unsupported configuration construct */
- VIR_ERR_CONFIG_UNSUPPORTED,
- /** timeout occurred during operation */
- VIR_ERR_OPERATION_TIMEOUT,
- /** a migration worked, but making the VM persist on the dest
- * host failed */
- VIR_ERR_MIGRATE_PERSIST_FAILED,
- /** a synchronous hook script failed */
- VIR_ERR_HOOK_SCRIPT_FAILED,
- /** invalid domain snapshot */
- VIR_ERR_INVALID_DOMAIN_SNAPSHOT,
- /** domain snapshot not found */
- VIR_ERR_NO_DOMAIN_SNAPSHOT,
- /** stream pointer not valid */
- VIR_ERR_INVALID_STREAM,
- /** valid API use but unsupported by the given driver */
- VIR_ERR_ARGUMENT_UNSUPPORTED,
- /** storage pool probe failed */
- VIR_ERR_STORAGE_PROBE_FAILED,
- /** storage pool already built */
- VIR_ERR_STORAGE_POOL_BUILT,
- /** force was not requested for a risky domain snapshot
- revert */
- VIR_ERR_SNAPSHOT_REVERT_RISKY,
- /** operation on a domain was canceled/aborted by user */
- VIR_ERR_OPERATION_ABORTED,
- /** authentication cancelled */
- VIR_ERR_AUTH_CANCELLED,
- /** The metadata is not present */
- VIR_ERR_NO_DOMAIN_METADATA,
- /** Migration is not safe */
- VIR_ERR_MIGRATE_UNSAFE,
- /** integer overflow */
- VIR_ERR_OVERFLOW,
- /** action prevented by block copy job */
- VIR_ERR_BLOCK_COPY_ACTIVE,
-
- /** unknown error */
- VIR_ERR_UNKNOWN; // must be the last entry!
+ VIR_ERR_OK, VIR_ERR_INTERNAL_ERROR, /* internal error */
+ VIR_ERR_NO_MEMORY, /* memory allocation failure */
+ VIR_ERR_NO_SUPPORT, /* no support for this function */
+ VIR_ERR_UNKNOWN_HOST, /* could not resolve hostname */
+ VIR_ERR_NO_CONNECT, /* can't connect to hypervisor */
+ VIR_ERR_INVALID_CONN, /* invalid connection object */
+ VIR_ERR_INVALID_DOMAIN, /* invalid domain object */
+ VIR_ERR_INVALID_ARG, /* invalid function argument */
+ VIR_ERR_OPERATION_FAILED, /* a command to hypervisor failed */
+ VIR_ERR_GET_FAILED, /* a HTTP GET command to failed */
+ VIR_ERR_POST_FAILED, /* a HTTP POST command to failed */
+ VIR_ERR_HTTP_ERROR, /* unexpected HTTP error code */
+ VIR_ERR_SEXPR_SERIAL, /* failure to serialize an S-Expr */
+ VIR_ERR_NO_XEN, /* could not open Xen hypervisor control */
+ VIR_ERR_XEN_CALL, /* failure doing an hypervisor call */
+ VIR_ERR_OS_TYPE, /* unknown OS type */
+ VIR_ERR_NO_KERNEL, /* missing kernel information */
+ VIR_ERR_NO_ROOT, /* missing root device information */
+ VIR_ERR_NO_SOURCE, /* missing source device information */
+ VIR_ERR_NO_TARGET, /* missing target device information */
+ VIR_ERR_NO_NAME, /* missing domain name information */
+ VIR_ERR_NO_OS, /* missing domain OS information */
+ VIR_ERR_NO_DEVICE, /* missing domain devices information */
+ VIR_ERR_NO_XENSTORE, /* could not open Xen Store control */
+ VIR_ERR_DRIVER_FULL, /* too many drivers registered */
+ VIR_ERR_CALL_FAILED, /* not supported by the drivers (DEPRECATED) */
+ VIR_ERR_XML_ERROR, /* an XML description is not well formed or broken */
+ VIR_ERR_DOM_EXIST, /* the domain already exist */
+ VIR_ERR_OPERATION_DENIED, /*
+ * operation forbidden on read-only
+ * connections
+ */
+ VIR_ERR_OPEN_FAILED, /* failed to open a conf file */
+ VIR_ERR_READ_FAILED, /* failed to read a conf file */
+ VIR_ERR_PARSE_FAILED, /* failed to parse a conf file */
+ VIR_ERR_CONF_SYNTAX, /* failed to parse the syntax of a conf file */
+ VIR_ERR_WRITE_FAILED, /* failed to write a conf file */
+ VIR_ERR_XML_DETAIL, /* detail of an XML error */
+ VIR_ERR_INVALID_NETWORK, /* invalid network object */
+ VIR_ERR_NETWORK_EXIST, /* the network already exist */
+ VIR_ERR_SYSTEM_ERROR, /* general system call failure */
+ VIR_ERR_RPC, /* some sort of RPC error */
+ VIR_ERR_GNUTLS_ERROR, /* error from a GNUTLS call */
+ VIR_WAR_NO_NETWORK, /* failed to start network */
+ VIR_ERR_NO_DOMAIN, /* domain not found or unexpectedly disappeared */
+ VIR_ERR_NO_NETWORK, /* network not found */
+ VIR_ERR_INVALID_MAC, /* invalid MAC address */
+ VIR_ERR_AUTH_FAILED, /* authentication failed */
+ VIR_ERR_INVALID_STORAGE_POOL, /* invalid storage pool object */
+ VIR_ERR_INVALID_STORAGE_VOL, /* invalid storage vol object */
+ VIR_WAR_NO_STORAGE, /* failed to start storage */
+ VIR_ERR_NO_STORAGE_POOL, /* storage pool not found */
+ VIR_ERR_NO_STORAGE_VOL, /* storage pool not found */
+ VIR_WAR_NO_NODE, /* failed to start node driver */
+ VIR_ERR_INVALID_NODE_DEVICE, /* invalid node device object */
+ VIR_ERR_NO_NODE_DEVICE, /* node device not found */
+ VIR_ERR_NO_SECURITY_MODEL, /* security model not found */
+ VIR_ERR_OPERATION_INVALID, /* operation is not applicable at this time */
+ VIR_WAR_NO_INTERFACE, /* failed to start interface driver */
+ VIR_ERR_NO_INTERFACE, /* interface driver not running */
+ VIR_ERR_INVALID_INTERFACE, /* invalid interface object */
+ VIR_ERR_MULTIPLE_INTERFACES, /* more than one matching interface found */
+ VIR_WAR_NO_SECRET, /* failed to start secret storage */
+ VIR_ERR_INVALID_SECRET, /* invalid secret */
+ VIR_ERR_NO_SECRET, /* secret not found */
+ VIR_ERR_CONFIG_UNSUPPORTED, /* unsupported configuration construct */
+ VIR_ERR_OPERATION_TIMEOUT, /* timeout occurred during operation */
+ VIR_ERR_MIGRATE_PERSIST_FAILED, /* a migration worked, but making the
+ VM persist on the dest host failed */
+ VIR_ERR_HOOK_SCRIPT_FAILED, /* a synchronous hook script failed */
+ VIR_ERR_INVALID_DOMAIN_SNAPSHOT, /* invalid domain snapshot */
+ VIR_ERR_NO_DOMAIN_SNAPSHOT, /* domain snapshot not found */
+ VIR_ERR_INVALID_STREAM, /* stream pointer not valid */
+ VIR_ERR_ARGUMENT_UNSUPPORTED, /* valid API use but unsupported by
+ the given driver */
+ VIR_ERR_STORAGE_PROBE_FAILED, /* storage pool probe failed */
+ VIR_ERR_STORAGE_POOL_BUILT, /* storage pool already built */
+ VIR_ERR_SNAPSHOT_REVERT_RISKY, /* force was not requested for a
+ risky domain snapshot revert */
+ VIR_ERR_OPERATION_ABORTED, /* operation on a domain was
+ canceled/aborted by user */
+ VIR_ERR_AUTH_CANCELLED, /* authentication cancelled */
+ VIR_ERR_NO_DOMAIN_METADATA, /* The metadata is not present */
+ VIR_ERR_MIGRATE_UNSAFE, /* Migration is not safe */
+ VIR_ERR_OVERFLOW, /* integer overflow */
+ VIR_ERR_BLOCK_COPY_ACTIVE, /* action prevented by block copy job */
+ VIR_ERR_UNKNOWN; /* unknown error (must be the last entry!) */
protected static final ErrorNumber wrap(int value) {
return safeElementAt(value, values());
@@ -340,9 +213,9 @@ public class Error implements Serializable {
private NetworkPointer VNP; /* Deprecated */
public Error(virError vError) {
- code = ErrorNumber.wrap(vError.code);
- domain = ErrorDomain.wrap(vError.domain);
- level = ErrorLevel.wrap(vError.level);
+ code = code.wrap(vError.code);
+ domain = domain.wrap(vError.domain);
+ level = level.wrap(vError.level);
message = vError.message;
str1 = vError.str1;
str2 = vError.str2;
@@ -355,9 +228,9 @@ public class Error implements Serializable {
}
/**
- * Gets the error code
+ * Gets he error code
*
- * @return a VirErrorNumber
+ * @return a VirErroNumber
*/
public ErrorNumber getCode() {
return code;
@@ -421,7 +294,7 @@ public class Error implements Serializable {
}
/**
- * Returns a human-readable informative error message
+ * Returns human-readable informative error messag
*
* @return error message
*/
diff --git a/src/main/java/org/libvirt/ErrorHandler.java
b/src/main/java/org/libvirt/ErrorHandler.java
index c2e7337..434c85d 100644
--- a/src/main/java/org/libvirt/ErrorHandler.java
+++ b/src/main/java/org/libvirt/ErrorHandler.java
@@ -3,11 +3,6 @@ package org.libvirt;
import org.libvirt.jna.Libvirt;
import org.libvirt.jna.virError;
-import static org.libvirt.Library.libvirt;
-
-import com.sun.jna.Pointer;
-import com.sun.jna.PointerType;
-
/**
* Utility class which processes the last error from the libvirt library. It
* turns errors into Libvirt Exceptions.
@@ -16,7 +11,14 @@ import com.sun.jna.PointerType;
*/
public class ErrorHandler {
- private static final void processError() throws LibvirtException {
+ /**
+ * Look for the latest error from libvirt not tied to a connection
+ *
+ * @param libvirt
+ * the active connection
+ * @throws LibvirtException
+ */
+ public static void processError(Libvirt libvirt) throws LibvirtException {
virError vError = libvirt.virGetLastError();
if (vError != null) {
Error error = new Error(vError);
@@ -28,44 +30,4 @@ public class ErrorHandler {
}
}
}
-
- /**
- * Calls {@link #processError()} when the given libvirt return code
- * indicates an error.
- *
- * @param ret libvirt return code, indicating error if -1.
- * @return {@code ret}
- * @throws LibvirtException
- */
- static final int processError(int ret) throws LibvirtException {
- if (ret == -1) processError();
- return ret;
- }
-
- /**
- * Calls {@link #processError()} if {@code arg} is null.
- *
- * @param arg An arbitrary object returned by libvirt.
- * @return {@code arg}
- * @throws LibvirtException
- */
- static final <T extends PointerType> T processError(T arg) throws
LibvirtException {
- if (arg == null) processError();
- return arg;
- }
-
- static final Pointer processError(Pointer arg) throws LibvirtException {
- if (arg == null) processError();
- return arg;
- }
-
- static final String processError(String str) throws LibvirtException {
- if (str == null) processError();
- return str;
- }
-
- static final long processErrorIfZero(long ret) throws LibvirtException {
- if (ret == 0) processError();
- return ret;
- }
}
diff --git a/src/main/java/org/libvirt/Interface.java
b/src/main/java/org/libvirt/Interface.java
index e0ddc3f..7782fb9 100644
--- a/src/main/java/org/libvirt/Interface.java
+++ b/src/main/java/org/libvirt/Interface.java
@@ -2,7 +2,6 @@ package org.libvirt;
import org.libvirt.jna.InterfacePointer;
import static org.libvirt.Library.libvirt;
-import static org.libvirt.ErrorHandler.processError;
import com.sun.jna.Pointer;
@@ -41,37 +40,27 @@ public class Interface {
}
/**
- * Activate an interface (i.e. call "ifup").
- * <p>
- * If there was an open network config transaction at the time
- * this interface was defined (that is, if
- * virInterfaceChangeBegin() had been called), the interface will
- * be brought back down (and then undefined) if
- * virInterfaceChangeRollback() is called.
+ * Create and start a defined network. If the call succeed the network moves
+ * from the defined to the running networks pools.
*
* @throws LibvirtException
*/
public int create() throws LibvirtException {
- return processError(libvirt.virInterfaceCreate(VIP));
+ int returnValue = libvirt.virInterfaceCreate(VIP);
+ processError();
+ return returnValue;
}
/**
- * Deactivate an interface (i.e. call "ifdown").
- * <p>
- * This does not remove the interface from the config, and does
- * not free the associated virInterfacePtr object.
- * <p>
- * If there is an open network config transaction at the time this
- * interface is destroyed (that is, if virInterfaceChangeBegin()
- * had been called), and if the interface is later undefined and
- * then virInterfaceChangeRollback() is called, the restoral of
- * the interface definition will also bring the interface back
- * up.
+ * Destroy the network object. The running instance is shutdown if not down
+ * already and all resources used by it are given back to the hypervisor.
*
* @throws LibvirtException
*/
public int destroy() throws LibvirtException {
- return processError(libvirt.virInterfaceDestroy(VIP));
+ int returnValue = libvirt.virInterfaceDestroy(VIP);
+ processError();
+ return returnValue;
}
@Override
@@ -84,12 +73,13 @@ public class Interface {
* structure is freed and should not be used thereafter.
*
* @throws LibvirtException
- * @return number of references left (>= 0)
+ * @return number of references left (>= 0) for success, -1 for failure.
*/
public int free() throws LibvirtException {
int success = 0;
if (VIP != null) {
- success = processError(libvirt.virInterfaceFree(VIP));
+ success = libvirt.virInterfaceFree(VIP);
+ processError();
VIP = null;
}
@@ -102,7 +92,9 @@ public class Interface {
* @throws LibvirtException
*/
public String getMACString() throws LibvirtException {
- return processError(libvirt.virInterfaceGetMACString(VIP));
+ String name = libvirt.virInterfaceGetMACString(VIP);
+ processError();
+ return name;
}
/**
@@ -111,7 +103,9 @@ public class Interface {
* @throws LibvirtException
*/
public String getName() throws LibvirtException {
- return processError(libvirt.virInterfaceGetName(VIP));
+ String name = libvirt.virInterfaceGetName(VIP);
+ processError();
+ return name;
}
/**
@@ -120,7 +114,8 @@ public class Interface {
* @throws LibvirtException
*/
public String getXMLDescription(int flags) throws LibvirtException {
- Pointer xml = processError(libvirt.virInterfaceGetXMLDesc(VIP, flags));
+ Pointer xml = libvirt.virInterfaceGetXMLDesc(VIP, flags);
+ processError();
try {
return Library.getString(xml);
} finally {
@@ -134,11 +129,21 @@ public class Interface {
* @see <a
*
href="http://www.libvirt.org/html/libvirt-libvirt.html#virInterfaceI...
* Documentation</a>
- * @return 1 if running, 0 if inactive
+ * @return 1 if running, 0 if inactive, -1 on error
* @throws LibvirtException
*/
public int isActive() throws LibvirtException {
- return processError(libvirt.virInterfaceIsActive(VIP));
+ int returnValue = libvirt.virInterfaceIsActive(VIP);
+ processError();
+ return returnValue;
+ }
+
+ /**
+ * Error handling logic to throw errors. Must be called after every libvirt
+ * call.
+ */
+ protected void processError() throws LibvirtException {
+ virConnect.processError();
}
/**
@@ -148,6 +153,8 @@ public class Interface {
* @throws LibvirtException
*/
public int undefine() throws LibvirtException {
- return processError(libvirt.virInterfaceUndefine(VIP));
+ int returnValue = libvirt.virInterfaceUndefine(VIP);
+ processError();
+ return returnValue;
}
}
diff --git a/src/main/java/org/libvirt/Library.java
b/src/main/java/org/libvirt/Library.java
index 6f12c37..0136095 100644
--- a/src/main/java/org/libvirt/Library.java
+++ b/src/main/java/org/libvirt/Library.java
@@ -1,7 +1,6 @@
package org.libvirt;
import org.libvirt.jna.Libvirt;
-import static org.libvirt.ErrorHandler.processError;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
@@ -24,9 +23,10 @@ final class Library {
// Load the native part
static {
+ Libvirt.INSTANCE.virInitialize();
libvirt = Libvirt.INSTANCE;
try {
- processError(libvirt.virInitialize());
+ ErrorHandler.processError(Libvirt.INSTANCE);
} catch (Exception e) {
e.printStackTrace();
}
diff --git a/src/main/java/org/libvirt/Network.java
b/src/main/java/org/libvirt/Network.java
index 2a77028..2244c5d 100644
--- a/src/main/java/org/libvirt/Network.java
+++ b/src/main/java/org/libvirt/Network.java
@@ -3,7 +3,6 @@ package org.libvirt;
import org.libvirt.jna.Libvirt;
import org.libvirt.jna.NetworkPointer;
import static org.libvirt.Library.libvirt;
-import static org.libvirt.ErrorHandler.processError;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
@@ -44,7 +43,8 @@ public class Network {
* @throws LibvirtException
*/
public void create() throws LibvirtException {
- processError(libvirt.virNetworkCreate(VNP));
+ libvirt.virNetworkCreate(VNP);
+ processError();
}
/**
@@ -56,7 +56,8 @@ public class Network {
* @throws LibvirtException
*/
public void destroy() throws LibvirtException {
- processError(libvirt.virNetworkDestroy(VNP));
+ libvirt.virNetworkDestroy(VNP);
+ processError();
}
@Override
@@ -70,12 +71,13 @@ public class Network {
* return an error.
*
* @throws LibvirtException
- * @return number of references left (>= 0)
+ * @return number of references left (>= 0) for success, -1 for failure.
*/
public int free() throws LibvirtException {
int success = 0;
if (VNP != null) {
- success = processError(libvirt.virNetworkFree(VNP));
+ success = libvirt.virNetworkFree(VNP);
+ processError();
VNP = null;
}
@@ -91,7 +93,8 @@ public class Network {
*/
public boolean getAutostart() throws LibvirtException {
IntByReference autoStart = new IntByReference();
- processError(libvirt.virNetworkGetAutostart(VNP, autoStart));
+ libvirt.virNetworkGetAutostart(VNP, autoStart);
+ processError();
return (autoStart.getValue() != 0) ? true : false;
}
@@ -103,7 +106,8 @@ public class Network {
* @throws LibvirtException
*/
public String getBridgeName() throws LibvirtException {
- final Pointer ptr = processError(libvirt.virNetworkGetBridgeName(VNP));
+ final Pointer ptr = libvirt.virNetworkGetBridgeName(VNP);
+ processError();
try {
return Library.getString(ptr);
} finally {
@@ -127,7 +131,9 @@ public class Network {
* @throws LibvirtException
*/
public String getName() throws LibvirtException {
- return processError(libvirt.virNetworkGetName(VNP));
+ String returnValue = libvirt.virNetworkGetName(VNP);
+ processError();
+ return returnValue;
}
/**
@@ -139,8 +145,13 @@ public class Network {
*/
public int[] getUUID() throws LibvirtException {
byte[] bytes = new byte[Libvirt.VIR_UUID_BUFLEN];
- processError(libvirt.virNetworkGetUUID(VNP, bytes));
- return Connect.convertUUIDBytes(bytes);
+ int success = libvirt.virNetworkGetUUID(VNP, bytes);
+ processError();
+ int[] returnValue = new int[0];
+ if (success == 0) {
+ returnValue = Connect.convertUUIDBytes(bytes);
+ }
+ return returnValue;
}
/**
@@ -152,8 +163,13 @@ public class Network {
*/
public String getUUIDString() throws LibvirtException {
byte[] bytes = new byte[Libvirt.VIR_UUID_STRING_BUFLEN];
- processError(libvirt.virNetworkGetUUIDString(VNP, bytes));
- return Native.toString(bytes);
+ int success = libvirt.virNetworkGetUUIDString(VNP, bytes);
+ processError();
+ String returnValue = null;
+ if (success == 0) {
+ returnValue = Native.toString(bytes);
+ }
+ return returnValue;
}
/**
@@ -167,7 +183,8 @@ public class Network {
* @throws LibvirtException
*/
public String getXMLDesc(int flags) throws LibvirtException {
- Pointer ptr = processError(libvirt.virNetworkGetXMLDesc(VNP, flags));
+ Pointer ptr = libvirt.virNetworkGetXMLDesc(VNP, flags);
+ processError();
try {
return Library.getString(ptr);
} finally {
@@ -185,7 +202,9 @@ public class Network {
* @throws LibvirtException
*/
public int isActive() throws LibvirtException {
- return processError(libvirt.virNetworkIsActive(VNP));
+ int returnValue = libvirt.virNetworkIsActive(VNP);
+ processError();
+ return returnValue;
}
/**
@@ -199,7 +218,13 @@ public class Network {
* @throws LibvirtException
*/
public int isPersistent() throws LibvirtException {
- return processError(libvirt.virNetworkIsPersistent(VNP));
+ int returnValue = libvirt.virNetworkIsPersistent(VNP);
+ processError();
+ return returnValue;
+ }
+
+ protected void processError() throws LibvirtException {
+ virConnect.processError();
}
/**
@@ -212,7 +237,8 @@ public class Network {
*/
public void setAutostart(boolean autostart) throws LibvirtException {
int autoValue = autostart ? 1 : 0;
- processError(libvirt.virNetworkSetAutostart(VNP, autoValue));
+ libvirt.virNetworkSetAutostart(VNP, autoValue);
+ processError();
}
/**
@@ -221,7 +247,8 @@ public class Network {
* @throws LibvirtException
*/
public void undefine() throws LibvirtException {
- processError(libvirt.virNetworkUndefine(VNP));
+ libvirt.virNetworkUndefine(VNP);
+ processError();
}
}
diff --git a/src/main/java/org/libvirt/NetworkFilter.java
b/src/main/java/org/libvirt/NetworkFilter.java
index 4f4bc6c..ba4d2ea 100644
--- a/src/main/java/org/libvirt/NetworkFilter.java
+++ b/src/main/java/org/libvirt/NetworkFilter.java
@@ -3,7 +3,6 @@ package org.libvirt;
import org.libvirt.jna.Libvirt;
import org.libvirt.jna.NetworkFilterPointer;
import static org.libvirt.Library.libvirt;
-import static org.libvirt.ErrorHandler.processError;
import com.sun.jna.Native;
@@ -33,12 +32,13 @@ public class NetworkFilter {
* exist.
*
* @throws LibvirtException
- * @return <em>ignore</em> (always 0)
+ * @return 0 on success, or -1 on error.
*/
public int free() throws LibvirtException {
int success = 0;
if (NFP != null) {
- success = processError(libvirt.virNWFilterFree(NFP));
+ success = libvirt.virNWFilterFree(NFP);
+ processError();
NFP = null;
}
@@ -52,7 +52,9 @@ public class NetworkFilter {
* @throws LibvirtException
*/
public String getName() throws LibvirtException {
- return processError(libvirt.virNWFilterGetName(NFP));
+ String returnValue = libvirt.virNWFilterGetName(NFP);
+ processError();
+ return returnValue;
}
/**
@@ -64,8 +66,13 @@ public class NetworkFilter {
*/
public int[] getUUID() throws LibvirtException {
byte[] bytes = new byte[Libvirt.VIR_UUID_BUFLEN];
- processError(libvirt.virNWFilterGetUUID(NFP, bytes));
- return Connect.convertUUIDBytes(bytes);
+ int success = libvirt.virNWFilterGetUUID(NFP, bytes);
+ processError();
+ int[] returnValue = new int[0];
+ if (success == 0) {
+ returnValue = Connect.convertUUIDBytes(bytes);
+ }
+ return returnValue;
}
/**
@@ -77,8 +84,13 @@ public class NetworkFilter {
*/
public String getUUIDString() throws LibvirtException {
byte[] bytes = new byte[Libvirt.VIR_UUID_STRING_BUFLEN];
- processError(libvirt.virNWFilterGetUUIDString(NFP, bytes));
- return Native.toString(bytes);
+ int success = libvirt.virNWFilterGetUUIDString(NFP, bytes);
+ processError();
+ String returnValue = null;
+ if (success == 0) {
+ returnValue = Native.toString(bytes);
+ }
+ return returnValue;
}
/**
@@ -90,7 +102,17 @@ public class NetworkFilter {
* @return the XML document
*/
public String getXMLDesc() throws LibvirtException {
- return processError(libvirt.virNWFilterGetXMLDesc(NFP, 0));
+ String returnValue = libvirt.virNWFilterGetXMLDesc(NFP, 0);
+ processError();
+ return returnValue;
+ }
+
+ /**
+ * Error handling logic to throw errors. Must be called after every libvirt
+ * call.
+ */
+ protected void processError() throws LibvirtException {
+ virConnect.processError();
}
/**
@@ -99,6 +121,7 @@ public class NetworkFilter {
* @throws LibvirtException
*/
public void undefine() throws LibvirtException {
- processError(libvirt.virNWFilterUndefine(NFP));
+ libvirt.virNWFilterUndefine(NFP);
+ processError();
}
}
diff --git a/src/main/java/org/libvirt/Secret.java
b/src/main/java/org/libvirt/Secret.java
index 868fcc8..5332e02 100644
--- a/src/main/java/org/libvirt/Secret.java
+++ b/src/main/java/org/libvirt/Secret.java
@@ -2,12 +2,11 @@ package org.libvirt;
import org.libvirt.jna.Libvirt;
import org.libvirt.jna.SecretPointer;
-import org.libvirt.jna.SizeT;
-import org.libvirt.jna.SizeTByReference;
import static org.libvirt.Library.libvirt;
-import static org.libvirt.ErrorHandler.processError;
import com.sun.jna.Native;
+import com.sun.jna.NativeLong;
+import com.sun.jna.ptr.LongByReference;
import com.sun.jna.Pointer;
import java.nio.ByteBuffer;
@@ -40,12 +39,13 @@ public class Secret {
* Release the secret handle. The underlying secret continues to exist.
*
* @throws LibvirtException
- * @return <em>ignore</em> (always 0)
+ * @return 0 on success, or -1 on error.
*/
public int free() throws LibvirtException {
int success = 0;
if (VSP != null) {
- success = processError(libvirt.virSecretFree(VSP));
+ success = libvirt.virSecretFree(VSP);
+ processError();
VSP = null;
}
@@ -61,7 +61,9 @@ public class Secret {
* @throws LibvirtException
*/
public String getUsageID() throws LibvirtException {
- return processError(libvirt.virSecretGetUsageID(VSP));
+ String returnValue = libvirt.virSecretGetUsageID(VSP);
+ processError();
+ return returnValue;
}
/**
@@ -73,8 +75,13 @@ public class Secret {
*/
public int[] getUUID() throws LibvirtException {
byte[] bytes = new byte[Libvirt.VIR_UUID_BUFLEN];
- processError(libvirt.virSecretGetUUID(VSP, bytes));
- return Connect.convertUUIDBytes(bytes);
+ int success = libvirt.virSecretGetUUID(VSP, bytes);
+ processError();
+ int[] returnValue = new int[0];
+ if (success == 0) {
+ returnValue = Connect.convertUUIDBytes(bytes);
+ }
+ return returnValue;
}
/**
@@ -86,8 +93,13 @@ public class Secret {
*/
public String getUUIDString() throws LibvirtException {
byte[] bytes = new byte[Libvirt.VIR_UUID_STRING_BUFLEN];
- processError(libvirt.virSecretGetUUIDString(VSP, bytes));
- return Native.toString(bytes);
+ int success = libvirt.virSecretGetUUIDString(VSP, bytes);
+ processError();
+ String returnValue = null;
+ if (success == 0) {
+ returnValue = Native.toString(bytes);
+ }
+ return returnValue;
}
/**
@@ -108,8 +120,9 @@ public class Secret {
* @return the value of the secret, or null on failure.
*/
public byte[] getByteValue() throws LibvirtException {
- SizeTByReference value_size = new SizeTByReference();
- Pointer value = processError(libvirt.virSecretGetValue(VSP, value_size, 0));
+ LongByReference value_size = new LongByReference();
+ Pointer value = libvirt.virSecretGetValue(VSP, value_size, 0);
+ processError();
ByteBuffer bb = value.getByteBuffer(0, value_size.getValue());
byte[] returnValue = new byte[bb.remaining()];
bb.get(returnValue);
@@ -122,33 +135,49 @@ public class Secret {
* @return the XML document
*/
public String getXMLDesc() throws LibvirtException {
- return processError(libvirt.virSecretGetXMLDesc(VSP, 0));
+ String returnValue = libvirt.virSecretGetXMLDesc(VSP, 0);
+ processError();
+ return returnValue;
+ }
+
+ /**
+ * Error handling logic to throw errors. Must be called after every libvirt
+ * call.
+ */
+ protected void processError() throws LibvirtException {
+ virConnect.processError();
}
/**
* Sets the value of the secret
*
- * @return <em>ignore</em> (always 0)
+ * @return 0 on success, -1 on failure.
*/
public int setValue(String value) throws LibvirtException {
- return processError(libvirt.virSecretSetValue(VSP, value, new
SizeT(value.length()), 0));
+ int returnValue = libvirt.virSecretSetValue(VSP, value, new
NativeLong(value.length()), 0);
+ processError();
+ return returnValue;
}
/**
* Sets the value of the secret
*
- * @return <em>ignore</em> (always 0)
+ * @return 0 on success, -1 on failure.
*/
public int setValue(byte[] value) throws LibvirtException {
- return processError(libvirt.virSecretSetValue(VSP, value, new
SizeT(value.length), 0));
+ int returnValue = libvirt.virSecretSetValue(VSP, value, new
NativeLong(value.length), 0);
+ processError();
+ return returnValue;
}
/**
* Undefines, but does not free, the Secret.
*
- * @return <em>ignore</em> (always 0)
+ * @return 0 on success, -1 on failure.
*/
public int undefine() throws LibvirtException {
- return processError(libvirt.virSecretUndefine(VSP));
+ int returnValue = libvirt.virSecretUndefine(VSP);
+ processError();
+ return returnValue;
}
}
diff --git a/src/main/java/org/libvirt/StoragePool.java
b/src/main/java/org/libvirt/StoragePool.java
index 14ecab8..2d59f68 100644
--- a/src/main/java/org/libvirt/StoragePool.java
+++ b/src/main/java/org/libvirt/StoragePool.java
@@ -5,10 +5,8 @@ import org.libvirt.jna.StoragePoolPointer;
import org.libvirt.jna.StorageVolPointer;
import org.libvirt.jna.virStoragePoolInfo;
import static org.libvirt.Library.libvirt;
-import static org.libvirt.ErrorHandler.processError;
import com.sun.jna.Native;
-import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
/**
@@ -74,7 +72,8 @@ public class StoragePool {
* future flags, use 0 for now
*/
public void build(int flags) throws LibvirtException {
- processError(libvirt.virStoragePoolBuild(VSPP, flags));
+ libvirt.virStoragePoolBuild(VSPP, flags);
+ processError();
}
/**
@@ -84,7 +83,8 @@ public class StoragePool {
* future flags, use 0 for now
*/
public void create(int flags) throws LibvirtException {
- processError(libvirt.virStoragePoolCreate(VSPP, flags));
+ libvirt.virStoragePoolCreate(VSPP, flags);
+ processError();
}
/**
@@ -95,7 +95,8 @@ public class StoragePool {
* flags for obliteration process
*/
public void delete(int flags) throws LibvirtException {
- processError(libvirt.virStoragePoolDelete(VSPP, flags));
+ libvirt.virStoragePoolDelete(VSPP, flags);
+ processError();
}
/**
@@ -105,7 +106,8 @@ public class StoragePool {
* This does not free the associated virStoragePoolPtr object.
*/
public void destroy() throws LibvirtException {
- processError(libvirt.virStoragePoolDestroy(VSPP));
+ libvirt.virStoragePoolDestroy(VSPP);
+ processError();
}
@Override
@@ -118,12 +120,13 @@ public class StoragePool {
* not change the state of the pool on the host.
*
* @throws LibvirtException
- * @return number of references left (>= 0)
+ * @return number of references left (>= 0) for success, -1 for failure.
*/
public int free() throws LibvirtException {
int success = 0;
if (VSPP != null) {
- success = processError(libvirt.virStoragePoolFree(VSPP));
+ success = libvirt.virStoragePoolFree(VSPP);
+ processError();
VSPP = null;
}
return success;
@@ -138,7 +141,8 @@ public class StoragePool {
*/
public boolean getAutostart() throws LibvirtException {
IntByReference autoStart = new IntByReference();
- processError(libvirt.virStoragePoolGetAutostart(VSPP, autoStart));
+ libvirt.virStoragePoolGetAutostart(VSPP, autoStart);
+ processError();
return autoStart.getValue() != 0 ? true : false;
}
@@ -160,7 +164,8 @@ public class StoragePool {
*/
public StoragePoolInfo getInfo() throws LibvirtException {
virStoragePoolInfo vInfo = new virStoragePoolInfo();
- processError(libvirt.virStoragePoolGetInfo(VSPP, vInfo));
+ libvirt.virStoragePoolGetInfo(VSPP, vInfo);
+ processError();
return new StoragePoolInfo(vInfo);
}
@@ -171,7 +176,9 @@ public class StoragePool {
* @throws LibvirtException
*/
public String getName() throws LibvirtException {
- return processError(libvirt.virStoragePoolGetName(VSPP));
+ String returnValue = libvirt.virStoragePoolGetName(VSPP);
+ processError();
+ return returnValue;
}
/**
@@ -182,8 +189,13 @@ public class StoragePool {
*/
public int[] getUUID() throws LibvirtException {
byte[] bytes = new byte[Libvirt.VIR_UUID_BUFLEN];
- processError(libvirt.virStoragePoolGetUUID(VSPP, bytes));
- return Connect.convertUUIDBytes(bytes);
+ int success = libvirt.virStoragePoolGetUUID(VSPP, bytes);
+ processError();
+ int[] returnValue = new int[0];
+ if (success == 0) {
+ returnValue = Connect.convertUUIDBytes(bytes);
+ }
+ return returnValue;
}
/**
@@ -194,8 +206,13 @@ public class StoragePool {
*/
public String getUUIDString() throws LibvirtException {
byte[] bytes = new byte[Libvirt.VIR_UUID_STRING_BUFLEN];
- processError(libvirt.virStoragePoolGetUUIDString(VSPP, bytes));
- return Native.toString(bytes);
+ int success = libvirt.virStoragePoolGetUUIDString(VSPP, bytes);
+ processError();
+ String returnValue = null;
+ if (success == 0) {
+ returnValue = Native.toString(bytes);
+ }
+ return returnValue;
}
/**
@@ -207,7 +224,9 @@ public class StoragePool {
* @return a XML document -java @throws LibvirtException
*/
public String getXMLDesc(int flags) throws LibvirtException {
- return processError(libvirt.virStoragePoolGetXMLDesc(VSPP, flags));
+ String returnValue = libvirt.virStoragePoolGetXMLDesc(VSPP, flags);
+ processError();
+ return returnValue;
}
/**
@@ -216,11 +235,13 @@ public class StoragePool {
* @see <a
*
href="http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoo...
* Documentation</a>
- * @return 1 if running, 0 if inactive
+ * @return 1 if running, 0 if inactive, -1 on error
* @throws LibvirtException
*/
public int isActive() throws LibvirtException {
- return processError(libvirt.virStoragePoolIsActive(VSPP));
+ int returnValue = libvirt.virStoragePoolIsActive(VSPP);
+ processError();
+ return returnValue;
}
/**
@@ -230,11 +251,13 @@ public class StoragePool {
* @see <a
*
href="http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoo...
* Documentation</a>
- * @return 1 if persistent, 0 if transient
+ * @return 1 if persistent, 0 if transient, -1 on error
* @throws LibvirtException
*/
public int isPersistent() throws LibvirtException {
- return processError(libvirt.virStoragePoolIsPersistent(VSPP));
+ int returnValue = libvirt.virStoragePoolIsPersistent(VSPP);
+ processError();
+ return returnValue;
}
/**
@@ -246,15 +269,10 @@ public class StoragePool {
*/
public String[] listVolumes() throws LibvirtException {
int num = numOfVolumes();
- if (num > 0) {
- Pointer[] ptrs = new Pointer[num];
-
- int got = processError(libvirt.virStoragePoolListVolumes(VSPP, ptrs, num));
-
- return Library.toStringArray(ptrs, got);
- } else {
- return Library.NO_STRINGS;
- }
+ String[] returnValue = new String[num];
+ libvirt.virStoragePoolListVolumes(VSPP, returnValue, num);
+ processError();
+ return returnValue;
}
/**
@@ -264,7 +282,13 @@ public class StoragePool {
* @throws LibvirtException
*/
public int numOfVolumes() throws LibvirtException {
- return processError(libvirt.virStoragePoolNumOfVolumes(VSPP));
+ int returnValue = libvirt.virStoragePoolNumOfVolumes(VSPP);
+ processError();
+ return returnValue;
+ }
+
+ protected void processError() throws LibvirtException {
+ virConnect.processError();
}
/**
@@ -277,7 +301,8 @@ public class StoragePool {
* @throws LibvirtException
*/
public void refresh(int flags) throws LibvirtException {
- processError(libvirt.virStoragePoolRefresh(VSPP, flags));
+ libvirt.virStoragePoolRefresh(VSPP, flags);
+ processError();
}
/**
@@ -303,7 +328,8 @@ public class StoragePool {
* @throws LibvirtException
*/
public StorageVol storageVolCreateXML(String xmlDesc, int flags) throws
LibvirtException {
- StorageVolPointer sPtr = processError(libvirt.virStorageVolCreateXML(VSPP,
xmlDesc, flags));
+ StorageVolPointer sPtr = libvirt.virStorageVolCreateXML(VSPP, xmlDesc, flags);
+ processError();
return new StorageVol(virConnect, sPtr);
}
@@ -312,12 +338,13 @@ public class StoragePool {
* as input. Information for the new volume (name, perms) are passed via a
* typical volume XML description.
*
- * @return The storage volume
+ * @return The storage volume, or {@code null} on error.
* @throws LibvirtException
*/
public StorageVol storageVolCreateXMLFrom(String xmlDesc, StorageVol cloneVolume, int
flags)
throws LibvirtException {
- StorageVolPointer sPtr = processError(libvirt.virStorageVolCreateXMLFrom(VSPP,
xmlDesc, cloneVolume.VSVP, flags));
+ StorageVolPointer sPtr = libvirt.virStorageVolCreateXMLFrom(VSPP, xmlDesc,
cloneVolume.VSVP, flags);
+ processError();
return new StorageVol(virConnect, sPtr);
}
@@ -327,13 +354,13 @@ public class StoragePool {
*
* @param name
* name of storage volume
- * @return a StorageVol object, or {@code null} if not found.
+ * @return The StorageVol object found
* @throws LibvirtException
*/
public StorageVol storageVolLookupByName(String name) throws LibvirtException {
- StorageVolPointer sPtr = processError(libvirt.virStorageVolLookupByName(VSPP,
name));
-
- return (sPtr == null) ? null : new StorageVol(virConnect, sPtr);
+ StorageVolPointer sPtr = libvirt.virStorageVolLookupByName(VSPP, name);
+ processError();
+ return new StorageVol(virConnect, sPtr);
}
/**
@@ -342,7 +369,8 @@ public class StoragePool {
* @throws LibvirtException
*/
public void undefine() throws LibvirtException {
- processError(libvirt.virStoragePoolUndefine(VSPP));
+ libvirt.virStoragePoolUndefine(VSPP);
+ processError();
}
}
diff --git a/src/main/java/org/libvirt/StorageVol.java
b/src/main/java/org/libvirt/StorageVol.java
index 47b79f6..561cb4d 100644
--- a/src/main/java/org/libvirt/StorageVol.java
+++ b/src/main/java/org/libvirt/StorageVol.java
@@ -4,9 +4,6 @@ import org.libvirt.jna.StoragePoolPointer;
import org.libvirt.jna.StorageVolPointer;
import org.libvirt.jna.virStorageVolInfo;
import static org.libvirt.Library.libvirt;
-import static org.libvirt.ErrorHandler.processError;
-
-import com.sun.jna.Pointer;
/**
* An acutal storage bucket.
@@ -85,7 +82,8 @@ public class StorageVol {
* @throws LibvirtException
*/
public void delete(int flags) throws LibvirtException {
- processError(libvirt.virStorageVolDelete(VSVP, flags));
+ libvirt.virStorageVolDelete(VSVP, flags);
+ processError();
}
@Override
@@ -98,12 +96,13 @@ public class StorageVol {
* to exist
*
* @throws LibvirtException
- * @return number of references left (>= 0)
+ * @return number of references left (>= 0) for success, -1 for failure.
*/
public int free() throws LibvirtException {
int success = 0;
if (VSVP != null) {
- success = processError(libvirt.virStorageVolFree(VSVP));
+ libvirt.virStorageVolFree(VSVP);
+ processError();
VSVP = null;
}
return success;
@@ -128,7 +127,8 @@ public class StorageVol {
*/
public StorageVolInfo getInfo() throws LibvirtException {
virStorageVolInfo vInfo = new virStorageVolInfo();
- processError(libvirt.virStorageVolGetInfo(VSVP, vInfo));
+ libvirt.virStorageVolGetInfo(VSVP, vInfo);
+ processError();
return new StorageVolInfo(vInfo);
}
@@ -140,7 +140,9 @@ public class StorageVol {
* @throws LibvirtException
*/
public String getKey() throws LibvirtException {
- return processError(libvirt.virStorageVolGetKey(VSVP));
+ String returnValue = libvirt.virStorageVolGetKey(VSVP);
+ processError();
+ return returnValue;
}
/**
@@ -150,7 +152,9 @@ public class StorageVol {
* @throws LibvirtException
*/
public String getName() throws LibvirtException {
- return processError(libvirt.virStorageVolGetName(VSVP));
+ String returnValue = libvirt.virStorageVolGetName(VSVP);
+ processError();
+ return returnValue;
}
/**
@@ -163,13 +167,9 @@ public class StorageVol {
* @throws LibvirtException
*/
public String getPath() throws LibvirtException {
- Pointer p = processError(libvirt.virStorageVolGetPath(VSVP));
-
- try {
- return Library.getString(p);
- } finally {
- Library.free(p);
- }
+ String returnValue = libvirt.virStorageVolGetPath(VSVP);
+ processError();
+ return returnValue;
}
/**
@@ -181,35 +181,43 @@ public class StorageVol {
* @throws LibvirtException
*/
public String getXMLDesc(int flags) throws LibvirtException {
- Pointer p = processError(libvirt.virStorageVolGetXMLDesc(VSVP, flags));
+ String returnValue = libvirt.virStorageVolGetXMLDesc(VSVP, flags);
+ processError();
+ return returnValue;
+ }
- try {
- return Library.getString(p);
- } finally {
- Library.free(p);
- }
+ /**
+ * Error handling logic which should be called after every libvirt call
+ *
+ * @throws LibvirtException
+ */
+ protected void processError() throws LibvirtException {
+ virConnect.processError();
}
/**
* Fetch a storage pool which contains this volume
*
- * @return StoragePool object, or {@code null} if not found.
+ * @return StoragePool object,
* @throws LibvirtException
*/
public StoragePool storagePoolLookupByVolume() throws LibvirtException {
- StoragePoolPointer ptr =
processError(libvirt.virStoragePoolLookupByVolume(VSVP));
- return (ptr == null) ? null : new StoragePool(virConnect, ptr);
+ StoragePoolPointer ptr = libvirt.virStoragePoolLookupByVolume(VSVP);
+ processError();
+ return new StoragePool(virConnect, ptr);
}
/**
* Ensure data previously on a volume is not accessible to future reads
*
* @see <a
href="http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVol...
Documentation</a>
- * @return <em>ignore</em> (always 0)
+ * @return 0 on success, or -1 on error
* @throws LibvirtException
*/
public int wipe() throws LibvirtException {
- return processError(libvirt.virStorageVolWipe(VSVP, 0));
+ int returnValue = libvirt.virStorageVolWipe(VSVP, 0);
+ processError();
+ return returnValue;
}
/**
@@ -220,10 +228,12 @@ public class StorageVol {
* new capacity for volume
* @param flags
* flags for resizing, see libvirt API for exact flags
- * @return <em>ignore</em> (always 0)
+ * @return 0 on success, or -1 on error
* @throws LibvirtException
*/
public int resize(long capacity, int flags) throws LibvirtException {
- return processError(libvirt.virStorageVolResize(VSVP, capacity, flags));
+ int returnValue = libvirt.virStorageVolResize(VSVP, capacity, flags);
+ processError();
+ return returnValue;
}
}
diff --git a/src/main/java/org/libvirt/Stream.java
b/src/main/java/org/libvirt/Stream.java
index c36ed70..84e300c 100644
--- a/src/main/java/org/libvirt/Stream.java
+++ b/src/main/java/org/libvirt/Stream.java
@@ -1,10 +1,10 @@
package org.libvirt;
import org.libvirt.jna.Libvirt;
-import org.libvirt.jna.SizeT;
import org.libvirt.jna.StreamPointer;
import static org.libvirt.Library.libvirt;
-import static org.libvirt.ErrorHandler.processError;
+
+import com.sun.jna.NativeLong;
public class Stream {
@@ -28,11 +28,11 @@ public class Stream {
/**
* Request that the in progress data transfer be cancelled abnormally before
* the end of the stream has been reached
- *
- * @return <em>ignore</em> (always 0)
*/
public int abort() throws LibvirtException {
- return processError(libvirt.virStreamAbort(VSP));
+ int returnValue = libvirt.virStreamAbort(VSP);
+ processError();
+ return returnValue;
}
/**
@@ -46,11 +46,13 @@ public class Stream {
* the events to monitor
* @param cb
* the callback method
- * @return <em>ignore</em> (always 0)
+ * @return 0 for success, -1 for failure
* @throws LibvirtException
*/
public int addCallback(int events, Libvirt.VirStreamEventCallback cb) throws
LibvirtException {
- return processError(libvirt.virStreamEventAddCallback(VSP, events, cb, null,
null));
+ int returnValue = libvirt.virStreamEventAddCallback(VSP, events, cb, null,
null);
+ processError();
+ return returnValue;
}
@Override
@@ -62,24 +64,27 @@ public class Stream {
* Indicate that there is no further data is to be transmitted on the
* stream.
*
- * @return <em>ignore</em> (always 0)
+ * @return 0 if success, -1 if failure
* @throws LibvirtException
*/
public int finish() throws LibvirtException {
- return processError(libvirt.virStreamFinish(VSP));
+ int returnValue = libvirt.virStreamFinish(VSP);
+ processError();
+ return returnValue;
}
/**
* Decrement the reference count on a stream, releasing the stream object if
* the reference count has hit zero.
*
- * @return <em>ignore</em> (always 0)
* @throws LibvirtException
+ * @return 0 on success, or -1 on error.
*/
public int free() throws LibvirtException {
int success = 0;
if (VSP != null) {
- processError(libvirt.virStreamFree(VSP));
+ success = libvirt.virStreamFree(VSP);
+ processError();
VSP = null;
}
@@ -87,15 +92,25 @@ public class Stream {
}
/**
- * Receives data from the stream into the buffer provided.
+ * Error handling logic to throw errors. Must be called after every libvirt
+ * call.
+ */
+ protected void processError() throws LibvirtException {
+ virConnect.processError();
+ }
+
+ /**
+ * Receieves data from teh stream into the buffer provided.
*
* @param data
- * buffer to put the data into
+ * the put the sata into
* @return the number of bytes read, -1 on error, -2 if the buffer is empty
* @throws LibvirtException
*/
public int receive(byte[] data) throws LibvirtException {
- return processError(libvirt.virStreamRecv(VSP, data, new SizeT(data.length)));
+ int returnValue = libvirt.virStreamRecv(VSP, data, new NativeLong(data.length));
+ processError();
+ return returnValue;
}
/**
@@ -104,22 +119,26 @@ public class Stream {
* @see <a
href="http://www.libvirt.org/html/libvirt-libvirt.html#virStreamRecv...
* @param handler
* the callback handler
- * @return <em>ignore</em> (always 0)
+ * @return 0 if successfule, -1 otherwise
* @throws LibvirtException
*/
public int receiveAll(Libvirt.VirStreamSinkFunc handler) throws LibvirtException {
- return processError(libvirt.virStreamRecvAll(VSP, handler, null));
+ int returnValue = libvirt.virStreamRecvAll(VSP, handler, null);
+ processError();
+ return returnValue;
}
/**
* Remove an event callback from the stream
*
* @see <a
href="http://www.libvirt.org/html/libvirt-libvirt.html#virStreamEven...
Docs</a>
- * @return <em>ignore</em> (always 0)
+ * @return 0 for success, -1 for failure
* @throws LibvirtException
*/
public int removeCallback() throws LibvirtException {
- return processError(libvirt.virStreamEventRemoveCallback(VSP));
+ int returnValue = libvirt.virStreamEventRemoveCallback(VSP);
+ processError();
+ return returnValue;
}
/**
@@ -132,7 +151,9 @@ public class Stream {
* @throws LibvirtException
*/
public int send(String data) throws LibvirtException {
- return processError(libvirt.virStreamSend(VSP, data, new SizeT(data.length())));
+ int returnValue = libvirt.virStreamSend(VSP, data, new
NativeLong(data.length()));
+ processError();
+ return returnValue;
}
/**
@@ -143,11 +164,13 @@ public class Stream {
* Documentation</a>
* @param handler
* the callback handler
- * @return <em>ignore</em> (always 0)
+ * @return 0 if successfule, -1 otherwise
* @throws LibvirtException
*/
public int sendAll(Libvirt.VirStreamSourceFunc handler) throws LibvirtException {
- return processError(libvirt.virStreamSendAll(VSP, handler, null));
+ int returnValue = libvirt.virStreamSendAll(VSP, handler, null);
+ processError();
+ return returnValue;
}
/**
@@ -156,10 +179,12 @@ public class Stream {
* @see <a
href="http://www.libvirt.org/html/libvirt-libvirt.html#virStreamEven...
Docs</a>
* @param events
* the events to monitor
- * @return <em>ignore</em> (always 0)
+ * @return 0 for success, -1 for failure
* @throws LibvirtException
*/
public int updateCallback(int events) throws LibvirtException {
- return processError(libvirt.virStreamEventUpdateCallback(VSP, events));
+ int returnValue = libvirt.virStreamEventUpdateCallback(VSP, events);
+ processError();
+ return returnValue;
}
}
diff --git a/src/main/java/org/libvirt/jna/Libvirt.java
b/src/main/java/org/libvirt/jna/Libvirt.java
index 0e4c9fc..230d63c 100644
--- a/src/main/java/org/libvirt/jna/Libvirt.java
+++ b/src/main/java/org/libvirt/jna/Libvirt.java
@@ -4,7 +4,6 @@ import com.sun.jna.Callback;
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.NativeLong;
-import com.sun.jna.Platform;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.LongByReference;
@@ -97,13 +96,14 @@ public interface Libvirt extends Library {
void eventCallback(ConnectionPointer virConnectPtr, DomainPointer
virDomainPointer, Pointer opaque) ;
}
- Libvirt INSTANCE = (Libvirt) Native.loadLibrary(Platform.isWindows() ?
"virt-0" : "virt", Libvirt.class);
+ Libvirt INSTANCE = (Libvirt) Native.loadLibrary("virt", Libvirt.class);
// Constants we need
public static int VIR_UUID_BUFLEN = 16;
public static int VIR_UUID_STRING_BUFLEN = (36 + 1);
public static int VIR_DOMAIN_SCHED_FIELD_LENGTH = 80;
+ public static int VIR_NODE_CPU_STATS_FIELD_LENGTH = 256;
// Connection Functions
String virConnectBaselineCPU(ConnectionPointer virConnectPtr, String[] xmlCPUs, int
ncpus, int flags);
@@ -180,20 +180,26 @@ public interface Libvirt extends Library {
int virDomainAbortJob(DomainPointer virDomainPtr);
int virDomainAttachDevice(DomainPointer virDomainPtr, String deviceXML);
int virDomainAttachDeviceFlags(DomainPointer virDomainPtr, String deviceXML, int
flags);
- int virDomainBlockStats(DomainPointer virDomainPtr, String path, virDomainBlockStats
stats, SizeT size);
+ int virDomainBlockStats(DomainPointer virDomainPtr, String path, virDomainBlockStats
stats, int size);
int virDomainBlockResize(DomainPointer virDomainPtr, String disk, long size, int
flags);
int virDomainCoreDump(DomainPointer virDomainPtr, String to, int flags);
+ int virDomainGetVcpus(DomainPointer virDomainPtr, virDomainCPUStats[] stats, int
nr_stats,char[] map, int flags);
int virDomainCreate(DomainPointer virDomainPtr);
int virDomainCreateWithFlags(DomainPointer virDomainPtr, int flags);
DomainPointer virDomainCreateLinux(ConnectionPointer virConnectPtr, String xmlDesc,
int flags);
DomainPointer virDomainCreateXML(ConnectionPointer virConnectPtr, String xmlDesc, int
flags);
DomainPointer virDomainDefineXML(ConnectionPointer virConnectPtr, String xmlDesc);
int virDomainDestroy(DomainPointer virDomainPtr);
+ int virDomainDestroyFlags(DomainPointer virDomainPtr,long flags);
int virDomainDetachDevice(DomainPointer virDomainPtr, String deviceXML);
int virDomainDetachDeviceFlags(DomainPointer virDomainPtr, String deviceXML, int
flags);
int virDomainFree(DomainPointer virDomainPtr);
int virDomainGetAutostart(DomainPointer virDomainPtr, IntByReference value);
int virDomainGetBlockInfo(DomainPointer virDomainPtr, String path, virDomainBlockInfo
info, int flags);
+
+ int virDomainGetCPUStats(DomainPointer virDomainPtr,virTypedParameter[] params,
+ long nparams,int start_cpu,long ncpus,long flags);
+
int virDomainGetID(DomainPointer virDomainPtr);
int virDomainGetInfo(DomainPointer virDomainPtr, virDomainInfo vInfo);
int virDomainGetJobInfo(DomainPointer virDomainPtr, virDomainJobInfo vInfo);
@@ -210,7 +216,7 @@ public interface Libvirt extends Library {
Pointer virDomainGetXMLDesc(DomainPointer virDomainPtr, int flags);
int virDomainHasCurrentSnapshot(DomainPointer virDomainPtr, int flags);
int virDomainHasManagedSaveImage(DomainPointer virDomainPtr, int flags);
- int virDomainInterfaceStats(DomainPointer virDomainPtr, String path,
virDomainInterfaceStats stats, SizeT size);
+ int virDomainInterfaceStats(DomainPointer virDomainPtr, String path,
virDomainInterfaceStats stats, int size);
int virDomainIsActive(DomainPointer virDomainPtr);
int virDomainIsPersistent(DomainPointer virDomainPtr);
DomainPointer virDomainLookupByID(ConnectionPointer virConnectPtr, int id);
@@ -241,6 +247,7 @@ public interface Libvirt extends Library {
int virDomainSetSchedulerParameters(DomainPointer virDomainPtr, virSchedParameter[]
params, int nparams);
int virDomainSetVcpus(DomainPointer virDomainPtr, int nvcpus);
int virDomainShutdown(DomainPointer virDomainPtr);
+ int virDomainShutdownFlags(DomainPointer virDomainPtr,long flags);
int virDomainSuspend(DomainPointer virDomainPtr);
int virDomainUpdateDeviceFlags(DomainPointer virDomainPtr, String xml, int flags);
int virDomainUndefine(DomainPointer virDomainPtr);
@@ -271,7 +278,10 @@ public interface Libvirt extends Library {
int virNodeGetCellsFreeMemory(ConnectionPointer virConnectPtr, LongByReference
freeMems, int startCell,
int maxCells);
long virNodeGetFreeMemory(ConnectionPointer virConnectPtr);
-
+
+ int virNodeGetCPUStats(ConnectionPointer virConnectPtr, int cpuNum,
+ virNodeCPUStats[] stats,IntByReference nparams, long flags);
+
// Node/Device functions
int virNodeNumOfDevices(ConnectionPointer virConnectPtr, String capabilityName, int
flags);
int virNodeListDevices(ConnectionPointer virConnectPtr, String capabilityName,
Pointer[] names, int maxnames,
@@ -280,7 +290,7 @@ public interface Libvirt extends Library {
String virNodeDeviceGetName(DevicePointer virDevicePointer);
String virNodeDeviceGetParent(DevicePointer virDevicePointer);
int virNodeDeviceNumOfCaps(DevicePointer virDevicePointer);
- int virNodeDeviceListCaps(DevicePointer virDevicePointer, Pointer[] names, int
maxNames);
+ int virNodeDeviceListCaps(DevicePointer virDevicePointer, String[] names, int
maxNames);
String virNodeDeviceGetXMLDesc(DevicePointer virDevicePointer);
int virNodeDeviceFree(DevicePointer virDevicePointer);
int virNodeDeviceDettach(DevicePointer virDevicePointer);
@@ -303,7 +313,7 @@ public interface Libvirt extends Library {
int virStoragePoolGetUUID(StoragePoolPointer storagePoolPtr, byte[] uuidString);
int virStoragePoolGetUUIDString(StoragePoolPointer storagePoolPtr, byte[]
uuidString);
String virStoragePoolGetXMLDesc(StoragePoolPointer storagePoolPtr, int flags);
- int virStoragePoolListVolumes(StoragePoolPointer storagePoolPtr, Pointer[] names, int
maxnames);
+ int virStoragePoolListVolumes(StoragePoolPointer storagePoolPtr, String[] names, int
maxnames);
int virStoragePoolIsActive(StoragePoolPointer storagePoolPtr);
int virStoragePoolIsPersistent(StoragePoolPointer storagePoolPtr);
StoragePoolPointer virStoragePoolLookupByName(ConnectionPointer virConnectPtr, String
name);
@@ -324,8 +334,8 @@ public interface Libvirt extends Library {
int virStorageVolGetInfo(StorageVolPointer storageVolPtr, virStorageVolInfo info);
String virStorageVolGetKey(StorageVolPointer storageVolPtr);
String virStorageVolGetName(StorageVolPointer storageVolPtr);
- Pointer virStorageVolGetPath(StorageVolPointer storageVolPtr);
- Pointer virStorageVolGetXMLDesc(StorageVolPointer storageVolPtr, int flags);
+ String virStorageVolGetPath(StorageVolPointer storageVolPtr);
+ String virStorageVolGetXMLDesc(StorageVolPointer storageVolPtr, int flags);
StorageVolPointer virStorageVolLookupByKey(ConnectionPointer virConnectPtr, String
name);
StorageVolPointer virStorageVolLookupByName(StoragePoolPointer storagePoolPtr, String
name);
StorageVolPointer virStorageVolLookupByPath(ConnectionPointer virConnectPtr, String
path);
@@ -351,13 +361,13 @@ public interface Libvirt extends Library {
int virSecretGetUUID(SecretPointer virSecretPtr, byte[] uuidString);
int virSecretGetUUIDString(SecretPointer virSecretPtr, byte[] uuidString);
String virSecretGetUsageID(SecretPointer virSecretPtr);
- Pointer virSecretGetValue(SecretPointer virSecretPtr, SizeTByReference value_size,
int flags);
+ Pointer virSecretGetValue(SecretPointer virSecretPtr, LongByReference value_size, int
flags);
String virSecretGetXMLDesc(SecretPointer virSecretPtr, int flags);
SecretPointer virSecretLookupByUsage(ConnectionPointer virConnectPtr, int usageType,
String usageID);
SecretPointer virSecretLookupByUUID(ConnectionPointer virConnectPtr, byte[]
uuidBytes);
SecretPointer virSecretLookupByUUIDString(ConnectionPointer virConnectPtr, String
uuidstr);
- int virSecretSetValue(SecretPointer virSecretPtr, String value, SizeT value_size, int
flags);
- int virSecretSetValue(SecretPointer virSecretPtr, byte[] value, SizeT value_size, int
flags);
+ int virSecretSetValue(SecretPointer virSecretPtr, String value, NativeLong
value_size, int flags);
+ int virSecretSetValue(SecretPointer virSecretPtr, byte[] value, NativeLong
value_size, int flags);
int virSecretUndefine(SecretPointer virSecretPtr);
//Stream Methods
@@ -369,18 +379,18 @@ public interface Libvirt extends Library {
int virStreamFinish(StreamPointer virStreamPtr) ;
int virStreamFree(StreamPointer virStreamPtr) ;
StreamPointer virStreamNew(ConnectionPointer virConnectPtr, int flags) ;
- int virStreamSend(StreamPointer virStreamPtr, String data, SizeT size);
+ int virStreamSend(StreamPointer virStreamPtr, String data, NativeLong size);
int virStreamSendAll(StreamPointer virStreamPtr, Libvirt.VirStreamSourceFunc handler,
Pointer opaque);
- int virStreamRecv(StreamPointer virStreamPtr, byte[] data, SizeT length);
+ int virStreamRecv(StreamPointer virStreamPtr, byte[] data, NativeLong length);
int virStreamRecvAll(StreamPointer virStreamPtr, Libvirt.VirStreamSinkFunc handler,
Pointer opaque);
//DomainSnapshot Methods
DomainSnapshotPointer virDomainSnapshotCreateXML(DomainPointer virDomainPtr, String
xmlDesc, int flags);
DomainSnapshotPointer virDomainSnapshotCurrent(DomainPointer virDomainPtr, int
flags);
int virDomainSnapshotDelete(DomainSnapshotPointer virDomainSnapshotPtr, int flags);
- Pointer virDomainSnapshotGetXMLDesc(DomainSnapshotPointer virDomainSnapshotPtr, int
flags);
+ String virDomainSnapshotGetXMLDesc(DomainSnapshotPointer virDomainSnapshotPtr, int
flags);
int virDomainSnapshotFree(DomainSnapshotPointer virDomainSnapshotPtr);
- int virDomainSnapshotListNames(DomainPointer virDomainPtr, Pointer[] names, int
nameslen, int flags);
+ int virDomainSnapshotListNames(DomainPointer virDomainPtr, String[] names, int
nameslen, int flags);
DomainSnapshotPointer virDomainSnapshotLookupByName(DomainPointer virDomainPtr,
String name, int flags);
int virDomainSnapshotNum(DomainPointer virDomainPtr, int flags);
diff --git a/src/main/java/org/libvirt/jna/VirUnion.java
b/src/main/java/org/libvirt/jna/VirUnion.java
new file mode 100644
index 0000000..ba089e0
--- /dev/null
+++ b/src/main/java/org/libvirt/jna/VirUnion.java
@@ -0,0 +1,14 @@
+package org.libvirt.jna;
+
+import com.sun.jna.Union;
+import com.sun.jna.ptr.ByteByReference;
+
+public class VirUnion extends Union{
+ public int i;
+ public long ui;
+ public long l;
+ public long ul;
+ public double d;
+ public char b;
+ public ByteByReference s = new ByteByReference();
+}
diff --git a/src/main/java/org/libvirt/jna/virConnectAuth.java
b/src/main/java/org/libvirt/jna/virConnectAuth.java
index 0451348..ece61f6 100644
--- a/src/main/java/org/libvirt/jna/virConnectAuth.java
+++ b/src/main/java/org/libvirt/jna/virConnectAuth.java
@@ -15,11 +15,11 @@ public class virConnectAuth extends Structure {
public Libvirt.VirConnectAuthCallback cb;
public Pointer cbdata;
- private static final List<String> fields = Arrays.asList(
+ private static final List fields = Arrays.asList(
"credtype", "ncredtype", "cb",
"cbdata");
@Override
- protected List<String> getFieldOrder() {
+ protected List getFieldOrder() {
return fields;
}
}
diff --git a/src/main/java/org/libvirt/jna/virConnectCredential.java
b/src/main/java/org/libvirt/jna/virConnectCredential.java
index 316b1f4..6dd4a75 100644
--- a/src/main/java/org/libvirt/jna/virConnectCredential.java
+++ b/src/main/java/org/libvirt/jna/virConnectCredential.java
@@ -17,12 +17,12 @@ public class virConnectCredential extends Structure implements
Structure.ByRefer
public String result;
public int resultlen;
- private static final List<String> fields = Arrays.asList(
+ private static final List fields = Arrays.asList(
"type", "prompt", "challenge",
"defresult",
"result", "resultlen");
@Override
- protected List<String> getFieldOrder() {
+ protected List getFieldOrder() {
return fields;
}
}
diff --git a/src/main/java/org/libvirt/jna/virDomainBlockInfo.java
b/src/main/java/org/libvirt/jna/virDomainBlockInfo.java
index 5a88ba3..fb1b845 100644
--- a/src/main/java/org/libvirt/jna/virDomainBlockInfo.java
+++ b/src/main/java/org/libvirt/jna/virDomainBlockInfo.java
@@ -10,11 +10,11 @@ public class virDomainBlockInfo extends Structure {
public long allocation;
public long physical;
- private static final List<String> fields = Arrays.asList(
+ private static final List fields = Arrays.asList(
"capacity", "allocation", "physical");
@Override
- protected List<String> getFieldOrder() {
+ protected List getFieldOrder() {
return fields;
}
}
diff --git a/src/main/java/org/libvirt/jna/virDomainBlockStats.java
b/src/main/java/org/libvirt/jna/virDomainBlockStats.java
index e48629a..a7331f6 100644
--- a/src/main/java/org/libvirt/jna/virDomainBlockStats.java
+++ b/src/main/java/org/libvirt/jna/virDomainBlockStats.java
@@ -20,11 +20,11 @@ public class virDomainBlockStats extends Structure {
public long errs; // this is a long long in the code, so a long mapping is
// correct
- private static final List<String> fields = Arrays.asList(
+ private static final List fields = Arrays.asList(
"rd_req", "rd_bytes", "wr_req",
"wr_bytes", "errs");
@Override
- protected List<String> getFieldOrder() {
+ protected List getFieldOrder() {
return fields;
}
}
diff --git a/src/main/java/org/libvirt/jna/virDomainCPUStats.java
b/src/main/java/org/libvirt/jna/virDomainCPUStats.java
new file mode 100644
index 0000000..04d5377
--- /dev/null
+++ b/src/main/java/org/libvirt/jna/virDomainCPUStats.java
@@ -0,0 +1,21 @@
+package org.libvirt.jna;
+
+import java.util.Arrays;
+import java.util.List;
+
+import com.sun.jna.Structure;
+
+public class virDomainCPUStats extends Structure{
+ public long number ;
+ public long state ;
+ public long cpuTime;
+ public long cpu;
+
+ private static final List fields = Arrays.asList( "number",
"state",
+ "cpuTime","cpu");
+
+ @Override
+ protected List getFieldOrder() {
+ return fields;
+ }
+}
diff --git a/src/main/java/org/libvirt/jna/virDomainInfo.java
b/src/main/java/org/libvirt/jna/virDomainInfo.java
index ff20d16..0b667f6 100644
--- a/src/main/java/org/libvirt/jna/virDomainInfo.java
+++ b/src/main/java/org/libvirt/jna/virDomainInfo.java
@@ -16,11 +16,11 @@ public class virDomainInfo extends Structure {
public short nrVirtCpu;
public long cpuTime;
- private static final List<String> fields = Arrays.asList(
+ private static final List fields = Arrays.asList(
"state", "maxMem", "memory",
"nrVirtCpu", "cpuTime");
@Override
- protected List<String> getFieldOrder() {
+ protected List getFieldOrder() {
return fields;
}
}
diff --git a/src/main/java/org/libvirt/jna/virDomainInterfaceStats.java
b/src/main/java/org/libvirt/jna/virDomainInterfaceStats.java
index 9b98aa8..eea6a49 100644
--- a/src/main/java/org/libvirt/jna/virDomainInterfaceStats.java
+++ b/src/main/java/org/libvirt/jna/virDomainInterfaceStats.java
@@ -26,12 +26,12 @@ public class virDomainInterfaceStats extends Structure {
public long tx_drop; // this is a long long in the code, so a long mapping
// is correct
- private static final List<String> fields = Arrays.asList(
+ private static final List fields = Arrays.asList(
"rx_bytes", "rx_packets", "rx_errs",
"rx_drop",
"tx_bytes", "tx_packets", "tx_errs",
"tx_drop");
@Override
- protected List<String> getFieldOrder() {
+ protected List getFieldOrder() {
return fields;
}
}
diff --git a/src/main/java/org/libvirt/jna/virDomainJobInfo.java
b/src/main/java/org/libvirt/jna/virDomainJobInfo.java
index 1bab587..0398901 100644
--- a/src/main/java/org/libvirt/jna/virDomainJobInfo.java
+++ b/src/main/java/org/libvirt/jna/virDomainJobInfo.java
@@ -19,13 +19,13 @@ public class virDomainJobInfo extends Structure {
public long fileProcessed;
public long fileRemaining;
- private static final List<String> fields = Arrays.asList(
+ private static final List fields = Arrays.asList(
"type", "timeElapsed", "timeRemaining",
"dataTotal",
"dataProcessed", "dataRemaining", "memTotal",
"memProcessed",
"memRemaining", "fileTotal", "fileProcessed",
"fileRemaining");
@Override
- protected List<String> getFieldOrder() {
+ protected List getFieldOrder() {
return fields;
}
}
diff --git a/src/main/java/org/libvirt/jna/virDomainMemoryStats.java
b/src/main/java/org/libvirt/jna/virDomainMemoryStats.java
index dfbd3f9..b14fb95 100644
--- a/src/main/java/org/libvirt/jna/virDomainMemoryStats.java
+++ b/src/main/java/org/libvirt/jna/virDomainMemoryStats.java
@@ -9,10 +9,10 @@ public class virDomainMemoryStats extends Structure {
public int tag ;
public long val ;
- private static final List<String> fields = Arrays.asList( "tag",
"val");
+ private static final List fields = Arrays.asList( "tag", "val");
@Override
- protected List<String> getFieldOrder() {
+ protected List getFieldOrder() {
return fields;
}
}
diff --git a/src/main/java/org/libvirt/jna/virError.java
b/src/main/java/org/libvirt/jna/virError.java
index e58f5f3..36b9f69 100644
--- a/src/main/java/org/libvirt/jna/virError.java
+++ b/src/main/java/org/libvirt/jna/virError.java
@@ -22,12 +22,12 @@ public class virError extends Structure {
public int int2;
public NetworkPointer net;
- private static final List<String> fields = Arrays.asList(
+ private static final List fields = Arrays.asList(
"code", "domain", "message", "level",
"conn", "dom",
"str1", "str2", "str3", "int1",
"int2", "net");
@Override
- protected List<String> getFieldOrder() {
+ protected List getFieldOrder() {
return fields;
}
}
diff --git a/src/main/java/org/libvirt/jna/virNodeCPUStats.java
b/src/main/java/org/libvirt/jna/virNodeCPUStats.java
new file mode 100644
index 0000000..89c1a24
--- /dev/null
+++ b/src/main/java/org/libvirt/jna/virNodeCPUStats.java
@@ -0,0 +1,19 @@
+package org.libvirt.jna;
+
+import java.util.Arrays;
+import java.util.List;
+
+import com.sun.jna.NativeLong;
+import com.sun.jna.Structure;
+
+public class virNodeCPUStats extends Structure{
+ public byte[] tag = new byte[80];
+ public long val ;
+
+ private static final List fields = Arrays.asList( "tag", "val");
+
+ @Override
+ protected List getFieldOrder() {
+ return fields;
+ }
+}
diff --git a/src/main/java/org/libvirt/jna/virNodeInfo.java
b/src/main/java/org/libvirt/jna/virNodeInfo.java
index 7a7716e..9ff1251 100644
--- a/src/main/java/org/libvirt/jna/virNodeInfo.java
+++ b/src/main/java/org/libvirt/jna/virNodeInfo.java
@@ -25,12 +25,12 @@ public class virNodeInfo extends Structure {
public int cores;
public int threads;
- private static final List<String> fields = Arrays.asList(
+ private static final List fields = Arrays.asList(
"model", "memory", "cpus", "mhz",
"nodes",
"sockets", "cores", "threads");
@Override
- protected List<String> getFieldOrder() {
+ protected List getFieldOrder() {
return fields;
}
}
diff --git a/src/main/java/org/libvirt/jna/virSchedParameter.java
b/src/main/java/org/libvirt/jna/virSchedParameter.java
index f3787a9..f579ef0 100644
--- a/src/main/java/org/libvirt/jna/virSchedParameter.java
+++ b/src/main/java/org/libvirt/jna/virSchedParameter.java
@@ -13,11 +13,11 @@ public class virSchedParameter extends Structure {
public int type;
public virSchedParameterValue value;
- private static final List<String> fields = Arrays.asList(
+ private static final List fields = Arrays.asList(
"field", "type", "value");
@Override
- protected List<String> getFieldOrder() {
+ protected List getFieldOrder() {
return fields;
}
}
diff --git a/src/main/java/org/libvirt/jna/virStoragePoolInfo.java
b/src/main/java/org/libvirt/jna/virStoragePoolInfo.java
index 7077175..fe20f0f 100644
--- a/src/main/java/org/libvirt/jna/virStoragePoolInfo.java
+++ b/src/main/java/org/libvirt/jna/virStoragePoolInfo.java
@@ -17,11 +17,11 @@ public class virStoragePoolInfo extends Structure {
public long available; // this is a long long in the code, so a long mapping
// is correct
- private static final List<String> fields = Arrays.asList(
+ private static final List fields = Arrays.asList(
"state", "capacity", "allocation",
"available");
@Override
- protected List<String> getFieldOrder() {
+ protected List getFieldOrder() {
return fields;
}
}
diff --git a/src/main/java/org/libvirt/jna/virStorageVolInfo.java
b/src/main/java/org/libvirt/jna/virStorageVolInfo.java
index 8bf2d5c..93132ea 100644
--- a/src/main/java/org/libvirt/jna/virStorageVolInfo.java
+++ b/src/main/java/org/libvirt/jna/virStorageVolInfo.java
@@ -15,11 +15,11 @@ public class virStorageVolInfo extends Structure {
public long allocation; // this is a long long in the code, so a long
// mapping is correct
- private static final List<String> fields = Arrays.asList(
+ private static final List fields = Arrays.asList(
"type", "capacity", "allocation");
@Override
- protected List<String> getFieldOrder() {
+ protected List getFieldOrder() {
return fields;
}
}
diff --git a/src/main/java/org/libvirt/jna/virTypedParameter.java
b/src/main/java/org/libvirt/jna/virTypedParameter.java
new file mode 100644
index 0000000..4fe48f6
--- /dev/null
+++ b/src/main/java/org/libvirt/jna/virTypedParameter.java
@@ -0,0 +1,22 @@
+package org.libvirt.jna;
+
+import java.util.Arrays;
+import java.util.List;
+
+import com.sun.jna.Structure;
+
+public class virTypedParameter extends Structure{
+
+ public byte[] field = new byte[80];
+ public int type;
+ public VirUnion value;
+
+ private static final List fields = Arrays.asList( "field", "type",
+ "value");
+ @Override
+ protected List getFieldOrder() {
+ // TODO Auto-generated method stub
+ return fields;
+ }
+
+}
diff --git a/src/main/java/org/libvirt/jna/virVcpuInfo.java
b/src/main/java/org/libvirt/jna/virVcpuInfo.java
index bc1a539..96eca2f 100644
--- a/src/main/java/org/libvirt/jna/virVcpuInfo.java
+++ b/src/main/java/org/libvirt/jna/virVcpuInfo.java
@@ -15,11 +15,11 @@ public class virVcpuInfo extends Structure {
// is correct
public int cpu;
- private static final List<String> fields = Arrays.asList(
+ private static final List fields = Arrays.asList(
"number", "state", "cpuTime",
"cpu");
@Override
- protected List<String> getFieldOrder() {
+ protected List getFieldOrder() {
return fields;
}
}
--
1.8.3.2