From: Cédric Bosdonnat <cedric.bosdonnat(a)free.fr>
---
src/main/java/org/libvirt/Connect.java | 46 +++++++++++++++++++++++++
src/main/java/org/libvirt/jna/Libvirt.java | 2 ++
src/test/java/org/libvirt/TestJavaBindings.java | 1 +
3 files changed, 49 insertions(+)
diff --git a/src/main/java/org/libvirt/Connect.java
b/src/main/java/org/libvirt/Connect.java
index fedc60e..390ed89 100644
--- a/src/main/java/org/libvirt/Connect.java
+++ b/src/main/java/org/libvirt/Connect.java
@@ -24,6 +24,7 @@ import com.sun.jna.Memory;
import com.sun.jna.NativeLong;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.LongByReference;
+import com.sun.jna.ptr.PointerByReference;
/**
* The Connect object represents a connection to a local or remote
@@ -33,6 +34,28 @@ import com.sun.jna.ptr.LongByReference;
*/
public class Connect {
+ static final class ListAllDomainsFlags {
+ static final int VIR_CONNECT_LIST_DOMAINS_ACTIVE = (1 << 0);
+ static final int VIR_CONNECT_LIST_DOMAINS_INACTIVE = (1 << 1);
+
+ static final int VIR_CONNECT_LIST_DOMAINS_PERSISTENT = (1 << 2);
+ static final int VIR_CONNECT_LIST_DOMAINS_TRANSIENT = (1 << 3);
+
+ static final int VIR_CONNECT_LIST_DOMAINS_RUNNING = (1 << 4);
+ static final int VIR_CONNECT_LIST_DOMAINS_PAUSED = (1 << 5);
+ static final int VIR_CONNECT_LIST_DOMAINS_SHUTOFF = (1 << 6);
+ static final int VIR_CONNECT_LIST_DOMAINS_OTHER = (1 << 7);
+
+ static final int VIR_CONNECT_LIST_DOMAINS_MANAGEDSAVE = (1 << 8);
+ static final int VIR_CONNECT_LIST_DOMAINS_NO_MANAGEDSAVE = (1 << 9);
+
+ static final int VIR_CONNECT_LIST_DOMAINS_AUTOSTART = (1 << 10);
+ static final int VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART = (1 << 11);
+
+ static final int VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT = (1 << 12);
+ static final int VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT = (1 << 13);
+ }
+
/**
* Get the version of a connection.
*
@@ -758,6 +781,29 @@ public class Connect {
}
/**
+ * Lists a possibly filtered list of all the domains.
+ *
+ * @param flags bitwise-OR of ListAllDomainsFlags
+ *
+ * @return and array of the IDs of the active domains
+ * @throws LibvirtException
+ */
+ public Domain[] listAllDomains(int flags) throws LibvirtException {
+ PointerByReference domainsRef = new PointerByReference();
+ int ret = libvirt.virConnectListAllDomains(VCP, domainsRef, flags);
+ processError(ret);
+
+ Pointer[] pointers = domainsRef.getValue().getPointerArray(0);
+ Domain[] domains = new Domain[ret];
+ for (int i = 0; i < ret; i++) {
+ DomainPointer domainPtr = new DomainPointer();
+ domainPtr.setPointer(pointers[i]);
+ domains[i] = new Domain(this, domainPtr);
+ }
+ return domains;
+ }
+
+ /**
* Provides the list of names of interfaces on this host
*
* @return an Array of Strings that contains the names of the interfaces on
diff --git a/src/main/java/org/libvirt/jna/Libvirt.java
b/src/main/java/org/libvirt/jna/Libvirt.java
index 0e4c9fc..1331f80 100644
--- a/src/main/java/org/libvirt/jna/Libvirt.java
+++ b/src/main/java/org/libvirt/jna/Libvirt.java
@@ -8,6 +8,7 @@ import com.sun.jna.Platform;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.LongByReference;
+import com.sun.jna.ptr.PointerByReference;
/**
* The libvirt interface which is exposed via JNA. The complete API is
@@ -135,6 +136,7 @@ public interface Libvirt extends Library {
int virConnectListDefinedStoragePools(ConnectionPointer virConnectPtr, Pointer[]
names, int maxnames);
int virConnectListDefinedInterfaces(ConnectionPointer virConnectPtr, Pointer[] name,
int maxNames);
int virConnectListDomains(ConnectionPointer virConnectPtr, int[] ids, int maxnames);
+ int virConnectListAllDomains(ConnectionPointer virConnectPtr, PointerByReference
domains, int flags);
int virConnectListInterfaces(ConnectionPointer virConnectPtr, Pointer[] name, int
maxNames);
int virConnectListNetworks(ConnectionPointer virConnectPtr, Pointer[] name, int
maxnames);
int virConnectListNWFilters(ConnectionPointer virConnectPtr, Pointer[] name, int
maxnames);
diff --git a/src/test/java/org/libvirt/TestJavaBindings.java
b/src/test/java/org/libvirt/TestJavaBindings.java
index 0123e6a..2703aa3 100644
--- a/src/test/java/org/libvirt/TestJavaBindings.java
+++ b/src/test/java/org/libvirt/TestJavaBindings.java
@@ -137,6 +137,7 @@ public final class TestJavaBindings extends TestCase {
assertEquals("Number of listed domains", 2,
conn.listDomains().length);
assertEquals("Number of defined domains", 1,
conn.numOfDefinedDomains());
assertEquals("Number of listed defined domains", 1,
conn.listDefinedDomains().length);
+ assertEquals("Number of all listed domains", 3,
conn.listAllDomains(0).length);
assertTrue("Domain1 should be persistent", dom1.isPersistent() == 1);
assertTrue("Domain1 should not be active", dom1.isActive() == 0);
assertTrue("Domain2 should be active", dom2.isActive() == 1);
--
1.8.4.5