diff --git a/api/src/com/cloud/api/commands/CreateVolumeCmd.java b/api/src/com/cloud/api/commands/CreateVolumeCmd.java index a8a7ad035b7..913fc992eac 100644 --- a/api/src/com/cloud/api/commands/CreateVolumeCmd.java +++ b/api/src/com/cloud/api/commands/CreateVolumeCmd.java @@ -58,7 +58,7 @@ public class CreateVolumeCmd extends BaseAsyncCreateCmd { @Parameter(name=ApiConstants.SIZE, type=CommandType.LONG, description="Arbitrary volume size. Mutually exclusive with diskOfferingId") private Long size; - @Parameter(name=ApiConstants.SNAPSHOT_ID, type=CommandType.LONG, description="the snapshot ID for the disk volume. Either diskOfferingId or snapshotId must be passed in.") + @Parameter(name=ApiConstants.SNAPSHOT_ID, type=CommandType.LONG, description="the snapshot ID for the disk volume. If snapshot id is passed in, a private disk offering id must be passed in as well (no disk size, only tags).") private Long snapshotId; @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, description="the ID of the availability zone") @@ -145,7 +145,7 @@ public class CreateVolumeCmd extends BaseAsyncCreateCmd { @Override public void create() throws ResourceAllocationException{ - + Volume volume = _storageService.allocVolume(this); if (volume != null) { this.setEntityId(volume.getId()); diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index a13944a2768..62c4a40c12d 100755 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -518,7 +518,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag // Create an event Long templateId = originalVolume.getTemplateId(); ; - Long diskOfferingId = originalVolume.getDiskOfferingId(); + Long diskOfferingId = volume.getDiskOfferingId(); if (createdVolume.getPath() != null) { Long offeringId = null; @@ -1442,16 +1442,29 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag size = (size * 1024 * 1024 * 1024);// custom size entered is in GB, to be converted to bytes } } else { + DiskOfferingVO privOffering = null; Long snapshotId = cmd.getSnapshotId(); Snapshot snapshotCheck = _snapshotDao.findById(snapshotId); + diskOfferingId = cmd.getDiskOfferingId(); if (snapshotCheck == null) { throw new InvalidParameterValueException("unable to find a snapshot with id " + snapshotId); } + if(diskOfferingId == null) { + throw new InvalidParameterValueException("Please specify a valid private disk offering"); + } else { + privOffering = _diskOfferingDao.findById(diskOfferingId); + if(privOffering == null) { + throw new InvalidParameterValueException("Please specify a valid private disk offering"); + } else { + if(!privOffering.isCustomized()) + throw new InvalidParameterValueException("Please specify a valid private disk offering"); + } + } + VolumeVO vol = _volsDao.findByIdIncludingRemoved(snapshotCheck.getVolumeId()); zoneId = vol.getDataCenterId(); - diskOfferingId = vol.getDiskOfferingId(); - size = vol.getSize(); + size = vol.getSize(); //we maintain size from org vol ; disk offering is used for tags purposes if (account != null) { if (isAdmin(account.getType())) {