ESX: make esxVI_GetVirtualMachineIdentity() robust

* src/esx/esx_driver.c: add configStatus to the requested properties
  to check it in esxVI_GetVirtualMachineIdentity()
* src/esx/esx_vi.[ch]: add esxVI_GetManagedEntityStatus()
  and use it in esxVI_GetVirtualMachineIdentity()
* src/esx/esx_vi_types.[ch]: add VI type esxVI_ManagedEntityStatus
This commit is contained in:
Matthias Bolte 2009-09-04 18:03:22 +02:00 committed by Daniel Veillard
parent 902aaabb11
commit 1f8988b580
5 changed files with 107 additions and 23 deletions

View File

@ -851,9 +851,10 @@ esxDomainLookupByID(virConnectPtr conn, int id)
} }
if (esxVI_String_AppendValueListToList(conn, &propertyNameList, if (esxVI_String_AppendValueListToList(conn, &propertyNameList,
"configStatus\0"
"name\0" "name\0"
"runtime.powerState\0" "runtime.powerState\0"
"summary.config.uuid\0") < 0 || "config.uuid\0") < 0 ||
esxVI_GetObjectContent(conn, priv->host, priv->host->vmFolder, esxVI_GetObjectContent(conn, priv->host, priv->host->vmFolder,
"VirtualMachine", propertyNameList, "VirtualMachine", propertyNameList,
esxVI_Boolean_True, &virtualMachineList) < 0) { esxVI_Boolean_True, &virtualMachineList) < 0) {
@ -939,9 +940,10 @@ esxDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
} }
if (esxVI_String_AppendValueListToList(conn, &propertyNameList, if (esxVI_String_AppendValueListToList(conn, &propertyNameList,
"configStatus\0"
"name\0" "name\0"
"runtime.powerState\0" "runtime.powerState\0"
"summary.config.uuid\0") < 0 || "config.uuid\0") < 0 ||
esxVI_GetObjectContent(conn, priv->host, priv->host->vmFolder, esxVI_GetObjectContent(conn, priv->host, priv->host->vmFolder,
"VirtualMachine", propertyNameList, "VirtualMachine", propertyNameList,
esxVI_Boolean_True, &virtualMachineList) < 0) { esxVI_Boolean_True, &virtualMachineList) < 0) {
@ -1030,9 +1032,10 @@ esxDomainLookupByName(virConnectPtr conn, const char *name)
} }
if (esxVI_String_AppendValueListToList(conn, &propertyNameList, if (esxVI_String_AppendValueListToList(conn, &propertyNameList,
"configStatus\0"
"name\0" "name\0"
"runtime.powerState\0" "runtime.powerState\0"
"summary.config.uuid\0") < 0 || "config.uuid\0") < 0 ||
esxVI_GetObjectContent(conn, priv->host, priv->host->vmFolder, esxVI_GetObjectContent(conn, priv->host, priv->host->vmFolder,
"VirtualMachine", propertyNameList, "VirtualMachine", propertyNameList,
esxVI_Boolean_True, &virtualMachineList) < 0) { esxVI_Boolean_True, &virtualMachineList) < 0) {

View File

@ -1358,6 +1358,30 @@ esxVI_GetObjectContent(virConnectPtr conn, esxVI_Context *ctx,
int
esxVI_GetManagedEntityStatus(virConnectPtr conn,
esxVI_ObjectContent *objectContent,
const char *propertyName,
esxVI_ManagedEntityStatus *managedEntityStatus)
{
esxVI_DynamicProperty *dynamicProperty;
for (dynamicProperty = objectContent->propSet; dynamicProperty != NULL;
dynamicProperty = dynamicProperty->_next) {
if (STREQ(dynamicProperty->name, propertyName)) {
return esxVI_ManagedEntityStatus_CastFromAnyType
(conn, dynamicProperty->val, managedEntityStatus);
}
}
ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
"Missing '%s' property", propertyName);
return -1;
}
int int
esxVI_GetVirtualMachinePowerState(virConnectPtr conn, esxVI_GetVirtualMachinePowerState(virConnectPtr conn,
esxVI_ObjectContent *virtualMachine, esxVI_ObjectContent *virtualMachine,
@ -1445,6 +1469,7 @@ esxVI_GetVirtualMachineIdentity(virConnectPtr conn,
{ {
const char *uuid_string = NULL; const char *uuid_string = NULL;
esxVI_DynamicProperty *dynamicProperty = NULL; esxVI_DynamicProperty *dynamicProperty = NULL;
esxVI_ManagedEntityStatus configStatus = esxVI_ManagedEntityStatus_Undefined;
if (STRNEQ(virtualMachine->obj->type, "VirtualMachine")) { if (STRNEQ(virtualMachine->obj->type, "VirtualMachine")) {
ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
@ -1496,30 +1521,43 @@ esxVI_GetVirtualMachineIdentity(virConnectPtr conn,
} }
if (uuid != NULL) { if (uuid != NULL) {
for (dynamicProperty = virtualMachine->propSet; if (esxVI_GetManagedEntityStatus(conn, virtualMachine, "configStatus",
dynamicProperty != NULL; &configStatus) < 0) {
dynamicProperty = dynamicProperty->_next) { goto failure;
if (STREQ(dynamicProperty->name, "summary.config.uuid")) { }
if (esxVI_AnyType_ExpectType(conn, dynamicProperty->val,
esxVI_Type_String) < 0) { if (configStatus == esxVI_ManagedEntityStatus_Green) {
goto failure; for (dynamicProperty = virtualMachine->propSet;
dynamicProperty != NULL;
dynamicProperty = dynamicProperty->_next) {
if (STREQ(dynamicProperty->name, "config.uuid")) {
if (esxVI_AnyType_ExpectType(conn, dynamicProperty->val,
esxVI_Type_String) < 0) {
goto failure;
}
uuid_string = dynamicProperty->val->string;
break;
} }
uuid_string = dynamicProperty->val->string;
break;
} }
}
if (uuid_string == NULL) { if (uuid_string == NULL) {
ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
"Could not get UUID of virtual machine"); "Could not get UUID of virtual machine");
goto failure; goto failure;
} }
if (virUUIDParse(uuid_string, uuid) < 0) { if (virUUIDParse(uuid_string, uuid) < 0) {
ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
"Could not parse UUID from string '%s'", uuid_string); "Could not parse UUID from string '%s'",
goto failure; uuid_string);
goto failure;
}
} else {
memset(uuid, 0, VIR_UUID_BUFLEN);
VIR_WARN0("Cannot access UUID, because 'configStatus' property "
"indicates a config problem");
} }
} }

View File

@ -232,6 +232,11 @@ int esxVI_GetObjectContent(virConnectPtr conn, esxVI_Context *ctx,
esxVI_Boolean recurse, esxVI_Boolean recurse,
esxVI_ObjectContent **objectContentList); esxVI_ObjectContent **objectContentList);
int esxVI_GetManagedEntityStatus
(virConnectPtr conn, esxVI_ObjectContent *objectContent,
const char *propertyName,
esxVI_ManagedEntityStatus *managedEntityStatus);
int esxVI_GetVirtualMachinePowerState int esxVI_GetVirtualMachinePowerState
(virConnectPtr conn, esxVI_ObjectContent *virtualMachine, (virConnectPtr conn, esxVI_ObjectContent *virtualMachine,
esxVI_VirtualMachinePowerState *powerState); esxVI_VirtualMachinePowerState *powerState);

View File

@ -1053,6 +1053,25 @@ esxVI_DateTime_Deserialize(virConnectPtr conn, xmlNodePtr node,
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* VI Enum: ManagedEntityStatus
*/
static const esxVI_Enumeration _esxVI_ManagedEntityStatus_Enumeration = {
"ManagedEntityStatus", {
{ "gray", esxVI_ManagedEntityStatus_Gray },
{ "green", esxVI_ManagedEntityStatus_Green },
{ "yellow", esxVI_ManagedEntityStatus_Yellow },
{ "red", esxVI_ManagedEntityStatus_Red },
{ NULL, -1 },
},
};
/* esxVI_ManagedEntityStatus_CastFromAnyType */
ESX_VI__TEMPLATE__ENUMERATION__CAST_FROM_ANY_TYPE(ManagedEntityStatus);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* VI Enum: ObjectUpdateKind * VI Enum: ObjectUpdateKind
*/ */

View File

@ -52,6 +52,7 @@ typedef struct _esxVI_DateTime esxVI_DateTime;
* VI Enums * VI Enums
*/ */
typedef enum _esxVI_ManagedEntityStatus esxVI_ManagedEntityStatus;
typedef enum _esxVI_ObjectUpdateKind esxVI_ObjectUpdateKind; typedef enum _esxVI_ObjectUpdateKind esxVI_ObjectUpdateKind;
typedef enum _esxVI_PerfSummaryType esxVI_PerfSummaryType; typedef enum _esxVI_PerfSummaryType esxVI_PerfSummaryType;
typedef enum _esxVI_PerfStatsType esxVI_PerfStatsType; typedef enum _esxVI_PerfStatsType esxVI_PerfStatsType;
@ -276,6 +277,24 @@ int esxVI_DateTime_Deserialize(virConnectPtr conn, xmlNodePtr node,
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* VI Enum: ManagedEntityStatus
*/
enum _esxVI_ManagedEntityStatus {
esxVI_ManagedEntityStatus_Undefined = 0,
esxVI_ManagedEntityStatus_Gray,
esxVI_ManagedEntityStatus_Green,
esxVI_ManagedEntityStatus_Yellow,
esxVI_ManagedEntityStatus_Red,
};
int esxVI_ManagedEntityStatus_CastFromAnyType
(virConnectPtr conn, esxVI_AnyType *anyType,
esxVI_ManagedEntityStatus *managedEntityStatus);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* VI Enum: ObjectUpdateKind * VI Enum: ObjectUpdateKind
*/ */