+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:
*
esxNumberOfDefinedDomains, /* numOfDefinedDomains */
esxDomainCreate, /* domainCreate */
NULL, /* domainDefineXML */
- NULL, /* domainUndefine */
+ esxDomainUndefine, /* domainUndefine */
NULL, /* domainAttachDevice */
NULL, /* domainDetachDevice */
NULL, /* domainGetAutostart */
+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,
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,