-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Use ACPI event to reboot VM on KVM, and Use 'forced' reboot option to stop and start the VM(s) #4681
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
yadvr
merged 3 commits into
apache:master
from
shapeblue:cs-kvm-libvirt-acpi-reboot-and-forced-reboot
Mar 6, 2021
Merged
Use ACPI event to reboot VM on KVM, and Use 'forced' reboot option to stop and start the VM(s) #4681
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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
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
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
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 |
|---|---|---|
|
|
@@ -800,7 +800,7 @@ private boolean resetVMPasswordInternal(Long vmId, String password) throws Resou | |
| return true; | ||
| } | ||
|
|
||
| if (rebootVirtualMachine(userId, vmId, false) == null) { | ||
| if (rebootVirtualMachine(userId, vmId, false, false) == null) { | ||
| s_logger.warn("Failed to reboot the vm " + vmInstance); | ||
| return false; | ||
| } else { | ||
|
|
@@ -911,7 +911,7 @@ private boolean resetVMSSHKeyInternal(Long vmId, String sshPublicKey, String pas | |
| s_logger.debug("Vm " + vmInstance + " is stopped, not rebooting it as a part of SSH Key reset"); | ||
| return true; | ||
| } | ||
| if (rebootVirtualMachine(userId, vmId, false) == null) { | ||
| if (rebootVirtualMachine(userId, vmId, false, false) == null) { | ||
| s_logger.warn("Failed to reboot the vm " + vmInstance); | ||
| return false; | ||
| } else { | ||
|
|
@@ -948,7 +948,7 @@ public boolean stopVirtualMachine(long userId, long vmId) { | |
| return status; | ||
| } | ||
|
|
||
| private UserVm rebootVirtualMachine(long userId, long vmId, boolean enterSetup) throws InsufficientCapacityException, ResourceUnavailableException { | ||
| private UserVm rebootVirtualMachine(long userId, long vmId, boolean enterSetup, boolean forced) throws InsufficientCapacityException, ResourceUnavailableException { | ||
| UserVmVO vm = _vmDao.findById(vmId); | ||
|
|
||
| if (s_logger.isTraceEnabled()) { | ||
|
|
@@ -963,6 +963,15 @@ private UserVm rebootVirtualMachine(long userId, long vmId, boolean enterSetup) | |
| if (vm.getState() == State.Running && vm.getHostId() != null) { | ||
| collectVmDiskStatistics(vm); | ||
| collectVmNetworkStatistics(vm); | ||
|
|
||
| if (forced) { | ||
| Host vmOnHost = _hostDao.findById(vm.getHostId()); | ||
| if (vmOnHost == null || vmOnHost.getResourceState() != ResourceState.Enabled || vmOnHost.getStatus() != Status.Up ) { | ||
| throw new CloudRuntimeException("Unable to force reboot the VM as the host: " + vm.getHostId() + " is not in the right state"); | ||
| } | ||
| return forceRebootVirtualMachine(vmId, vm.getHostId(), enterSetup); | ||
| } | ||
|
|
||
| DataCenterVO dc = _dcDao.findById(vm.getDataCenterId()); | ||
| try { | ||
| if (dc.getNetworkType() == DataCenter.NetworkType.Advanced) { | ||
|
|
@@ -986,7 +995,7 @@ private UserVm rebootVirtualMachine(long userId, long vmId, boolean enterSetup) | |
| throw new CloudRuntimeException("Concurrent operations on starting router. " + e); | ||
| } catch (Exception ex){ | ||
| throw new CloudRuntimeException("Router start failed due to" + ex); | ||
| }finally { | ||
| } finally { | ||
| if (s_logger.isInfoEnabled()) { | ||
| s_logger.info(String.format("Rebooting vm %s%s.", vm.getInstanceName(), enterSetup? " entering hardware setup menu" : " as is")); | ||
| } | ||
|
|
@@ -1007,6 +1016,24 @@ private UserVm rebootVirtualMachine(long userId, long vmId, boolean enterSetup) | |
| } | ||
| } | ||
|
|
||
| private UserVm forceRebootVirtualMachine(long vmId, long hostId, boolean enterSetup) { | ||
| try { | ||
| if (stopVirtualMachine(vmId, false) != null) { | ||
| Map<VirtualMachineProfile.Param,Object> params = null; | ||
| if (enterSetup) { | ||
| params = new HashMap(); | ||
| params.put(VirtualMachineProfile.Param.BootIntoSetup, Boolean.TRUE); | ||
| } | ||
| return startVirtualMachine(vmId, null, null, hostId, params, null).first(); | ||
| } | ||
| } catch (ResourceUnavailableException e) { | ||
| throw new CloudRuntimeException("Unable to reboot the VM: " + vmId, e); | ||
| } catch (CloudException e) { | ||
| throw new CloudRuntimeException("Unable to reboot the VM: " + vmId, e); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| @ActionEvent(eventType = EventTypes.EVENT_VM_UPGRADE, eventDescription = "upgrading Vm") | ||
| /* | ||
|
|
@@ -2887,7 +2914,7 @@ public UserVm rebootVirtualMachine(RebootVMCmd cmd) throws InsufficientCapacityE | |
| // Verify input parameters | ||
| UserVmVO vmInstance = _vmDao.findById(vmId); | ||
| if (vmInstance == null) { | ||
| throw new InvalidParameterValueException("unable to find a virtual machine with id " + vmId); | ||
| throw new InvalidParameterValueException("Unable to find a virtual machine with id " + vmId); | ||
| } | ||
|
|
||
| _accountMgr.checkAccess(caller, null, true, vmInstance); | ||
|
|
@@ -2909,7 +2936,8 @@ public UserVm rebootVirtualMachine(RebootVMCmd cmd) throws InsufficientCapacityE | |
| if (enterSetup != null && enterSetup && !HypervisorType.VMware.equals(vmInstance.getHypervisorType())) { | ||
| throw new InvalidParameterValueException("Booting into a hardware setup menu is not implemented on " + vmInstance.getHypervisorType()); | ||
| } | ||
| UserVm userVm = rebootVirtualMachine(CallContext.current().getCallingUserId(), vmId, enterSetup == null ? false : cmd.getBootIntoSetup()); | ||
|
|
||
| UserVm userVm = rebootVirtualMachine(CallContext.current().getCallingUserId(), vmId, enterSetup == null ? false : cmd.getBootIntoSetup(), cmd.isForced()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sureshanaparti does forced parameter cause it to perform a stop/start at orchestration level?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes @rhtyd |
||
| if (userVm != null ) { | ||
| // update the vmIdCountMap if the vm is in advanced shared network with out services | ||
| final List<NicVO> nics = _nicDao.listByVmId(vmId); | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sureshanaparti is this a new behaviour, did it use to throw exception/fail when host is not enabled or up without forced=true?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rhtyd Start VM can fail (or) either pick another host when the VM's host is not Enabled / not Up. As the force reboot stops and starts the VM, there are chances that start VM would fail in that case, and so it's safe to not allow when force reboot when host is not Enabled / not Up.