DaanHoogland commented on code in PR #7554:
URL: https://github.com/apache/cloudstack/pull/7554#discussion_r1210325040
##########
api/src/main/java/org/apache/cloudstack/api/command/admin/vm/MigrateVirtualMachineWithVolumeCmd.java:
##########
@@ -146,28 +152,31 @@ public ApiCommandResourceType getApiResourceType() {
@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.",
+ 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 = null;
+ if (getHostId() != null) {
+ 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.");
+ }
Review Comment:
ok, i see now what I missed. If we enter this block because
`Boolean.TRUE.equals(autoSelect)` we do nothing and just pass a `null` to
`migrateVirtualMachineWithVolume`. I think this would read easier if the block
was extracted into a new method.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]