-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Changes from all commits
51ea345
9bdc324
f5aed32
92b8f73
c1a1e2a
62a4886
a258544
90b1ff5
e7216e1
6e54dc3
06e3a8a
0d8175c
107fd3a
73e1c2b
6530abe
File filter
Filter by extension
Conversations
Jump to
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) { | ||
|
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. @ustcweizhou whenever host / storage pool is not specified in the cmd, instead of directly picking a suitable dest host to migrate to, I think it is better to confirm it (from the user) through a API cmd param (something like chooseHost / selectHost). If user is not OK to auto select host, then throw appropriate message.
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 ok.
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. @weizhouapache host id in the cmd is UUID, so i think it is better to take input from another param when host id is null. If host id is not null, ignore auto selection.
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 yes, I am currently working on the coding, same as you said. ps: cloudstack supports projectid=-1, so it is feasible to support hostid=-1 but it might have big impact on other apis. |
||
| 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.