@@ -2043,7 +2043,6 @@ protected StartAnswer execute(StartCommand cmd) {
20432043 VirtualMachineDefinedProfileSpec diskProfileSpec = null ;
20442044 VirtualMachineDefinedProfileSpec vmProfileSpec = null ;
20452045
2046-
20472046 DeployAsIsInfoTO deployAsIsInfo = vmSpec .getDeployAsIsInfo ();
20482047 boolean deployAsIs = deployAsIsInfo != null ;
20492048
@@ -2087,7 +2086,6 @@ protected StartAnswer execute(StartCommand cmd) {
20872086 }
20882087
20892088 VirtualMachineDiskInfoBuilder diskInfoBuilder = null ;
2090- VirtualDevice [] nicDevices = null ;
20912089 VirtualMachineMO vmMo = hyperHost .findVmOnHyperHost (vmInternalCSName );
20922090 DiskControllerType systemVmScsiControllerType = DiskControllerType .lsilogic ;
20932091 int firstScsiControllerBusNum = 0 ;
@@ -2104,7 +2102,6 @@ protected StartAnswer execute(StartCommand cmd) {
21042102 diskDatastores = vmMo .getAllDiskDatastores ();
21052103 diskInfoBuilder = vmMo .getDiskInfoBuilder ();
21062104 hasSnapshot = vmMo .hasSnapshot ();
2107- nicDevices = vmMo .getNicDevices ();
21082105
21092106 tearDownVmDevices (vmMo , hasSnapshot , deployAsIs );
21102107 ensureDiskControllersInternal (vmMo , systemVm , controllerInfo , systemVmScsiControllerType ,
@@ -2120,17 +2117,20 @@ protected StartAnswer execute(StartCommand cmd) {
21202117 }
21212118
21222119 takeVmFromOtherHyperHost (hyperHost , vmInternalCSName );
2120+ vmMo = hyperHost .findVmOnHyperHost (vmInternalCSName );
21232121
2124- if (getVmPowerState (vmMo ) != PowerState .PowerOff )
2125- vmMo .safePowerOff (_shutdownWaitMs );
2122+ if (vmMo != null ) {
2123+ if (getVmPowerState (vmMo ) != PowerState .PowerOff )
2124+ vmMo .safePowerOff (_shutdownWaitMs );
21262125
2127- diskInfoBuilder = vmMo .getDiskInfoBuilder ();
2128- hasSnapshot = vmMo .hasSnapshot ();
2129- diskDatastores = vmMo .getAllDiskDatastores ();
2126+ diskInfoBuilder = vmMo .getDiskInfoBuilder ();
2127+ hasSnapshot = vmMo .hasSnapshot ();
2128+ diskDatastores = vmMo .getAllDiskDatastores ();
21302129
2131- tearDownVmDevices (vmMo , hasSnapshot , deployAsIs );
2132- ensureDiskControllersInternal (vmMo , systemVm , controllerInfo , systemVmScsiControllerType ,
2133- numScsiControllerForSystemVm , firstScsiControllerBusNum , deployAsIs );
2130+ tearDownVmDevices (vmMo , hasSnapshot , deployAsIs );
2131+ ensureDiskControllersInternal (vmMo , systemVm , controllerInfo , systemVmScsiControllerType ,
2132+ numScsiControllerForSystemVm , firstScsiControllerBusNum , deployAsIs );
2133+ }
21342134 } else {
21352135 // 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).
21362136 VirtualMachineMO existingVmInDc = dcMo .findVm (vmInternalCSName );
@@ -2147,7 +2147,7 @@ protected StartAnswer execute(StartCommand cmd) {
21472147 vmMo = hyperHost .findVmOnHyperHost (vmInternalCSName );
21482148 if (vmMo == null ) {
21492149 logger .info ("Cloned deploy-as-is VM " + vmInternalCSName + " is not in this host, relocating it" );
2150- vmMo = takeVmFromOtherHyperHost (hyperHost , vmInternalCSName );
2150+ takeVmFromOtherHyperHost (hyperHost , vmInternalCSName );
21512151 }
21522152 } else {
21532153 DiskTO rootDisk = null ;
@@ -2257,11 +2257,11 @@ protected StartAnswer execute(StartCommand cmd) {
22572257 vmConfigSpec .setCpuHotAddEnabled (vmMo .isCpuHotAddSupported (guestOsId ) && vmSpec .isEnableDynamicallyScaleVm ());
22582258 }
22592259
2260- if (!vmMo .isMemoryHotAddSupported (guestOsId ) && vmSpec .isEnableDynamicallyScaleVm ()){
2260+ if (!vmMo .isMemoryHotAddSupported (guestOsId ) && vmSpec .isEnableDynamicallyScaleVm ()) {
22612261 logger .warn ("hotadd of memory is not supported, dynamic scaling feature can not be applied to vm: " + vmInternalCSName );
22622262 }
22632263
2264- if (!vmMo .isCpuHotAddSupported (guestOsId ) && vmSpec .isEnableDynamicallyScaleVm ()){
2264+ if (!vmMo .isCpuHotAddSupported (guestOsId ) && vmSpec .isEnableDynamicallyScaleVm ()) {
22652265 logger .warn ("hotadd of cpu is not supported, dynamic scaling feature can not be applied to vm: " + vmInternalCSName );
22662266 }
22672267
@@ -2715,9 +2715,11 @@ protected StartAnswer execute(StartCommand cmd) {
27152715 }
27162716
27172717 private boolean powerOnVM (final VirtualMachineMO vmMo , final String vmInternalCSName , final String vmNameOnVcenter ) throws Exception {
2718- int retry = 20 ;
2719- while (retry -- > 0 ) {
2718+ final int retry = 20 ;
2719+ int retryAttempt = 0 ;
2720+ while (++retryAttempt <= retry ) {
27202721 try {
2722+ logger .debug (String .format ("VM %s, powerOn attempt #%d" , vmInternalCSName , retryAttempt ));
27212723 return vmMo .powerOn ();
27222724 } catch (Exception e ) {
27232725 logger .info (String .format ("Got exception while power on VM %s with hostname %s" , vmInternalCSName , vmNameOnVcenter ), e );
@@ -3284,7 +3286,7 @@ private void tearDownVm(VirtualMachineMO vmMo) throws Exception {
32843286
32853287 int getReservedMemoryMb (VirtualMachineTO vmSpec ) {
32863288 if (vmSpec .getDetails ().get (VMwareGuru .VmwareReserveMemory .key ()).equalsIgnoreCase ("true" )) {
3287- if (vmSpec .getDetails ().get (VmDetailConstants .RAM_RESERVATION ) != null ){
3289+ if (vmSpec .getDetails ().get (VmDetailConstants .RAM_RESERVATION ) != null ) {
32883290 float reservedMemory = (vmSpec .getMaxRam () * Float .parseFloat (vmSpec .getDetails ().get (VmDetailConstants .RAM_RESERVATION )));
32893291 return (int ) (reservedMemory / ResourceType .bytesToMiB );
32903292 }
@@ -4913,7 +4915,7 @@ private Answer migrateVolume(MigrateVolumeCommand cmd) {
49134915 VmwareHypervisorHost dsHost = hyperHostInTargetCluster == null ? hyperHost : hyperHostInTargetCluster ;
49144916 String targetDsName = cmd .getTargetPool ().getUuid ();
49154917 morDestinationDS = HypervisorHostHelper .findDatastoreWithBackwardsCompatibility (dsHost , targetDsName );
4916- if (morDestinationDS == null ) {
4918+ if (morDestinationDS == null ) {
49174919 String msg = "Unable to find the target datastore: " + targetDsName + " on host: " + dsHost .getHyperHostName ();
49184920 logger .error (msg );
49194921 throw new CloudRuntimeException (msg );
0 commit comments