Skip to content

Commit 175367b

Browse files
committed
another review comment
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent d85781d commit 175367b

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

api/src/main/java/org/apache/cloudstack/api/command/admin/vm/MigrateVirtualMachineWithVolumeCmd.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,19 @@ public ApiCommandResourceType getApiResourceType() {
150150
return ApiCommandResourceType.VirtualMachine;
151151
}
152152

153+
private Host getDestinationHost() {
154+
if (getHostId() == null) {
155+
return null;
156+
}
157+
Host destinationHost = _resourceService.getHost(getHostId());
158+
// OfflineVmwareMigration: destination host would have to not be a required parameter for stopped VMs
159+
if (destinationHost == null) {
160+
s_logger.error(String.format("Unable to find the host with ID [%s].", getHostId()));
161+
throw new InvalidParameterValueException("Unable to find the specified host to migrate the VM.");
162+
}
163+
return destinationHost;
164+
}
165+
153166
@Override
154167
public void execute() {
155168
if (hostId == null && MapUtils.isEmpty(migrateVolumeTo) && !Boolean.TRUE.equals(autoSelect)) {
@@ -169,15 +182,7 @@ public void execute() {
169182
try {
170183
VirtualMachine migratedVm = null;
171184
if (getHostId() != null || Boolean.TRUE.equals(autoSelect)) {
172-
Host destinationHost = null;
173-
if (getHostId() != null) {
174-
destinationHost = _resourceService.getHost(getHostId());
175-
// OfflineVmwareMigration: destination host would have to not be a required parameter for stopped VMs
176-
if (destinationHost == null) {
177-
s_logger.error(String.format("Unable to find the host with ID [%s].", getHostId()));
178-
throw new InvalidParameterValueException("Unable to find the specified host to migrate the VM.");
179-
}
180-
}
185+
Host destinationHost = getDestinationHost();
181186
migratedVm = _userVmService.migrateVirtualMachineWithVolume(getVirtualMachineId(), destinationHost, getVolumeToPool());
182187
} else if (MapUtils.isNotEmpty(migrateVolumeTo)) {
183188
migratedVm = _userVmService.vmStorageMigration(getVirtualMachineId(), getVolumeToPool());

0 commit comments

Comments
 (0)