cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kelv...@apache.org
Subject git commit: updated refs/heads/master to 16b022b
Date Fri, 04 Oct 2013 23:14:46 GMT
Updated Branches:
  refs/heads/master ff336c3e9 -> 16b022b1b


CLOUDSTACK-4802: Change VM start flow to better support VM snapshot on certian version of
vSphere, (vSphere 5.0 Update 2). If we detect that VM has pending VM snapshot, we will fully
honor VM disk info from vCenter, since in some version of vSphere (vSphere 5.0 U2) does not
allow disk-editting when VM has pending snapshot.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/16b022b1
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/16b022b1
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/16b022b1

Branch: refs/heads/master
Commit: 16b022b1b1e9bf97420ed4110244d8c9a9601a49
Parents: ff336c3
Author: Kelven Yang <kelveny@gmail.com>
Authored: Fri Oct 4 15:59:08 2013 -0700
Committer: Kelven Yang <kelveny@gmail.com>
Committed: Fri Oct 4 16:13:56 2013 -0700

----------------------------------------------------------------------
 .../vmware/resource/VmwareResource.java         | 78 ++++++++++++--------
 .../hypervisor/vmware/mo/VirtualMachineMO.java  | 28 ++++++-
 2 files changed, 75 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/16b022b1/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
index 6b3731ce..a35a966 100755
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
@@ -2629,6 +2629,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource,
Vmwa
             DatacenterMO dcMo = new DatacenterMO(hyperHost.getContext(), hyperHost.getHyperHostDatacenter());
             VirtualMachineDiskInfoBuilder diskInfoBuilder = null;
             VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(vmInternalCSName);
+            boolean hasSnapshot = false;
             if (vmMo != null) {
                 s_logger.info("VM " + vmInternalCSName + " already exists, tear down devices
for reconfiguration");
                 if (getVmState(vmMo) != State.Stopped)
@@ -2636,7 +2637,11 @@ public class VmwareResource implements StoragePoolResource, ServerResource,
Vmwa
              
                 // retrieve disk information before we tear down
                 diskInfoBuilder = vmMo.getDiskInfoBuilder();
-                vmMo.tearDownDevices(new Class<?>[] { VirtualDisk.class, VirtualEthernetCard.class
});
+                hasSnapshot = vmMo.hasSnapshot();
+                if(!hasSnapshot)
+                	vmMo.tearDownDevices(new Class<?>[] { VirtualDisk.class, VirtualEthernetCard.class
});
+                else
+                	vmMo.tearDownDevices(new Class<?>[] { VirtualEthernetCard.class });
                 vmMo.ensureScsiDeviceController();
             } else {
                 ManagedObjectReference morDc = hyperHost.getHyperHostDatacenter();
@@ -2654,7 +2659,11 @@ public class VmwareResource implements StoragePoolResource, ServerResource,
Vmwa
                         vmMo.safePowerOff(_shutdown_waitMs);
                     
                     diskInfoBuilder = vmMo.getDiskInfoBuilder();
-                    vmMo.tearDownDevices(new Class<?>[] { VirtualDisk.class, VirtualEthernetCard.class
});
+                    hasSnapshot = vmMo.hasSnapshot();
+                    if(!hasSnapshot)
+                    	vmMo.tearDownDevices(new Class<?>[] { VirtualDisk.class, VirtualEthernetCard.class
});
+                    else
+                    	vmMo.tearDownDevices(new Class<?>[] { VirtualEthernetCard.class
});
                     vmMo.ensureScsiDeviceController();
                 } else {
                     int ramMb = (int) (vmSpec.getMinRam() / (1024 * 1024));
@@ -2810,37 +2819,45 @@ public class VmwareResource implements StoragePoolResource, ServerResource,
Vmwa
             //
             DiskTO[] sortedDisks = sortVolumesByDeviceId(disks);
             for (DiskTO vol : sortedDisks) {
-                deviceConfigSpecArray[i] = new VirtualDeviceConfigSpec();
-
                 if (vol.getType() == Volume.Type.ISO)
                 	continue;
-                
+            
                 VirtualMachineDiskInfo matchingExistingDisk = getMatchingExistingDisk(diskInfoBuilder,
vol);
                 controllerKey = getDiskController(matchingExistingDisk, vol, vmSpec, ideControllerKey,
scsiControllerKey);
 
-                VolumeObjectTO volumeTO = (VolumeObjectTO)vol.getData();
-                PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO)volumeTO.getDataStore();
-                Pair<ManagedObjectReference, DatastoreMO> volumeDsDetails = dataStoresDetails.get(primaryStore.getUuid());
-                assert (volumeDsDetails != null);
-                VirtualDevice device;
-                
-                String[] diskChain = syncDiskChain(dcMo, vmMo, vmSpec, 
-                    	vol, matchingExistingDisk,
-                    	dataStoresDetails);
-                if(controllerKey == scsiControllerKey && VmwareHelper.isReservedScsiDeviceNumber(scsiUnitNumber))
-                	scsiUnitNumber++;
-                device = VmwareHelper.prepareDiskDevice(vmMo, null, controllerKey, 
-                	diskChain, 
-                	volumeDsDetails.first(),
-                    (controllerKey == ideControllerKey) ? ideUnitNumber++ : scsiUnitNumber++,
i + 1);
-                
-                deviceConfigSpecArray[i].setDevice(device);
-            	deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.ADD);
-
-                if(s_logger.isDebugEnabled())
-                    s_logger.debug("Prepare volume at new device " + _gson.toJson(device));
-
-                i++;
+                if(!hasSnapshot) {
+                    deviceConfigSpecArray[i] = new VirtualDeviceConfigSpec();
+                    
+	                VolumeObjectTO volumeTO = (VolumeObjectTO)vol.getData();
+	                PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO)volumeTO.getDataStore();
+	                Pair<ManagedObjectReference, DatastoreMO> volumeDsDetails = dataStoresDetails.get(primaryStore.getUuid());
+	                assert (volumeDsDetails != null);
+	                
+	                String[] diskChain = syncDiskChain(dcMo, vmMo, vmSpec, 
+	                    	vol, matchingExistingDisk,
+	                    	dataStoresDetails);
+	                if(controllerKey == scsiControllerKey && VmwareHelper.isReservedScsiDeviceNumber(scsiUnitNumber))
+	                	scsiUnitNumber++;
+	                VirtualDevice device = VmwareHelper.prepareDiskDevice(vmMo, null, controllerKey,

+	                	diskChain, 
+	                	volumeDsDetails.first(),
+	                    (controllerKey == ideControllerKey) ? ideUnitNumber++ : scsiUnitNumber++,
i + 1);
+	                
+	                deviceConfigSpecArray[i].setDevice(device);
+	            	deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.ADD);
+	
+	                if(s_logger.isDebugEnabled())
+	                    s_logger.debug("Prepare volume at new device " + _gson.toJson(device));
+	
+	                i++;
+                } else {
+	                if(controllerKey == scsiControllerKey && VmwareHelper.isReservedScsiDeviceNumber(scsiUnitNumber))
+	                	scsiUnitNumber++;
+	                if(controllerKey == ideControllerKey) 
+	                	ideUnitNumber++;
+	                else
+	                	scsiUnitNumber++;
+                }
             }
 
             //
@@ -2887,7 +2904,8 @@ public class VmwareResource implements StoragePoolResource, ServerResource,
Vmwa
                 nicCount++;
             }
 
-            vmConfigSpec.getDeviceChange().addAll(Arrays.asList(deviceConfigSpecArray));
+            for(int j = 0; j < i; j++)
+            	vmConfigSpec.getDeviceChange().add(deviceConfigSpecArray[j]);
 
             //
             // Setup VM options
@@ -5412,7 +5430,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource,
Vmwa
                         // tear down all devices first before we destroy the VM to avoid
accidently delete disk backing files
                         if (getVmState(vmMo) != State.Stopped)
                             vmMo.safePowerOff(_shutdown_waitMs);
-                        vmMo.tearDownDevices(new Class<?>[] { VirtualDisk.class, VirtualEthernetCard.class
});
+                        vmMo.tearDownDevices(new Class<?>[] { /* VirtualDisk.class,
*/ VirtualEthernetCard.class });
                         vmMo.destroy();
 
                         for (NetworkDetails netDetails : networks) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/16b022b1/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
----------------------------------------------------------------------
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
index 56f2f38..a9536cf 100644
--- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
@@ -577,6 +577,14 @@ public class VirtualMachineMO extends BaseMO {
 		}
 		return null;
 	}
+	
+	public boolean hasSnapshot() throws Exception {
+		VirtualMachineSnapshotInfo info = getSnapshotInfo();
+		if(info != null) {
+			return info.getCurrentSnapshot() != null;
+		}
+		return false;
+	}
 
 	public boolean createFullClone(String cloneName, ManagedObjectReference morFolder, ManagedObjectReference
morResourcePool,
 		ManagedObjectReference morDs) throws Exception {
@@ -1629,6 +1637,7 @@ public class VirtualMachineMO extends BaseMO {
 
 	public void tearDownDevices(Class<?>[] deviceClasses) throws Exception {
 		VirtualDevice[] devices = getMatchedDevices(deviceClasses);
+
 		if(devices.length > 0) {
     		VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
     	    VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[devices.length];
@@ -1637,9 +1646,9 @@ public class VirtualMachineMO extends BaseMO {
     	    	deviceConfigSpecArray[i] = new VirtualDeviceConfigSpec();
     	    	deviceConfigSpecArray[i].setDevice(devices[i]);
     	    	deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.REMOVE);
+    	    	vmConfigSpec.getDeviceChange().add(deviceConfigSpecArray[i]);
     	    }
 
-    	    vmConfigSpec.getDeviceChange().addAll(Arrays.asList(deviceConfigSpecArray));
     		if(!configureVm(vmConfigSpec)) {
                 throw new Exception("Failed to detach devices");
             }
@@ -2021,6 +2030,10 @@ public class VirtualMachineMO extends BaseMO {
 	    return detachedDiskFiles; 
 	}
 	
+	public List<VirtualDevice> getAllDeviceList() throws Exception {
+		return (List<VirtualDevice>)_context.getVimClient().getDynamicProperty(_mor, "config.hardware.device");
+	}
+	
 	public VirtualDisk[] getAllDiskDevice() throws Exception {
 		List<VirtualDisk> deviceList = new ArrayList<VirtualDisk>();
 		List<VirtualDevice> devices = (List<VirtualDevice>)_context.getVimClient().getDynamicProperty(_mor,
"config.hardware.device");
@@ -2034,6 +2047,19 @@ public class VirtualMachineMO extends BaseMO {
 
 		return deviceList.toArray(new VirtualDisk[0]);
 	}
+	
+	public VirtualDisk getDiskDeviceByBusName(List<VirtualDevice> allDevices, String busName)
throws Exception {
+		for(VirtualDevice device : allDevices ) {
+			if(device instanceof VirtualDisk) {
+				VirtualDisk disk = (VirtualDisk)device;
+				String diskBusName = getDeviceBusName(allDevices, (VirtualDevice)disk);
+				if(busName.equalsIgnoreCase(diskBusName))
+					return disk;
+			}
+		}
+		
+		return null;
+	}
 
 	public VirtualDisk[] getAllIndependentDiskDevice() throws Exception {
 		List<VirtualDisk> independentDisks = new ArrayList<VirtualDisk>();


Mime
View raw message