Search in sources :

Example 36 with Volume

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

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

the class CreateTemplateCmd method getEntityOwnerId.

@Override
public long getEntityOwnerId() {
    Long volumeId = getVolumeId();
    Long snapshotId = getSnapshotId();
    Long accountId = null;
    if (volumeId != null) {
        Volume volume = _entityMgr.findById(Volume.class, volumeId);
        if (volume != null) {
            accountId = volume.getAccountId();
        } else {
            throw new InvalidParameterValueException("Unable to find volume by id=" + volumeId);
        }
    } else {
        Snapshot snapshot = _entityMgr.findById(Snapshot.class, snapshotId);
        if (snapshot != null) {
            accountId = snapshot.getAccountId();
        } else {
            throw new InvalidParameterValueException("Unable to find snapshot by id=" + snapshotId);
        }
    }
    Account account = _accountService.getAccount(accountId);
    //Can create templates for enabled projects/accounts only
    if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
        Project project = _projectService.findByProjectAccountId(accountId);
        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");
        }
    } else if (account.getState() == Account.State.disabled) {
        throw new PermissionDeniedException("The owner of template is disabled: " + account);
    }
    return accountId;
}
Also used : Snapshot(com.cloud.storage.Snapshot) 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 38 with Volume

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

Example 39 with Volume

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

the class UploadVolumeCmd method execute.

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
    Volume volume = _storageService.uploadVolume(this);
    if (volume != null) {
        VolumeResponse response = _responseGenerator.createVolumeResponse(volume);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to upload volume");
    }
}
Also used : VolumeResponse(com.cloud.api.response.VolumeResponse) ServerApiException(com.cloud.api.ServerApiException) Volume(com.cloud.storage.Volume)

Example 40 with Volume

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

the class UserVmManagerImpl method updateVirtualMachine.

@Override
@ActionEvent(eventType = EventTypes.EVENT_VM_UPDATE, eventDescription = "updating Vm")
public UserVm updateVirtualMachine(UpdateVMCmd cmd) throws ResourceUnavailableException, InsufficientCapacityException {
    String displayName = cmd.getDisplayName();
    String group = cmd.getGroup();
    Boolean ha = cmd.getHaEnable();
    Boolean isDisplayVm = cmd.getDisplayVm();
    Long id = cmd.getId();
    Long osTypeId = cmd.getOsTypeId();
    String userData = cmd.getUserData();
    Boolean isDynamicallyScalable = cmd.isDynamicallyScalable();
    String hostName = cmd.getHostName();
    Map<String, String> details = cmd.getDetails();
    Account caller = CallContext.current().getCallingAccount();
    List<Long> securityGroupIdList = getSecurityGroupIdList(cmd);
    boolean cleanupDetails = cmd.isCleanupDetails();
    // Input validation and permission checks
    UserVmVO vmInstance = _vmDao.findById(id);
    if (vmInstance == null) {
        throw new InvalidParameterValueException("unable to find virtual machine with id " + id);
    }
    _accountMgr.checkAccess(caller, null, true, vmInstance);
    //If the flag is specified and is changed
    if (isDisplayVm != null && isDisplayVm != vmInstance.isDisplayVm()) {
        //update vm
        vmInstance.setDisplayVm(isDisplayVm);
        // Resource limit changes
        ServiceOffering offering = _serviceOfferingDao.findByIdIncludingRemoved(vmInstance.getServiceOfferingId());
        _resourceLimitMgr.changeResourceCount(vmInstance.getAccountId(), ResourceType.user_vm, isDisplayVm);
        _resourceLimitMgr.changeResourceCount(vmInstance.getAccountId(), ResourceType.cpu, isDisplayVm, new Long(offering.getCpu()));
        _resourceLimitMgr.changeResourceCount(vmInstance.getAccountId(), ResourceType.memory, isDisplayVm, new Long(offering.getRamSize()));
        // Usage
        saveUsageEvent(vmInstance);
        // take care of the root volume as well.
        List<VolumeVO> rootVols = _volsDao.findByInstanceAndType(id, Volume.Type.ROOT);
        if (!rootVols.isEmpty()) {
            _volumeService.updateDisplay(rootVols.get(0), isDisplayVm);
        }
        // take care of the data volumes as well.
        List<VolumeVO> dataVols = _volsDao.findByInstanceAndType(id, Volume.Type.DATADISK);
        for (Volume dataVol : dataVols) {
            _volumeService.updateDisplay(dataVol, isDisplayVm);
        }
    }
    if (cleanupDetails) {
        _vmDetailsDao.removeDetails(id);
    } else if (details != null && !details.isEmpty()) {
        vmInstance.setDetails(details);
        _vmDao.saveDetails(vmInstance);
    }
    return updateVirtualMachine(id, displayName, group, ha, isDisplayVm, osTypeId, userData, isDynamicallyScalable, cmd.getHttpMethod(), cmd.getCustomId(), hostName, cmd.getInstanceName(), securityGroupIdList);
}
Also used : Account(com.cloud.user.Account) ServiceOffering(com.cloud.offering.ServiceOffering) VolumeVO(com.cloud.storage.VolumeVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Volume(com.cloud.storage.Volume) ActionEvent(com.cloud.event.ActionEvent)

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