@@ -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