@@ -1043,7 +1043,26 @@ public boolean validateVolumeSizeInBytes(long size) {
10431043 return true ;
10441044 }
10451045
1046- private VolumeVO allocateVolumeOnStorage (Long volumeId , Long storageId ) throws ExecutionException , InterruptedException {
1046+ private VolumeVO createVolumeOnStoragePool (Long volumeId , Long storageId ) throws ExecutionException , InterruptedException {
1047+ VolumeVO volume = _volsDao .findById (volumeId );
1048+ StoragePool destPool = (StoragePool ) dataStoreMgr .getDataStore (storageId , DataStoreRole .Primary );
1049+ if (destPool == null ) {
1050+ throw new InvalidParameterValueException ("Failed to find the destination storage pool: " + storageId );
1051+ } else if (destPool .isInMaintenance ()) {
1052+ throw new InvalidParameterValueException (String .format ("Cannot create volume %s on storage pool %s as the storage pool is in maintenance mode." ,
1053+ volume .getUuid (), destPool .getName ()));
1054+ }
1055+
1056+ if (destPool .getDataCenterId () != volume .getDataCenterId ()) {
1057+ throw new InvalidParameterValueException (String .format ("Cannot create volume %s in zone %s on storage pool %s in zone %s." ,
1058+ volume .getUuid (), volume .getDataCenterId (), destPool .getUuid (), destPool .getDataCenterId ()));
1059+ }
1060+
1061+ DiskOfferingVO diskOffering = _diskOfferingDao .findById (volume .getDiskOfferingId ());
1062+ if (!doesStoragePoolSupportDiskOffering (destPool , diskOffering )) {
1063+ throw new InvalidParameterValueException (String .format ("Disk offering: %s is not compatible with the storage pool" , diskOffering .getUuid ()));
1064+ }
1065+
10471066 DataStore destStore = dataStoreMgr .getDataStore (storageId , DataStoreRole .Primary );
10481067 VolumeInfo destVolume = volFactory .getVolume (volumeId , destStore );
10491068 AsyncCallFuture <VolumeApiResult > createVolumeFuture = volService .createVolumeAsync (destVolume , destStore );
@@ -1086,7 +1105,7 @@ public VolumeVO createVolume(CreateVolumeCmd cmd) {
10861105 }
10871106 }
10881107 } else if (cmd .getStorageId () != null ) {
1089- volume = allocateVolumeOnStorage (cmd .getEntityId (), cmd .getStorageId ());
1108+ volume = createVolumeOnStoragePool (cmd .getEntityId (), cmd .getStorageId ());
10901109 }
10911110 return volume ;
10921111 } catch (Exception e ) {
0 commit comments