Search in sources :

Example 61 with Project

use of com.cloud.projects.Project in project cosmic by MissionCriticalCloud.

the class ApiResponseHelper method createVMSnapshotResponse.

@Override
public VMSnapshotResponse createVMSnapshotResponse(final VMSnapshot vmSnapshot) {
    final VMSnapshotResponse vmSnapshotResponse = new VMSnapshotResponse();
    vmSnapshotResponse.setId(vmSnapshot.getUuid());
    vmSnapshotResponse.setName(vmSnapshot.getName());
    vmSnapshotResponse.setState(vmSnapshot.getState());
    vmSnapshotResponse.setCreated(vmSnapshot.getCreated());
    vmSnapshotResponse.setDescription(vmSnapshot.getDescription());
    vmSnapshotResponse.setDisplayName(vmSnapshot.getDisplayName());
    final UserVm vm = ApiDBUtils.findUserVmById(vmSnapshot.getVmId());
    if (vm != null) {
        vmSnapshotResponse.setVirtualMachineid(vm.getUuid());
    }
    if (vmSnapshot.getParent() != null) {
        final VMSnapshot vmSnapshotParent = ApiDBUtils.getVMSnapshotById(vmSnapshot.getParent());
        if (vmSnapshotParent != null) {
            vmSnapshotResponse.setParent(vmSnapshotParent.getUuid());
            vmSnapshotResponse.setParentName(vmSnapshotParent.getDisplayName());
        }
    }
    populateOwner(vmSnapshotResponse, vmSnapshot);
    final Project project = ApiDBUtils.findProjectByProjectAccountId(vmSnapshot.getAccountId());
    if (project != null) {
        vmSnapshotResponse.setProjectId(project.getUuid());
        vmSnapshotResponse.setProjectName(project.getName());
    }
    vmSnapshotResponse.setCurrent(vmSnapshot.getCurrent());
    vmSnapshotResponse.setType(vmSnapshot.getType().toString());
    vmSnapshotResponse.setObjectName("vmsnapshot");
    return vmSnapshotResponse;
}
Also used : Project(com.cloud.projects.Project) UserVm(com.cloud.uservm.UserVm) VMSnapshotResponse(com.cloud.api.response.VMSnapshotResponse) VMSnapshot(com.cloud.vm.snapshot.VMSnapshot)

Example 62 with Project

use of com.cloud.projects.Project in project cosmic by MissionCriticalCloud.

the class SuspendProjectCmd method execute.

@Override
public void execute() throws ConcurrentOperationException, ResourceUnavailableException {
    CallContext.current().setEventDetails("Project Id: " + id);
    final Project project = _projectService.suspendProject(id);
    if (project != null) {
        final ProjectResponse response = _responseGenerator.createProjectResponse(project);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to suspend a project");
    }
}
Also used : Project(com.cloud.projects.Project) ProjectResponse(com.cloud.api.response.ProjectResponse) ServerApiException(com.cloud.api.ServerApiException)

Example 63 with Project

use of com.cloud.projects.Project in project cosmic by MissionCriticalCloud.

the class ResizeVolumeCmd method getEntityOwnerId.

@Override
public long getEntityOwnerId() {
    final Volume volume = _entityMgr.findById(Volume.class, getEntityId());
    if (volume == null) {
        throw new InvalidParameterValueException("Unable to find volume by id=" + id);
    }
    final Account account = _accountService.getAccount(volume.getAccountId());
    // Can resize volumes for enabled projects/accounts only
    if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
        final 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.utils.exception.InvalidParameterValueException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException)

Example 64 with Project

use of com.cloud.projects.Project in project cosmic by MissionCriticalCloud.

the class ActivateProjectCmd method execute.

// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    CallContext.current().setEventDetails("Project id: " + getId());
    final Project project = _projectService.activateProject(getId());
    if (project != null) {
        final ProjectResponse response = _responseGenerator.createProjectResponse(project);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to activate a project");
    }
}
Also used : Project(com.cloud.projects.Project) ProjectResponse(com.cloud.api.response.ProjectResponse) ServerApiException(com.cloud.api.ServerApiException)

Example 65 with Project

use of com.cloud.projects.Project in project cloudstack by apache.

the class AssociateIPAddrCmd method getEntityOwnerId.

@Override
public long getEntityOwnerId() {
    Account caller = CallContext.current().getCallingAccount();
    if (accountName != null && domainId != null) {
        Account account = _accountService.finalizeOwner(caller, accountName, domainId, projectId);
        return account.getId();
    } else if (projectId != null) {
        Project project = _projectService.getProject(projectId);
        if (project != null) {
            if (project.getState() == Project.State.Active) {
                return project.getProjectAccountId();
            } else {
                throw new PermissionDeniedException("Can't add resources to the project with specified projectId in state=" + project.getState() + " as it's no longer active");
            }
        } else {
            throw new InvalidParameterValueException("Unable to find project by ID");
        }
    } else if (networkId != null) {
        Network network = _networkService.getNetwork(networkId);
        if (network == null) {
            throw new InvalidParameterValueException("Unable to find network by network id specified");
        }
        NetworkOffering offering = _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId());
        DataCenter zone = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
        if (zone.getNetworkType() == NetworkType.Basic && offering.isElasticIp() && offering.isElasticLb()) {
            // shared network with EIP/ELB service.
            return caller.getAccountId();
        }
        return network.getAccountId();
    } else if (vpcId != null) {
        Vpc vpc = _entityMgr.findById(Vpc.class, getVpcId());
        if (vpc == null) {
            throw new InvalidParameterValueException("Can't find enabled VPC by ID specified");
        }
        return vpc.getAccountId();
    }
    return caller.getAccountId();
}
Also used : Account(com.cloud.user.Account) Project(com.cloud.projects.Project) DataCenter(com.cloud.dc.DataCenter) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) NetworkOffering(com.cloud.offering.NetworkOffering) Network(com.cloud.network.Network) Vpc(com.cloud.network.vpc.Vpc) PermissionDeniedException(com.cloud.exception.PermissionDeniedException)

Aggregations

Project (com.cloud.projects.Project)89 Account (com.cloud.user.Account)55 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)28 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)27 Domain (com.cloud.domain.Domain)20 ArrayList (java.util.ArrayList)20 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)18 DomainVO (com.cloud.domain.DomainVO)12 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)11 Pair (com.cloud.utils.Pair)11 List (java.util.List)11 ServerApiException (com.cloud.api.ServerApiException)10 ProjectAccount (com.cloud.projects.ProjectAccount)10 Volume (com.cloud.storage.Volume)10 UserAccount (com.cloud.user.UserAccount)10 DB (com.cloud.utils.db.DB)10 ProjectResponse (com.cloud.api.response.ProjectResponse)9 Filter (com.cloud.utils.db.Filter)9 DataCenterVO (com.cloud.dc.DataCenterVO)8 VlanVO (com.cloud.dc.VlanVO)6