]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
ESX: make esxVI_GetVirtualMachineIdentity() robust
authorMatthias Bolte <matthias.bolte@googlemail.com>
Fri, 4 Sep 2009 16:03:22 +0000 (18:03 +0200)
committerDaniel Veillard <veillard@redhat.com>
Fri, 4 Sep 2009 16:03:22 +0000 (18:03 +0200)
* 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

src/esx/esx_driver.c
src/esx/esx_vi.c
src/esx/esx_vi.h
src/esx/esx_vi_types.c
src/esx/esx_vi_types.h

index fc225cfbb60585736500f5b4b9cfbd1e4f10ea76..8f3c047a406f3a7670fbd31d461276a3e9953add 100644 (file)
@@ -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) {
index dfcb35217a1216e0e40e001916db674528047dfe..08911d0a310150d70d5b081a483a381a61405e05 100644 (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
 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;
+            }
+        } else {
+            memset(uuid, 0, VIR_UUID_BUFLEN);
 
-        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;
+            VIR_WARN0("Cannot access UUID, because 'configStatus' property "
+                      "indicates a config problem");
         }
     }
 
index 7119f4b1ec6a3a074820f7cfaa9f2cd5df47ca99..efb9bffe7d8813152ddb3e96ccbc63bdc26a9a9c 100644 (file)
@@ -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);
index e1eabcc33a1b1fb7265d6f25039409f0cd8a6b3a..68b79947429ec6abbb9c83a6112ab0f76b24216b 100644 (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
  */
index 84d657d0440352df7c05184cf505d4b45d02514e..2e69601e4592327599e027ec97a57f50265af802 100644 (file)
@@ -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
  */