]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
esx: Destroy virtual machine on a vCenter if available
authorMatthias Bolte <matthias.bolte@googlemail.com>
Sat, 12 Dec 2009 19:51:35 +0000 (20:51 +0100)
committerMatthias Bolte <matthias.bolte@googlemail.com>
Fri, 18 Dec 2009 18:29:39 +0000 (19:29 +0100)
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.

src/esx/esx_driver.c

index 8ea616bf1663e07344ced708e3c138492a5d5ab9..c0754f58fb56f08638c3771336970add45c0e7e2 100644 (file)
@@ -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;
     }