Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.4k
server: Optional destination host when migrate a vm#4378
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
51ea3459bdc324f5aed3292b8f73c1a1e2a62a4886a25854490b1ff5e7216e16e54dc306e3a8a0d8175c107fd3a73e1c2b6530abeFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -29,6 +29,7 @@ | ||
| import org.apache.cloudstack.api.response.StoragePoolResponse; | ||
| import org.apache.cloudstack.api.response.UserVmResponse; | ||
| import org.apache.cloudstack.context.CallContext; | ||
| import org.apache.commons.lang.BooleanUtils; | ||
| import com.cloud.event.EventTypes; | ||
| import com.cloud.exception.ConcurrentOperationException; | ||
| @@ -60,7 +61,7 @@ public class MigrateVMCmd extends BaseAsyncCmd { | ||
| type = CommandType.UUID, | ||
| entityType = HostResponse.class, | ||
| required = false, | ||
| description = "Destination Host ID to migrate VM to. Required for live migrating a VM from host to host") | ||
| description = "Destination Host ID to migrate VM to.") | ||
| private Long hostId; | ||
| @Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID, | ||
| @@ -77,6 +78,12 @@ public class MigrateVMCmd extends BaseAsyncCmd { | ||
| description = "Destination storage pool ID to migrate VM volumes to. Required for migrating the root disk volume") | ||
| private Long storageId; | ||
| @Parameter(name = ApiConstants.AUTO_SELECT, | ||
| since = "4.16.0", | ||
| type = CommandType.BOOLEAN, | ||
| description = "Automatically select a destination host which do not require storage migration, if hostId and storageId are not specified. false by default") | ||
| private Boolean autoSelect; | ||
| ///////////////////////////////////////////////////// | ||
| /////////////////// Accessors /////////////////////// | ||
| ///////////////////////////////////////////////////// | ||
| @@ -93,6 +100,10 @@ public Long getStoragePoolId() { | ||
| return storageId; | ||
| } | ||
| public Boolean isAutoSelect() { | ||
| return BooleanUtils.isNotFalse(autoSelect); | ||
| } | ||
| ///////////////////////////////////////////////////// | ||
| /////////////// API Implementation/////////////////// | ||
| ///////////////////////////////////////////////////// | ||
| @@ -132,10 +143,6 @@ public String getEventDescription() { | ||
| @Override | ||
| public void execute() { | ||
| if (getHostId() == null && getStoragePoolId() == null) { | ||
| throw new InvalidParameterValueException("Either hostId or storageId must be specified"); | ||
| } | ||
| if (getHostId() != null && getStoragePoolId() != null) { | ||
| throw new InvalidParameterValueException("Only one of hostId and storageId can be specified"); | ||
| } | ||
| @@ -146,17 +153,6 @@ public void execute() { | ||
| } | ||
| Host destinationHost = null; | ||
| if (getHostId() != null) { | ||
| destinationHost = _resourceService.getHost(getHostId()); | ||
| if (destinationHost == null) { | ||
| throw new InvalidParameterValueException("Unable to find the host to migrate the VM, host id=" + getHostId()); | ||
| } | ||
| if (destinationHost.getType() != Host.Type.Routing) { | ||
| throw new InvalidParameterValueException("The specified host(" + destinationHost.getName() + ") is not suitable to migrate the VM, please specify another one"); | ||
| } | ||
| CallContext.current().setEventDetails("VM Id: " + getVirtualMachineId() + " to host Id: " + getHostId()); | ||
| } | ||
| // OfflineMigration performed when this parameter is specified | ||
| StoragePool destStoragePool = null; | ||
| if (getStoragePoolId() != null) { | ||
| @@ -165,13 +161,24 @@ public void execute() { | ||
| throw new InvalidParameterValueException("Unable to find the storage pool to migrate the VM"); | ||
| } | ||
| CallContext.current().setEventDetails("VM Id: " + getVirtualMachineId() + " to storage pool Id: " + getStoragePoolId()); | ||
| } else if (getHostId() != null) { | ||
| destinationHost = _resourceService.getHost(getHostId()); | ||
| if (destinationHost == null) { | ||
| throw new InvalidParameterValueException("Unable to find the host to migrate the VM, host id=" + getHostId()); | ||
| } | ||
| if (destinationHost.getType() != Host.Type.Routing) { | ||
| throw new InvalidParameterValueException("The specified host(" + destinationHost.getName() + ") is not suitable to migrate the VM, please specify another one"); | ||
| } | ||
| CallContext.current().setEventDetails("VM Id: " + getVirtualMachineId() + " to host Id: " + getHostId()); | ||
| } else if (! isAutoSelect()) { | ||
| throw new InvalidParameterValueException("Please specify a host or storage as destination, or pass 'autoselect=true' to automatically select a destination host which do not require storage migration"); | ||
| } | ||
| try { | ||
| VirtualMachine migratedVm = null; | ||
| if (getHostId() != null) { | ||
| if (getStoragePoolId() == null) { | ||
| ||
| migratedVm = _userVmService.migrateVirtualMachine(getVirtualMachineId(), destinationHost); | ||
| } else if (getStoragePoolId() != null) { | ||
| } else { | ||
| migratedVm = _userVmService.vmStorageMigration(getVirtualMachineId(), destStoragePool); | ||
| } | ||
| if (migratedVm != null) { | ||
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.
@weizhouapache just to check, auto select here picks the suitable host for VM migration. In the similar way, any possibility to pick suitable storage ? If so, can this API have both parameters: autoselecthost & autoselectstorage (only one of them should be true).
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
this pr works only if storage migraiotn is not required.
it can be improved in a new pr.