提交 ad866fd1 编写于 作者: M Matthias Bolte 提交者: Daniel Veillard

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()
上级 3e8cb460
......@@ -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 */
......
......@@ -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,
......
......@@ -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,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册