[libvirt] [PATCH] ESX: Unify naming of VI API utility and convenience functions.

Matthias Bolte matthias.bolte at googlemail.com
Wed Oct 28 20:10:11 UTC 2009


Unified function naming scheme:
- 'lookup' functions query the ESX or vCenter for information
- 'get' functions return information from a local object

* src/esx/esx_driver.c, src/esx/esx_vi.[ch]: unify function naming
---
 src/esx/esx_driver.c |   95 ++++++++++++++++++++++++++++----------------------
 src/esx/esx_vi.c     |   77 +++++++++++++++++++++++-----------------
 src/esx/esx_vi.h     |   32 +++++++++-------
 3 files changed, 116 insertions(+), 88 deletions(-)

diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index a0efa5d..93fb5a9 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -90,9 +90,10 @@ esxSupportsLongMode(virConnectPtr conn)
 
     if (esxVI_String_AppendValueToList(conn, &propertyNameList,
                                        "hardware.cpuFeature") < 0 ||
-        esxVI_GetObjectContent(conn, priv->host, priv->host->hostFolder,
-                               "HostSystem", propertyNameList,
-                               esxVI_Boolean_True, &hostSystem) < 0) {
+        esxVI_LookupObjectContentByType(conn, priv->host,
+                                        priv->host->hostFolder,
+                                        "HostSystem", propertyNameList,
+                                        esxVI_Boolean_True, &hostSystem) < 0) {
         goto failure;
     }
 
@@ -522,9 +523,10 @@ esxSupportsVMotion(virConnectPtr conn)
 
     if (esxVI_String_AppendValueToList(conn, &propertyNameList,
                                        "capability.vmotionSupported") < 0 ||
-        esxVI_GetObjectContent(conn, priv->host, priv->host->hostFolder,
-                               "HostSystem", propertyNameList,
-                               esxVI_Boolean_True, &hostSystem) < 0) {
+        esxVI_LookupObjectContentByType(conn, priv->host,
+                                        priv->host->hostFolder,
+                                        "HostSystem", propertyNameList,
+                                        esxVI_Boolean_True, &hostSystem) < 0) {
         goto failure;
     }
 
@@ -653,9 +655,10 @@ esxGetHostname(virConnectPtr conn)
           (conn, &propertyNameList,
            "config.network.dnsConfig.hostName\0"
            "config.network.dnsConfig.domainName\0") < 0 ||
-        esxVI_GetObjectContent(conn, priv->host, priv->host->hostFolder,
-                               "HostSystem", propertyNameList,
-                               esxVI_Boolean_True, &hostSystem) < 0) {
+        esxVI_LookupObjectContentByType(conn, priv->host,
+                                        priv->host->hostFolder,
+                                        "HostSystem", propertyNameList,
+                                        esxVI_Boolean_True, &hostSystem) < 0) {
         goto failure;
     }
 
@@ -750,9 +753,10 @@ esxNodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo)
                                            "hardware.memorySize\0"
                                            "hardware.numaInfo.numNodes\0"
                                            "summary.hardware.cpuModel\0") < 0 ||
-        esxVI_GetObjectContent(conn, priv->host, priv->host->hostFolder,
-                               "HostSystem", propertyNameList,
-                               esxVI_Boolean_True, &hostSystem) < 0) {
+        esxVI_LookupObjectContentByType(conn, priv->host,
+                                        priv->host->hostFolder,
+                                        "HostSystem", propertyNameList,
+                                        esxVI_Boolean_True, &hostSystem) < 0) {
         goto failure;
     }
 
@@ -914,9 +918,10 @@ esxListDomains(virConnectPtr conn, int *ids, int maxids)
 
     if (esxVI_String_AppendValueToList(conn, &propertyNameList,
                                        "runtime.powerState") < 0 ||
-        esxVI_GetObjectContent(conn, priv->host, priv->host->vmFolder,
-                               "VirtualMachine", propertyNameList,
-                               esxVI_Boolean_True, &virtualMachineList) < 0) {
+        esxVI_LookupObjectContentByType(conn, priv->host, priv->host->vmFolder,
+                                        "VirtualMachine", propertyNameList,
+                                        esxVI_Boolean_True,
+                                        &virtualMachineList) < 0) {
         goto failure;
     }
 
@@ -970,7 +975,7 @@ esxNumberOfDomains(virConnectPtr conn)
         return -1;
     }
 
-    return esxVI_GetNumberOfDomainsByPowerState
+    return esxVI_LookupNumberOfDomainsByPowerState
              (conn, priv->host, esxVI_VirtualMachinePowerState_PoweredOn,
               esxVI_Boolean_False);
 }
@@ -999,9 +1004,10 @@ esxDomainLookupByID(virConnectPtr conn, int id)
                                            "name\0"
                                            "runtime.powerState\0"
                                            "config.uuid\0") < 0 ||
-        esxVI_GetObjectContent(conn, priv->host, priv->host->vmFolder,
-                               "VirtualMachine", propertyNameList,
-                               esxVI_Boolean_True, &virtualMachineList) < 0) {
+        esxVI_LookupObjectContentByType(conn, priv->host, priv->host->vmFolder,
+                                        "VirtualMachine", propertyNameList,
+                                        esxVI_Boolean_True,
+                                        &virtualMachineList) < 0) {
         goto failure;
     }
 
@@ -1082,9 +1088,10 @@ esxDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
                                            "name\0"
                                            "runtime.powerState\0"
                                            "config.uuid\0") < 0 ||
-        esxVI_GetObjectContent(conn, priv->host, priv->host->vmFolder,
-                               "VirtualMachine", propertyNameList,
-                               esxVI_Boolean_True, &virtualMachineList) < 0) {
+        esxVI_LookupObjectContentByType(conn, priv->host, priv->host->vmFolder,
+                                        "VirtualMachine", propertyNameList,
+                                        esxVI_Boolean_True,
+                                        &virtualMachineList) < 0) {
         goto failure;
     }
 
@@ -1168,9 +1175,10 @@ esxDomainLookupByName(virConnectPtr conn, const char *name)
                                            "name\0"
                                            "runtime.powerState\0"
                                            "config.uuid\0") < 0 ||
-        esxVI_GetObjectContent(conn, priv->host, priv->host->vmFolder,
-                               "VirtualMachine", propertyNameList,
-                               esxVI_Boolean_True, &virtualMachineList) < 0) {
+        esxVI_LookupObjectContentByType(conn, priv->host, priv->host->vmFolder,
+                                        "VirtualMachine", propertyNameList,
+                                        esxVI_Boolean_True,
+                                        &virtualMachineList) < 0) {
         goto failure;
     }
 
@@ -2042,10 +2050,10 @@ esxDomainGetMaxVcpus(virDomainPtr domain)
 
     if (esxVI_String_AppendValueToList(domain->conn, &propertyNameList,
                                        "capability.maxSupportedVcpus") < 0 ||
-        esxVI_GetObjectContent(domain->conn, priv->host,
-                               priv->host->hostFolder, "HostSystem",
-                               propertyNameList, esxVI_Boolean_True,
-                               &hostSystem) < 0) {
+        esxVI_LookupObjectContentByType(domain->conn, priv->host,
+                                        priv->host->hostFolder, "HostSystem",
+                                        propertyNameList, esxVI_Boolean_True,
+                                        &hostSystem) < 0) {
         goto failure;
     }
 
@@ -2270,9 +2278,10 @@ esxListDefinedDomains(virConnectPtr conn, char **const names, int maxnames)
     if (esxVI_String_AppendValueListToList(conn, &propertyNameList,
                                            "name\0"
                                            "runtime.powerState\0") < 0 ||
-        esxVI_GetObjectContent(conn, priv->host, priv->host->vmFolder,
-                               "VirtualMachine", propertyNameList,
-                               esxVI_Boolean_True, &virtualMachineList) < 0) {
+        esxVI_LookupObjectContentByType(conn, priv->host, priv->host->vmFolder,
+                                        "VirtualMachine", propertyNameList,
+                                        esxVI_Boolean_True,
+                                        &virtualMachineList) < 0) {
         goto failure;
     }
 
@@ -2337,7 +2346,7 @@ esxNumberOfDefinedDomains(virConnectPtr conn)
         return -1;
     }
 
-    return esxVI_GetNumberOfDomainsByPowerState
+    return esxVI_LookupNumberOfDomainsByPowerState
              (conn, priv->host, esxVI_VirtualMachinePowerState_PoweredOn,
               esxVI_Boolean_True);
 }
@@ -2550,8 +2559,8 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml ATTRIBUTE_UNUSED)
         goto failure;
     }
 
-    if (esxVI_GetResourcePool(conn, priv->host, hostSystem,
-                              &resourcePool) < 0) {
+    if (esxVI_LookupResourcePoolByHostSystem(conn, priv->host, hostSystem,
+                                             &resourcePool) < 0) {
         goto failure;
     }
 
@@ -3071,8 +3080,8 @@ esxDomainMigratePerform(virDomainPtr domain,
         goto failure;
     }
 
-    if (esxVI_GetResourcePool(domain->conn, priv->vCenter, hostSystem,
-                              &resourcePool) < 0) {
+    if (esxVI_LookupResourcePoolByHostSystem(domain->conn, priv->vCenter,
+                                             hostSystem, &resourcePool) < 0) {
         goto failure;
     }
 
@@ -3172,8 +3181,8 @@ esxNodeGetFreeMemory(virConnectPtr conn)
         goto failure;
     }
 
-    if (esxVI_GetResourcePool(conn, priv->host, hostSystem,
-                              &managedObjectReference) < 0) {
+    if (esxVI_LookupResourcePoolByHostSystem(conn, priv->host, hostSystem,
+                                             &managedObjectReference) < 0) {
         goto failure;
     }
 
@@ -3182,9 +3191,11 @@ esxNodeGetFreeMemory(virConnectPtr conn)
     /* Get memory usage of resource pool */
     if (esxVI_String_AppendValueToList(conn, &propertyNameList,
                                        "runtime.memory") < 0 ||
-        esxVI_GetObjectContent(conn, priv->host, managedObjectReference,
-                               "ResourcePool", propertyNameList,
-                               esxVI_Boolean_False, &resourcePool) < 0) {
+        esxVI_LookupObjectContentByType(conn, priv->host,
+                                        managedObjectReference,
+                                        "ResourcePool", propertyNameList,
+                                        esxVI_Boolean_False,
+                                        &resourcePool) < 0) {
         goto failure;
     }
 
diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
index fa971d8..dc51e20 100644
--- a/src/esx/esx_vi.c
+++ b/src/esx/esx_vi.c
@@ -374,9 +374,10 @@ esxVI_Context_Connect(virConnectPtr conn, esxVI_Context *ctx, const char *url,
     }
 
     /* Get pointer to Datacenter for later use */
-    if (esxVI_GetObjectContent(conn, ctx, ctx->service->rootFolder,
-                               "Datacenter", propertyNameList,
-                               esxVI_Boolean_True, &datacenterList) < 0) {
+    if (esxVI_LookupObjectContentByType(conn, ctx, ctx->service->rootFolder,
+                                        "Datacenter", propertyNameList,
+                                        esxVI_Boolean_True,
+                                        &datacenterList) < 0) {
         goto failure;
     }
 
@@ -1061,6 +1062,10 @@ esxVI_List_Deserialize(virConnectPtr conn, xmlNodePtr node, esxVI_List **list,
 
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  * Utility and Convenience Functions
+ *
+ * Function naming scheme:
+ *  - 'lookup' functions query the ESX or vCenter for information
+ *  - 'get' functions get information from a local object
  */
 
 int
@@ -1301,9 +1306,11 @@ esxVI_EnsureSession(virConnectPtr conn, esxVI_Context *ctx)
 #else
     if (esxVI_String_AppendValueToList(conn, &propertyNameList,
                                        "currentSession") < 0 ||
-        esxVI_GetObjectContent(conn, ctx, ctx->service->sessionManager,
-                               "SessionManager", propertyNameList,
-                               esxVI_Boolean_False, &sessionManager) < 0) {
+        esxVI_LookupObjectContentByType(conn, ctx,
+                                        ctx->service->sessionManager,
+                                        "SessionManager", propertyNameList,
+                                        esxVI_Boolean_False,
+                                        &sessionManager) < 0) {
         goto failure;
     }
 
@@ -1358,11 +1365,12 @@ esxVI_EnsureSession(virConnectPtr conn, esxVI_Context *ctx)
 
 
 int
-esxVI_GetObjectContent(virConnectPtr conn, esxVI_Context *ctx,
-                       esxVI_ManagedObjectReference *root,
-                       const char *type, esxVI_String *propertyNameList,
-                       esxVI_Boolean recurse,
-                       esxVI_ObjectContent **objectContentList)
+esxVI_LookupObjectContentByType(virConnectPtr conn, esxVI_Context *ctx,
+                                esxVI_ManagedObjectReference *root,
+                                const char *type,
+                                esxVI_String *propertyNameList,
+                                esxVI_Boolean recurse,
+                                esxVI_ObjectContent **objectContentList)
 {
     int result = 0;
     esxVI_ObjectSpec *objectSpec = NULL;
@@ -1479,9 +1487,9 @@ esxVI_GetVirtualMachinePowerState(virConnectPtr conn,
 
 
 int
-esxVI_GetNumberOfDomainsByPowerState(virConnectPtr conn, esxVI_Context *ctx,
-                                     esxVI_VirtualMachinePowerState powerState,
-                                     esxVI_Boolean inverse)
+esxVI_LookupNumberOfDomainsByPowerState(virConnectPtr conn, esxVI_Context *ctx,
+                                        esxVI_VirtualMachinePowerState powerState,
+                                        esxVI_Boolean inverse)
 {
     esxVI_String *propertyNameList = NULL;
     esxVI_ObjectContent *virtualMachineList = NULL;
@@ -1492,9 +1500,10 @@ esxVI_GetNumberOfDomainsByPowerState(virConnectPtr conn, esxVI_Context *ctx,
 
     if (esxVI_String_AppendValueToList(conn, &propertyNameList,
                                        "runtime.powerState") < 0 ||
-        esxVI_GetObjectContent(conn, ctx, ctx->vmFolder, "VirtualMachine",
-                               propertyNameList, esxVI_Boolean_True,
-                               &virtualMachineList) < 0) {
+        esxVI_LookupObjectContentByType(conn, ctx, ctx->vmFolder,
+                                        "VirtualMachine", propertyNameList,
+                                        esxVI_Boolean_True,
+                                        &virtualMachineList) < 0) {
         goto failure;
     }
 
@@ -1646,9 +1655,10 @@ esxVI_GetVirtualMachineIdentity(virConnectPtr conn,
 
 
 
-int esxVI_GetResourcePool(virConnectPtr conn, esxVI_Context *ctx,
-                          esxVI_ObjectContent *hostSystem,
-                          esxVI_ManagedObjectReference **resourcePool)
+int
+esxVI_LookupResourcePoolByHostSystem
+  (virConnectPtr conn, esxVI_Context *ctx, esxVI_ObjectContent *hostSystem,
+   esxVI_ManagedObjectReference **resourcePool)
 {
     int result = 0;
     esxVI_String *propertyNameList = NULL;
@@ -1684,9 +1694,10 @@ int esxVI_GetResourcePool(virConnectPtr conn, esxVI_Context *ctx,
 
     if (esxVI_String_AppendValueToList(conn, &propertyNameList,
                                        "resourcePool") < 0 ||
-        esxVI_GetObjectContent(conn, ctx, managedObjectReference,
-                               "ComputeResource", propertyNameList,
-                               esxVI_Boolean_False, &computeResource) < 0) {
+        esxVI_LookupObjectContentByType(conn, ctx, managedObjectReference,
+                                        "ComputeResource", propertyNameList,
+                                        esxVI_Boolean_False,
+                                        &computeResource) < 0) {
         goto failure;
     }
 
@@ -1751,9 +1762,9 @@ esxVI_LookupHostSystemByIp(virConnectPtr conn, esxVI_Context *ctx,
         goto failure;
     }
 
-    if (esxVI_GetObjectContent(conn, ctx, managedObjectReference,
-                               "HostSystem", propertyNameList,
-                               esxVI_Boolean_False, hostSystem) < 0) {
+    if (esxVI_LookupObjectContentByType(conn, ctx, managedObjectReference,
+                                        "HostSystem", propertyNameList,
+                                        esxVI_Boolean_False, hostSystem) < 0) {
         goto failure;
     }
 
@@ -1803,9 +1814,10 @@ esxVI_LookupVirtualMachineByUuid(virConnectPtr conn, esxVI_Context *ctx,
         }
     }
 
-    if (esxVI_GetObjectContent(conn, ctx, managedObjectReference,
-                               "VirtualMachine", propertyNameList,
-                               esxVI_Boolean_False, virtualMachine) < 0) {
+    if (esxVI_LookupObjectContentByType(conn, ctx, managedObjectReference,
+                                        "VirtualMachine", propertyNameList,
+                                        esxVI_Boolean_False,
+                                        virtualMachine) < 0) {
         goto failure;
     }
 
@@ -1852,9 +1864,10 @@ esxVI_LookupDatastoreByName(virConnectPtr conn, esxVI_Context *ctx,
         goto failure;
     }
 
-    if (esxVI_GetObjectContent(conn, ctx, ctx->datacenter,
-                               "Datastore", completePropertyNameList,
-                               esxVI_Boolean_True, &datastoreList) < 0) {
+    if (esxVI_LookupObjectContentByType(conn, ctx, ctx->datacenter,
+                                        "Datastore", completePropertyNameList,
+                                        esxVI_Boolean_True,
+                                        &datastoreList) < 0) {
         goto failure;
     }
 
diff --git a/src/esx/esx_vi.h b/src/esx/esx_vi.h
index 6ba6bed..4892fde 100644
--- a/src/esx/esx_vi.h
+++ b/src/esx/esx_vi.h
@@ -192,29 +192,33 @@ int esxVI_List_Deserialize(virConnectPtr conn, xmlNodePtr node,
 
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  * Utility and Convenience Functions
+ *
+ * Function naming scheme:
+ *  - 'lookup' functions query the ESX or vCenter for information
+ *  - 'get' functions get information from a local object
  */
 
-int
-esxVI_Alloc(virConnectPtr conn, void **ptrptr, size_t size);
+int esxVI_Alloc(virConnectPtr conn, void **ptrptr, size_t size);
 
-int
-esxVI_CheckSerializationNecessity(virConnectPtr conn, const char *element,
-                                  esxVI_Boolean required);
+int esxVI_CheckSerializationNecessity(virConnectPtr conn, const char *element,
+                                      esxVI_Boolean required);
 
 int esxVI_BuildFullTraversalSpecItem
       (virConnectPtr conn, esxVI_SelectionSpec **fullTraversalSpecList,
        const char *name, const char *type, const char *path,
        const char *selectSetNames);
+
 int esxVI_BuildFullTraversalSpecList
       (virConnectPtr conn, esxVI_SelectionSpec **fullTraversalSpecList);
 
 int esxVI_EnsureSession(virConnectPtr conn, esxVI_Context *ctx);
 
-int esxVI_GetObjectContent(virConnectPtr conn, esxVI_Context *ctx,
-                           esxVI_ManagedObjectReference *root,
-                           const char *type, esxVI_String *propertyNameList,
-                           esxVI_Boolean recurse,
-                           esxVI_ObjectContent **objectContentList);
+int esxVI_LookupObjectContentByType(virConnectPtr conn, esxVI_Context *ctx,
+                                    esxVI_ManagedObjectReference *root,
+                                    const char *type,
+                                    esxVI_String *propertyNameList,
+                                    esxVI_Boolean recurse,
+                                    esxVI_ObjectContent **objectContentList);
 
 int esxVI_GetManagedEntityStatus
       (virConnectPtr conn, esxVI_ObjectContent *objectContent,
@@ -225,7 +229,7 @@ int esxVI_GetVirtualMachinePowerState
       (virConnectPtr conn, esxVI_ObjectContent *virtualMachine,
        esxVI_VirtualMachinePowerState *powerState);
 
-int esxVI_GetNumberOfDomainsByPowerState
+int esxVI_LookupNumberOfDomainsByPowerState
       (virConnectPtr conn, esxVI_Context *ctx,
        esxVI_VirtualMachinePowerState powerState, esxVI_Boolean inverse);
 
@@ -233,9 +237,9 @@ int esxVI_GetVirtualMachineIdentity(virConnectPtr conn,
                                     esxVI_ObjectContent *virtualMachine,
                                     int *id, char **name, unsigned char *uuid);
 
-int esxVI_GetResourcePool(virConnectPtr conn, esxVI_Context *ctx,
-                          esxVI_ObjectContent *hostSystem,
-                          esxVI_ManagedObjectReference **resourcePool);
+int esxVI_LookupResourcePoolByHostSystem
+      (virConnectPtr conn, esxVI_Context *ctx, esxVI_ObjectContent *hostSystem,
+       esxVI_ManagedObjectReference **resourcePool);
 
 int esxVI_LookupHostSystemByIp(virConnectPtr conn, esxVI_Context *ctx,
                                const char *ipAddress,
-- 
1.6.0.4




More information about the libvir-list mailing list