mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 22:25:25 +00:00
esx: Undefine virtual machine on a vCenter if available
Undefining a virtual machine on an ESX server leaves a orphan on the vCenter behind. So undefine a virtual machine on a vCenter if available to fix this problem.
This commit is contained in:
parent
a5d8d265a2
commit
46306c9c85
@ -2673,19 +2673,25 @@ esxDomainUndefine(virDomainPtr domain)
|
|||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
esxPrivate *priv = (esxPrivate *)domain->conn->privateData;
|
esxPrivate *priv = (esxPrivate *)domain->conn->privateData;
|
||||||
|
esxVI_Context *ctx = NULL;
|
||||||
esxVI_ObjectContent *virtualMachine = NULL;
|
esxVI_ObjectContent *virtualMachine = NULL;
|
||||||
esxVI_String *propertyNameList = NULL;
|
esxVI_String *propertyNameList = NULL;
|
||||||
esxVI_VirtualMachinePowerState powerState;
|
esxVI_VirtualMachinePowerState powerState;
|
||||||
|
|
||||||
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;
|
goto failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (esxVI_String_AppendValueToList(domain->conn, &propertyNameList,
|
if (esxVI_String_AppendValueToList(domain->conn, &propertyNameList,
|
||||||
"runtime.powerState") < 0 ||
|
"runtime.powerState") < 0 ||
|
||||||
esxVI_LookupVirtualMachineByUuid(domain->conn, priv->host,
|
esxVI_LookupVirtualMachineByUuid(domain->conn, ctx, domain->uuid,
|
||||||
domain->uuid, propertyNameList,
|
propertyNameList, &virtualMachine,
|
||||||
&virtualMachine,
|
|
||||||
esxVI_Occurrence_RequiredItem) < 0 ||
|
esxVI_Occurrence_RequiredItem) < 0 ||
|
||||||
esxVI_GetVirtualMachinePowerState(domain->conn, virtualMachine,
|
esxVI_GetVirtualMachinePowerState(domain->conn, virtualMachine,
|
||||||
&powerState) < 0) {
|
&powerState) < 0) {
|
||||||
@ -2699,7 +2705,7 @@ esxDomainUndefine(virDomainPtr domain)
|
|||||||
goto failure;
|
goto failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (esxVI_UnregisterVM(domain->conn, priv->host, virtualMachine->obj) < 0) {
|
if (esxVI_UnregisterVM(domain->conn, ctx, virtualMachine->obj) < 0) {
|
||||||
goto failure;
|
goto failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user