@@ -2041,7 +2041,6 @@ protected StartAnswer execute(StartCommand cmd) {
20412041 VirtualMachineDefinedProfileSpec diskProfileSpec = null ;
20422042 VirtualMachineDefinedProfileSpec vmProfileSpec = null ;
20432043
2044-
20452044 DeployAsIsInfoTO deployAsIsInfo = vmSpec .getDeployAsIsInfo ();
20462045 boolean deployAsIs = deployAsIsInfo != null ;
20472046
@@ -2085,7 +2084,6 @@ protected StartAnswer execute(StartCommand cmd) {
20852084 }
20862085
20872086 VirtualMachineDiskInfoBuilder diskInfoBuilder = null ;
2088- VirtualDevice [] nicDevices = null ;
20892087 VirtualMachineMO vmMo = hyperHost .findVmOnHyperHost (vmInternalCSName );
20902088 DiskControllerType systemVmScsiControllerType = DiskControllerType .lsilogic ;
20912089 int firstScsiControllerBusNum = 0 ;
@@ -2102,7 +2100,6 @@ protected StartAnswer execute(StartCommand cmd) {
21022100 diskDatastores = vmMo .getAllDiskDatastores ();
21032101 diskInfoBuilder = vmMo .getDiskInfoBuilder ();
21042102 hasSnapshot = vmMo .hasSnapshot ();
2105- nicDevices = vmMo .getNicDevices ();
21062103
21072104 tearDownVmDevices (vmMo , hasSnapshot , deployAsIs );
21082105 ensureDiskControllersInternal (vmMo , systemVm , controllerInfo , systemVmScsiControllerType ,
@@ -2118,17 +2115,20 @@ protected StartAnswer execute(StartCommand cmd) {
21182115 }
21192116
21202117 takeVmFromOtherHyperHost (hyperHost , vmInternalCSName );
2118+ vmMo = hyperHost .findVmOnHyperHost (vmInternalCSName );
21212119
2122- if (getVmPowerState (vmMo ) != PowerState .PowerOff )
2123- vmMo .safePowerOff (_shutdownWaitMs );
2120+ if (vmMo != null ) {
2121+ if (getVmPowerState (vmMo ) != PowerState .PowerOff )
2122+ vmMo .safePowerOff (_shutdownWaitMs );
21242123
2125- diskInfoBuilder = vmMo .getDiskInfoBuilder ();
2126- hasSnapshot = vmMo .hasSnapshot ();
2127- diskDatastores = vmMo .getAllDiskDatastores ();
2124+ diskInfoBuilder = vmMo .getDiskInfoBuilder ();
2125+ hasSnapshot = vmMo .hasSnapshot ();
2126+ diskDatastores = vmMo .getAllDiskDatastores ();
21282127
2129- tearDownVmDevices (vmMo , hasSnapshot , deployAsIs );
2130- ensureDiskControllersInternal (vmMo , systemVm , controllerInfo , systemVmScsiControllerType ,
2131- numScsiControllerForSystemVm , firstScsiControllerBusNum , deployAsIs );
2128+ tearDownVmDevices (vmMo , hasSnapshot , deployAsIs );
2129+ ensureDiskControllersInternal (vmMo , systemVm , controllerInfo , systemVmScsiControllerType ,
2130+ numScsiControllerForSystemVm , firstScsiControllerBusNum , deployAsIs );
2131+ }
21322132 } else {
21332133 // If a VM with the same name is found in a different cluster in the DC, unregister the old VM and configure a new VM (cold-migration).
21342134 VirtualMachineMO existingVmInDc = dcMo .findVm (vmInternalCSName );
@@ -2145,7 +2145,7 @@ protected StartAnswer execute(StartCommand cmd) {
21452145 vmMo = hyperHost .findVmOnHyperHost (vmInternalCSName );
21462146 if (vmMo == null ) {
21472147 logger .info ("Cloned deploy-as-is VM " + vmInternalCSName + " is not in this host, relocating it" );
2148- vmMo = takeVmFromOtherHyperHost (hyperHost , vmInternalCSName );
2148+ takeVmFromOtherHyperHost (hyperHost , vmInternalCSName );
21492149 }
21502150 } else {
21512151 DiskTO rootDisk = null ;
@@ -2255,11 +2255,11 @@ protected StartAnswer execute(StartCommand cmd) {
22552255 vmConfigSpec .setCpuHotAddEnabled (vmMo .isCpuHotAddSupported (guestOsId ) && vmSpec .isEnableDynamicallyScaleVm ());
22562256 }
22572257
2258- if (!vmMo .isMemoryHotAddSupported (guestOsId ) && vmSpec .isEnableDynamicallyScaleVm ()){
2258+ if (!vmMo .isMemoryHotAddSupported (guestOsId ) && vmSpec .isEnableDynamicallyScaleVm ()) {
22592259 logger .warn ("hotadd of memory is not supported, dynamic scaling feature can not be applied to vm: " + vmInternalCSName );
22602260 }
22612261
2262- if (!vmMo .isCpuHotAddSupported (guestOsId ) && vmSpec .isEnableDynamicallyScaleVm ()){
2262+ if (!vmMo .isCpuHotAddSupported (guestOsId ) && vmSpec .isEnableDynamicallyScaleVm ()) {
22632263 logger .warn ("hotadd of cpu is not supported, dynamic scaling feature can not be applied to vm: " + vmInternalCSName );
22642264 }
22652265
@@ -2709,9 +2709,11 @@ protected StartAnswer execute(StartCommand cmd) {
27092709 }
27102710
27112711 private boolean powerOnVM (final VirtualMachineMO vmMo , final String vmInternalCSName , final String vmNameOnVcenter ) throws Exception {
2712- int retry = 20 ;
2713- while (retry -- > 0 ) {
2712+ final int retry = 20 ;
2713+ int retryAttempt = 0 ;
2714+ while (++retryAttempt <= retry ) {
27142715 try {
2716+ logger .debug (String .format ("VM %s, powerOn attempt #%d" , vmInternalCSName , retryAttempt ));
27152717 return vmMo .powerOn ();
27162718 } catch (Exception e ) {
27172719 logger .info (String .format ("Got exception while power on VM %s with hostname %s" , vmInternalCSName , vmNameOnVcenter ), e );
@@ -3227,7 +3229,7 @@ private void tearDownVm(VirtualMachineMO vmMo) throws Exception {
32273229
32283230 int getReservedMemoryMb (VirtualMachineTO vmSpec ) {
32293231 if (vmSpec .getDetails ().get (VMwareGuru .VmwareReserveMemory .key ()).equalsIgnoreCase ("true" )) {
3230- if (vmSpec .getDetails ().get (VmDetailConstants .RAM_RESERVATION ) != null ){
3232+ if (vmSpec .getDetails ().get (VmDetailConstants .RAM_RESERVATION ) != null ) {
32313233 float reservedMemory = (vmSpec .getMaxRam () * Float .parseFloat (vmSpec .getDetails ().get (VmDetailConstants .RAM_RESERVATION )));
32323234 return (int ) (reservedMemory / ResourceType .bytesToMiB );
32333235 }
@@ -4856,7 +4858,7 @@ private Answer migrateVolume(MigrateVolumeCommand cmd) {
48564858 VmwareHypervisorHost dsHost = hyperHostInTargetCluster == null ? hyperHost : hyperHostInTargetCluster ;
48574859 String targetDsName = cmd .getTargetPool ().getUuid ();
48584860 morDestinationDS = HypervisorHostHelper .findDatastoreWithBackwardsCompatibility (dsHost , targetDsName );
4859- if (morDestinationDS == null ) {
4861+ if (morDestinationDS == null ) {
48604862 String msg = "Unable to find the target datastore: " + targetDsName + " on host: " + dsHost .getHyperHostName ();
48614863 logger .error (msg );
48624864 throw new CloudRuntimeException (msg );
0 commit comments