-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Make kvm domain persistent when unmanaged from CS #11541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
88333b3
persist kvm domain when unmanaged from CS
sudo87 b8901a1
fetch domainxml from vm
sudo87 097583f
Merge branch 'main' into persistentKVM
sudo87 c9bfec1
cleanup code
sudo87 be93681
rescontruct vmspec to unmanage Stopped VM
sudo87 24c4280
handle initial review comments
sudo87 9bde784
add boot type, mode and uefi flag
sudo87 bd5d79c
Merge branch 'main' into persistentKVM
sudo87 da3c455
unit tests to improve coverage
sudo87 8524275
add integration tests for unmanaging kvm instance
sudo87 2c18496
trim whitespace
sudo87 7df8733
use any available host if last host is not there
sudo87 f118a9f
look for kvm hosts only, fix unit test
sudo87 0a693a2
lookup in cluster for host
sudo87 a16fa51
add hostid in unmanageVirtualMachine cmd and response
sudo87 237cda9
generate unmanage event and improve code coverage
sudo87 d5e4259
fix unmanage stopped instance in vmware
sudo87 9604964
merge main changes
sudo87 c5d6b2f
Use forced true to unmanage instance with config drive
sudo87 4e36aa1
include import unmanaged instance fix from #11753
sudo87 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
core/src/main/java/com/cloud/agent/api/UnmanageInstanceAnswer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
| // | ||
|
|
||
| package com.cloud.agent.api; | ||
|
|
||
| public class UnmanageInstanceAnswer extends Answer { | ||
|
|
||
| public UnmanageInstanceAnswer(UnmanageInstanceCommand cmd, boolean success, String details) { | ||
| super(cmd, success, details); | ||
| } | ||
| } |
56 changes: 56 additions & 0 deletions
56
core/src/main/java/com/cloud/agent/api/UnmanageInstanceCommand.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| // | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
| // | ||
|
|
||
| package com.cloud.agent.api; | ||
|
|
||
| import com.cloud.agent.api.to.VirtualMachineTO; | ||
|
|
||
| /** | ||
| */ | ||
| public class UnmanageInstanceCommand extends Command { | ||
| String instanceName; | ||
| boolean executeInSequence = false; | ||
| VirtualMachineTO vm; | ||
|
|
||
| @Override | ||
| public boolean executeInSequence() { | ||
| //VR start doesn't go through queue | ||
| if (instanceName != null && instanceName.startsWith("r-")) { | ||
| return false; | ||
| } | ||
| return executeInSequence; | ||
| } | ||
|
|
||
| public UnmanageInstanceCommand(VirtualMachineTO vm) { | ||
| this.vm = vm; | ||
| this.instanceName = vm.getName(); | ||
| } | ||
|
|
||
| public UnmanageInstanceCommand(String instanceName) { | ||
| this.instanceName = instanceName; | ||
| } | ||
|
|
||
| public String getInstanceName() { | ||
| return instanceName; | ||
| } | ||
|
|
||
| public VirtualMachineTO getVm() { | ||
| return vm; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
...java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtUnmanageInstanceCommandWrapper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| // | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
| // | ||
|
|
||
| package com.cloud.hypervisor.kvm.resource.wrapper; | ||
|
|
||
| import java.net.URISyntaxException; | ||
|
|
||
| import org.libvirt.Connect; | ||
| import org.libvirt.Domain; | ||
| import org.libvirt.LibvirtException; | ||
|
|
||
| import com.cloud.agent.api.Answer; | ||
| import com.cloud.agent.api.UnmanageInstanceAnswer; | ||
| import com.cloud.agent.api.UnmanageInstanceCommand; | ||
| import com.cloud.agent.api.to.VirtualMachineTO; | ||
| import com.cloud.exception.InternalErrorException; | ||
| import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource; | ||
| import com.cloud.hypervisor.kvm.resource.LibvirtKvmAgentHook; | ||
| import com.cloud.hypervisor.kvm.resource.LibvirtVMDef; | ||
| import com.cloud.resource.CommandWrapper; | ||
| import com.cloud.resource.ResourceWrapper; | ||
|
|
||
| @ResourceWrapper(handles = UnmanageInstanceCommand.class) | ||
| public final class LibvirtUnmanageInstanceCommandWrapper extends CommandWrapper<UnmanageInstanceCommand, Answer, LibvirtComputingResource> { | ||
|
|
||
|
|
||
| @Override | ||
| public Answer execute(final UnmanageInstanceCommand command, final LibvirtComputingResource libvirtComputingResource) { | ||
| String instanceName = command.getInstanceName(); | ||
| VirtualMachineTO vmSpec = command.getVm(); | ||
| final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper(); | ||
| logger.debug("Attempting to unmanage KVM instance: {}", instanceName); | ||
| Domain dom = null; | ||
| Connect conn = null; | ||
| try { | ||
| if (vmSpec == null) { | ||
| conn = libvirtUtilitiesHelper.getConnectionByVmName(instanceName); | ||
| dom = conn.domainLookupByName(instanceName); | ||
| String domainXML = dom.getXMLDesc(1); | ||
| conn.domainDefineXML(domainXML).free(); | ||
| } else { | ||
| // define domain using reconstructed vmSpec | ||
| logger.debug("Unmanaging Stopped KVM instance: {}", instanceName); | ||
| LibvirtVMDef vm = libvirtComputingResource.createVMFromSpec(vmSpec); | ||
| libvirtComputingResource.createVbd(conn, vmSpec, instanceName, vm); | ||
| conn = libvirtUtilitiesHelper.getConnectionByType(vm.getHvsType()); | ||
| String vmInitialSpecification = vm.toString(); | ||
| String vmFinalSpecification = performXmlTransformHook(vmInitialSpecification, libvirtComputingResource); | ||
| conn.domainDefineXML(vmFinalSpecification).free(); | ||
| } | ||
| logger.debug("Successfully unmanaged KVM instance: {}", instanceName); | ||
| return new UnmanageInstanceAnswer(command, true, "Successfully unmanaged"); | ||
| } catch (final LibvirtException e) { | ||
| logger.warn("LibvirtException occurred during unmanaging instance: {} ", instanceName, e); | ||
| return new UnmanageInstanceAnswer(command, false, e.getMessage()); | ||
| } catch (final URISyntaxException | InternalErrorException e) { | ||
| logger.warn("URISyntaxException ", e); | ||
| return new UnmanageInstanceAnswer(command, false, e.getMessage()); | ||
| } finally { | ||
| if (dom != null) { | ||
| try { | ||
| dom.free(); | ||
| } catch (LibvirtException e) { | ||
| logger.error("Ignore libvirt error on free.", e); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private String performXmlTransformHook(String vmInitialSpecification, final LibvirtComputingResource libvirtComputingResource) { | ||
| String vmFinalSpecification; | ||
| try { | ||
| // if transformer fails, everything must go as it's just skipped. | ||
| LibvirtKvmAgentHook t = libvirtComputingResource.getTransformer(); | ||
| vmFinalSpecification = (String) t.handle(vmInitialSpecification); | ||
| if (null == vmFinalSpecification) { | ||
| logger.warn("Libvirt XML transformer returned NULL, will use XML specification unchanged."); | ||
| vmFinalSpecification = vmInitialSpecification; | ||
| } | ||
| } catch(Exception e) { | ||
| logger.warn("Exception occurred when handling LibVirt XML transformer hook: {}", e); | ||
| vmFinalSpecification = vmInitialSpecification; | ||
| } | ||
| return vmFinalSpecification; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.