Search in sources :

Example 1 with ChangeOfferingForVolumeCmd

use of org.apache.cloudstack.api.command.user.volume.ChangeOfferingForVolumeCmd in project cloudstack by apache.

the class UserVmManagerImpl method changeDiskOfferingForRootVolume.

private void changeDiskOfferingForRootVolume(Long vmId, DiskOfferingVO newDiskOffering, Map<String, String> customParameters) throws ResourceAllocationException {
    List<VolumeVO> vols = _volsDao.findReadyAndAllocatedRootVolumesByInstance(vmId);
    for (final VolumeVO rootVolumeOfVm : vols) {
        DiskOfferingVO currentRootDiskOffering = _diskOfferingDao.findById(rootVolumeOfVm.getDiskOfferingId());
        HypervisorType hypervisorType = _volsDao.getHypervisorType(rootVolumeOfVm.getId());
        if (HypervisorType.Simulator != hypervisorType) {
            Long minIopsInNewDiskOffering = null;
            Long maxIopsInNewDiskOffering = null;
            boolean autoMigrate = false;
            boolean shrinkOk = false;
            if (customParameters.containsKey(ApiConstants.MIN_IOPS)) {
                minIopsInNewDiskOffering = Long.parseLong(customParameters.get(ApiConstants.MIN_IOPS));
            }
            if (customParameters.containsKey(ApiConstants.MAX_IOPS)) {
                minIopsInNewDiskOffering = Long.parseLong(customParameters.get(ApiConstants.MAX_IOPS));
            }
            if (customParameters.containsKey(ApiConstants.AUTO_MIGRATE)) {
                autoMigrate = Boolean.parseBoolean(customParameters.get(ApiConstants.AUTO_MIGRATE));
            }
            if (customParameters.containsKey(ApiConstants.SHRINK_OK)) {
                shrinkOk = Boolean.parseBoolean(customParameters.get(ApiConstants.SHRINK_OK));
            }
            ChangeOfferingForVolumeCmd changeOfferingForVolumeCmd = new ChangeOfferingForVolumeCmd(rootVolumeOfVm.getId(), newDiskOffering.getId(), minIopsInNewDiskOffering, maxIopsInNewDiskOffering, autoMigrate, shrinkOk);
            Volume result = _volumeService.changeDiskOfferingForVolume(changeOfferingForVolumeCmd);
            if (result == null) {
                throw new CloudRuntimeException("Failed to change disk offering of the root volume");
            }
        } else if (newDiskOffering.getDiskSize() > 0 && currentRootDiskOffering.getDiskSize() != newDiskOffering.getDiskSize()) {
            throw new InvalidParameterValueException("Hypervisor " + hypervisorType + " does not support volume resize");
        }
    }
}
Also used : HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) VolumeVO(com.cloud.storage.VolumeVO) Volume(com.cloud.storage.Volume) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ChangeOfferingForVolumeCmd(org.apache.cloudstack.api.command.user.volume.ChangeOfferingForVolumeCmd)

Aggregations

InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)1 DiskOfferingVO (com.cloud.storage.DiskOfferingVO)1 Volume (com.cloud.storage.Volume)1 VolumeVO (com.cloud.storage.VolumeVO)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 ChangeOfferingForVolumeCmd (org.apache.cloudstack.api.command.user.volume.ChangeOfferingForVolumeCmd)1