bug CS-14739: Check for the volume and vm hypervisor compatibility before attaching the volume to vm in case the volume is on secondary storage.

This commit is contained in:
Nitin Mehta 2012-05-04 16:30:08 +05:30
parent 9fbc81e405
commit 0d2422720b
4 changed files with 25 additions and 1 deletions

View File

@ -33,7 +33,7 @@ public interface Volume extends ControlledEntity, BasedOn, StateObject<Volume.St
Expunging("The volume is being expunging"),
Destroy("The volume is destroyed, and can't be recovered."),
Uploading ("The volume upload is in progress"),
Uploaded ("The volume is uploaded"),
Uploaded ("The volume is uploaded and present on secondary storage"),
UploadError ("The volume couldnt be uploaded");
String _description;

View File

@ -226,4 +226,6 @@ public interface StorageManager extends StorageService, Manager {
Long clusterId, ServiceOfferingVO offering,
DiskOfferingVO diskOffering, List<StoragePoolVO> avoids, long size,
HypervisorType hyperType) throws NoTransitionException;
String getSupportedImageFormatForCluster(Long clusterId);
}

View File

@ -3802,4 +3802,21 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
return _volumeDao.search(sc, searchFilter);
}
@Override
public String getSupportedImageFormatForCluster(Long clusterId) {
ClusterVO cluster = ApiDBUtils.findClusterById(clusterId);
if (cluster.getHypervisorType() == HypervisorType.XenServer) {
return "vhd";
} else if (cluster.getHypervisorType() == HypervisorType.KVM) {
return "qcow2";
} else if (cluster.getHypervisorType() == HypervisorType.VMware) {
return "ova";
} else if (cluster.getHypervisorType() == HypervisorType.Ovm) {
return "raw";
} else {
return null;
}
}
}

View File

@ -590,6 +590,11 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
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(_storageMgr.getSupportedImageFormatForCluster(rootDiskPool.getClusterId()) != volHostVO.getFormat().getFileExtension()){
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();