Search in sources :

Example 61 with Volume

use of com.cloud.storage.Volume in project cloudstack by apache.

the class ResizeVolumeCmdByAdmin method execute.

@Override
public void execute() throws ResourceAllocationException {
    Volume volume = null;
    try {
        CallContext.current().setEventDetails("Volume Id: " + getEntityId() + " to size " + getSize() + "G");
        volume = _volumeService.resizeVolume(this);
    } catch (InvalidParameterValueException ex) {
        s_logger.info(ex.getMessage());
        throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, ex.getMessage());
    }
    if (volume != null) {
        VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Full, volume);
        //FIXME - have to be moved to ApiResponseHelper
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to resize volume");
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) VolumeResponse(org.apache.cloudstack.api.response.VolumeResponse) Volume(com.cloud.storage.Volume) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException)

Example 62 with Volume

use of com.cloud.storage.Volume in project cloudstack by apache.

the class ResizeVolumeCmd method getEntityOwnerId.

@Override
public long getEntityOwnerId() {
    Volume volume = _entityMgr.findById(Volume.class, getEntityId());
    if (volume == null) {
        throw new InvalidParameterValueException("Unable to find volume by id=" + id);
    }
    Account account = _accountService.getAccount(volume.getAccountId());
    //Can resize volumes for enabled projects/accounts only
    if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
        Project project = _projectService.findByProjectAccountId(volume.getAccountId());
        if (project.getState() != Project.State.Active) {
            throw new PermissionDeniedException("Can't add resources to  project id=" + project.getId() + " in state=" + project.getState() + " as it's no longer active");
        }
    } else if (account.getState() == Account.State.disabled) {
        throw new PermissionDeniedException("The owner of volume " + id + "  is disabled: " + account);
    }
    return volume.getAccountId();
}
Also used : Account(com.cloud.user.Account) Project(com.cloud.projects.Project) Volume(com.cloud.storage.Volume) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException)

Example 63 with Volume

use of com.cloud.storage.Volume in project cloudstack by apache.

the class UpdateVolumeCmd method execute.

@Override
public void execute() {
    CallContext.current().setEventDetails("Volume Id: " + getId());
    Volume result = _volumeService.updateVolume(getId(), getPath(), getState(), getStorageId(), getDisplayVolume(), getCustomId(), getEntityOwnerId(), getChainInfo());
    if (result != null) {
        VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Restricted, result);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update volume");
    }
}
Also used : VolumeResponse(org.apache.cloudstack.api.response.VolumeResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) Volume(com.cloud.storage.Volume)

Example 64 with Volume

use of com.cloud.storage.Volume in project cloudstack by apache.

the class AttachVolumeCmd method execute.

@Override
public void execute() {
    CallContext.current().setEventDetails("Volume Id: " + getId() + " VmId: " + getVirtualMachineId());
    Volume result = _volumeService.attachVolumeToVM(this);
    if (result != null) {
        VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Restricted, result);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to attach volume");
    }
}
Also used : VolumeResponse(org.apache.cloudstack.api.response.VolumeResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) Volume(com.cloud.storage.Volume)

Example 65 with Volume

use of com.cloud.storage.Volume in project cloudstack by apache.

the class CreateVolumeCmd method create.

@Override
public void create() throws ResourceAllocationException {
    Volume volume = _volumeService.allocVolume(this);
    if (volume != null) {
        setEntityId(volume.getId());
        setEntityUuid(volume.getUuid());
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create volume");
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) Volume(com.cloud.storage.Volume)

Aggregations

Volume (com.cloud.storage.Volume)70 StoragePool (com.cloud.storage.StoragePool)21 ServerApiException (org.apache.cloudstack.api.ServerApiException)16 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)15 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)15 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)14 VolumeResponse (org.apache.cloudstack.api.response.VolumeResponse)14 ArrayList (java.util.ArrayList)12 Account (com.cloud.user.Account)11 VolumeVO (com.cloud.storage.VolumeVO)10 DiskProfile (com.cloud.vm.DiskProfile)10 StoragePoolAllocator (org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator)10 Test (org.junit.Test)10 DataCenterDeployment (com.cloud.deploy.DataCenterDeployment)9 HashMap (java.util.HashMap)9 DeploymentPlan (com.cloud.deploy.DeploymentPlan)8 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)8 VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)8 Project (com.cloud.projects.Project)7 VmWorkAttachVolume (com.cloud.vm.VmWorkAttachVolume)7