@@ -384,13 +384,26 @@ public DeployDestination planDeployment(VirtualMachineProfile vmProfile, Deploym
384384 boolean considerLastHost = vm .getLastHostId () != null && haVmTag == null &&
385385 (considerLastHostStr == null || Boolean .TRUE .toString ().equalsIgnoreCase (considerLastHostStr ));
386386 if (considerLastHost ) {
387+ logger .debug ("This VM has last host_id: {}" , vm .getLastHostId ());
387388 HostVO host = _hostDao .findById (vm .getLastHostId ());
388- logger .debug ("This VM has last host_id specified, trying to choose the same host: " + host );
389- lastHost = host ;
389+ if (host == null ) {
390+ if (Boolean .TRUE .toString ().equalsIgnoreCase (considerLastHostStr )) {
391+ throw new CloudRuntimeException ("Failed to deploy VM, last host doesn't exists" );
392+ }
393+ } else {
394+ if (host .isInMaintenanceStates ()) {
395+ if (Boolean .TRUE .toString ().equalsIgnoreCase (considerLastHostStr )) {
396+ throw new CloudRuntimeException ("Failed to deploy VM, last host is in maintenance state" );
397+ }
398+ } else {
399+ logger .debug ("VM's last {}, trying to choose the same host" , host );
400+ lastHost = host ;
390401
391- DeployDestination deployDestination = deployInVmLastHost (vmProfile , plan , avoids , planner , vm , dc , offering , cpuRequested , ramRequested , volumesRequireEncryption );
392- if (deployDestination != null ) {
393- return deployDestination ;
402+ DeployDestination deployDestination = deployInVmLastHost (vmProfile , plan , avoids , planner , vm , dc , offering , cpuRequested , ramRequested , volumesRequireEncryption );
403+ if (deployDestination != null ) {
404+ return deployDestination ;
405+ }
406+ }
394407 }
395408 }
396409
@@ -1474,7 +1487,7 @@ private Pair<Boolean, Boolean> findVMStorageRequirements(VirtualMachineProfile v
14741487
14751488 protected Pair <Host , Map <Volume , StoragePool >> findPotentialDeploymentResources (List <Host > suitableHosts , Map <Volume , List <StoragePool >> suitableVolumeStoragePools ,
14761489 ExcludeList avoid , PlannerResourceUsage resourceUsageRequired , List <Volume > readyAndReusedVolumes , List <Long > preferredHosts , VirtualMachine vm ) {
1477- logger .debug ("Trying to find a potenial host and associated storage pools from the suitable host/pool lists for this VM" );
1490+ logger .debug ("Trying to find a potential host and associated storage pools from the suitable host/pool lists for this VM" );
14781491
14791492 boolean hostCanAccessPool = false ;
14801493 boolean haveEnoughSpace = false ;
0 commit comments