--- src/org/libvirt/Connect.java | 187 ++++++++++++++--------- src/org/libvirt/ConnectAuth.java | 15 ++- src/org/libvirt/Domain.java | 7 +- src/org/libvirt/ErrorHandler.java | 3 +- src/org/libvirt/Network.java | 5 +- src/org/libvirt/StoragePool.java | 129 ++++++++++------ src/org/libvirt/StoragePoolInfo.java | 6 + src/org/libvirt/StorageVol.java | 67 ++++++--- src/org/libvirt/StorageVolInfo.java | 6 + src/org/libvirt/jna/Libvirt.java | 209 +++++++++++++++---------- src/org/libvirt/jna/virConnectAuth.java | 11 ++ src/org/libvirt/jna/virConnectCredential.java | 12 ++ src/test.java | 16 +- 13 files changed, 438 insertions(+), 235 deletions(-) create mode 100644 src/org/libvirt/jna/virConnectAuth.java create mode 100644 src/org/libvirt/jna/virConnectCredential.java diff --git a/src/org/libvirt/Connect.java b/src/org/libvirt/Connect.java index bab1d23..900f6fc 100644 --- a/src/org/libvirt/Connect.java +++ b/src/org/libvirt/Connect.java @@ -1,13 +1,22 @@ package org.libvirt; +import java.util.Arrays; + import org.libvirt.LibvirtException; import org.libvirt.StoragePool; import org.libvirt.StorageVol; +import org.libvirt.jna.ConnectionPointer; +import org.libvirt.jna.DomainPointer; import org.libvirt.jna.Libvirt; +import org.libvirt.jna.NetworkPointer; +import org.libvirt.jna.StoragePoolPointer; +import org.libvirt.jna.StorageVolPointer; +import org.libvirt.jna.virConnectAuth; import org.libvirt.jna.virError; import org.libvirt.jna.virNodeInfo; import com.sun.jna.Native; +import com.sun.jna.NativeLong; import com.sun.jna.Pointer; import com.sun.jna.ptr.ByReference; import com.sun.jna.ptr.LongByReference; @@ -34,7 +43,7 @@ public class Connect { /** * the native virConnectPtr. */ - protected Pointer VCP; + protected ConnectionPointer VCP; /** @@ -82,8 +91,18 @@ public class Connect { * @see <a href="http://libvirt.org/uri.html">The URI documentation</a> */ public Connect(String uri, ConnectAuth auth, int flags) throws LibvirtException { - throw new RuntimeException("Not Implemented") ; -// VCP = _openAuth(uri, auth, flags); + virConnectAuth vAuth = new virConnectAuth() ; + vAuth.cb = auth ; + vAuth.cbdata = null ; + vAuth.ncredtype = auth.credType.length ; + vAuth.credtype = new int[vAuth.ncredtype] ; + + for (int x = 0 ; x < vAuth.ncredtype ; x++) { + vAuth.credtype[x] = auth.credType[x].ordinal() ; + } + + VCP = libvirt.virConnectOpenAuth(uri, vAuth, flags) ; + processError() ; } /** @@ -378,7 +397,7 @@ public class Connect { public Network networkLookupByName(String name) throws LibvirtException { Network returnValue = null ; - Pointer ptr = libvirt.virNetworkLookupByName(VCP, name) ; + NetworkPointer ptr = libvirt.virNetworkLookupByName(VCP, name) ; processError() ; if (ptr != null) { returnValue = new Network(this, ptr) ; @@ -397,12 +416,9 @@ public class Connect { */ public Network networkLookupByUUID(int[] UUID) throws LibvirtException { - StringBuilder uuidString = new StringBuilder() ; - for (int i : UUID) { - uuidString.append(i) ; - } + String uuidString = Connect.createUUIDString(UUID) ; Network returnValue = null ; - Pointer ptr = libvirt.virNetworkLookupByUUID(VCP, uuidString.toString()) ; + NetworkPointer ptr = libvirt.virNetworkLookupByUUID(VCP, uuidString) ; processError() ; if (ptr != null) { returnValue = new Network(this, ptr) ; @@ -421,7 +437,7 @@ public class Connect { public Network networkLookupByUUIDString(String UUID) throws LibvirtException { Network returnValue = null ; - Pointer ptr = libvirt.virNetworkLookupByUUIDString(VCP, UUID); + NetworkPointer ptr = libvirt.virNetworkLookupByUUIDString(VCP, UUID); processError() ; if (ptr != null) { returnValue = new Network(this, ptr) ; @@ -442,7 +458,7 @@ public class Connect { public Network networkCreateXML(String xmlDesc) throws LibvirtException { Network returnValue = null ; - Pointer ptr = libvirt.virNetworkCreateXML(VCP, xmlDesc) ; + NetworkPointer ptr = libvirt.virNetworkCreateXML(VCP, xmlDesc) ; processError() ; if (ptr != null) { returnValue = new Network(this, ptr) ; @@ -463,7 +479,7 @@ public class Connect { public Network networkDefineXML(String xmlDesc) throws LibvirtException { Network returnValue = null ; - Pointer ptr = libvirt.virNetworkDefineXML(VCP, xmlDesc) ; + NetworkPointer ptr = libvirt.virNetworkDefineXML(VCP, xmlDesc) ; processError() ; if (ptr != null) { returnValue = new Network(this, ptr) ; @@ -481,7 +497,7 @@ public class Connect { */ public Domain domainLookupByID(int id) throws LibvirtException { Domain returnValue = null ; - Pointer ptr = libvirt.virDomainLookupByID(VCP, id) ; + DomainPointer ptr = libvirt.virDomainLookupByID(VCP, id) ; processError() ; if (ptr != null) { returnValue = new Domain(this, ptr) ; @@ -499,7 +515,7 @@ public class Connect { */ public Domain domainLookupByName(String name) throws LibvirtException { Domain returnValue = null ; - Pointer ptr = libvirt.virDomainLookupByName(VCP, name) ; + DomainPointer ptr = libvirt.virDomainLookupByName(VCP, name) ; processError() ; if (ptr != null) { returnValue = new Domain(this, ptr) ; @@ -517,12 +533,9 @@ public class Connect { * @throws LibvirtException */ public Domain domainLookupByUUID(int[] UUID) throws LibvirtException { - StringBuilder uuidString = new StringBuilder() ; - for (int i : UUID) { - uuidString.append(i) ; - } + String uuidString = Connect.createUUIDString(UUID) ; Domain returnValue = null ; - Pointer ptr = libvirt.virDomainLookupByUUID(VCP, uuidString.toString()) ; + DomainPointer ptr = libvirt.virDomainLookupByUUID(VCP, uuidString) ; processError() ; if (ptr != null) { returnValue = new Domain(this, ptr) ; @@ -540,7 +553,7 @@ public class Connect { public Domain domainLookupByUUIDString(String UUID) throws LibvirtException { Domain returnValue = null ; - Pointer ptr = libvirt.virDomainLookupByUUIDString(VCP, UUID) ; + DomainPointer ptr = libvirt.virDomainLookupByUUIDString(VCP, UUID) ; processError() ; if (ptr != null) { returnValue = new Domain(this, ptr) ; @@ -563,7 +576,7 @@ public class Connect { public Domain domainCreateLinux(String xmlDesc, int flags) throws LibvirtException { Domain returnValue = null ; - Pointer ptr = libvirt.virDomainCreateLinux(VCP, xmlDesc, flags) ; + DomainPointer ptr = libvirt.virDomainCreateLinux(VCP, xmlDesc, flags) ; processError() ; if (ptr != null) { returnValue = new Domain(this, ptr) ; @@ -582,7 +595,7 @@ public class Connect { */ public Domain domainDefineXML(String xmlDesc) throws LibvirtException { Domain returnValue = null ; - Pointer ptr = libvirt.virDomainDefineXML(VCP, xmlDesc) ; + DomainPointer ptr = libvirt.virDomainDefineXML(VCP, xmlDesc) ; processError() ; if (ptr != null) { returnValue = new Domain(this, ptr) ; @@ -601,7 +614,7 @@ public class Connect { */ public Domain domainCreateXML(String xmlDesc, int flags) throws LibvirtException { Domain returnValue = null ; - Pointer ptr = libvirt.virDomainCreateXML(VCP, xmlDesc, flags) ; + DomainPointer ptr = libvirt.virDomainCreateXML(VCP, xmlDesc, flags) ; processError() ; if (ptr != null) { returnValue = new Domain(this, ptr) ; @@ -617,12 +630,10 @@ public class Connect { * @throws LibvirtException */ public void restore(String from) throws LibvirtException { - throw new RuntimeException("Not Implemented") ; -// _virDomainRestore(VCP, from); + libvirt.virDomainRestore(VCP, from); + processError() ; } -// private native int _virDomainRestore(long VCP, String from) -// throws LibvirtException; /** * Returns a NodeInfo object describing the hardware configuration of the node. @@ -647,11 +658,10 @@ public class Connect { * @throws LibvirtException */ public void setDom0Memory(long memory) throws LibvirtException { - throw new RuntimeException("Not Implemented") ; -// _setDom0Memory(memory); + libvirt.virDomainSetMemory(null, new NativeLong(memory)) ; + processError() ; } -// private native int _setDom0Memory(long memory) throws LibvirtException; /** * Provides the number of inactive storage pools @@ -660,11 +670,11 @@ public class Connect { * @throws LibvirtException */ public int numOfDefinedStoragePools() throws LibvirtException { - throw new RuntimeException("Not Implemented") ; -// return _numOfDefinedStoragePools(VCP); + int returnValue = libvirt.virConnectNumOfDefinedStoragePools(VCP); + processError() ; + return returnValue ; } -// private native int _numOfDefinedStoragePools(long VCP) throws LibvirtException; /** * Provides the number of active storage pools @@ -673,11 +683,11 @@ public class Connect { * @throws LibvirtException */ public int numOfStoragePools() throws LibvirtException { - throw new RuntimeException("Not Implemented") ; -// return _numOfStoragePools(VCP); + int returnValue = libvirt.virConnectNumOfStoragePools(VCP); + processError() ; + return returnValue ; } -// private native int _numOfStoragePools(long VCP) throws LibvirtException; /** * Provides the list of names of inactive storage pools. @@ -686,12 +696,13 @@ public class Connect { * @throws LibvirtException */ public String[] listDefinedStoragePools() throws LibvirtException { - throw new RuntimeException("Not Implemented") ; -// return _listDefinedStoragePools(VCP); + int num = this.numOfDefinedStoragePools() ; + String[] returnValue = new String[num] ; + libvirt.virConnectListDefinedStoragePools(VCP, returnValue, num) ; + processError() ; + return returnValue ; } -// private native String[] _listDefinedStoragePools(long VCP) -// throws LibvirtException; /** * Provides the list of names of active storage pools. @@ -700,12 +711,13 @@ public class Connect { * @throws LibvirtException */ public String[] listStoragePools() throws LibvirtException { - throw new RuntimeException("Not Implemented") ; -// return _listStoragePools(VCP); + int num = this.numOfStoragePools() ; + String[] returnValue = new String[num] ; + libvirt.virConnectListStoragePools(VCP, returnValue, num) ; + processError() ; + return returnValue ; } -// private native String[] _listStoragePools(long VCP) -// throws LibvirtException; /** * Create a new storage based on its XML description. @@ -718,12 +730,11 @@ public class Connect { */ public StoragePool storagePoolCreateXML(String xmlDesc, int flags) throws LibvirtException { - throw new RuntimeException("Not Implemented") ; -// return new StoragePool(this, _virStoragePoolCreateXML(VCP, xmlDesc, flags)); + StoragePoolPointer ptr = libvirt.virStoragePoolCreateXML(VCP, xmlDesc, flags) ; + processError() ; + return new StoragePool(this, ptr) ; } -// private native long _virStoragePoolCreateXML(long VCP, String xmlDesc, int flags) -// throws LibvirtException; /** * Define a new inactive storage pool based on its XML description. @@ -736,12 +747,11 @@ public class Connect { */ public StoragePool storagePoolDefineXML(String xml, int flags) throws LibvirtException { - throw new RuntimeException("Not Implemented") ; -// return new StoragePool(this, _virStoragePoolDefineXML(VCP, xml, flags)); + StoragePoolPointer ptr = libvirt.virStoragePoolDefineXML(VCP, xml, flags) ; + processError() ; + return new StoragePool(this, ptr) ; } -// private native long _virStoragePoolDefineXML(long VCP, String xml, int flags) -// throws LibvirtException; /** * Fetch a storage pool based on its unique name @@ -752,12 +762,11 @@ public class Connect { */ public StoragePool storagePoolLookupByName(String name) throws LibvirtException { - throw new RuntimeException("Not Implemented") ; -// return new StoragePool(this, _virStoragePoolLookupByName(VCP, name)); + StoragePoolPointer ptr = libvirt.virStoragePoolLookupByName(VCP, name) ; + processError() ; + return new StoragePool(this, ptr) ; } -// private native long _virStoragePoolLookupByName(long VCP, String name) -// throws LibvirtException; /** * Fetch a storage pool based on its globally unique id @@ -768,11 +777,16 @@ public class Connect { */ public StoragePool storagePoolLookupByUUID(int[] UUID) throws LibvirtException { - throw new RuntimeException("Not Implemented") ; -// return new StoragePool(this, _virStoragePoolLookupByUUID(VCP, UUID)); + String uuidString = Connect.createUUIDString(UUID) ; + StoragePool returnValue = null ; + StoragePoolPointer ptr = libvirt.virStoragePoolLookupByUUID(VCP, uuidString) ; + processError() ; + if (ptr != null) { + returnValue = new StoragePool(this, ptr) ; + } + return returnValue ; } -// private native long _virStoragePoolLookupByUUID(long VCP, int[] UUID); /** * Fetch a storage pool based on its globally unique id @@ -782,13 +796,16 @@ public class Connect { * @throws LibvirtException */ public StoragePool storagePoolLookupByUUIDString(String UUID) - throws LibvirtException { - throw new RuntimeException("Not Implemented") ; -// return new StoragePool(this, _virStoragePoolLookupByUUIDString(VCP, UUID)); + throws LibvirtException { + StoragePool returnValue = null ; + StoragePoolPointer ptr = libvirt.virStoragePoolLookupByUUIDString(VCP, UUID) ; + processError() ; + if (ptr != null) { + returnValue = new StoragePool(this, ptr) ; + } + return returnValue ; } -// private native long _virStoragePoolLookupByUUIDString(long VCP, String UUID) -// throws LibvirtException; /** * Fetch a a storage volume based on its globally unique key @@ -796,12 +813,13 @@ public class Connect { * @param key globally unique key * @return a storage volume */ - public StorageVol storageVolLookupByKey(String key){ - throw new RuntimeException("Not Implemented") ; -// return new StorageVol(this, _virStorageVolLookupByKey(VCP, key)); + public StorageVol storageVolLookupByKey(String key) + throws LibvirtException { + StorageVolPointer sPtr = libvirt.virStorageVolLookupByKey(VCP, key) ; + processError() ; + return new StorageVol(this, sPtr) ; } -// private native long _virStorageVolLookupByKey(long VCP, String key); /** * Fetch a storage volume based on its locally (host) unique path @@ -809,18 +827,28 @@ public class Connect { * @param path locally unique path * @return a storage volume */ - public StorageVol storageVolLookupByPath(String path){ - throw new RuntimeException("Not Implemented") ; -// return new StorageVol(this, _virStorageVolLookupByPath(VCP, path)); + public StorageVol storageVolLookupByPath(String path) + throws LibvirtException { + StorageVolPointer sPtr = libvirt.virStorageVolLookupByPath(VCP, path) ; + processError() ; + return new StorageVol(this, sPtr) ; } -// private native long _virStorageVolLookupByPath(long VCP, String path); - + /** + * call the error handling logic. Should be called after + * every libvirt call + * @throws LibvirtException + */ protected void processError() throws LibvirtException { ErrorHandler.processError(libvirt, VCP) ; } + + /** + * Helper function to convert bytes into ints for the + * UUID calls + */ public static int[] convertUUIDBytes(byte bytes[]) { int[] returnValue = new int[Libvirt.VIR_UUID_BUFLEN] ; for (int x = 0 ; x < Libvirt.VIR_UUID_BUFLEN ; x++) { @@ -828,5 +856,18 @@ public class Connect { } return returnValue ; } + + + /** + * Helper function to convert UUIDs into a stirng + * for the UUID calls + */ + public static String createUUIDString(int[] UUID) { + StringBuilder uuidString = new StringBuilder() ; + for (int i : UUID) { + uuidString.append(i) ; + } + return uuidString.toString() ; + } } diff --git a/src/org/libvirt/ConnectAuth.java b/src/org/libvirt/ConnectAuth.java index b18a47b..ad70365 100644 --- a/src/org/libvirt/ConnectAuth.java +++ b/src/org/libvirt/ConnectAuth.java @@ -1,5 +1,10 @@ package org.libvirt; +import org.libvirt.jna.Libvirt; +import org.libvirt.jna.virConnectCredential; + +import com.sun.jna.Pointer; + /** * We diverge from the C implementation * There is no explicit cbdata field, you should just add any extra data to the child class's instance. @@ -7,7 +12,7 @@ package org.libvirt; * @author stoty * */ -public abstract class ConnectAuth { +public abstract class ConnectAuth implements Libvirt.VirConnectAuthCallback { /** * @author stoty * @@ -126,6 +131,13 @@ public abstract class ConnectAuth { } + + + public int authCallback(virConnectCredential[] cred, int ncred, Pointer cbdata) { + System.out.println("HELLO!!!!!!!!!!!!!!!!!!!!!!!!!") ; + return 1 ; + } + /** * List of supported ConnectCredential.CredentialType values */ @@ -137,4 +149,5 @@ public abstract class ConnectAuth { * @return 0 if the defresult field contains a vailde response, -1 otherwise */ public abstract int callback(Credential[] cred); + } diff --git a/src/org/libvirt/Domain.java b/src/org/libvirt/Domain.java index ab8cd94..6f57b96 100644 --- a/src/org/libvirt/Domain.java +++ b/src/org/libvirt/Domain.java @@ -1,5 +1,6 @@ package org.libvirt; +import org.libvirt.jna.DomainPointer; import org.libvirt.jna.Libvirt; import org.libvirt.jna.virDomainBlockStats; import org.libvirt.jna.virDomainInfo; @@ -39,7 +40,7 @@ public class Domain { /** * the native virDomainPtr. */ - private Pointer VDP; + private DomainPointer VDP; /** * The Connect Object that represents the Hypervisor of this Domain @@ -59,7 +60,7 @@ public class Domain { * @param virConnect the Domain's hypervisor * @param VDP the native virDomainPtr */ - Domain(Connect virConnect, Pointer VDP){ + Domain(Connect virConnect, DomainPointer VDP){ this.virConnect = virConnect; this.VDP = VDP; this.libvirt = virConnect.libvirt ; @@ -540,7 +541,7 @@ public class Domain { * @throws LibvirtException */ public Domain migrate(Connect dconn, long flags, String dname, String uri, long bandwidth) throws LibvirtException{ - Pointer newPtr = 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) ; } diff --git a/src/org/libvirt/ErrorHandler.java b/src/org/libvirt/ErrorHandler.java index 7f77937..2cc260a 100644 --- a/src/org/libvirt/ErrorHandler.java +++ b/src/org/libvirt/ErrorHandler.java @@ -1,5 +1,6 @@ package org.libvirt; +import org.libvirt.jna.ConnectionPointer; import org.libvirt.jna.Libvirt; import org.libvirt.jna.virError; @@ -18,7 +19,7 @@ public class ErrorHandler } } - public static void processError(Libvirt libvirt, Pointer conn) throws LibvirtException + public static void processError(Libvirt libvirt, ConnectionPointer conn) throws LibvirtException { virError vError = new virError() ; int errorCode = libvirt.virConnCopyLastError(conn, vError) ; diff --git a/src/org/libvirt/Network.java b/src/org/libvirt/Network.java index c18f239..39afde2 100644 --- a/src/org/libvirt/Network.java +++ b/src/org/libvirt/Network.java @@ -1,6 +1,7 @@ package org.libvirt; import org.libvirt.jna.Libvirt; +import org.libvirt.jna.NetworkPointer; import com.sun.jna.Native; import com.sun.jna.Pointer; @@ -12,7 +13,7 @@ public class Network { /** * The native virNetworkPtr */ - protected Pointer VNP; + protected NetworkPointer VNP; /** * The Connect Object that represents the Hypervisor of this Network @@ -31,7 +32,7 @@ public class Network { * @param virConnect * @param VNP */ - Network(Connect virConnect, Pointer VNP){ + Network(Connect virConnect, NetworkPointer VNP){ this.virConnect = virConnect; this.VNP = VNP; this.libvirt = virConnect.libvirt ; diff --git a/src/org/libvirt/StoragePool.java b/src/org/libvirt/StoragePool.java index 6fc3db4..5ef5423 100644 --- a/src/org/libvirt/StoragePool.java +++ b/src/org/libvirt/StoragePool.java @@ -1,5 +1,13 @@ package org.libvirt; +import org.libvirt.jna.Libvirt; +import org.libvirt.jna.StoragePoolPointer; +import org.libvirt.jna.StorageVolPointer; +import org.libvirt.jna.virStoragePoolInfo; + +import com.sun.jna.Native; +import com.sun.jna.ptr.IntByReference; + public class StoragePool { static final class BuildFlags{ @@ -31,12 +39,17 @@ public class StoragePool { /** * the native virStoragePoolPtr. */ - private long VSPP; + protected StoragePoolPointer VSPP; /** * The VirConnect Object that represents the Hypervisor of this Domain */ - private Connect virConnect; + protected Connect virConnect; + + /** + * the libvirt instance + */ + protected Libvirt libvirt ; /** @@ -46,9 +59,10 @@ public class StoragePool { * @param virConnect the Domain's hypervisor * @param VSPP the native virStoragePoolPtr */ - StoragePool(Connect virConnect, long VSPP){ + StoragePool(Connect virConnect, StoragePoolPointer VSPP){ this.virConnect = virConnect; this.VSPP = VSPP; + this.libvirt = virConnect.libvirt ; } /** @@ -57,10 +71,10 @@ public class StoragePool { * @param flags future flags, use 0 for now */ public void build(int flags) throws LibvirtException{ - _build(VSPP, flags); + libvirt.virStoragePoolBuild(VSPP, flags); + processError() ; } - private native int _build(long VSPP, int flags) throws LibvirtException; /** * Starts this inactive storage pool @@ -68,11 +82,11 @@ public class StoragePool { * @param flags future flags, use 0 for now */ public void create(int flags) throws LibvirtException{ - _create(VSPP, flags); + libvirt.virStoragePoolCreate(VSPP, flags); + processError() ; } - private native int _create(long VSPP, int flags) throws LibvirtException; - + /** * Delete the underlying pool resources. This is a non-recoverable operation. * The virStoragePool object itself is not free'd. @@ -80,10 +94,10 @@ public class StoragePool { * @param flags flags for obliteration process */ public void delete(int flags) throws LibvirtException{ - _delete(VSPP, flags); + libvirt.virStoragePoolDelete(VSPP, flags); + processError() ; } - private native int _delete(long VSPP, int flags) throws LibvirtException; /** * Destroy an active storage pool. @@ -92,20 +106,20 @@ public class StoragePool { * This does not free the associated virStoragePoolPtr object. */ public void destroy() throws LibvirtException{ - _destroy(VSPP); + libvirt.virStoragePoolDestroy(VSPP); + processError() ; } - private native int _destroy(long VSPP) throws LibvirtException; /** * Free a storage pool object, releasing all memory associated with it. * Does not change the state of the pool on the host. */ public void free() throws LibvirtException{ - _free(VSPP); + libvirt.virStoragePoolFree(VSPP); + processError() ; } - private native int _free(long VSPP) throws LibvirtException; /** @@ -115,10 +129,12 @@ public class StoragePool { * @throws LibvirtException */ public boolean getAutostart() throws LibvirtException{ - return _getAutostart(VSPP); + IntByReference autoStart = new IntByReference() ; + libvirt.virStoragePoolGetAutostart(VSPP, autoStart) ; + processError() ; + return autoStart.getValue() != 0 ? true : false ; } - private native boolean _getAutostart(long VSPP) throws LibvirtException; /** * Provides the connection pointer associated with a storage pool. @@ -128,6 +144,8 @@ public class StoragePool { public Connect getConnect(){ return virConnect; } + + /** * Get volatile information about the storage pool such as free space / usage summary * @@ -135,10 +153,12 @@ public class StoragePool { * @throws LibvirtException */ public StoragePoolInfo getInfo() throws LibvirtException{ - return _getInfo(VSPP); + virStoragePoolInfo vInfo = new virStoragePoolInfo() ; + libvirt.virStoragePoolGetInfo(VSPP, vInfo ) ; + processError() ; + return new StoragePoolInfo(vInfo) ; } - private native StoragePoolInfo _getInfo(long VSPP) throws LibvirtException; /** * Fetch the locally unique name of the storage pool @@ -147,10 +167,11 @@ public class StoragePool { * @throws LibvirtException */ public String getName() throws LibvirtException{ - return _getName(VSPP); + String returnValue = libvirt.virStoragePoolGetName(VSPP) ; + processError() ; + return returnValue ; } - private native String _getName(long VSPP) throws LibvirtException; /** * Fetch the globally unique ID of this storage pool @@ -159,11 +180,16 @@ public class StoragePool { * @throws LibvirtException */ public int[] getUUID() throws LibvirtException{ - return _getUUID(VSPP); + byte[] bytes = new byte[Libvirt.VIR_UUID_BUFLEN] ; + int success = libvirt.virStoragePoolGetUUID(VSPP, bytes) ; + processError() ; + int[] returnValue = new int[0] ; + if (success == 0) { + returnValue = Connect.convertUUIDBytes(bytes) ; + } + return returnValue ; } - private native int[] _getUUID(long VSPP) throws LibvirtException; - /** * Fetch the globally unique ID of the storage pool as a string @@ -172,10 +198,16 @@ public class StoragePool { * @throws LibvirtException */ public String getUUIDString() throws LibvirtException{ - return _getUUIDString(VSPP); + byte[] bytes = new byte[Libvirt.VIR_UUID_STRING_BUFLEN] ; + int success = libvirt.virStoragePoolGetUUIDString(VSPP, bytes) ; + processError() ; + String returnValue = null ; + if (success == 0) { + returnValue = Native.toString(bytes) ; + } + return returnValue ; } - private native String _getUUIDString(long VSPP) throws LibvirtException; /** * Fetch an XML document describing all aspects of the storage pool. @@ -186,10 +218,11 @@ public class StoragePool { *-java @throws LibvirtException */ public String getXMLDesc(int flags) throws LibvirtException{ - return _getXMLDesc(VSPP, flags); + String returnValue = libvirt.virStoragePoolGetXMLDesc(VSPP, flags) ; + processError() ; + return returnValue ; } - private native String _getXMLDesc(long VSPP, int flags) throws LibvirtException; /** * Fetch list of storage volume names @@ -198,11 +231,13 @@ public class StoragePool { * @throws LibvirtException */ public String[] listVolumes() throws LibvirtException { - return _listVolumes(VSPP); + int num = this.numOfVolumes() ; + String[] returnValue = new String[num] ; + libvirt.virStoragePoolListVolumes(VSPP, returnValue, num) ; + processError() ; + return returnValue ; } - private native String[] _listVolumes(long VSPP) - throws LibvirtException; /** * Fetch the number of storage volumes within a pool @@ -211,10 +246,11 @@ public class StoragePool { * @throws LibvirtException */ public int numOfVolumes() throws LibvirtException { - return _numOfVolumes(VSPP); + int returnValue = libvirt.virStoragePoolNumOfVolumes(VSPP) ; + processError() ; + return returnValue ; } - private native int _numOfVolumes(long VSPP) throws LibvirtException; /** * Request that the pool refresh its list of volumes. @@ -224,10 +260,10 @@ public class StoragePool { * @throws LibvirtException */ public void refresh(int flags) throws LibvirtException { - _refresh(VSPP, flags); + libvirt.virStoragePoolRefresh(VSPP) ; + processError() ; } - private native int _refresh(long VSPP, int flags) throws LibvirtException; /** * Sets the autostart flag @@ -236,10 +272,9 @@ public class StoragePool { * @throws LibvirtException */ public void setAutostart(int autostart) throws LibvirtException { - _setAutostart(VSPP, autostart); + libvirt.virStoragePoolSetAutostart(VSPP, autostart) ; } - private native int _setAutostart(long VSPP, int autostart) throws LibvirtException; /** * Undefine an inactive storage pool @@ -247,10 +282,10 @@ public class StoragePool { * @throws LibvirtException */ public void undefine() throws LibvirtException { - _undefine(VSPP); + libvirt.virStoragePoolUndefine(VSPP) ; + processError() ; } - - private native int _undefine(long VSPP) throws LibvirtException; + /** * Fetch an object representing to a storage volume based on its name within a pool @@ -261,11 +296,11 @@ public class StoragePool { */ public StorageVol storageVolLookupByName(String name) throws LibvirtException { - return new StorageVol(virConnect, _storageVolLookupByName(VSPP, name)); + StorageVolPointer sPtr = libvirt.virStorageVolLookupByName(VSPP, name) ; + processError() ; + return new StorageVol(virConnect, sPtr) ; } - private native long _storageVolLookupByName(long VSPP, String name) - throws LibvirtException; /** * Create a storage volume within a pool based on an XML description. Not all pools support creation of volumes @@ -277,10 +312,14 @@ public class StoragePool { */ public StorageVol storageVolCreateXML(String xmlDesc, int flags) throws LibvirtException { - return new StorageVol(virConnect, _storageVolCreateXML(VSPP, xmlDesc, flags)); + StorageVolPointer sPtr = libvirt.virStorageVolCreateXML(VSPP, xmlDesc, flags) ; + processError() ; + return new StorageVol(virConnect, sPtr) ; } - private native long _storageVolCreateXML(long VSPP, String xmlDesc, int flags) - throws LibvirtException; + + protected void processError() throws LibvirtException { + virConnect.processError() ; + } } diff --git a/src/org/libvirt/StoragePoolInfo.java b/src/org/libvirt/StoragePoolInfo.java index 33a3758..2b5b601 100644 --- a/src/org/libvirt/StoragePoolInfo.java +++ b/src/org/libvirt/StoragePoolInfo.java @@ -1,5 +1,7 @@ package org.libvirt; +import org.libvirt.jna.virStoragePoolInfo; + public class StoragePoolInfo { /** @@ -61,6 +63,10 @@ public class StoragePoolInfo { this.allocation = allocation; this.available = available; } + + StoragePoolInfo(virStoragePoolInfo vInfo) { + this(vInfo.state, vInfo.capacity, vInfo.allocation, vInfo.available) ; + } public String toString(){ StringBuffer result = new StringBuffer(""); diff --git a/src/org/libvirt/StorageVol.java b/src/org/libvirt/StorageVol.java index 97694e1..0eb4efb 100644 --- a/src/org/libvirt/StorageVol.java +++ b/src/org/libvirt/StorageVol.java @@ -1,5 +1,10 @@ package org.libvirt; +import org.libvirt.jna.Libvirt; +import org.libvirt.jna.StoragePoolPointer; +import org.libvirt.jna.StorageVolPointer; +import org.libvirt.jna.virStorageVolInfo; + public class StorageVol { static final class DeleteFlags{ @@ -27,12 +32,17 @@ public class StorageVol { /** * the native virStorageVolPtr. */ - private long VSVP; + protected StorageVolPointer VSVP; /** * The VirConnect Object that represents the Hypervisor of this Domain */ - private Connect virConnect; + protected Connect virConnect; + + /** + * the libvirt instance + */ + protected Libvirt libvirt ; /** @@ -42,9 +52,10 @@ public class StorageVol { * @param virConnect the Domain's hypervisor * @param VSVP the native virStorageVolPtr */ - StorageVol(Connect virConnect, long VSVP){ + StorageVol(Connect virConnect, StorageVolPointer VSVP){ this.virConnect = virConnect; this.VSVP = VSVP; + this.libvirt = virConnect.libvirt ; } /** @@ -55,11 +66,11 @@ public class StorageVol { */ public StoragePool storagePoolLookupByVolume() throws LibvirtException { - return new StoragePool(virConnect, _storagePoolLookupByVolume(VSVP)); + StoragePoolPointer ptr = libvirt.virStoragePoolLookupByVolume(VSVP) ; + processError() ; + return new StoragePool(virConnect, ptr) ; } - - private native long _storagePoolLookupByVolume(long VSVP) - throws LibvirtException; + /** * Delete the storage volume from the pool @@ -68,10 +79,10 @@ public class StorageVol { * @throws LibvirtException */ public void delete(int flags) throws LibvirtException{ - _delete(VSVP, flags); + libvirt.virStorageVolDelete(VSVP, flags) ; + processError() ; } - private native int _delete(long VSVP, int flags) throws LibvirtException; /** * Release the storage volume handle. The underlying storage volume contains to exist @@ -79,10 +90,10 @@ public class StorageVol { * @throws LibvirtException */ public void free() throws LibvirtException{ - _free(VSVP); + libvirt.virStorageVolFree(VSVP) ; + processError() ; } - private native int _free(long VSVP) throws LibvirtException; /** * Provides the connection object associated with a storage volume. The reference counter on the connection is not increased by this call. @@ -100,10 +111,12 @@ public class StorageVol { * @throws LibvirtException */ public StorageVolInfo getInfo() throws LibvirtException{ - return _getInfo(VSVP); + virStorageVolInfo vInfo = new virStorageVolInfo() ; + libvirt.virStorageVolGetInfo(VSVP, vInfo) ; + processError() ; + return new StorageVolInfo(vInfo) ; } - private native StorageVolInfo _getInfo(long VSVP) throws LibvirtException; /** * Fetch the storage volume key. This is globally unique, so the same volume will have the same key no matter what host it is accessed from @@ -112,10 +125,11 @@ public class StorageVol { * @throws LibvirtException */ public String getKey() throws LibvirtException{ - return _getKey(VSVP); + String returnValue = libvirt.virStorageVolGetKey(VSVP) ; + processError() ; + return returnValue ; } - private native String _getKey(long VSVP) throws LibvirtException; /** * Fetch the storage volume name. This is unique within the scope of a pool @@ -124,10 +138,11 @@ public class StorageVol { * @throws LibvirtException */ public String getName() throws LibvirtException{ - return _getName(VSVP); + String returnValue = libvirt.virStorageVolGetName(VSVP) ; + processError() ; + return returnValue ; } - private native String _getName(long VSVP) throws LibvirtException; /** * Fetch the storage volume path. @@ -138,10 +153,11 @@ public class StorageVol { * @throws LibvirtException */ public String getPath() throws LibvirtException{ - return _getPath(VSVP); + String returnValue = libvirt.virStorageVolGetPath(VSVP) ; + processError() ; + return returnValue ; } - private native String _getPath(long VSVP) throws LibvirtException; /** * Fetch an XML document describing all aspects of this storage volume @@ -151,8 +167,17 @@ public class StorageVol { * @throws LibvirtException */ public String getXMLDesc(int flags) throws LibvirtException{ - return _getXMLDesc(VSVP, flags); + String returnValue = libvirt.virStorageVolGetXMLDesc(VSVP, flags) ; + processError() ; + return returnValue ; } - private native String _getXMLDesc(long VSVP, int flags) throws LibvirtException; + + /** + * Error handling logic which should be called after every libvirt call + * @throws LibvirtException + */ + protected void processError() throws LibvirtException { + virConnect.processError() ; + } } diff --git a/src/org/libvirt/StorageVolInfo.java b/src/org/libvirt/StorageVolInfo.java index e63b823..9887d4a 100644 --- a/src/org/libvirt/StorageVolInfo.java +++ b/src/org/libvirt/StorageVolInfo.java @@ -1,5 +1,7 @@ package org.libvirt; +import org.libvirt.jna.virStorageVolInfo; + public class StorageVolInfo { /** @@ -42,6 +44,10 @@ public class StorageVolInfo { this.capacity = capacity; this.allocation = allocation; } + + StorageVolInfo(virStorageVolInfo volInfo) { + this(volInfo.type, volInfo.capacity, volInfo.allocation) ; + } public String toString(){ StringBuffer result = new StringBuffer(""); diff --git a/src/org/libvirt/jna/Libvirt.java b/src/org/libvirt/jna/Libvirt.java index ec67c6f..1d51e2d 100644 --- a/src/org/libvirt/jna/Libvirt.java +++ b/src/org/libvirt/jna/Libvirt.java @@ -2,14 +2,12 @@ package org.libvirt.jna; import com.sun.jna.Callback; -import com.sun.jna.Library ; +import com.sun.jna.Library; import com.sun.jna.Native; import com.sun.jna.NativeLong; import com.sun.jna.Pointer; -import com.sun.jna.Structure.ByReference; import com.sun.jna.ptr.IntByReference; import com.sun.jna.ptr.LongByReference; -import com.sun.jna.ptr.PointerByReference; public interface Libvirt extends Library { @@ -28,88 +26,137 @@ public interface Libvirt extends Library public void virResetLastError() ; //Connection Functions - public int virConnCopyLastError(Pointer virConnectPtr, virError to) ; - public int virConnectClose(Pointer virConnectPtr) ; - public String virConnectGetCapabilities(Pointer virConnectPtr) ; - public String virConnectGetHostname(Pointer virConnectPtr) ; - public virError virConnGetLastError(Pointer virConnectPtr) ; - public int virConnectGetMaxVcpus(Pointer virConnectPtr, String type) ; - public String virConnectGetType(Pointer virConnectPtr) ; - public String virConnectGetURI(Pointer virConnectPtr) ; - public int virConnectGetVersion(Pointer virConnectPtr, LongByReference hvVer) ; - public int virConnectListDomains(Pointer virConnectPtr, int[] ids, int maxnames) ; - public int virConnectListNetworks(Pointer virConnectPtr, String[] name, int maxnames) ; - public int virConnectListDefinedDomains(Pointer virConnectPtr, String[] name, int maxnames) ; - public int virConnectListDefinedNetworks(Pointer virConnectPtr, String[] name, int maxnames) ; - public int virConnectNumOfDomains(Pointer virConnectPtr) ; - public int virConnectNumOfDefinedDomains(Pointer virConnectPtr) ; - public int virConnectNumOfDefinedNetworks(Pointer virConnectPtr) ; - public int virConnectNumOfNetworks(Pointer virConnectPtr) ; - public int virConnResetLastError(Pointer virConnectPtr) ; - public Pointer virConnectOpen(String name) ; - public Pointer virConnectOpenReadOnly(String name) ; + public int virConnCopyLastError(ConnectionPointer virConnectPtr, virError to) ; + public int virConnectClose(ConnectionPointer virConnectPtr) ; + public String virConnectGetCapabilities(ConnectionPointer virConnectPtr) ; + public String virConnectGetHostname(ConnectionPointer virConnectPtr) ; + public virError virConnGetLastError(ConnectionPointer virConnectPtr) ; + public int virConnectGetMaxVcpus(ConnectionPointer virConnectPtr, String type) ; + public String virConnectGetType(ConnectionPointer virConnectPtr) ; + public String virConnectGetURI(ConnectionPointer virConnectPtr) ; + public int virConnectGetVersion(ConnectionPointer virConnectPtr, LongByReference hvVer) ; + public int virConnectListDomains(ConnectionPointer virConnectPtr, int[] ids, int maxnames) ; + public int virConnectListNetworks(ConnectionPointer virConnectPtr, String[] name, int maxnames) ; + public int virConnectListStoragePools(ConnectionPointer virConnectPtr, String[] names, int maxnames) ; + public int virConnectListDefinedStoragePools(ConnectionPointer virConnectPtr, String[] names, int maxnames) ; + public int virConnectListDefinedDomains(ConnectionPointer virConnectPtr, String[] name, int maxnames) ; + public int virConnectListDefinedNetworks(ConnectionPointer virConnectPtr, String[] name, int maxnames) ; + public int virConnectNumOfDomains(ConnectionPointer virConnectPtr) ; + public int virConnectNumOfDefinedDomains(ConnectionPointer virConnectPtr) ; + public int virConnectNumOfDefinedNetworks(ConnectionPointer virConnectPtr) ; + public int virConnectNumOfDefinedStoragePools(ConnectionPointer virConnectPtr) ; + public int virConnectNumOfNetworks(ConnectionPointer virConnectPtr) ; + public int virConnectNumOfStoragePools(ConnectionPointer virConnectPtr) ; + public int virConnResetLastError(ConnectionPointer virConnectPtr) ; + public ConnectionPointer virConnectOpen(String name) ; + public ConnectionPointer virConnectOpenAuth(String name, virConnectAuth auth, int flags) ; + public ConnectionPointer virConnectOpenReadOnly(String name) ; // Node functions - public int virNodeGetInfo(Pointer virConnectPtr, virNodeInfo virNodeInfo) ; + public int virNodeGetInfo(ConnectionPointer virConnectPtr, virNodeInfo virNodeInfo) ; + + // Storage Pool + public int virStoragePoolBuild(StoragePoolPointer storagePoolPtr, int flags) ; + public int virStoragePoolCreate(StoragePoolPointer storagePoolPtr, int flags) ; + public StoragePoolPointer virStoragePoolCreateXML(ConnectionPointer virConnectPtr, String xml, int flags) ; + public StoragePoolPointer virStoragePoolDefineXML(ConnectionPointer virConnectPtr, String xml, int flags) ; + public int virStoragePoolDelete(StoragePoolPointer storagePoolPtr, int flags) ; + public int virStoragePoolDestroy(StoragePoolPointer storagePoolPtr) ; + public int virStoragePoolFree(StoragePoolPointer storagePoolPtr) ; + public int virStoragePoolGetAutostart(StoragePoolPointer storagePoolPtr, IntByReference value) ; + public int virStoragePoolGetInfo(StoragePoolPointer storagePoolPtr, virStoragePoolInfo info) ; + public String virStoragePoolGetName(StoragePoolPointer storagePoolPtr) ; + public int virStoragePoolGetUUID(StoragePoolPointer storagePoolPtr, byte[] uuidString) ; + public int virStoragePoolGetUUIDString(StoragePoolPointer storagePoolPtr, byte[] uuidString) ; + public String virStoragePoolGetXMLDesc(StoragePoolPointer storagePoolPtr, int flags) ; + public int virStoragePoolListVolumes(StoragePoolPointer storagePoolPtr, String[] names, int maxnames) ; + public StoragePoolPointer virStoragePoolLookupByName(ConnectionPointer virConnectPtr, String name) ; + public StoragePoolPointer virStoragePoolLookupByUUIDString(ConnectionPointer virConnectPtr, String uuidstr) ; + public StoragePoolPointer virStoragePoolLookupByUUID(ConnectionPointer virConnectPtr, String uuidstr) ; + public StoragePoolPointer virStoragePoolLookupByVolume(StorageVolPointer storageVolPtr) ; + public int virStoragePoolNumOfVolumes(StoragePoolPointer storagePoolPtr) ; + public int virStoragePoolRefresh(StoragePoolPointer storagePoolPtr) ; + public int virStoragePoolSetAutostart(StoragePoolPointer storagePoolPtr, int autostart) ; + public int virStoragePoolUndefine(StoragePoolPointer storagePoolPtr) ; + + // Storage Vol + public StorageVolPointer virStorageVolCreateXML(StoragePoolPointer storagePoolPtr, String xml, int flags) ; + public StorageVolPointer virStorageVolLookupByKey(ConnectionPointer virConnectPtr, String name) ; + public StorageVolPointer virStorageVolLookupByName(StoragePoolPointer storagePoolPtr, String name) ; + public StorageVolPointer virStorageVolLookupByPath(ConnectionPointer virConnectPtr, String path) ; + public int virStorageVolDelete(StorageVolPointer storageVolPtr, int flags) ; + public int virStorageVolFree(StorageVolPointer storageVolPtr) ; + public int virStorageVolGetInfo(StorageVolPointer storageVolPtr, virStorageVolInfo info) ; + public String virStorageVolGetKey(StorageVolPointer storageVolPtr) ; + public String virStorageVolGetName(StorageVolPointer storageVolPtr) ; + public String virStorageVolGetPath(StorageVolPointer storageVolPtr) ; + public String virStorageVolGetXMLDesc(StorageVolPointer storageVolPtr, int flags) ; // Network functions - public int virNetworkCreate(Pointer virConnectPtr) ; - public Pointer virNetworkCreateXML(Pointer virConnectPtr, String xmlDesc) ; - public Pointer virNetworkDefineXML(Pointer virConnectPtr, String xmlDesc) ; - public int virNetworkDestroy(Pointer virConnectPtr) ; - public int virNetworkFree(Pointer virConnectPtr) ; - public int virNetworkGetAutostart(Pointer virNetworkPtr, IntByReference value) ; - public String virNetworkGetBridgeName(Pointer virNetworkPtr) ; - public String virNetworkGetName(Pointer virNetworkPtr) ; - public int virNetworkGetUUID(Pointer virNetworkPtr, byte[] uuidString) ; - public int virNetworkGetUUIDString(Pointer virNetworkPtr, byte[] uuidString) ; - public String virNetworkGetXMLDesc(Pointer virNetworkPtr, int flags) ; - public Pointer virNetworkLookupByName(Pointer virConnectPtr, String name) ; - public Pointer virNetworkLookupByUUIDString(Pointer virConnectPtr, String uuidstr) ; - public Pointer virNetworkLookupByUUID(Pointer virConnectPtr, String uuidstr) ; - public int virNetworkSetAutostart(Pointer virConnectPtr, int autoStart) ; - public int virNetworkUndefine(Pointer virConnectPtr) ; + public int virNetworkCreate(NetworkPointer virConnectPtr) ; + public NetworkPointer virNetworkCreateXML(ConnectionPointer virConnectPtr, String xmlDesc) ; + public NetworkPointer virNetworkDefineXML(ConnectionPointer virConnectPtr, String xmlDesc) ; + public int virNetworkDestroy(NetworkPointer virConnectPtr) ; + public int virNetworkFree(NetworkPointer virConnectPtr) ; + public int virNetworkGetAutostart(NetworkPointer virNetworkPtr, IntByReference value) ; + public String virNetworkGetBridgeName(NetworkPointer virNetworkPtr) ; + public String virNetworkGetName(NetworkPointer virNetworkPtr) ; + public int virNetworkGetUUID(NetworkPointer virNetworkPtr, byte[] uuidString) ; + public int virNetworkGetUUIDString(NetworkPointer virNetworkPtr, byte[] uuidString) ; + public String virNetworkGetXMLDesc(NetworkPointer virNetworkPtr, int flags) ; + public NetworkPointer virNetworkLookupByName(ConnectionPointer virConnectPtr, String name) ; + public NetworkPointer virNetworkLookupByUUIDString(ConnectionPointer virConnectPtr, String uuidstr) ; + public NetworkPointer virNetworkLookupByUUID(ConnectionPointer virConnectPtr, String uuidstr) ; + public int virNetworkSetAutostart(NetworkPointer virConnectPtr, int autoStart) ; + public int virNetworkUndefine(NetworkPointer virConnectPtr) ; // Domain functions - public int virDomainAttachDevice(Pointer virDomainPtr, String deviceXML) ; - public int virDomainBlockStats(Pointer virDomainPtr, String path, virDomainBlockStats stats, int size) ; - public int virDomainCreate(Pointer virDomainPtr) ; - public Pointer virDomainCreateLinux(Pointer virConnectPtr, String xmlDesc, int flags) ; - public Pointer virDomainCreateXML(Pointer virConnectPtr, String xmlDesc, int flags) ; - public int virDomainCoreDump(Pointer virDomainPtr, String to, int flags) ; - public Pointer virDomainDefineXML(Pointer virConnectPtr, String xmlDesc) ; - public int virDomainDetachDevice(Pointer virDomainPtr, String deviceXML) ; - public int virDomainDestroy(Pointer virDomainPtr) ; - public int virDomainFree(Pointer virDomainPtr) ; - public int virDomainGetAutostart(Pointer virDomainPtr, IntByReference value) ; - public int virDomainGetID(Pointer virDomainPtr) ; - public int virDomainGetInfo(Pointer virDomainPtr, virDomainInfo vInfo) ; - public NativeLong virDomainGetMaxMemory(Pointer virDomainPtr) ; - public int virDomainGetMaxVcpus(Pointer virDomainPtr) ; - public String virDomainGetName(Pointer virDomainPtr) ; - public String virDomainGetOSType(Pointer virDomainPtr) ; - public int virDomainGetUUID(Pointer virDomainPtr, byte[] uuidString) ; - public int virDomainGetUUIDString(Pointer virDomainPtr, byte[] uuidString) ; - public String virDomainGetXMLDesc(Pointer virDomainPtr, int flags) ; - public String virDomainGetSchedulerType(Pointer virDomainPtr, IntByReference nparams) ; - public int virDomainGetSchedulerParameters(Pointer virDomainPtr, virSchedParameter[] params, IntByReference nparams) ; - public int virDomainGetVcpus(Pointer virDomainPtr, virVcpuInfo[] info, int maxInfo, byte[] cpumaps, int maplen) ; - public int virDomainInterfaceStats(Pointer virDomainPtr, String path, virDomainInterfaceStats stats, int size) ; - public Pointer virDomainLookupByID(Pointer virConnectPtr, int id) ; - public Pointer virDomainLookupByName(Pointer virConnectPtr, String name) ; - public Pointer virDomainLookupByUUID(Pointer virConnectPtr, String uuidstr) ; - public Pointer virDomainLookupByUUIDString(Pointer virConnectPtr, String uuidstr) ; - public Pointer virDomainMigrate(Pointer virDomainPtr, Pointer virConnectPtr, NativeLong flags, String dname, String uri, NativeLong bandwidth) ; - public int virDomainPinVcpu(Pointer virDomainPtr, int vcpu, byte[] cpumap, int maplen) ; - public int virDomainReboot(Pointer virDomainPtr, int flags) ; - public int virDomainResume(Pointer virDomainPtr) ; - public int virDomainSave(Pointer virDomainPtr, String to) ; - public int virDomainSetAutostart(Pointer virDomainPtr, int autoStart) ; - public int virDomainSetSchedulerParameters(Pointer virDomainPtr, virSchedParameter[] params, IntByReference nparams) ; - public int virDomainSetMaxMemory(Pointer virDomainPtr, NativeLong maxMemory) ; - public int virDomainSetMemory(Pointer virDomainPtr, NativeLong maxMemory) ; - public int virDomainSetVcpus(Pointer virDomainPtr, int nvcpus) ; - public int virDomainShutdown(Pointer virDomainPtr) ; - public int virDomainSuspend(Pointer virDomainPtr) ; - public int virDomainUndefine(Pointer virDomainPtr) ; + public int virDomainAttachDevice(DomainPointer virDomainPtr, String deviceXML) ; + public int virDomainBlockStats(DomainPointer virDomainPtr, String path, virDomainBlockStats stats, int size) ; + public int virDomainCreate(DomainPointer virDomainPtr) ; + public DomainPointer virDomainCreateLinux(ConnectionPointer virConnectPtr, String xmlDesc, int flags) ; + public DomainPointer virDomainCreateXML(ConnectionPointer virConnectPtr, String xmlDesc, int flags) ; + public int virDomainCoreDump(DomainPointer virDomainPtr, String to, int flags) ; + public DomainPointer virDomainDefineXML(ConnectionPointer virConnectPtr, String xmlDesc) ; + public int virDomainDetachDevice(DomainPointer virDomainPtr, String deviceXML) ; + public int virDomainDestroy(DomainPointer virDomainPtr) ; + public int virDomainFree(DomainPointer virDomainPtr) ; + public int virDomainGetAutostart(DomainPointer virDomainPtr, IntByReference value) ; + public int virDomainGetID(DomainPointer virDomainPtr) ; + public int virDomainGetInfo(DomainPointer virDomainPtr, virDomainInfo vInfo) ; + public NativeLong virDomainGetMaxMemory(DomainPointer virDomainPtr) ; + public int virDomainGetMaxVcpus(DomainPointer virDomainPtr) ; + public String virDomainGetName(DomainPointer virDomainPtr) ; + public String virDomainGetOSType(DomainPointer virDomainPtr) ; + public int virDomainGetUUID(DomainPointer virDomainPtr, byte[] uuidString) ; + public int virDomainGetUUIDString(DomainPointer virDomainPtr, byte[] uuidString) ; + public String virDomainGetXMLDesc(DomainPointer virDomainPtr, int flags) ; + public String virDomainGetSchedulerType(DomainPointer virDomainPtr, IntByReference nparams) ; + public int virDomainGetSchedulerParameters(DomainPointer virDomainPtr, virSchedParameter[] params, IntByReference nparams) ; + public int virDomainGetVcpus(DomainPointer virDomainPtr, virVcpuInfo[] info, int maxInfo, byte[] cpumaps, int maplen) ; + public int virDomainInterfaceStats(DomainPointer virDomainPtr, String path, virDomainInterfaceStats stats, int size) ; + public DomainPointer virDomainLookupByID(ConnectionPointer virConnectPtr, int id) ; + public DomainPointer virDomainLookupByName(ConnectionPointer virConnectPtr, String name) ; + public DomainPointer virDomainLookupByUUID(ConnectionPointer virConnectPtr, String uuidstr) ; + public DomainPointer virDomainLookupByUUIDString(ConnectionPointer virConnectPtr, String uuidstr) ; + public DomainPointer virDomainMigrate(DomainPointer virDomainPtr, ConnectionPointer virConnectPtr, NativeLong flags, String dname, String uri, NativeLong bandwidth) ; + public int virDomainPinVcpu(DomainPointer virDomainPtr, int vcpu, byte[] cpumap, int maplen) ; + public int virDomainReboot(DomainPointer virDomainPtr, int flags) ; + public int virDomainResume(DomainPointer virDomainPtr) ; + public int virDomainRestore(ConnectionPointer virConnectPtr, String from) ; + public int virDomainSave(DomainPointer virDomainPtr, String to) ; + public int virDomainSetAutostart(DomainPointer virDomainPtr, int autoStart) ; + public int virDomainSetSchedulerParameters(DomainPointer virDomainPtr, virSchedParameter[] params, IntByReference nparams) ; + public int virDomainSetMaxMemory(DomainPointer virDomainPtr, NativeLong maxMemory) ; + public int virDomainSetMemory(DomainPointer virDomainPtr, NativeLong maxMemory) ; + public int virDomainSetVcpus(DomainPointer virDomainPtr, int nvcpus) ; + public int virDomainShutdown(DomainPointer virDomainPtr) ; + public int virDomainSuspend(DomainPointer virDomainPtr) ; + public int virDomainUndefine(DomainPointer virDomainPtr) ; + + // Callbacks + interface VirConnectAuthCallback extends Callback { + public int authCallback(virConnectCredential[] cred, int ncred, Pointer cbdata) ; + + } } diff --git a/src/org/libvirt/jna/virConnectAuth.java b/src/org/libvirt/jna/virConnectAuth.java new file mode 100644 index 0000000..8c94b6e --- /dev/null +++ b/src/org/libvirt/jna/virConnectAuth.java @@ -0,0 +1,11 @@ +package org.libvirt.jna; + +import com.sun.jna.Pointer; +import com.sun.jna.Structure; + +public class virConnectAuth extends Structure { + public int[] credtype ; + public int ncredtype ; + public Libvirt.VirConnectAuthCallback cb ; + public Pointer cbdata ; +} diff --git a/src/org/libvirt/jna/virConnectCredential.java b/src/org/libvirt/jna/virConnectCredential.java new file mode 100644 index 0000000..1fbd5e7 --- /dev/null +++ b/src/org/libvirt/jna/virConnectCredential.java @@ -0,0 +1,12 @@ +package org.libvirt.jna; + +import com.sun.jna.Structure; + +public class virConnectCredential extends Structure { + public int type ; + public String prompt ; + public String challenge ; + public String defresult ; + public String[] result ; + public int resultlen ; +} \ No newline at end of file diff --git a/src/test.java b/src/test.java index 40e0afc..24ed75e 100644 --- a/src/test.java +++ b/src/test.java @@ -19,17 +19,17 @@ public class test { Integer.decode("0xf0"), Integer.decode("0x3c"), Integer.decode("0x87"), Integer.decode("0xd2"), Integer.decode("0x1e"), Integer.decode("0x67")} ; //For testing the authentication -// ConnectAuth defaultAuth = new ConnectAuthDefault(); + ConnectAuth defaultAuth = new ConnectAuthDefault(); //You need to configure your libvirtd for remote/authenticated connections, and adjust the URL below //for this to work. Otherwise, you'll get an error -// try{ -// conn = new Connect("test+tcp://localhost/default", defaultAuth, 0); -// System.out.println("Encrypted connection successful!"); -// } catch (LibvirtException e){ -// System.out.println("exception caught:"+e); -// System.out.println(e.getError()); -// } + try{ + conn = new Connect("test+tcp://localhost/default", defaultAuth, 0); + System.out.println("Encrypted connection successful!"); + } catch (LibvirtException e){ + System.out.println("exception caught:"+e); + System.out.println(e.getError()); + } try{ conn = new Connect("test:///default", false); -- 1.6.0.6 -- Libvir-list mailing list Libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list