Search in sources :

Example 1 with Volume

use of com.cloud.storage.Volume 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 2 with Volume

use of com.cloud.storage.Volume in project CloudStack-archive by CloudStack-extras.

the class DeployDestination method toString.

@Override
public String toString() {
    Long dcId = null;
    Long podId = null;
    Long clusterId = null;
    Long hostId = null;
    if (_dc != null) {
        dcId = _dc.getId();
    }
    if (_pod != null) {
        podId = _pod.getId();
    }
    if (_cluster != null) {
        clusterId = _cluster.getId();
    }
    if (_host != null) {
        hostId = _host.getId();
    }
    StringBuilder destination = new StringBuilder("Dest[Zone(Id)-Pod(Id)-Cluster(Id)-Host(Id)-Storage(Volume(Id|Type-->Pool(Id))] : Dest[");
    destination.append("Zone(").append(dcId).append(")").append("-");
    destination.append("Pod(").append(podId).append(")").append("-");
    destination.append("Cluster(").append(clusterId).append(")").append("-");
    destination.append("Host(").append(hostId).append(")").append("-");
    destination.append("Storage(");
    if (_storage != null) {
        String storageStr = "";
        for (Volume vol : _storage.keySet()) {
            if (!storageStr.equals("")) {
                storageStr = storageStr + ", ";
            }
            storageStr = storageStr + "Volume(" + vol.getId() + "|" + vol.getVolumeType().name() + "-->Pool(" + _storage.get(vol).getId() + ")";
        }
        destination.append(storageStr);
    }
    return destination.append(")]").toString();
}
Also used : Volume(com.cloud.storage.Volume)

Example 3 with Volume

use of com.cloud.storage.Volume 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 Volume

use of com.cloud.storage.Volume in project CloudStack-archive by CloudStack-extras.

the class CreateSnapshotCmd method getEntityOwnerId.

@Override
public long getEntityOwnerId() {
    Volume volume = _entityMgr.findById(Volume.class, getVolumeId());
    if (volume == null) {
        throw new InvalidParameterValueException("Unable to find volume by id=" + volumeId);
    }
    Account account = _accountService.getAccount(volume.getAccountId());
    //Can create templates 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 the 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 template 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 5 with Volume

use of com.cloud.storage.Volume in project CloudStack-archive by CloudStack-extras.

the class CreateSnapshotPolicyCmd method getEntityOwnerId.

@Override
public long getEntityOwnerId() {
    Volume volume = _entityMgr.findById(Volume.class, getVolumeId());
    if (volume == null) {
        throw new InvalidParameterValueException("Unable to find volume by id=" + volumeId);
    }
    Account account = _accountService.getAccount(volume.getAccountId());
    //Can create templates for enabled projects/accounts only
    if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
        Project project = _projectService.findByProjectAccountId(volume.getAccountId());
        if (project.getState() != Project.State.Active) {
            PermissionDeniedException ex = new PermissionDeniedException("Can't add resources to the specified project id in state=" + project.getState() + " as it's no longer active");
            ex.addProxyObject(project, project.getId(), "projectId");
            throw ex;
        }
    } else if (account.getState() == Account.State.disabled) {
        throw new PermissionDeniedException("The owner of template 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)

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