* 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()
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index 8194b49..85f9e4c 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -1356,7 +1356,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; @@ -1421,7 +1422,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; @@ -1484,7 +1486,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; @@ -1538,7 +1541,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; @@ -1593,7 +1597,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; @@ -1671,7 +1676,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; } @@ -1733,7 +1739,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; @@ -1792,7 +1799,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 || @@ -1870,7 +1878,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; } @@ -2141,7 +2150,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; @@ -2273,7 +2283,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; } @@ -2548,7 +2559,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; @@ -2611,7 +2623,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; @@ -2724,7 +2737,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; } @@ -2850,7 +2864,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) { @@ -3059,7 +3074,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; } diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c index 0919774..0a531cb 100644 --- a/src/esx/esx_vi.c +++ b/src/esx/esx_vi.c @@ -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) { diff --git a/src/esx/esx_vi.h b/src/esx/esx_vi.h index 992f201..54fe82e 100644 --- a/src/esx/esx_vi.h +++ b/src/esx/esx_vi.h @@ -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, diff --git a/src/esx/esx_vi_methods.c b/src/esx/esx_vi_methods.c index 571bfab..dfcd4a0 100644 --- a/src/esx/esx_vi_methods.c +++ b/src/esx/esx_vi_methods.c @@ -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) {
-- Libvir-list mailing list Libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list