@@ -2042,7 +2042,6 @@ protected StartAnswer execute(StartCommand cmd) {
20422042 VirtualMachineDefinedProfileSpec diskProfileSpec = null ;
20432043 VirtualMachineDefinedProfileSpec vmProfileSpec = null ;
20442044
2045-
20462045 DeployAsIsInfoTO deployAsIsInfo = vmSpec .getDeployAsIsInfo ();
20472046 boolean deployAsIs = deployAsIsInfo != null ;
20482047
@@ -2086,7 +2085,6 @@ protected StartAnswer execute(StartCommand cmd) {
20862085 }
20872086
20882087 VirtualMachineDiskInfoBuilder diskInfoBuilder = null ;
2089- VirtualDevice [] nicDevices = null ;
20902088 VirtualMachineMO vmMo = hyperHost .findVmOnHyperHost (vmInternalCSName );
20912089 DiskControllerType systemVmScsiControllerType = DiskControllerType .lsilogic ;
20922090 int firstScsiControllerBusNum = 0 ;
@@ -2103,7 +2101,6 @@ protected StartAnswer execute(StartCommand cmd) {
21032101 diskDatastores = vmMo .getAllDiskDatastores ();
21042102 diskInfoBuilder = vmMo .getDiskInfoBuilder ();
21052103 hasSnapshot = vmMo .hasSnapshot ();
2106- nicDevices = vmMo .getNicDevices ();
21072104
21082105 tearDownVmDevices (vmMo , hasSnapshot , deployAsIs );
21092106 ensureDiskControllersInternal (vmMo , systemVm , controllerInfo , systemVmScsiControllerType ,
@@ -2119,17 +2116,20 @@ protected StartAnswer execute(StartCommand cmd) {
21192116 }
21202117
21212118 takeVmFromOtherHyperHost (hyperHost , vmInternalCSName );
2119+ vmMo = hyperHost .findVmOnHyperHost (vmInternalCSName );
21222120
2123- if (getVmPowerState (vmMo ) != PowerState .PowerOff )
2124- vmMo .safePowerOff (_shutdownWaitMs );
2121+ if (vmMo != null ) {
2122+ if (getVmPowerState (vmMo ) != PowerState .PowerOff )
2123+ vmMo .safePowerOff (_shutdownWaitMs );
21252124
2126- diskInfoBuilder = vmMo .getDiskInfoBuilder ();
2127- hasSnapshot = vmMo .hasSnapshot ();
2128- diskDatastores = vmMo .getAllDiskDatastores ();
2125+ diskInfoBuilder = vmMo .getDiskInfoBuilder ();
2126+ hasSnapshot = vmMo .hasSnapshot ();
2127+ diskDatastores = vmMo .getAllDiskDatastores ();
21292128
2130- tearDownVmDevices (vmMo , hasSnapshot , deployAsIs );
2131- ensureDiskControllersInternal (vmMo , systemVm , controllerInfo , systemVmScsiControllerType ,
2132- numScsiControllerForSystemVm , firstScsiControllerBusNum , deployAsIs );
2129+ tearDownVmDevices (vmMo , hasSnapshot , deployAsIs );
2130+ ensureDiskControllersInternal (vmMo , systemVm , controllerInfo , systemVmScsiControllerType ,
2131+ numScsiControllerForSystemVm , firstScsiControllerBusNum , deployAsIs );
2132+ }
21332133 } else {
21342134 // 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).
21352135 VirtualMachineMO existingVmInDc = dcMo .findVm (vmInternalCSName );
@@ -2146,7 +2146,7 @@ protected StartAnswer execute(StartCommand cmd) {
21462146 vmMo = hyperHost .findVmOnHyperHost (vmInternalCSName );
21472147 if (vmMo == null ) {
21482148 logger .info ("Cloned deploy-as-is VM " + vmInternalCSName + " is not in this host, relocating it" );
2149- vmMo = takeVmFromOtherHyperHost (hyperHost , vmInternalCSName );
2149+ takeVmFromOtherHyperHost (hyperHost , vmInternalCSName );
21502150 }
21512151 } else {
21522152 DiskTO rootDisk = null ;
@@ -2256,11 +2256,11 @@ protected StartAnswer execute(StartCommand cmd) {
22562256 vmConfigSpec .setCpuHotAddEnabled (vmMo .isCpuHotAddSupported (guestOsId ) && vmSpec .isEnableDynamicallyScaleVm ());
22572257 }
22582258
2259- if (!vmMo .isMemoryHotAddSupported (guestOsId ) && vmSpec .isEnableDynamicallyScaleVm ()){
2259+ if (!vmMo .isMemoryHotAddSupported (guestOsId ) && vmSpec .isEnableDynamicallyScaleVm ()) {
22602260 logger .warn ("hotadd of memory is not supported, dynamic scaling feature can not be applied to vm: " + vmInternalCSName );
22612261 }
22622262
2263- if (!vmMo .isCpuHotAddSupported (guestOsId ) && vmSpec .isEnableDynamicallyScaleVm ()){
2263+ if (!vmMo .isCpuHotAddSupported (guestOsId ) && vmSpec .isEnableDynamicallyScaleVm ()) {
22642264 logger .warn ("hotadd of cpu is not supported, dynamic scaling feature can not be applied to vm: " + vmInternalCSName );
22652265 }
22662266
@@ -2731,9 +2731,11 @@ private void syncVolumeDatastoreAndPathForDatastoreCluster(DiskTO vol, VirtualMa
27312731 }
27322732
27332733 private boolean powerOnVM (final VirtualMachineMO vmMo , final String vmInternalCSName , final String vmNameOnVcenter ) throws Exception {
2734- int retry = 20 ;
2735- while (retry -- > 0 ) {
2734+ final int retry = 20 ;
2735+ int retryAttempt = 0 ;
2736+ while (++retryAttempt <= retry ) {
27362737 try {
2738+ logger .debug (String .format ("VM %s, powerOn attempt #%d" , vmInternalCSName , retryAttempt ));
27372739 return vmMo .powerOn ();
27382740 } catch (Exception e ) {
27392741 logger .info (String .format ("Got exception while power on VM %s with hostname %s" , vmInternalCSName , vmNameOnVcenter ), e );
@@ -3300,7 +3302,7 @@ private void tearDownVm(VirtualMachineMO vmMo) throws Exception {
33003302
33013303 int getReservedMemoryMb (VirtualMachineTO vmSpec ) {
33023304 if (vmSpec .getDetails ().get (VMwareGuru .VmwareReserveMemory .key ()).equalsIgnoreCase ("true" )) {
3303- if (vmSpec .getDetails ().get (VmDetailConstants .RAM_RESERVATION ) != null ){
3305+ if (vmSpec .getDetails ().get (VmDetailConstants .RAM_RESERVATION ) != null ) {
33043306 float reservedMemory = (vmSpec .getMaxRam () * Float .parseFloat (vmSpec .getDetails ().get (VmDetailConstants .RAM_RESERVATION )));
33053307 return (int ) (reservedMemory / ResourceType .bytesToMiB );
33063308 }
@@ -4927,7 +4929,7 @@ private Answer migrateVolume(MigrateVolumeCommand cmd) {
49274929 VmwareHypervisorHost dsHost = hyperHostInTargetCluster == null ? hyperHost : hyperHostInTargetCluster ;
49284930 String targetDsName = cmd .getTargetPool ().getUuid ();
49294931 morDestinationDS = HypervisorHostHelper .findDatastoreWithBackwardsCompatibility (dsHost , targetDsName );
4930- if (morDestinationDS == null ) {
4932+ if (morDestinationDS == null ) {
49314933 String msg = "Unable to find the target datastore: " + targetDsName + " on host: " + dsHost .getHyperHostName ();
49324934 logger .error (msg );
49334935 throw new CloudRuntimeException (msg );
0 commit comments