From ad866fd196af460c755839bb29bc022cb3202945 Mon Sep 17 00:00:00 2001 From: Matthias Bolte Date: Fri, 4 Sep 2009 18:30:10 +0200 Subject: [PATCH] ESX add domain undefine based on esxVI_UnregisterVM * 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 | 56 +++++++++++++++++++++++++++++++++++++++- src/esx/esx_vi_methods.c | 51 ++++++++++++++++++++++++++++++++++++ src/esx/esx_vi_methods.h | 3 +++ 3 files changed, 109 insertions(+), 1 deletion(-) diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index 9b1ea80432..8d1af7150c 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -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 */ diff --git a/src/esx/esx_vi_methods.c b/src/esx/esx_vi_methods.c index 3bc5e43320..571bfab47d 100644 --- a/src/esx/esx_vi_methods.c +++ b/src/esx/esx_vi_methods.c @@ -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, ""); + + if (esxVI_ManagedObjectReference_Serialize(conn, virtualMachine, "_this", + &buffer, + esxVI_Boolean_True) < 0) { + goto failure; + } + + virBufferAddLit(&buffer, ""); + 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, diff --git a/src/esx/esx_vi_methods.h b/src/esx/esx_vi_methods.h index 630bff20a2..e63184fe9d 100644 --- a/src/esx/esx_vi_methods.h +++ b/src/esx/esx_vi_methods.h @@ -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, -- 2.47.2