[PATCH 8/9] esx: Add implementation for virConnectListAllDomains()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Esx doesn't use the common virDomainObjimplementation so
this patch adds a separate implementation.

This driver implementation supports only the following filter flags:
VIR_CONNECT_LIST_DOMAINS_ACTIVE
VIR_CONNECT_LIST_DOMAINS_INACTIVE
VIR_CONNECT_LIST_DOMAINS_TRANSIENT
VIR_CONNECT_LIST_DOMAINS_PERSISTENT
The latter two of these are irelevant as Esx only supports persistent
domains, so specifying only VIR_CONNECT_LIST_DOMAINS_TRANSIENT results
into an empty list.
---
New in series. UNTESTED!!! (I don't have access to esx, compiles)
---
 src/esx/esx_driver.c |  108 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 108 insertions(+), 0 deletions(-)

diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index b3f1948..ba47326 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -4948,6 +4948,113 @@ esxDomainGetMemoryParameters(virDomainPtr domain, virTypedParameterPtr params,
 }


+static int
+esxListAllDomains(virConnectPtr conn,
+                  virDomainPtr **domains,
+                  unsigned int flags)
+{
+    int ret = -1;
+    esxPrivate *priv = conn->privateData;
+    virDomainPtr dom;
+    virDomainPtr *doms = NULL;
+    size_t ndoms = 0;
+    esxVI_ObjectContent *virtualMachineList = NULL;
+    esxVI_ObjectContent *virtualMachine = NULL;
+    esxVI_String *propertyNameList = NULL;
+    esxVI_VirtualMachinePowerState powerState;
+    char *name = NULL;
+    int id;
+    unsigned char uuid[VIR_UUID_BUFLEN];
+    int count = 0;
+
+    virCheckFlags(VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                  VIR_CONNECT_LIST_DOMAINS_INACTIVE |
+                  VIR_CONNECT_LIST_DOMAINS_TRANSIENT |
+                  VIR_CONNECT_LIST_DOMAINS_PERSISTENT, -1);
+
+    if (esxVI_EnsureSession(priv->primary) < 0)
+        return -1;
+
+    if (esxVI_String_AppendValueToList(&propertyNameList,
+                                       "runtime.powerState") < 0 ||
+        esxVI_LookupVirtualMachineList(priv->primary, propertyNameList,
+                                       &virtualMachineList) < 0)
+        goto cleanup;
+
+    if (domains) {
+        if (VIR_ALLOC_N(doms, 1) < 0)
+            goto no_memory;
+        ndoms = 1;
+    }
+
+    for (virtualMachine = virtualMachineList; virtualMachine != NULL;
+         virtualMachine = virtualMachine->_next) {
+
+        VIR_FREE(name);
+
+        if (esxVI_GetVirtualMachineIdentity(virtualMachine, &id, &name, uuid) < 0 ||
+            esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0)
+            goto cleanup;
+
+        /* filter by state */
+        if (!(flags & VIR_CONNECT_LIST_DOMAINS_ACTIVE &&
+              flags & VIR_CONNECT_LIST_DOMAINS_INACTIVE)) {
+            if (flags & VIR_CONNECT_LIST_DOMAINS_ACTIVE &&
+                powerState == esxVI_VirtualMachinePowerState_PoweredOff)
+                continue;
+            if (flags & VIR_CONNECT_LIST_DOMAINS_INACTIVE &&
+                powerState != esxVI_VirtualMachinePowerState_PoweredOff)
+                continue;
+        }
+
+        /* filter by persistent state - all vbox domains are persistent */
+        if (flags & VIR_CONNECT_LIST_DOMAINS_TRANSIENT &&
+            !(flags & VIR_CONNECT_LIST_DOMAINS_PERSISTENT))
+            continue;
+
+        /* just count the machines */
+        if (!doms) {
+            count++;
+            continue;
+        }
+
+        if (!(dom = virGetDomain(conn, name, uuid)))
+            goto no_memory;
+
+        /* Only running/suspended virtual machines have an ID != -1 */
+        if (powerState != esxVI_VirtualMachinePowerState_PoweredOff)
+            dom->id = id;
+        else
+            dom->id = -1;
+
+        if (VIR_EXPAND_N(doms, ndoms, 1) < 0)
+            goto no_memory;
+        doms[count++] = dom;
+    }
+
+    if (doms)
+        *domains = doms;
+    doms = NULL;
+    ret = count;
+
+cleanup:
+    if (doms) {
+        for (id = 0; id < count; id++) {
+            if (doms[id])
+                virDomainFree(doms[id]);
+        }
+    }
+    VIR_FREE(doms);
+    VIR_FREE(name);
+    esxVI_String_Free(&propertyNameList);
+    esxVI_ObjectContent_Free(&virtualMachineList);
+    return ret;
+
+no_memory:
+    virReportOOMError();
+    goto cleanup;
+}
+

 static virDriver esxDriver = {
     .no = VIR_DRV_ESX,
@@ -5023,6 +5130,7 @@ static virDriver esxDriver = {
     .domainRevertToSnapshot = esxDomainRevertToSnapshot, /* 0.8.0 */
     .domainSnapshotDelete = esxDomainSnapshotDelete, /* 0.8.0 */
     .isAlive = esxIsAlive, /* 0.9.8 */
+    .listAllDomains = esxListAllDomains, /* 0.9.13 */
 };


-- 
1.7.3.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]