提交 c3aa1f8b 编写于 作者: M Matthias Bolte 提交者: Daniel Veillard

ESX add esxVI_Occurence enum to for occurences

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()
上级 0d4d04e5
......@@ -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;
}
......
......@@ -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) {
......
......@@ -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,
......
......@@ -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) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册