mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
storage: validate disk size range of custom disk offering when resize volume (#7073)
This commit is contained in:
parent
4bb43f7879
commit
3dc0e499dc
@ -154,6 +154,8 @@ public interface VolumeApiService {
|
|||||||
|
|
||||||
Volume recoverVolume(long volumeId);
|
Volume recoverVolume(long volumeId);
|
||||||
|
|
||||||
|
void validateCustomDiskOfferingSizeRange(Long sizeInGB);
|
||||||
|
|
||||||
boolean validateVolumeSizeInBytes(long size);
|
boolean validateVolumeSizeInBytes(long size);
|
||||||
|
|
||||||
Volume changeDiskOfferingForVolume(ChangeOfferingForVolumeCmd cmd) throws ResourceAllocationException;
|
Volume changeDiskOfferingForVolume(ChangeOfferingForVolumeCmd cmd) throws ResourceAllocationException;
|
||||||
|
|||||||
@ -715,12 +715,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
|
|||||||
if (size == null) {
|
if (size == null) {
|
||||||
throw new InvalidParameterValueException("This disk offering requires a custom size specified");
|
throw new InvalidParameterValueException("This disk offering requires a custom size specified");
|
||||||
}
|
}
|
||||||
Long customDiskOfferingMaxSize = VolumeOrchestrationService.CustomDiskOfferingMaxSize.value();
|
validateCustomDiskOfferingSizeRange(sizeInGB);
|
||||||
Long customDiskOfferingMinSize = VolumeOrchestrationService.CustomDiskOfferingMinSize.value();
|
|
||||||
|
|
||||||
if ((sizeInGB < customDiskOfferingMinSize) || (sizeInGB > customDiskOfferingMaxSize)) {
|
|
||||||
throw new InvalidParameterValueException("Volume size: " + sizeInGB + "GB is out of allowed range. Max: " + customDiskOfferingMaxSize + " Min:" + customDiskOfferingMinSize);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!diskOffering.isCustomized() && size != null) {
|
if (!diskOffering.isCustomized() && size != null) {
|
||||||
@ -872,6 +867,16 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
|
|||||||
_uuidMgr.generateUuid(Volume.class, cmd.getCustomId()), details);
|
_uuidMgr.generateUuid(Volume.class, cmd.getCustomId()), details);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void validateCustomDiskOfferingSizeRange(Long sizeInGB) {
|
||||||
|
Long customDiskOfferingMaxSize = VolumeOrchestrationService.CustomDiskOfferingMaxSize.value();
|
||||||
|
Long customDiskOfferingMinSize = VolumeOrchestrationService.CustomDiskOfferingMinSize.value();
|
||||||
|
|
||||||
|
if ((sizeInGB < customDiskOfferingMinSize) || (sizeInGB > customDiskOfferingMaxSize)) {
|
||||||
|
throw new InvalidParameterValueException(String.format("Volume size: %s GB is out of allowed range. Min: %s. Max: %s", sizeInGB, customDiskOfferingMinSize, customDiskOfferingMaxSize));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private VolumeVO commitVolume(final CreateVolumeCmd cmd, final Account caller, final Account owner, final Boolean displayVolume, final Long zoneId, final Long diskOfferingId,
|
private VolumeVO commitVolume(final CreateVolumeCmd cmd, final Account caller, final Account owner, final Boolean displayVolume, final Long zoneId, final Long diskOfferingId,
|
||||||
final Storage.ProvisioningType provisioningType, final Long size, final Long minIops, final Long maxIops, final VolumeVO parentVolume, final String userSpecifiedName, final String uuid, final Map<String, String> details) {
|
final Storage.ProvisioningType provisioningType, final Long size, final Long minIops, final Long maxIops, final VolumeVO parentVolume, final String userSpecifiedName, final String uuid, final Map<String, String> details) {
|
||||||
return Transaction.execute(new TransactionCallback<VolumeVO>() {
|
return Transaction.execute(new TransactionCallback<VolumeVO>() {
|
||||||
@ -1060,6 +1065,10 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
|
|||||||
throw new InvalidParameterValueException(String.format("Resize of volume %s is not allowed, since disk size is strictly fixed as per the disk offering", volume.getUuid()));
|
throw new InvalidParameterValueException(String.format("Resize of volume %s is not allowed, since disk size is strictly fixed as per the disk offering", volume.getUuid()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (diskOffering.isCustomized()) {
|
||||||
|
validateCustomDiskOfferingSizeRange(newSize);
|
||||||
|
}
|
||||||
|
|
||||||
if (isNotPossibleToResize(volume, diskOffering)) {
|
if (isNotPossibleToResize(volume, diskOffering)) {
|
||||||
throw new InvalidParameterValueException(
|
throw new InvalidParameterValueException(
|
||||||
"Failed to resize Root volume. The service offering of this Volume has been configured with a root disk size; "
|
"Failed to resize Root volume. The service offering of this Volume has been configured with a root disk size; "
|
||||||
@ -1138,6 +1147,8 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
|
|||||||
throw new InvalidParameterValueException("The new disk offering requires that a size be specified.");
|
throw new InvalidParameterValueException("The new disk offering requires that a size be specified.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
validateCustomDiskOfferingSizeRange(newSize);
|
||||||
|
|
||||||
// convert from GiB to bytes
|
// convert from GiB to bytes
|
||||||
newSize = newSize << 30;
|
newSize = newSize << 30;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -4187,12 +4187,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||||||
if (diskSize == null) {
|
if (diskSize == null) {
|
||||||
throw new InvalidParameterValueException("This disk offering requires a custom size specified");
|
throw new InvalidParameterValueException("This disk offering requires a custom size specified");
|
||||||
}
|
}
|
||||||
Long customDiskOfferingMaxSize = VolumeOrchestrationService.CustomDiskOfferingMaxSize.value();
|
_volumeService.validateCustomDiskOfferingSizeRange(diskSize);
|
||||||
Long customDiskOfferingMinSize = VolumeOrchestrationService.CustomDiskOfferingMinSize.value();
|
|
||||||
if ((diskSize < customDiskOfferingMinSize) || (diskSize > customDiskOfferingMaxSize)) {
|
|
||||||
throw new InvalidParameterValueException("VM Creation failed. Volume size: " + diskSize + "GB is out of allowed range. Max: " + customDiskOfferingMaxSize
|
|
||||||
+ " Min:" + customDiskOfferingMinSize);
|
|
||||||
}
|
|
||||||
size = diskSize * GiB_TO_BYTES;
|
size = diskSize * GiB_TO_BYTES;
|
||||||
} else {
|
} else {
|
||||||
size = diskOffering.getDiskSize();
|
size = diskOffering.getDiskSize();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user