diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index fc225cfbb6..8f3c047a40 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -851,9 +851,10 @@ esxDomainLookupByID(virConnectPtr conn, int id) } if (esxVI_String_AppendValueListToList(conn, &propertyNameList, + "configStatus\0" "name\0" "runtime.powerState\0" - "summary.config.uuid\0") < 0 || + "config.uuid\0") < 0 || esxVI_GetObjectContent(conn, priv->host, priv->host->vmFolder, "VirtualMachine", propertyNameList, esxVI_Boolean_True, &virtualMachineList) < 0) { @@ -939,9 +940,10 @@ esxDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid) } if (esxVI_String_AppendValueListToList(conn, &propertyNameList, + "configStatus\0" "name\0" "runtime.powerState\0" - "summary.config.uuid\0") < 0 || + "config.uuid\0") < 0 || esxVI_GetObjectContent(conn, priv->host, priv->host->vmFolder, "VirtualMachine", propertyNameList, esxVI_Boolean_True, &virtualMachineList) < 0) { @@ -1030,9 +1032,10 @@ esxDomainLookupByName(virConnectPtr conn, const char *name) } if (esxVI_String_AppendValueListToList(conn, &propertyNameList, + "configStatus\0" "name\0" "runtime.powerState\0" - "summary.config.uuid\0") < 0 || + "config.uuid\0") < 0 || esxVI_GetObjectContent(conn, priv->host, priv->host->vmFolder, "VirtualMachine", propertyNameList, esxVI_Boolean_True, &virtualMachineList) < 0) { diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c index dfcb35217a..08911d0a31 100644 --- a/src/esx/esx_vi.c +++ b/src/esx/esx_vi.c @@ -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 esxVI_GetVirtualMachinePowerState(virConnectPtr conn, esxVI_ObjectContent *virtualMachine, @@ -1445,6 +1469,7 @@ esxVI_GetVirtualMachineIdentity(virConnectPtr conn, { const char *uuid_string = NULL; esxVI_DynamicProperty *dynamicProperty = NULL; + esxVI_ManagedEntityStatus configStatus = esxVI_ManagedEntityStatus_Undefined; if (STRNEQ(virtualMachine->obj->type, "VirtualMachine")) { ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, @@ -1496,30 +1521,43 @@ esxVI_GetVirtualMachineIdentity(virConnectPtr conn, } if (uuid != NULL) { - for (dynamicProperty = virtualMachine->propSet; - dynamicProperty != NULL; - dynamicProperty = dynamicProperty->_next) { - if (STREQ(dynamicProperty->name, "summary.config.uuid")) { - if (esxVI_AnyType_ExpectType(conn, dynamicProperty->val, - esxVI_Type_String) < 0) { - goto failure; + if (esxVI_GetManagedEntityStatus(conn, virtualMachine, "configStatus", + &configStatus) < 0) { + goto failure; + } + + if (configStatus == esxVI_ManagedEntityStatus_Green) { + 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) { - ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, - "Could not get UUID of virtual machine"); - goto failure; - } + if (uuid_string == NULL) { + ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, + "Could not get UUID of virtual machine"); + goto failure; + } - if (virUUIDParse(uuid_string, uuid) < 0) { - ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, - "Could not parse UUID from string '%s'", uuid_string); - goto failure; + if (virUUIDParse(uuid_string, uuid) < 0) { + ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, + "Could not parse UUID from string '%s'", + uuid_string); + goto failure; + } + } else { + memset(uuid, 0, VIR_UUID_BUFLEN); + + VIR_WARN0("Cannot access UUID, because 'configStatus' property " + "indicates a config problem"); } } diff --git a/src/esx/esx_vi.h b/src/esx/esx_vi.h index 7119f4b1ec..efb9bffe7d 100644 --- a/src/esx/esx_vi.h +++ b/src/esx/esx_vi.h @@ -232,6 +232,11 @@ int esxVI_GetObjectContent(virConnectPtr conn, esxVI_Context *ctx, esxVI_Boolean recurse, esxVI_ObjectContent **objectContentList); +int esxVI_GetManagedEntityStatus + (virConnectPtr conn, esxVI_ObjectContent *objectContent, + const char *propertyName, + esxVI_ManagedEntityStatus *managedEntityStatus); + int esxVI_GetVirtualMachinePowerState (virConnectPtr conn, esxVI_ObjectContent *virtualMachine, esxVI_VirtualMachinePowerState *powerState); diff --git a/src/esx/esx_vi_types.c b/src/esx/esx_vi_types.c index e1eabcc33a..68b7994742 100644 --- a/src/esx/esx_vi_types.c +++ b/src/esx/esx_vi_types.c @@ -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 */ diff --git a/src/esx/esx_vi_types.h b/src/esx/esx_vi_types.h index 84d657d044..2e69601e45 100644 --- a/src/esx/esx_vi_types.h +++ b/src/esx/esx_vi_types.h @@ -52,6 +52,7 @@ typedef struct _esxVI_DateTime esxVI_DateTime; * VI Enums */ +typedef enum _esxVI_ManagedEntityStatus esxVI_ManagedEntityStatus; typedef enum _esxVI_ObjectUpdateKind esxVI_ObjectUpdateKind; typedef enum _esxVI_PerfSummaryType esxVI_PerfSummaryType; 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 */