ESX: Unify naming of VI API utility and convenience functions.

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
This commit is contained in:
Matthias Bolte 2009-10-18 21:31:46 +02:00
parent 7c7681dd90
commit 447ef8863c
3 changed files with 116 additions and 88 deletions

View File

@ -90,7 +90,8 @@ esxSupportsLongMode(virConnectPtr conn)
if (esxVI_String_AppendValueToList(conn, &propertyNameList, if (esxVI_String_AppendValueToList(conn, &propertyNameList,
"hardware.cpuFeature") < 0 || "hardware.cpuFeature") < 0 ||
esxVI_GetObjectContent(conn, priv->host, priv->host->hostFolder, esxVI_LookupObjectContentByType(conn, priv->host,
priv->host->hostFolder,
"HostSystem", propertyNameList, "HostSystem", propertyNameList,
esxVI_Boolean_True, &hostSystem) < 0) { esxVI_Boolean_True, &hostSystem) < 0) {
goto failure; goto failure;
@ -522,7 +523,8 @@ esxSupportsVMotion(virConnectPtr conn)
if (esxVI_String_AppendValueToList(conn, &propertyNameList, if (esxVI_String_AppendValueToList(conn, &propertyNameList,
"capability.vmotionSupported") < 0 || "capability.vmotionSupported") < 0 ||
esxVI_GetObjectContent(conn, priv->host, priv->host->hostFolder, esxVI_LookupObjectContentByType(conn, priv->host,
priv->host->hostFolder,
"HostSystem", propertyNameList, "HostSystem", propertyNameList,
esxVI_Boolean_True, &hostSystem) < 0) { esxVI_Boolean_True, &hostSystem) < 0) {
goto failure; goto failure;
@ -653,7 +655,8 @@ esxGetHostname(virConnectPtr conn)
(conn, &propertyNameList, (conn, &propertyNameList,
"config.network.dnsConfig.hostName\0" "config.network.dnsConfig.hostName\0"
"config.network.dnsConfig.domainName\0") < 0 || "config.network.dnsConfig.domainName\0") < 0 ||
esxVI_GetObjectContent(conn, priv->host, priv->host->hostFolder, esxVI_LookupObjectContentByType(conn, priv->host,
priv->host->hostFolder,
"HostSystem", propertyNameList, "HostSystem", propertyNameList,
esxVI_Boolean_True, &hostSystem) < 0) { esxVI_Boolean_True, &hostSystem) < 0) {
goto failure; goto failure;
@ -750,7 +753,8 @@ esxNodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo)
"hardware.memorySize\0" "hardware.memorySize\0"
"hardware.numaInfo.numNodes\0" "hardware.numaInfo.numNodes\0"
"summary.hardware.cpuModel\0") < 0 || "summary.hardware.cpuModel\0") < 0 ||
esxVI_GetObjectContent(conn, priv->host, priv->host->hostFolder, esxVI_LookupObjectContentByType(conn, priv->host,
priv->host->hostFolder,
"HostSystem", propertyNameList, "HostSystem", propertyNameList,
esxVI_Boolean_True, &hostSystem) < 0) { esxVI_Boolean_True, &hostSystem) < 0) {
goto failure; goto failure;
@ -914,9 +918,10 @@ esxListDomains(virConnectPtr conn, int *ids, int maxids)
if (esxVI_String_AppendValueToList(conn, &propertyNameList, if (esxVI_String_AppendValueToList(conn, &propertyNameList,
"runtime.powerState") < 0 || "runtime.powerState") < 0 ||
esxVI_GetObjectContent(conn, priv->host, priv->host->vmFolder, esxVI_LookupObjectContentByType(conn, priv->host, priv->host->vmFolder,
"VirtualMachine", propertyNameList, "VirtualMachine", propertyNameList,
esxVI_Boolean_True, &virtualMachineList) < 0) { esxVI_Boolean_True,
&virtualMachineList) < 0) {
goto failure; goto failure;
} }
@ -970,7 +975,7 @@ esxNumberOfDomains(virConnectPtr conn)
return -1; return -1;
} }
return esxVI_GetNumberOfDomainsByPowerState return esxVI_LookupNumberOfDomainsByPowerState
(conn, priv->host, esxVI_VirtualMachinePowerState_PoweredOn, (conn, priv->host, esxVI_VirtualMachinePowerState_PoweredOn,
esxVI_Boolean_False); esxVI_Boolean_False);
} }
@ -999,9 +1004,10 @@ esxDomainLookupByID(virConnectPtr conn, int id)
"name\0" "name\0"
"runtime.powerState\0" "runtime.powerState\0"
"config.uuid\0") < 0 || "config.uuid\0") < 0 ||
esxVI_GetObjectContent(conn, priv->host, priv->host->vmFolder, esxVI_LookupObjectContentByType(conn, priv->host, priv->host->vmFolder,
"VirtualMachine", propertyNameList, "VirtualMachine", propertyNameList,
esxVI_Boolean_True, &virtualMachineList) < 0) { esxVI_Boolean_True,
&virtualMachineList) < 0) {
goto failure; goto failure;
} }
@ -1082,9 +1088,10 @@ esxDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
"name\0" "name\0"
"runtime.powerState\0" "runtime.powerState\0"
"config.uuid\0") < 0 || "config.uuid\0") < 0 ||
esxVI_GetObjectContent(conn, priv->host, priv->host->vmFolder, esxVI_LookupObjectContentByType(conn, priv->host, priv->host->vmFolder,
"VirtualMachine", propertyNameList, "VirtualMachine", propertyNameList,
esxVI_Boolean_True, &virtualMachineList) < 0) { esxVI_Boolean_True,
&virtualMachineList) < 0) {
goto failure; goto failure;
} }
@ -1168,9 +1175,10 @@ esxDomainLookupByName(virConnectPtr conn, const char *name)
"name\0" "name\0"
"runtime.powerState\0" "runtime.powerState\0"
"config.uuid\0") < 0 || "config.uuid\0") < 0 ||
esxVI_GetObjectContent(conn, priv->host, priv->host->vmFolder, esxVI_LookupObjectContentByType(conn, priv->host, priv->host->vmFolder,
"VirtualMachine", propertyNameList, "VirtualMachine", propertyNameList,
esxVI_Boolean_True, &virtualMachineList) < 0) { esxVI_Boolean_True,
&virtualMachineList) < 0) {
goto failure; goto failure;
} }
@ -2042,7 +2050,7 @@ esxDomainGetMaxVcpus(virDomainPtr domain)
if (esxVI_String_AppendValueToList(domain->conn, &propertyNameList, if (esxVI_String_AppendValueToList(domain->conn, &propertyNameList,
"capability.maxSupportedVcpus") < 0 || "capability.maxSupportedVcpus") < 0 ||
esxVI_GetObjectContent(domain->conn, priv->host, esxVI_LookupObjectContentByType(domain->conn, priv->host,
priv->host->hostFolder, "HostSystem", priv->host->hostFolder, "HostSystem",
propertyNameList, esxVI_Boolean_True, propertyNameList, esxVI_Boolean_True,
&hostSystem) < 0) { &hostSystem) < 0) {
@ -2270,9 +2278,10 @@ esxListDefinedDomains(virConnectPtr conn, char **const names, int maxnames)
if (esxVI_String_AppendValueListToList(conn, &propertyNameList, if (esxVI_String_AppendValueListToList(conn, &propertyNameList,
"name\0" "name\0"
"runtime.powerState\0") < 0 || "runtime.powerState\0") < 0 ||
esxVI_GetObjectContent(conn, priv->host, priv->host->vmFolder, esxVI_LookupObjectContentByType(conn, priv->host, priv->host->vmFolder,
"VirtualMachine", propertyNameList, "VirtualMachine", propertyNameList,
esxVI_Boolean_True, &virtualMachineList) < 0) { esxVI_Boolean_True,
&virtualMachineList) < 0) {
goto failure; goto failure;
} }
@ -2337,7 +2346,7 @@ esxNumberOfDefinedDomains(virConnectPtr conn)
return -1; return -1;
} }
return esxVI_GetNumberOfDomainsByPowerState return esxVI_LookupNumberOfDomainsByPowerState
(conn, priv->host, esxVI_VirtualMachinePowerState_PoweredOn, (conn, priv->host, esxVI_VirtualMachinePowerState_PoweredOn,
esxVI_Boolean_True); esxVI_Boolean_True);
} }
@ -2550,7 +2559,7 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml ATTRIBUTE_UNUSED)
goto failure; goto failure;
} }
if (esxVI_GetResourcePool(conn, priv->host, hostSystem, if (esxVI_LookupResourcePoolByHostSystem(conn, priv->host, hostSystem,
&resourcePool) < 0) { &resourcePool) < 0) {
goto failure; goto failure;
} }
@ -3071,8 +3080,8 @@ esxDomainMigratePerform(virDomainPtr domain,
goto failure; goto failure;
} }
if (esxVI_GetResourcePool(domain->conn, priv->vCenter, hostSystem, if (esxVI_LookupResourcePoolByHostSystem(domain->conn, priv->vCenter,
&resourcePool) < 0) { hostSystem, &resourcePool) < 0) {
goto failure; goto failure;
} }
@ -3172,7 +3181,7 @@ esxNodeGetFreeMemory(virConnectPtr conn)
goto failure; goto failure;
} }
if (esxVI_GetResourcePool(conn, priv->host, hostSystem, if (esxVI_LookupResourcePoolByHostSystem(conn, priv->host, hostSystem,
&managedObjectReference) < 0) { &managedObjectReference) < 0) {
goto failure; goto failure;
} }
@ -3182,9 +3191,11 @@ esxNodeGetFreeMemory(virConnectPtr conn)
/* Get memory usage of resource pool */ /* Get memory usage of resource pool */
if (esxVI_String_AppendValueToList(conn, &propertyNameList, if (esxVI_String_AppendValueToList(conn, &propertyNameList,
"runtime.memory") < 0 || "runtime.memory") < 0 ||
esxVI_GetObjectContent(conn, priv->host, managedObjectReference, esxVI_LookupObjectContentByType(conn, priv->host,
managedObjectReference,
"ResourcePool", propertyNameList, "ResourcePool", propertyNameList,
esxVI_Boolean_False, &resourcePool) < 0) { esxVI_Boolean_False,
&resourcePool) < 0) {
goto failure; goto failure;
} }

View File

@ -374,9 +374,10 @@ esxVI_Context_Connect(virConnectPtr conn, esxVI_Context *ctx, const char *url,
} }
/* Get pointer to Datacenter for later use */ /* Get pointer to Datacenter for later use */
if (esxVI_GetObjectContent(conn, ctx, ctx->service->rootFolder, if (esxVI_LookupObjectContentByType(conn, ctx, ctx->service->rootFolder,
"Datacenter", propertyNameList, "Datacenter", propertyNameList,
esxVI_Boolean_True, &datacenterList) < 0) { esxVI_Boolean_True,
&datacenterList) < 0) {
goto failure; goto failure;
} }
@ -1061,6 +1062,10 @@ esxVI_List_Deserialize(virConnectPtr conn, xmlNodePtr node, esxVI_List **list,
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Utility and Convenience Functions * 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 int
@ -1301,9 +1306,11 @@ esxVI_EnsureSession(virConnectPtr conn, esxVI_Context *ctx)
#else #else
if (esxVI_String_AppendValueToList(conn, &propertyNameList, if (esxVI_String_AppendValueToList(conn, &propertyNameList,
"currentSession") < 0 || "currentSession") < 0 ||
esxVI_GetObjectContent(conn, ctx, ctx->service->sessionManager, esxVI_LookupObjectContentByType(conn, ctx,
ctx->service->sessionManager,
"SessionManager", propertyNameList, "SessionManager", propertyNameList,
esxVI_Boolean_False, &sessionManager) < 0) { esxVI_Boolean_False,
&sessionManager) < 0) {
goto failure; goto failure;
} }
@ -1358,9 +1365,10 @@ esxVI_EnsureSession(virConnectPtr conn, esxVI_Context *ctx)
int int
esxVI_GetObjectContent(virConnectPtr conn, esxVI_Context *ctx, esxVI_LookupObjectContentByType(virConnectPtr conn, esxVI_Context *ctx,
esxVI_ManagedObjectReference *root, esxVI_ManagedObjectReference *root,
const char *type, esxVI_String *propertyNameList, const char *type,
esxVI_String *propertyNameList,
esxVI_Boolean recurse, esxVI_Boolean recurse,
esxVI_ObjectContent **objectContentList) esxVI_ObjectContent **objectContentList)
{ {
@ -1479,7 +1487,7 @@ esxVI_GetVirtualMachinePowerState(virConnectPtr conn,
int int
esxVI_GetNumberOfDomainsByPowerState(virConnectPtr conn, esxVI_Context *ctx, esxVI_LookupNumberOfDomainsByPowerState(virConnectPtr conn, esxVI_Context *ctx,
esxVI_VirtualMachinePowerState powerState, esxVI_VirtualMachinePowerState powerState,
esxVI_Boolean inverse) esxVI_Boolean inverse)
{ {
@ -1492,8 +1500,9 @@ esxVI_GetNumberOfDomainsByPowerState(virConnectPtr conn, esxVI_Context *ctx,
if (esxVI_String_AppendValueToList(conn, &propertyNameList, if (esxVI_String_AppendValueToList(conn, &propertyNameList,
"runtime.powerState") < 0 || "runtime.powerState") < 0 ||
esxVI_GetObjectContent(conn, ctx, ctx->vmFolder, "VirtualMachine", esxVI_LookupObjectContentByType(conn, ctx, ctx->vmFolder,
propertyNameList, esxVI_Boolean_True, "VirtualMachine", propertyNameList,
esxVI_Boolean_True,
&virtualMachineList) < 0) { &virtualMachineList) < 0) {
goto failure; goto failure;
} }
@ -1646,8 +1655,9 @@ esxVI_GetVirtualMachineIdentity(virConnectPtr conn,
int esxVI_GetResourcePool(virConnectPtr conn, esxVI_Context *ctx, int
esxVI_ObjectContent *hostSystem, esxVI_LookupResourcePoolByHostSystem
(virConnectPtr conn, esxVI_Context *ctx, esxVI_ObjectContent *hostSystem,
esxVI_ManagedObjectReference **resourcePool) esxVI_ManagedObjectReference **resourcePool)
{ {
int result = 0; int result = 0;
@ -1684,9 +1694,10 @@ int esxVI_GetResourcePool(virConnectPtr conn, esxVI_Context *ctx,
if (esxVI_String_AppendValueToList(conn, &propertyNameList, if (esxVI_String_AppendValueToList(conn, &propertyNameList,
"resourcePool") < 0 || "resourcePool") < 0 ||
esxVI_GetObjectContent(conn, ctx, managedObjectReference, esxVI_LookupObjectContentByType(conn, ctx, managedObjectReference,
"ComputeResource", propertyNameList, "ComputeResource", propertyNameList,
esxVI_Boolean_False, &computeResource) < 0) { esxVI_Boolean_False,
&computeResource) < 0) {
goto failure; goto failure;
} }
@ -1751,7 +1762,7 @@ esxVI_LookupHostSystemByIp(virConnectPtr conn, esxVI_Context *ctx,
goto failure; goto failure;
} }
if (esxVI_GetObjectContent(conn, ctx, managedObjectReference, if (esxVI_LookupObjectContentByType(conn, ctx, managedObjectReference,
"HostSystem", propertyNameList, "HostSystem", propertyNameList,
esxVI_Boolean_False, hostSystem) < 0) { esxVI_Boolean_False, hostSystem) < 0) {
goto failure; goto failure;
@ -1803,9 +1814,10 @@ esxVI_LookupVirtualMachineByUuid(virConnectPtr conn, esxVI_Context *ctx,
} }
} }
if (esxVI_GetObjectContent(conn, ctx, managedObjectReference, if (esxVI_LookupObjectContentByType(conn, ctx, managedObjectReference,
"VirtualMachine", propertyNameList, "VirtualMachine", propertyNameList,
esxVI_Boolean_False, virtualMachine) < 0) { esxVI_Boolean_False,
virtualMachine) < 0) {
goto failure; goto failure;
} }
@ -1852,9 +1864,10 @@ esxVI_LookupDatastoreByName(virConnectPtr conn, esxVI_Context *ctx,
goto failure; goto failure;
} }
if (esxVI_GetObjectContent(conn, ctx, ctx->datacenter, if (esxVI_LookupObjectContentByType(conn, ctx, ctx->datacenter,
"Datastore", completePropertyNameList, "Datastore", completePropertyNameList,
esxVI_Boolean_True, &datastoreList) < 0) { esxVI_Boolean_True,
&datastoreList) < 0) {
goto failure; goto failure;
} }

View File

@ -192,27 +192,31 @@ int esxVI_List_Deserialize(virConnectPtr conn, xmlNodePtr node,
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Utility and Convenience Functions * 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 int esxVI_Alloc(virConnectPtr conn, void **ptrptr, size_t size);
esxVI_Alloc(virConnectPtr conn, void **ptrptr, size_t size);
int int esxVI_CheckSerializationNecessity(virConnectPtr conn, const char *element,
esxVI_CheckSerializationNecessity(virConnectPtr conn, const char *element,
esxVI_Boolean required); esxVI_Boolean required);
int esxVI_BuildFullTraversalSpecItem int esxVI_BuildFullTraversalSpecItem
(virConnectPtr conn, esxVI_SelectionSpec **fullTraversalSpecList, (virConnectPtr conn, esxVI_SelectionSpec **fullTraversalSpecList,
const char *name, const char *type, const char *path, const char *name, const char *type, const char *path,
const char *selectSetNames); const char *selectSetNames);
int esxVI_BuildFullTraversalSpecList int esxVI_BuildFullTraversalSpecList
(virConnectPtr conn, esxVI_SelectionSpec **fullTraversalSpecList); (virConnectPtr conn, esxVI_SelectionSpec **fullTraversalSpecList);
int esxVI_EnsureSession(virConnectPtr conn, esxVI_Context *ctx); int esxVI_EnsureSession(virConnectPtr conn, esxVI_Context *ctx);
int esxVI_GetObjectContent(virConnectPtr conn, esxVI_Context *ctx, int esxVI_LookupObjectContentByType(virConnectPtr conn, esxVI_Context *ctx,
esxVI_ManagedObjectReference *root, esxVI_ManagedObjectReference *root,
const char *type, esxVI_String *propertyNameList, const char *type,
esxVI_String *propertyNameList,
esxVI_Boolean recurse, esxVI_Boolean recurse,
esxVI_ObjectContent **objectContentList); esxVI_ObjectContent **objectContentList);
@ -225,7 +229,7 @@ int esxVI_GetVirtualMachinePowerState
(virConnectPtr conn, esxVI_ObjectContent *virtualMachine, (virConnectPtr conn, esxVI_ObjectContent *virtualMachine,
esxVI_VirtualMachinePowerState *powerState); esxVI_VirtualMachinePowerState *powerState);
int esxVI_GetNumberOfDomainsByPowerState int esxVI_LookupNumberOfDomainsByPowerState
(virConnectPtr conn, esxVI_Context *ctx, (virConnectPtr conn, esxVI_Context *ctx,
esxVI_VirtualMachinePowerState powerState, esxVI_Boolean inverse); esxVI_VirtualMachinePowerState powerState, esxVI_Boolean inverse);
@ -233,8 +237,8 @@ int esxVI_GetVirtualMachineIdentity(virConnectPtr conn,
esxVI_ObjectContent *virtualMachine, esxVI_ObjectContent *virtualMachine,
int *id, char **name, unsigned char *uuid); int *id, char **name, unsigned char *uuid);
int esxVI_GetResourcePool(virConnectPtr conn, esxVI_Context *ctx, int esxVI_LookupResourcePoolByHostSystem
esxVI_ObjectContent *hostSystem, (virConnectPtr conn, esxVI_Context *ctx, esxVI_ObjectContent *hostSystem,
esxVI_ManagedObjectReference **resourcePool); esxVI_ManagedObjectReference **resourcePool);
int esxVI_LookupHostSystemByIp(virConnectPtr conn, esxVI_Context *ctx, int esxVI_LookupHostSystemByIp(virConnectPtr conn, esxVI_Context *ctx,