-
Notifications
You must be signed in to change notification settings - Fork 1.3k
server,api,ui: host auto-select for migrateVirtualMachineWithVolume #7554
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
DaanHoogland
merged 12 commits into
apache:main
from
shapeblue:add-automigrate-localstorage
Jun 22, 2023
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f991e4e
server, api, ui: allow host auto-select for migrateVirtualMachineWith…
shwstppr 4b4404f
fix
shwstppr b14536a
Merge branch 'main' into add-automigrate-localstorage
shwstppr f2205e5
Merge branch 'main' into add-automigrate-localstorage
shwstppr 0f997aa
fix
shwstppr c1328e8
Merge branch 'main' into add-automigrate-localstorage
shwstppr ca89f2a
changes
shwstppr 919c4e6
fix
shwstppr 1d6b143
api: fix check
shwstppr f30597f
tests
shwstppr d85781d
review comments
shwstppr 175367b
another review comment
shwstppr 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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -83,6 +83,12 @@ public class MigrateVirtualMachineWithVolumeCmd extends BaseAsyncCmd { | |||||
| "<1b331390-59f2-4796-9993-bf11c6e76225>&migrateto[2].pool=<41fdb564-9d3b-447d-88ed-7628f7640cbc>") | ||||||
| private Map migrateVolumeTo; | ||||||
|
|
||||||
| @Parameter(name = ApiConstants.AUTO_SELECT, | ||||||
| since = "4.19.0", | ||||||
| type = CommandType.BOOLEAN, | ||||||
| description = "Automatically select a destination host for a running instance, if hostId is not specified. false by default") | ||||||
| private Boolean autoSelect; | ||||||
|
|
||||||
| ///////////////////////////////////////////////////// | ||||||
| /////////////////// Accessors /////////////////////// | ||||||
| ///////////////////////////////////////////////////// | ||||||
|
|
@@ -144,31 +150,39 @@ public ApiCommandResourceType getApiResourceType() { | |||||
| return ApiCommandResourceType.VirtualMachine; | ||||||
| } | ||||||
|
|
||||||
| private Host getDestinationHost() { | ||||||
| if (getHostId() == null) { | ||||||
| return null; | ||||||
| } | ||||||
| Host destinationHost = _resourceService.getHost(getHostId()); | ||||||
| // OfflineVmwareMigration: destination host would have to not be a required parameter for stopped VMs | ||||||
| if (destinationHost == null) { | ||||||
| s_logger.error(String.format("Unable to find the host with ID [%s].", getHostId())); | ||||||
| throw new InvalidParameterValueException("Unable to find the specified host to migrate the VM."); | ||||||
| } | ||||||
| return destinationHost; | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| public void execute() { | ||||||
| if (hostId == null && MapUtils.isEmpty(migrateVolumeTo)) { | ||||||
| throw new InvalidParameterValueException(String.format("Either %s or %s must be passed for migrating the VM.", ApiConstants.HOST_ID, ApiConstants.MIGRATE_TO)); | ||||||
| if (hostId == null && MapUtils.isEmpty(migrateVolumeTo) && !Boolean.TRUE.equals(autoSelect)) { | ||||||
| throw new InvalidParameterValueException(String.format("Either %s or %s must be passed or %s must be true for migrating the VM.", ApiConstants.HOST_ID, ApiConstants.MIGRATE_TO, ApiConstants.AUTO_SELECT)); | ||||||
| } | ||||||
|
|
||||||
| VirtualMachine virtualMachine = _userVmService.getVm(getVirtualMachineId()); | ||||||
| if (!VirtualMachine.State.Running.equals(virtualMachine.getState()) && hostId != null) { | ||||||
| if (!VirtualMachine.State.Running.equals(virtualMachine.getState()) && (hostId != null || Boolean.TRUE.equals(autoSelect))) { | ||||||
| throw new InvalidParameterValueException(String.format("%s is not in the Running state to migrate it to the new host.", virtualMachine)); | ||||||
| } | ||||||
|
|
||||||
| if (!VirtualMachine.State.Stopped.equals(virtualMachine.getState()) && hostId == null) { | ||||||
| throw new InvalidParameterValueException(String.format("%s is not in the Stopped state to migrate, use the %s parameter to migrate it to a new host.", | ||||||
| virtualMachine, ApiConstants.HOST_ID)); | ||||||
| if (!VirtualMachine.State.Stopped.equals(virtualMachine.getState()) && hostId == null && Boolean.FALSE.equals(autoSelect)) { | ||||||
| throw new InvalidParameterValueException(String.format("%s is not in the Stopped state to migrate, use the %s or %s parameter to migrate it to a new host.", | ||||||
|
Contributor
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. again, not really in scope:
Suggested change
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. Leaving this as it can be addressed separately |
||||||
| virtualMachine, ApiConstants.HOST_ID,ApiConstants.AUTO_SELECT)); | ||||||
| } | ||||||
|
|
||||||
| try { | ||||||
| VirtualMachine migratedVm = null; | ||||||
| if (hostId != null) { | ||||||
| Host destinationHost = _resourceService.getHost(getHostId()); | ||||||
| // OfflineVmwareMigration: destination host would have to not be a required parameter for stopped VMs | ||||||
| if (destinationHost == null) { | ||||||
| s_logger.error(String.format("Unable to find the host with ID [%s].", getHostId())); | ||||||
| throw new InvalidParameterValueException("Unable to find the specified host to migrate the VM."); | ||||||
| } | ||||||
| if (getHostId() != null || Boolean.TRUE.equals(autoSelect)) { | ||||||
| Host destinationHost = getDestinationHost(); | ||||||
| migratedVm = _userVmService.migrateVirtualMachineWithVolume(getVirtualMachineId(), destinationHost, getVolumeToPool()); | ||||||
| } else if (MapUtils.isNotEmpty(migrateVolumeTo)) { | ||||||
| migratedVm = _userVmService.vmStorageMigration(getVirtualMachineId(), getVolumeToPool()); | ||||||
|
|
||||||
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.
not in scope, but I think this meesage is misleading a bit:
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.
Leaving this as it can be addressed separately