@@ -2041,7 +2041,6 @@ protected StartAnswer execute(StartCommand cmd) {
2041
2041
VirtualMachineDefinedProfileSpec diskProfileSpec = null ;
2042
2042
VirtualMachineDefinedProfileSpec vmProfileSpec = null ;
2043
2043
2044
-
2045
2044
DeployAsIsInfoTO deployAsIsInfo = vmSpec .getDeployAsIsInfo ();
2046
2045
boolean deployAsIs = deployAsIsInfo != null ;
2047
2046
@@ -2085,7 +2084,6 @@ protected StartAnswer execute(StartCommand cmd) {
2085
2084
}
2086
2085
2087
2086
VirtualMachineDiskInfoBuilder diskInfoBuilder = null ;
2088
- VirtualDevice [] nicDevices = null ;
2089
2087
VirtualMachineMO vmMo = hyperHost .findVmOnHyperHost (vmInternalCSName );
2090
2088
DiskControllerType systemVmScsiControllerType = DiskControllerType .lsilogic ;
2091
2089
int firstScsiControllerBusNum = 0 ;
@@ -2102,7 +2100,6 @@ protected StartAnswer execute(StartCommand cmd) {
2102
2100
diskDatastores = vmMo .getAllDiskDatastores ();
2103
2101
diskInfoBuilder = vmMo .getDiskInfoBuilder ();
2104
2102
hasSnapshot = vmMo .hasSnapshot ();
2105
- nicDevices = vmMo .getNicDevices ();
2106
2103
2107
2104
tearDownVmDevices (vmMo , hasSnapshot , deployAsIs );
2108
2105
ensureDiskControllersInternal (vmMo , systemVm , controllerInfo , systemVmScsiControllerType ,
@@ -2118,17 +2115,20 @@ protected StartAnswer execute(StartCommand cmd) {
2118
2115
}
2119
2116
2120
2117
takeVmFromOtherHyperHost (hyperHost , vmInternalCSName );
2118
+ vmMo = hyperHost .findVmOnHyperHost (vmInternalCSName );
2121
2119
2122
- if (getVmPowerState (vmMo ) != PowerState .PowerOff )
2123
- vmMo .safePowerOff (_shutdownWaitMs );
2120
+ if (vmMo != null ) {
2121
+ if (getVmPowerState (vmMo ) != PowerState .PowerOff )
2122
+ vmMo .safePowerOff (_shutdownWaitMs );
2124
2123
2125
- diskInfoBuilder = vmMo .getDiskInfoBuilder ();
2126
- hasSnapshot = vmMo .hasSnapshot ();
2127
- diskDatastores = vmMo .getAllDiskDatastores ();
2124
+ diskInfoBuilder = vmMo .getDiskInfoBuilder ();
2125
+ hasSnapshot = vmMo .hasSnapshot ();
2126
+ diskDatastores = vmMo .getAllDiskDatastores ();
2128
2127
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
+ }
2132
2132
} else {
2133
2133
// 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).
2134
2134
VirtualMachineMO existingVmInDc = dcMo .findVm (vmInternalCSName );
@@ -2145,7 +2145,7 @@ protected StartAnswer execute(StartCommand cmd) {
2145
2145
vmMo = hyperHost .findVmOnHyperHost (vmInternalCSName );
2146
2146
if (vmMo == null ) {
2147
2147
logger .info ("Cloned deploy-as-is VM " + vmInternalCSName + " is not in this host, relocating it" );
2148
- vmMo = takeVmFromOtherHyperHost (hyperHost , vmInternalCSName );
2148
+ takeVmFromOtherHyperHost (hyperHost , vmInternalCSName );
2149
2149
}
2150
2150
} else {
2151
2151
DiskTO rootDisk = null ;
@@ -2255,11 +2255,11 @@ protected StartAnswer execute(StartCommand cmd) {
2255
2255
vmConfigSpec .setCpuHotAddEnabled (vmMo .isCpuHotAddSupported (guestOsId ) && vmSpec .isEnableDynamicallyScaleVm ());
2256
2256
}
2257
2257
2258
- if (!vmMo .isMemoryHotAddSupported (guestOsId ) && vmSpec .isEnableDynamicallyScaleVm ()){
2258
+ if (!vmMo .isMemoryHotAddSupported (guestOsId ) && vmSpec .isEnableDynamicallyScaleVm ()) {
2259
2259
logger .warn ("hotadd of memory is not supported, dynamic scaling feature can not be applied to vm: " + vmInternalCSName );
2260
2260
}
2261
2261
2262
- if (!vmMo .isCpuHotAddSupported (guestOsId ) && vmSpec .isEnableDynamicallyScaleVm ()){
2262
+ if (!vmMo .isCpuHotAddSupported (guestOsId ) && vmSpec .isEnableDynamicallyScaleVm ()) {
2263
2263
logger .warn ("hotadd of cpu is not supported, dynamic scaling feature can not be applied to vm: " + vmInternalCSName );
2264
2264
}
2265
2265
@@ -2709,9 +2709,11 @@ protected StartAnswer execute(StartCommand cmd) {
2709
2709
}
2710
2710
2711
2711
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 ) {
2714
2715
try {
2716
+ logger .debug (String .format ("VM %s, powerOn attempt #%d" , vmInternalCSName , retryAttempt ));
2715
2717
return vmMo .powerOn ();
2716
2718
} catch (Exception e ) {
2717
2719
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 {
3227
3229
3228
3230
int getReservedMemoryMb (VirtualMachineTO vmSpec ) {
3229
3231
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 ) {
3231
3233
float reservedMemory = (vmSpec .getMaxRam () * Float .parseFloat (vmSpec .getDetails ().get (VmDetailConstants .RAM_RESERVATION )));
3232
3234
return (int ) (reservedMemory / ResourceType .bytesToMiB );
3233
3235
}
@@ -4856,7 +4858,7 @@ private Answer migrateVolume(MigrateVolumeCommand cmd) {
4856
4858
VmwareHypervisorHost dsHost = hyperHostInTargetCluster == null ? hyperHost : hyperHostInTargetCluster ;
4857
4859
String targetDsName = cmd .getTargetPool ().getUuid ();
4858
4860
morDestinationDS = HypervisorHostHelper .findDatastoreWithBackwardsCompatibility (dsHost , targetDsName );
4859
- if (morDestinationDS == null ) {
4861
+ if (morDestinationDS == null ) {
4860
4862
String msg = "Unable to find the target datastore: " + targetDsName + " on host: " + dsHost .getHyperHostName ();
4861
4863
logger .error (msg );
4862
4864
throw new CloudRuntimeException (msg );
0 commit comments