@@ -2661,14 +2661,19 @@ protected StartAnswer execute(StartCommand cmd) {
26612661 DatacenterMO dcMo = new DatacenterMO (hyperHost .getContext (), hyperHost .getHyperHostDatacenter ());
26622662 VirtualMachineDiskInfoBuilder diskInfoBuilder = null ;
26632663 VirtualMachineMO vmMo = hyperHost .findVmOnHyperHost (vmInternalCSName );
2664+ boolean hasSnapshot = false ;
26642665 if (vmMo != null ) {
26652666 s_logger .info ("VM " + vmInternalCSName + " already exists, tear down devices for reconfiguration" );
26662667 if (getVmState (vmMo ) != State .Stopped )
26672668 vmMo .safePowerOff (_shutdown_waitMs );
26682669
26692670 // retrieve disk information before we tear down
26702671 diskInfoBuilder = vmMo .getDiskInfoBuilder ();
2671- vmMo .tearDownDevices (new Class <?>[] { VirtualDisk .class , VirtualEthernetCard .class });
2672+ hasSnapshot = vmMo .hasSnapshot ();
2673+ if (!hasSnapshot )
2674+ vmMo .tearDownDevices (new Class <?>[] { VirtualDisk .class , VirtualEthernetCard .class });
2675+ else
2676+ vmMo .tearDownDevices (new Class <?>[] { VirtualEthernetCard .class });
26722677 vmMo .ensureScsiDeviceController ();
26732678 } else {
26742679 ManagedObjectReference morDc = hyperHost .getHyperHostDatacenter ();
@@ -2686,7 +2691,11 @@ protected StartAnswer execute(StartCommand cmd) {
26862691 vmMo .safePowerOff (_shutdown_waitMs );
26872692
26882693 diskInfoBuilder = vmMo .getDiskInfoBuilder ();
2689- vmMo .tearDownDevices (new Class <?>[] { VirtualDisk .class , VirtualEthernetCard .class });
2694+ hasSnapshot = vmMo .hasSnapshot ();
2695+ if (!hasSnapshot )
2696+ vmMo .tearDownDevices (new Class <?>[] { VirtualDisk .class , VirtualEthernetCard .class });
2697+ else
2698+ vmMo .tearDownDevices (new Class <?>[] { VirtualEthernetCard .class });
26902699 vmMo .ensureScsiDeviceController ();
26912700 } else {
26922701 Pair <ManagedObjectReference , DatastoreMO > rootDiskDataStoreDetails = null ;
@@ -2840,37 +2849,45 @@ protected StartAnswer execute(StartCommand cmd) {
28402849 //
28412850 DiskTO [] sortedDisks = sortVolumesByDeviceId (disks );
28422851 for (DiskTO vol : sortedDisks ) {
2843- deviceConfigSpecArray [i ] = new VirtualDeviceConfigSpec ();
2844-
28452852 if (vol .getType () == Volume .Type .ISO )
28462853 continue ;
2847-
2854+
28482855 VirtualMachineDiskInfo matchingExistingDisk = getMatchingExistingDisk (diskInfoBuilder , vol );
28492856 controllerKey = getDiskController (matchingExistingDisk , vol , vmSpec , ideControllerKey , scsiControllerKey );
28502857
2851- VolumeObjectTO volumeTO = (VolumeObjectTO )vol .getData ();
2852- PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO )volumeTO .getDataStore ();
2853- Pair <ManagedObjectReference , DatastoreMO > volumeDsDetails = dataStoresDetails .get (primaryStore .getUuid ());
2854- assert (volumeDsDetails != null );
2855- VirtualDevice device ;
2856-
2857- String [] diskChain = syncDiskChain (dcMo , vmMo , vmSpec ,
2858- vol , matchingExistingDisk ,
2859- dataStoresDetails );
2860- if (controllerKey == scsiControllerKey && VmwareHelper .isReservedScsiDeviceNumber (scsiUnitNumber ))
2861- scsiUnitNumber ++;
2862- device = VmwareHelper .prepareDiskDevice (vmMo , null , controllerKey ,
2863- diskChain ,
2864- volumeDsDetails .first (),
2865- (controllerKey == ideControllerKey ) ? ideUnitNumber ++ : scsiUnitNumber ++, i + 1 );
2866-
2867- deviceConfigSpecArray [i ].setDevice (device );
2868- deviceConfigSpecArray [i ].setOperation (VirtualDeviceConfigSpecOperation .ADD );
2869-
2870- if (s_logger .isDebugEnabled ())
2871- s_logger .debug ("Prepare volume at new device " + _gson .toJson (device ));
2872-
2873- i ++;
2858+ if (!hasSnapshot ) {
2859+ deviceConfigSpecArray [i ] = new VirtualDeviceConfigSpec ();
2860+
2861+ VolumeObjectTO volumeTO = (VolumeObjectTO )vol .getData ();
2862+ PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO )volumeTO .getDataStore ();
2863+ Pair <ManagedObjectReference , DatastoreMO > volumeDsDetails = dataStoresDetails .get (primaryStore .getUuid ());
2864+ assert (volumeDsDetails != null );
2865+
2866+ String [] diskChain = syncDiskChain (dcMo , vmMo , vmSpec ,
2867+ vol , matchingExistingDisk ,
2868+ dataStoresDetails );
2869+ if (controllerKey == scsiControllerKey && VmwareHelper .isReservedScsiDeviceNumber (scsiUnitNumber ))
2870+ scsiUnitNumber ++;
2871+ VirtualDevice device = VmwareHelper .prepareDiskDevice (vmMo , null , controllerKey ,
2872+ diskChain ,
2873+ volumeDsDetails .first (),
2874+ (controllerKey == ideControllerKey ) ? ideUnitNumber ++ : scsiUnitNumber ++, i + 1 );
2875+
2876+ deviceConfigSpecArray [i ].setDevice (device );
2877+ deviceConfigSpecArray [i ].setOperation (VirtualDeviceConfigSpecOperation .ADD );
2878+
2879+ if (s_logger .isDebugEnabled ())
2880+ s_logger .debug ("Prepare volume at new device " + _gson .toJson (device ));
2881+
2882+ i ++;
2883+ } else {
2884+ if (controllerKey == scsiControllerKey && VmwareHelper .isReservedScsiDeviceNumber (scsiUnitNumber ))
2885+ scsiUnitNumber ++;
2886+ if (controllerKey == ideControllerKey )
2887+ ideUnitNumber ++;
2888+ else
2889+ scsiUnitNumber ++;
2890+ }
28742891 }
28752892
28762893 //
@@ -2917,7 +2934,8 @@ protected StartAnswer execute(StartCommand cmd) {
29172934 nicCount ++;
29182935 }
29192936
2920- vmConfigSpec .getDeviceChange ().addAll (Arrays .asList (deviceConfigSpecArray ));
2937+ for (int j = 0 ; j < i ; j ++)
2938+ vmConfigSpec .getDeviceChange ().add (deviceConfigSpecArray [j ]);
29212939
29222940 //
29232941 // Setup VM options
@@ -5479,7 +5497,7 @@ public Answer execute(DeleteCommand cmd) {
54795497 // tear down all devices first before we destroy the VM to avoid accidently delete disk backing files
54805498 if (getVmState (vmMo ) != State .Stopped )
54815499 vmMo .safePowerOff (_shutdown_waitMs );
5482- vmMo .tearDownDevices (new Class <?>[] { VirtualDisk .class , VirtualEthernetCard .class });
5500+ vmMo .tearDownDevices (new Class <?>[] { /* VirtualDisk.class, */ VirtualEthernetCard .class });
54835501 vmMo .destroy ();
54845502
54855503 for (NetworkDetails netDetails : networks ) {
0 commit comments