]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
esx: Undefine virtual machine on a vCenter if available
authorMatthias Bolte <matthias.bolte@googlemail.com>
Sun, 6 Dec 2009 23:59:56 +0000 (00:59 +0100)
committerMatthias Bolte <matthias.bolte@googlemail.com>
Fri, 18 Dec 2009 18:29:39 +0000 (19:29 +0100)
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.

src/esx/esx_driver.c

index 66fdf13a1b7605a10768d895a48af2d53c370f1e..8ea616bf1663e07344ced708e3c138492a5d5ab9 100644 (file)
@@ -2673,19 +2673,25 @@ esxDomainUndefine(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;
 
-    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_LookupVirtualMachineByUuid(domain->conn, priv->host,
-                                         domain->uuid, propertyNameList,
-                                         &virtualMachine,
+        esxVI_LookupVirtualMachineByUuid(domain->conn, ctx, domain->uuid,
+                                         propertyNameList, &virtualMachine,
                                          esxVI_Occurrence_RequiredItem) < 0 ||
         esxVI_GetVirtualMachinePowerState(domain->conn, virtualMachine,
                                           &powerState) < 0) {
@@ -2699,7 +2705,7 @@ esxDomainUndefine(virDomainPtr domain)
         goto failure;
     }
 
-    if (esxVI_UnregisterVM(domain->conn, priv->host, virtualMachine->obj) < 0) {
+    if (esxVI_UnregisterVM(domain->conn, ctx, virtualMachine->obj) < 0) {
         goto failure;
     }