提交 470764f0 编写于 作者: M Matthias Bolte

esx: Destroy virtual machine on a vCenter if available

If a virtual machine is destroyed on a ESX server then immediately
undefining this virtual machine on a vCenter may fail, because the
vCenter has not been informed about the status change yet. Therefore,
destroy a virtual machine on a vCenter if available, so the vCenter
is up-to-date when the virtual machine should be undefined.
上级 46306c9c
......@@ -1499,21 +1499,28 @@ esxDomainDestroy(virDomainPtr domain)
{
int result = 0;
esxPrivate *priv = (esxPrivate *)domain->conn->privateData;
esxVI_Context *ctx = NULL;
esxVI_ObjectContent *virtualMachine = NULL;
esxVI_String *propertyNameList = NULL;
esxVI_VirtualMachinePowerState powerState;
esxVI_ManagedObjectReference *task = NULL;
esxVI_TaskInfoState taskInfoState;
if (esxVI_EnsureSession(domain->conn, priv->host) < 0) {
if (priv->vCenter != NULL) {
ctx = priv->vCenter;
} else {
ctx = priv->host;
}
if (esxVI_EnsureSession(domain->conn, ctx) < 0) {
goto failure;
}
if (esxVI_String_AppendValueToList(domain->conn, &propertyNameList,
"runtime.powerState") < 0 ||
esxVI_LookupVirtualMachineByUuidAndPrepareForTask
(domain->conn, priv->host, domain->uuid, propertyNameList,
&virtualMachine, priv->autoAnswer) < 0 ||
(domain->conn, ctx, domain->uuid, propertyNameList, &virtualMachine,
priv->autoAnswer) < 0 ||
esxVI_GetVirtualMachinePowerState(domain->conn, virtualMachine,
&powerState) < 0) {
goto failure;
......@@ -1525,11 +1532,10 @@ esxDomainDestroy(virDomainPtr domain)
goto failure;
}
if (esxVI_PowerOffVM_Task(domain->conn, priv->host, virtualMachine->obj,
if (esxVI_PowerOffVM_Task(domain->conn, ctx, virtualMachine->obj,
&task) < 0 ||
esxVI_WaitForTaskCompletion(domain->conn, priv->host, task,
domain->uuid, priv->autoAnswer,
&taskInfoState) < 0) {
esxVI_WaitForTaskCompletion(domain->conn, ctx, task, domain->uuid,
priv->autoAnswer, &taskInfoState) < 0) {
goto failure;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册