]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
ESX add domain undefine based on esxVI_UnregisterVM
authorMatthias Bolte <matthias.bolte@googlemail.com>
Fri, 4 Sep 2009 16:30:10 +0000 (18:30 +0200)
committerDaniel Veillard <veillard@redhat.com>
Fri, 4 Sep 2009 16:30:10 +0000 (18:30 +0200)
* src/esx/esx_driver.c: add esxDomainUndefine() based on
  esxVI_UnregisterVM()
* src/esx/esx_vi_methods.[ch]: add esxVI_UnregisterVM()

src/esx/esx_driver.c
src/esx/esx_vi_methods.c
src/esx/esx_vi_methods.h

index 9b1ea804329fe28a0fef292485a25aacfbac1585..8d1af7150c7f5999d91c1eb574ff470410425fc8 100644 (file)
@@ -2399,6 +2399,60 @@ esxDomainCreate(virDomainPtr domain)
 
 
 
+static int
+esxDomainUndefine(virDomainPtr domain)
+{
+    int result = 0;
+    esxPrivate *priv = (esxPrivate *)domain->conn->privateData;
+    esxVI_ObjectContent *virtualMachine = NULL;
+    esxVI_String *propertyNameList = NULL;
+    esxVI_VirtualMachinePowerState powerState;
+
+    if (priv->phantom) {
+        ESX_ERROR(domain->conn, VIR_ERR_OPERATION_INVALID,
+                  "Not possible with a phantom connection");
+        goto failure;
+    }
+
+    if (esxVI_EnsureSession(domain->conn, priv->host) < 0) {
+        goto failure;
+    }
+
+    if (esxVI_String_AppendValueToList(domain->conn, &propertyNameList,
+                                       "runtime.powerState") < 0 ||
+        esxVI_LookupVirtualMachineByUuid(domain->conn, priv->host,
+                                         domain->uuid, propertyNameList,
+                                         &virtualMachine) < 0 ||
+        esxVI_GetVirtualMachinePowerState(domain->conn, virtualMachine,
+                                          &powerState) < 0) {
+        goto failure;
+    }
+
+    if (powerState != esxVI_VirtualMachinePowerState_Suspended &&
+        powerState != esxVI_VirtualMachinePowerState_PoweredOff) {
+        ESX_ERROR(domain->conn, VIR_ERR_OPERATION_INVALID,
+                  "Domain is not suspended or powered off");
+        goto failure;
+    }
+
+    if (esxVI_UnregisterVM(domain->conn, priv->host, virtualMachine->obj) < 0) {
+        goto failure;
+    }
+
+  cleanup:
+    esxVI_ObjectContent_Free(&virtualMachine);
+    esxVI_String_Free(&propertyNameList);
+
+    return result;
+
+  failure:
+    result = -1;
+
+    goto cleanup;
+}
+
+
+
 /*
  * The scheduler interface exposes basically the CPU ResourceAllocationInfo:
  *
@@ -3010,7 +3064,7 @@ static virDriver esxDriver = {
     esxNumberOfDefinedDomains,       /* numOfDefinedDomains */
     esxDomainCreate,                 /* domainCreate */
     NULL,                            /* domainDefineXML */
-    NULL,                            /* domainUndefine */
+    esxDomainUndefine,               /* domainUndefine */
     NULL,                            /* domainAttachDevice */
     NULL,                            /* domainDetachDevice */
     NULL,                            /* domainGetAutostart */
index 3bc5e43320d140d6378177bd70f7e2bfee1b8b38..571bfab47dc09307f90610696d2634643285457e 100644 (file)
@@ -520,6 +520,57 @@ esxVI_ReconfigVM_Task(virConnectPtr conn, esxVI_Context *ctx,
 
 
 
+int
+esxVI_UnregisterVM(virConnectPtr conn, esxVI_Context *ctx,
+                   esxVI_ManagedObjectReference *virtualMachine)
+{
+    int result = 0;
+    virBuffer buffer = VIR_BUFFER_INITIALIZER;
+    char *request = NULL;
+    esxVI_Response *response = NULL;
+
+    virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_HEADER);
+    virBufferAddLit(&buffer, "<UnregisterVM xmlns=\"urn:vim25\">");
+
+    if (esxVI_ManagedObjectReference_Serialize(conn, virtualMachine, "_this",
+                                               &buffer,
+                                               esxVI_Boolean_True) < 0) {
+        goto failure;
+    }
+
+    virBufferAddLit(&buffer, "</UnregisterVM>");
+    virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER);
+
+    if (virBufferError(&buffer)) {
+        virReportOOMError(conn);
+        goto failure;
+    }
+
+    request = virBufferContentAndReset(&buffer);
+
+    if (esxVI_Context_Execute(conn, ctx, request, NULL, &response,
+                              esxVI_Boolean_False) < 0) {
+        goto failure;
+    }
+
+  cleanup:
+    VIR_FREE(request);
+    esxVI_Response_Free(&response);
+
+    return result;
+
+  failure:
+    if (request == NULL) {
+        request = virBufferContentAndReset(&buffer);
+    }
+
+    result = -1;
+
+    goto cleanup;
+}
+
+
+
 int
 esxVI_CreateFilter(virConnectPtr conn, esxVI_Context *ctx,
                    esxVI_PropertyFilterSpec *propertyFilterSpec,
index 630bff20a2dd9796035fb22d5b1648858eae85f5..e63184fe9d37af2f1f7464e9f4aa548979e16dee 100644 (file)
@@ -72,6 +72,9 @@ int esxVI_ReconfigVM_Task(virConnectPtr conn, esxVI_Context *ctx,
                           esxVI_VirtualMachineConfigSpec *spec,
                           esxVI_ManagedObjectReference **task);
 
+int esxVI_UnregisterVM(virConnectPtr conn, esxVI_Context *ctx,
+                       esxVI_ManagedObjectReference *virtualMachine);
+
 int esxVI_CreateFilter(virConnectPtr conn, esxVI_Context *ctx,
                        esxVI_PropertyFilterSpec *propertyFilterSpec,
                        esxVI_Boolean partialUpdates,