Search in sources :

Example 6 with Account

use of com.cloud.user.Account in project CloudStack-archive by CloudStack-extras.

the class EnableAccountCmd method execute.

@Override
public void execute() {
    Account result = _accountService.enableAccount(getAccountName(), getDomainId(), getId());
    if (result != null) {
        AccountResponse response = _responseGenerator.createAccountResponse(result);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to enable account");
    }
}
Also used : Account(com.cloud.user.Account) ServerApiException(com.cloud.api.ServerApiException) AccountResponse(com.cloud.api.response.AccountResponse)

Example 7 with Account

use of com.cloud.user.Account in project CloudStack-archive by CloudStack-extras.

the class ListAccountsCmd method execute.

@Override
public void execute() {
    List<? extends Account> accounts = _accountService.searchForAccounts(this);
    ListResponse<AccountResponse> response = new ListResponse<AccountResponse>();
    List<AccountResponse> accountResponses = new ArrayList<AccountResponse>();
    for (Account account : accounts) {
        AccountResponse acctResponse = _responseGenerator.createAccountResponse(account);
        acctResponse.setObjectName("account");
        accountResponses.add(acctResponse);
    }
    response.setResponses(accountResponses);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : Account(com.cloud.user.Account) ListResponse(com.cloud.api.response.ListResponse) ArrayList(java.util.ArrayList) AccountResponse(com.cloud.api.response.AccountResponse)

Example 8 with Account

use of com.cloud.user.Account in project CloudStack-archive by CloudStack-extras.

the class ListIsosCmd method listInReadyState.

public boolean listInReadyState() {
    Account account = UserContext.current().getCaller();
    // It is account specific if account is admin type and domainId and accountName are not null
    boolean isAccountSpecific = (account == null || isAdmin(account.getType())) && (getAccountName() != null) && (getDomainId() != null);
    // Show only those that are downloaded.
    TemplateFilter templateFilter = TemplateFilter.valueOf(getIsoFilter());
    boolean onlyReady = (templateFilter == TemplateFilter.featured) || (templateFilter == TemplateFilter.selfexecutable) || (templateFilter == TemplateFilter.sharedexecutable) || (templateFilter == TemplateFilter.executable && isAccountSpecific) || (templateFilter == TemplateFilter.community);
    if (!onlyReady) {
        if (isReady() != null && isReady().booleanValue() != onlyReady) {
            onlyReady = isReady().booleanValue();
        }
    }
    return onlyReady;
}
Also used : Account(com.cloud.user.Account) TemplateFilter(com.cloud.template.VirtualMachineTemplate.TemplateFilter)

Example 9 with Account

use of com.cloud.user.Account 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 10 with Account

use of com.cloud.user.Account 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

Account (com.cloud.user.Account)566 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)254 ArrayList (java.util.ArrayList)152 ActionEvent (com.cloud.event.ActionEvent)114 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)98 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)82 List (java.util.List)80 Test (org.junit.Test)73 User (com.cloud.user.User)66 AccountVO (com.cloud.user.AccountVO)64 DB (com.cloud.utils.db.DB)61 Network (com.cloud.network.Network)60 Pair (com.cloud.utils.Pair)52 DataCenter (com.cloud.dc.DataCenter)49 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)46 Filter (com.cloud.utils.db.Filter)46 CallContext (org.apache.cloudstack.context.CallContext)45 DomainVO (com.cloud.domain.DomainVO)44 TransactionStatus (com.cloud.utils.db.TransactionStatus)44 NetworkVO (com.cloud.network.dao.NetworkVO)43