Only allow to attach a volume to a vm, when they are created by the same hypervisor.

This commit is contained in:
edison 2010-10-29 15:46:13 -07:00
parent 0e88439f44
commit f526a92b08
1 changed files with 8 additions and 2 deletions

View File

@ -462,6 +462,8 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
rootVolumeOfVm = rootVolumesOfVm.get(0);
}
HypervisorType rootDiskHyperType = _volsDao.getHypervisorType(rootVolumeOfVm.getId());
if (volume.getState().equals(Volume.State.Allocated)) {
/*Need to create the volume*/
VMTemplateVO rootDiskTmplt = _templateDao.findById(vm.getTemplateId());
@ -470,8 +472,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
StoragePoolVO rootDiskPool = _storagePoolDao.findById(rootVolumeOfVm.getPoolId());
ServiceOfferingVO svo = _serviceOfferingDao.findById(vm.getServiceOfferingId());
DiskOfferingVO diskVO = _diskOfferingDao.findById(volume.getDiskOfferingId());
HypervisorType rootDiskHyperType = _volsDao.getHypervisorType(rootVolumeOfVm.getId());
volume = _storageMgr.createVolume(volume, vm, rootDiskTmplt, dcVO, pod, rootDiskPool.getClusterId(), svo, diskVO, new ArrayList<StoragePoolVO>(), volume.getSize(), rootDiskHyperType);
if (volume == null) {
@ -479,6 +480,11 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
}
}
HypervisorType dataDiskHyperType = _volsDao.getHypervisorType(volume.getId());
if (rootDiskHyperType != dataDiskHyperType) {
throw new InvalidParameterValueException("Can't attach a volume created by: " + dataDiskHyperType + " to a " + rootDiskHyperType + " vm");
}
List<VolumeVO> vols = _volsDao.findByInstance(vmId);
if( deviceId != null ) {
if( deviceId.longValue() > 15 || deviceId.longValue() == 0 || deviceId.longValue() == 3) {