Search in sources :

Example 1 with VolumeResponse

use of com.cloud.api.response.VolumeResponse in project CloudStack-archive by CloudStack-extras.

the class AttachVolumeCmd method execute.

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

Example 2 with VolumeResponse

use of com.cloud.api.response.VolumeResponse in project CloudStack-archive by CloudStack-extras.

the class MigrateVolumeCmd method execute.

@Override
public void execute() {
    Volume result;
    try {
        result = _storageService.migrateVolume(getVolumeId(), getStoragePoolId());
        if (result != null) {
            VolumeResponse response = _responseGenerator.createVolumeResponse(result);
            response.setResponseName(getCommandName());
            this.setResponseObject(response);
        }
    } catch (ConcurrentOperationException e) {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to migrate volume: ");
    }
}
Also used : VolumeResponse(com.cloud.api.response.VolumeResponse) ServerApiException(com.cloud.api.ServerApiException) Volume(com.cloud.storage.Volume) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Example 3 with VolumeResponse

use of com.cloud.api.response.VolumeResponse in project CloudStack-archive by CloudStack-extras.

the class ListVolumesCmd method execute.

@Override
public void execute() {
    List<? extends Volume> volumes = _storageService.searchForVolumes(this);
    ListResponse<VolumeResponse> response = new ListResponse<VolumeResponse>();
    List<VolumeResponse> volResponses = new ArrayList<VolumeResponse>();
    for (Volume volume : volumes) {
        VolumeResponse volResponse = _responseGenerator.createVolumeResponse(volume);
        volResponse.setObjectName("volume");
        volResponses.add(volResponse);
    }
    response.setResponses(volResponses);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : ListResponse(com.cloud.api.response.ListResponse) VolumeResponse(com.cloud.api.response.VolumeResponse) Volume(com.cloud.storage.Volume) ArrayList(java.util.ArrayList)

Example 4 with VolumeResponse

use of com.cloud.api.response.VolumeResponse in project CloudStack-archive by CloudStack-extras.

the class DetachVolumeCmd method execute.

@Override
public void execute() {
    UserContext.current().setEventDetails("Volume Id: " + getId() + " VmId: " + getVirtualMachineId());
    Volume result = _userVmService.detachVolumeFromVM(this);
    if (result != null) {
        VolumeResponse response = _responseGenerator.createVolumeResponse(result);
        response.setResponseName("volume");
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to detach volume");
    }
}
Also used : VolumeResponse(com.cloud.api.response.VolumeResponse) ServerApiException(com.cloud.api.ServerApiException) Volume(com.cloud.storage.Volume)

Example 5 with VolumeResponse

use of com.cloud.api.response.VolumeResponse in project CloudStack-archive by CloudStack-extras.

the class CreateVolumeCmd method execute.

@Override
public void execute() {
    UserContext.current().setEventDetails("Volume Id: " + getEntityId() + ((getSnapshotId() == null) ? "" : " from snapshot: " + getSnapshotId()));
    Volume volume = _storageService.createVolume(this);
    if (volume != null) {
        VolumeResponse response = _responseGenerator.createVolumeResponse(volume);
        //FIXME - have to be moved to ApiResponseHelper
        // if the volume was created from a snapshot, snapshotId will be set so we pass it back in the response
        response.setSnapshotId(getSnapshotId());
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a volume");
    }
}
Also used : VolumeResponse(com.cloud.api.response.VolumeResponse) ServerApiException(com.cloud.api.ServerApiException) Volume(com.cloud.storage.Volume)

Aggregations

VolumeResponse (com.cloud.api.response.VolumeResponse)6 Volume (com.cloud.storage.Volume)6 ServerApiException (com.cloud.api.ServerApiException)5 ListResponse (com.cloud.api.response.ListResponse)1 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)1 ArrayList (java.util.ArrayList)1