bug CS-14945: Throw an error message if the user is trying to attach the volume in local only storage zone. Reviewed-by: Kishan
Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/feefa93c Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/feefa93c Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/feefa93c Branch: refs/heads/3.0.x Commit: feefa93cad150e85d64a363b74a6106bc1897bf0 Parents: 484077f Author: Nitin Mehta <[email protected]> Authored: Fri May 25 18:40:16 2012 +0530 Committer: Nitin Mehta <[email protected]> Committed: Fri May 25 18:40:16 2012 +0530 ---------------------------------------------------------------------- server/src/com/cloud/vm/UserVmManagerImpl.java | 40 ++++-------------- 1 files changed, 9 insertions(+), 31 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/feefa93c/server/src/com/cloud/vm/UserVmManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index fd5166e..63b85a5 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -580,35 +580,6 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager } HypervisorType rootDiskHyperType = vm.getHypervisorType(); - - /*if (volume.getState().equals(Volume.State.Allocated) || volume.getState().equals(Volume.State.UploadOp)) { - // Need to create the volume - VMTemplateVO rootDiskTmplt = _templateDao.findById(vm.getTemplateId()); - DataCenterVO dcVO = _dcDao.findById(vm.getDataCenterIdToDeployIn()); - HostPodVO pod = _podDao.findById(vm.getPodIdToDeployIn()); - StoragePoolVO rootDiskPool = _storagePoolDao.findById(rootVolumeOfVm.getPoolId()); - ServiceOfferingVO svo = _serviceOfferingDao.findById(vm.getServiceOfferingId()); - DiskOfferingVO diskVO = _diskOfferingDao.findById(volume.getDiskOfferingId()); - if (!volumeOnSec){ - volume = _storageMgr.createVolume(volume, vm, rootDiskTmplt, dcVO, pod, rootDiskPool.getClusterId(), svo, diskVO, new ArrayList<StoragePoolVO>(), volume.getSize(), rootDiskHyperType); - }else { - try { - // Format of data disk should be the same as root disk - if( ! volHostVO.getFormat().getFileExtension().equals(_storageMgr.getSupportedImageFormatForCluster(rootDiskPool.getClusterId())) ){ - throw new InvalidParameterValueException("Failed to attach volume to VM since volumes format " +volHostVO.getFormat().getFileExtension()+ - " is not compatible with the vm hypervisor type" ); - } - volume = _storageMgr.copyVolumeFromSecToPrimary(volume, vm, rootDiskTmplt, dcVO, pod, rootDiskPool.getClusterId(), svo, diskVO, new ArrayList<StoragePoolVO>(), volume.getSize(), rootDiskHyperType); - } catch (NoTransitionException e) { - e.printStackTrace(); - } - } - - if (volume == null) { - throw new CloudRuntimeException("Failed to create volume when attaching it to VM: " + vm.getHostName()); - } - }*/ - HypervisorType dataDiskHyperType = _volsDao.getHypervisorType(volume.getId()); if (dataDiskHyperType != HypervisorType.None && rootDiskHyperType != dataDiskHyperType) { throw new InvalidParameterValueException("Can't attach a volume created by: " + dataDiskHyperType + " to a " + rootDiskHyperType + " vm"); @@ -657,7 +628,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager ServiceOfferingVO svo = _serviceOfferingDao.findById(vm.getServiceOfferingId()); DiskOfferingVO diskVO = _diskOfferingDao.findById(volume.getDiskOfferingId()); Long clusterId = (rootDiskPool == null ? null : rootDiskPool.getClusterId()); - + if (!isVolumeOnSec){ volume = _storageMgr.createVolume(volume, vm, rootDiskTmplt, dcVO, pod, clusterId, svo, diskVO, new ArrayList<StoragePoolVO>(), volume.getSize(), rootDiskHyperType); }else { @@ -666,7 +637,14 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager if( ! volHostVO.getFormat().getFileExtension().equals(_storageMgr.getSupportedImageFormatForCluster(rootDiskPool.getClusterId())) ){ throw new InvalidParameterValueException("Failed to attach volume to VM since volumes format " +volHostVO.getFormat().getFileExtension() + " is not compatible with the vm hypervisor type" ); } - + + // Check that there is some shared storage. + StoragePoolVO vmRootVolumePool = _storagePoolDao.findById(rootVolumeOfVm.getPoolId()); + List<StoragePoolVO> sharedVMPools = _storagePoolDao.findPoolsByTags(vmRootVolumePool.getDataCenterId(), vmRootVolumePool.getPodId(), vmRootVolumePool.getClusterId(), null, true); + if (sharedVMPools.size() == 0) { + throw new CloudRuntimeException("Cannot attach volume since there are no shared storage pools in the VM's cluster to copy the uploaded volume to."); + } + volume = _storageMgr.copyVolumeFromSecToPrimary(volume, vm, rootDiskTmplt, dcVO, pod, rootDiskPool.getClusterId(), svo, diskVO, new ArrayList<StoragePoolVO>(), volume.getSize(), rootDiskHyperType); } catch (NoTransitionException e) { throw new CloudRuntimeException("Unable to transition the volume ",e);
