On 08/09/2016 08:39 AM, Jason Miesionczek wrote: > --- > src/hyperv/hyperv_driver.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 72 insertions(+) > > diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c > index db59ce1..bd028ed 100644 > --- a/src/hyperv/hyperv_driver.c > +++ b/src/hyperv/hyperv_driver.c > @@ -2205,6 +2205,76 @@ hypervDomainSetVcpus(virDomainPtr domain, unsigned int nvcpus) > return hypervDomainSetVcpusFlags(domain, nvcpus, 0); > } > > + > +static int > +hypervDomainUndefineFlags(virDomainPtr domain, unsigned int flags ATTRIBUTE_UNUSED) > +{ > + int result = -1, nb_params; > + const char *selector = "CreationClassName=Msvm_VirtualSystemManagementService"; > + char uuid_string[VIR_UUID_STRING_BUFLEN]; > + hypervPrivate *priv = domain->conn->privateData; > + invokeXmlParam *params = NULL; > + eprParam eprparam; > + virBuffer query = VIR_BUFFER_INITIALIZER; > + Msvm_ComputerSystem *computerSystem = NULL; > + > + virCheckFlags(0, -1); > + > + virUUIDFormat(domain->uuid, uuid_string); > + > + if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0) { > + goto cleanup; > + } > + > + /* Shutdown the VM if not disabled */ > + if (computerSystem->data->EnabledState != MSVM_COMPUTERSYSTEM_ENABLEDSTATE_DISABLED) { > + if (hypervDomainShutdown(domain) < 0) { > + goto cleanup; > + } > + } > + This seems to go against the virDomainUndefineFlags API description: * Undefine a domain. If the domain is running, it's converted to * transient domain, without stopping it. If the domain is inactive, * the domain configuration is removed. besides it wasn't clear to me earlier if Shutdown did anything. > + /* Deleting the VM */ > + > + /* Prepare EPR param */ > + virBufferFreeAndReset(&query); > + virBufferAddLit(&query, MSVM_COMPUTERSYSTEM_WQL_SELECT); > + virBufferAsprintf(&query, "where Name = \"%s\"", uuid_string); > + eprparam.query = &query; > + eprparam.wmiProviderURI = ROOT_VIRTUALIZATION; > + > + /* Create invokeXmlParam tab */ > + nb_params = 1; > + if (VIR_ALLOC_N(params, nb_params) < 0) > + goto cleanup; > + (*params).name = "ComputerSystem"; > + (*params).type = EPR_PARAM; > + (*params).param = &eprparam; Like before is this a repeatable sequence with something else.. > + > + /* Destroy VM */ > + if (hypervInvokeMethod(priv, params, nb_params, "DestroyVirtualSystem", > + MSVM_VIRTUALSYSTEMMANAGEMENTSERVICE_RESOURCE_URI, selector) < 0) { > + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not delete domain")); > + goto cleanup; > + } > + > + result = 0; > + > + cleanup: > + VIR_FREE(params); > + hypervFreeObject(priv, (hypervObject *) computerSystem); > + virBufferFreeAndReset(&query); > + > + return result; > +} > + > + > + > +static int > +hypervDomainUndefine(virDomainPtr domain) > +{ > + return hypervDomainUndefineFlags(domain, 0); > +} > + > static virHypervisorDriver hypervHypervisorDriver = { > .name = "Hyper-V", > .connectOpen = hypervConnectOpen, /* 0.9.5 */ > @@ -2258,6 +2328,8 @@ static virHypervisorDriver hypervHypervisorDriver = { > .domainSetMemoryFlags = hypervDomainSetMemoryFlags, /* 1.2.10 */ > .domainSetVcpus = hypervDomainSetVcpus, /* 1.2.10 */ > .domainSetVcpusFlags = hypervDomainSetVcpusFlags, /* 1.2.10 */ > + .domainUndefine = hypervDomainUndefine, /* 1.2.10 */ > + .domainUndefineFlags = hypervDomainUndefineFlags, /* 1.2.10 */ 2.3.0 at the earliest John > }; > > /* Retrieves host system UUID */ > -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list