]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
ESX add esxVI_Occurence enum to for occurences
authorMatthias Bolte <matthias.bolte@googlemail.com>
Wed, 23 Sep 2009 12:40:41 +0000 (14:40 +0200)
committerDaniel Veillard <veillard@redhat.com>
Wed, 23 Sep 2009 13:00:54 +0000 (15:00 +0200)
Add esxVI_Occurence enum to describe expected occurence of items
* src/esx/esx_driver.c: update the use of esxVI_LookupVirtualMachineByUuid()
* src/esx/esx_vi.c: add an esxVI_Occurence parameter to
  esxVI_LookupVirtualMachineByUuid() and take care if esxVI_FindByUuid()
  can't find anything for a given uuid
* src/esx/esx_vi.h: add esxVI_Occurence enum
* src/esx/esx_vi_methods.c: expect null or more items to be returned
  from esxVI_FindByUuid()

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

index f9ae9883271f979251f952c20a88159ccd860088..b37216f70fa9637e8b3ad839855aac7cdf769075 100644 (file)
@@ -1361,7 +1361,8 @@ esxDomainSuspend(virDomainPtr domain)
                                        "runtime.powerState") < 0 ||
         esxVI_LookupVirtualMachineByUuid(domain->conn, priv->host,
                                          domain->uuid, propertyNameList,
-                                         &virtualMachine) < 0 ||
+                                         &virtualMachine,
+                                         esxVI_Occurence_RequiredItem) < 0 ||
         esxVI_GetVirtualMachinePowerState(domain->conn, virtualMachine,
                                           &powerState) < 0) {
         goto failure;
@@ -1426,7 +1427,8 @@ esxDomainResume(virDomainPtr domain)
                                        "runtime.powerState") < 0 ||
         esxVI_LookupVirtualMachineByUuid(domain->conn, priv->host,
                                          domain->uuid, propertyNameList,
-                                         &virtualMachine) < 0 ||
+                                         &virtualMachine,
+                                         esxVI_Occurence_RequiredItem) < 0 ||
         esxVI_GetVirtualMachinePowerState(domain->conn, virtualMachine,
                                           &powerState) < 0) {
         goto failure;
@@ -1489,7 +1491,8 @@ esxDomainShutdown(virDomainPtr domain)
                                        "runtime.powerState") < 0 ||
         esxVI_LookupVirtualMachineByUuid(domain->conn, priv->host,
                                          domain->uuid, propertyNameList,
-                                         &virtualMachine) < 0 ||
+                                         &virtualMachine,
+                                         esxVI_Occurence_RequiredItem) < 0 ||
         esxVI_GetVirtualMachinePowerState(domain->conn, virtualMachine,
                                           &powerState) < 0) {
         goto failure;
@@ -1543,7 +1546,8 @@ esxDomainReboot(virDomainPtr domain, unsigned int flags ATTRIBUTE_UNUSED)
                                        "runtime.powerState") < 0 ||
         esxVI_LookupVirtualMachineByUuid(domain->conn, priv->host,
                                          domain->uuid, propertyNameList,
-                                         &virtualMachine) < 0 ||
+                                         &virtualMachine,
+                                         esxVI_Occurence_RequiredItem) < 0 ||
         esxVI_GetVirtualMachinePowerState(domain->conn, virtualMachine,
                                           &powerState) < 0) {
         goto failure;
@@ -1598,7 +1602,8 @@ esxDomainDestroy(virDomainPtr domain)
                                        "runtime.powerState") < 0 ||
         esxVI_LookupVirtualMachineByUuid(domain->conn, priv->host,
                                          domain->uuid, propertyNameList,
-                                         &virtualMachine) < 0 ||
+                                         &virtualMachine,
+                                         esxVI_Occurence_RequiredItem) < 0 ||
         esxVI_GetVirtualMachinePowerState(domain->conn, virtualMachine,
                                           &powerState) < 0) {
         goto failure;
@@ -1676,7 +1681,8 @@ esxDomainGetMaxMemory(virDomainPtr domain)
                                        "config.hardware.memoryMB") < 0 ||
         esxVI_LookupVirtualMachineByUuid(domain->conn, priv->host,
                                          domain->uuid, propertyNameList,
-                                         &virtualMachine) < 0) {
+                                         &virtualMachine,
+                                         esxVI_Occurence_RequiredItem) < 0) {
         goto failure;
     }
 
@@ -1738,7 +1744,8 @@ esxDomainSetMaxMemory(virDomainPtr domain, unsigned long memory)
 
     if (esxVI_LookupVirtualMachineByUuid(domain->conn, priv->host,
                                          domain->uuid, NULL,
-                                         &virtualMachine) < 0 ||
+                                         &virtualMachine,
+                                         esxVI_Occurence_RequiredItem) < 0 ||
         esxVI_VirtualMachineConfigSpec_Alloc(domain->conn, &spec) < 0 ||
         esxVI_Long_Alloc(domain->conn, &spec->memoryMB) < 0) {
         goto failure;
@@ -1797,7 +1804,8 @@ esxDomainSetMemory(virDomainPtr domain, unsigned long memory)
 
     if (esxVI_LookupVirtualMachineByUuid(domain->conn, priv->host,
                                          domain->uuid, NULL,
-                                         &virtualMachine) < 0 ||
+                                         &virtualMachine,
+                                         esxVI_Occurence_RequiredItem) < 0 ||
         esxVI_VirtualMachineConfigSpec_Alloc(domain->conn, &spec) < 0 ||
         esxVI_ResourceAllocationInfo_Alloc(domain->conn,
                                            &spec->memoryAllocation) < 0 ||
@@ -1875,7 +1883,8 @@ esxDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
                                            "config.memoryAllocation.limit\0") < 0 ||
         esxVI_LookupVirtualMachineByUuid(domain->conn, priv->host,
                                          domain->uuid, propertyNameList,
-                                         &virtualMachine) < 0) {
+                                         &virtualMachine,
+                                         esxVI_Occurence_RequiredItem) < 0) {
         goto failure;
     }
 
@@ -2146,7 +2155,8 @@ esxDomainSetVcpus(virDomainPtr domain, unsigned int nvcpus)
 
     if (esxVI_LookupVirtualMachineByUuid(domain->conn, priv->host,
                                          domain->uuid, NULL,
-                                         &virtualMachine) < 0 ||
+                                         &virtualMachine,
+                                         esxVI_Occurence_RequiredItem) < 0 ||
         esxVI_VirtualMachineConfigSpec_Alloc(domain->conn, &spec) < 0 ||
         esxVI_Int_Alloc(domain->conn, &spec->numCPUs) < 0) {
         goto failure;
@@ -2278,7 +2288,8 @@ esxDomainDumpXML(virDomainPtr domain, int flags)
                                        "config.files.vmPathName") < 0 ||
         esxVI_LookupVirtualMachineByUuid(domain->conn, priv->host,
                                          domain->uuid, propertyNameList,
-                                         &virtualMachine) < 0) {
+                                         &virtualMachine,
+                                         esxVI_Occurence_RequiredItem) < 0) {
         goto failure;
     }
 
@@ -2553,7 +2564,8 @@ esxDomainCreate(virDomainPtr domain)
                                        "runtime.powerState") < 0 ||
         esxVI_LookupVirtualMachineByUuid(domain->conn, priv->host,
                                          domain->uuid, propertyNameList,
-                                         &virtualMachine) < 0 ||
+                                         &virtualMachine,
+                                         esxVI_Occurence_RequiredItem) < 0 ||
         esxVI_GetVirtualMachinePowerState(domain->conn, virtualMachine,
                                           &powerState) < 0) {
         goto failure;
@@ -2616,7 +2628,8 @@ esxDomainUndefine(virDomainPtr domain)
                                        "runtime.powerState") < 0 ||
         esxVI_LookupVirtualMachineByUuid(domain->conn, priv->host,
                                          domain->uuid, propertyNameList,
-                                         &virtualMachine) < 0 ||
+                                         &virtualMachine,
+                                         esxVI_Occurence_RequiredItem) < 0 ||
         esxVI_GetVirtualMachinePowerState(domain->conn, virtualMachine,
                                           &powerState) < 0) {
         goto failure;
@@ -2729,7 +2742,8 @@ esxDomainGetSchedulerParameters(virDomainPtr domain,
                                            "config.cpuAllocation.shares\0") < 0 ||
         esxVI_LookupVirtualMachineByUuid(domain->conn, priv->host,
                                          domain->uuid, propertyNameList,
-                                         &virtualMachine) < 0) {
+                                         &virtualMachine,
+                                         esxVI_Occurence_RequiredItem) < 0) {
         goto failure;
     }
 
@@ -2855,7 +2869,8 @@ esxDomainSetSchedulerParameters(virDomainPtr domain,
 
     if (esxVI_LookupVirtualMachineByUuid(domain->conn, priv->host,
                                          domain->uuid, NULL,
-                                         &virtualMachine) < 0 ||
+                                         &virtualMachine,
+                                         esxVI_Occurence_RequiredItem) < 0 ||
         esxVI_VirtualMachineConfigSpec_Alloc(domain->conn, &spec) < 0 ||
         esxVI_ResourceAllocationInfo_Alloc(domain->conn,
                                            &spec->cpuAllocation) < 0) {
@@ -3064,7 +3079,8 @@ esxDomainMigratePerform(virDomainPtr domain,
     /* Lookup VirtualMachine, HostSystem and ResourcePool */
     if (esxVI_LookupVirtualMachineByUuid(domain->conn, priv->vCenter,
                                          domain->uuid, NULL,
-                                         &virtualMachine) < 0) {
+                                         &virtualMachine,
+                                         esxVI_Occurence_RequiredItem) < 0) {
         goto failure;
     }
 
index 091977468e8454677dd2c176a12eee92b4dab7b3..0a531cbe2bea244f953cbe892cbe5e8334089478 100644 (file)
@@ -1677,10 +1677,12 @@ int
 esxVI_LookupVirtualMachineByUuid(virConnectPtr conn, esxVI_Context *ctx,
                                  const unsigned char *uuid,
                                  esxVI_String *propertyNameList,
-                                 esxVI_ObjectContent **virtualMachine)
+                                 esxVI_ObjectContent **virtualMachine,
+                                 esxVI_Occurence occurence)
 {
     int result = 0;
     esxVI_ManagedObjectReference *managedObjectReference = NULL;
+    char uuid_string[VIR_UUID_STRING_BUFLEN] = "";
 
     if (virtualMachine == NULL || *virtualMachine != NULL) {
         ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid argument");
@@ -1692,6 +1694,18 @@ esxVI_LookupVirtualMachineByUuid(virConnectPtr conn, esxVI_Context *ctx,
         goto failure;
     }
 
+    if (managedObjectReference == NULL) {
+        if (occurence == esxVI_Occurence_OptionalItem) {
+            return 0;
+        } else {
+            virUUIDFormat(uuid, uuid_string);
+
+            ESX_VI_ERROR(conn, VIR_ERR_INTERNAL_ERROR,
+                         "Could not find domain with UUID '%s'", uuid_string);
+            goto failure;
+        }
+    }
+
     if (esxVI_GetObjectContent(conn, ctx, managedObjectReference,
                                "VirtualMachine", propertyNameList,
                                esxVI_Boolean_False, virtualMachine) < 0) {
index 992f20100762d236a4250cc1a7396a646cfc8001..54fe82e49d2da50dfdff40a5bc92da18b403c73f 100644 (file)
@@ -33,6 +33,7 @@
 
 typedef enum _esxVI_APIVersion esxVI_APIVersion;
 typedef enum _esxVI_ProductVersion esxVI_ProductVersion;
+typedef enum _esxVI_Occurence esxVI_Occurence;
 typedef struct _esxVI_Context esxVI_Context;
 typedef struct _esxVI_Response esxVI_Response;
 typedef struct _esxVI_Enumeration esxVI_Enumeration;
@@ -57,6 +58,13 @@ enum _esxVI_ProductVersion {
     esxVI_ProductVersion_VPX40
 };
 
+enum _esxVI_Occurence {
+    esxVI_Occurence_Undefined = 0,
+    esxVI_Occurence_RequiredItem,
+    esxVI_Occurence_OptionalItem,
+    esxVI_Occurence_List
+};
+
 
 
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
@@ -235,7 +243,8 @@ int esxVI_LookupHostSystemByIp(virConnectPtr conn, esxVI_Context *ctx,
 int esxVI_LookupVirtualMachineByUuid(virConnectPtr conn, esxVI_Context *ctx,
                                      const unsigned char *uuid,
                                      esxVI_String *propertyNameList,
-                                     esxVI_ObjectContent **virtualMachine);
+                                     esxVI_ObjectContent **virtualMachine,
+                                     esxVI_Occurence occurence);
 
 int esxVI_StartVirtualMachineTask(virConnectPtr conn, esxVI_Context *ctx,
                                   const char *name, const char *request,
index 571bfab47dc09307f90610696d2634643285457e..dfcd4a0b0b0354822a1e73a87c95ea988f556f95 100644 (file)
@@ -994,10 +994,18 @@ esxVI_FindByUuid(virConnectPtr conn, esxVI_Context *ctx,
 
     request = virBufferContentAndReset(&buffer);
 
+    /* FIXME: Use esxVI_Occurence instead of expectList */
     if (esxVI_Context_Execute(conn, ctx, request,
                               ESX_VI__SOAP__RESPONSE_XPATH("FindByUuid"),
-                              &response, esxVI_Boolean_False) < 0 ||
-        esxVI_ManagedObjectReference_Deserialize
+                              &response, esxVI_Boolean_True) < 0) {
+        goto failure;
+    }
+
+    if (response->node == NULL) {
+        goto cleanup;
+    }
+
+    if (esxVI_ManagedObjectReference_Deserialize
           (conn, response->node, managedObjectReference,
            vmSearch == esxVI_Boolean_True ? "VirtualMachine"
                                           : "HostSystem") < 0) {