Search in sources :

Example 11 with Account

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

the class ListTemplateOrIsoPermissionsCmd method execute.

@Override
public void execute() {
    List<String> accountNames = _templateService.listTemplatePermissions(this);
    Account account = UserContext.current().getCaller();
    boolean isAdmin = (isAdmin(account.getType()));
    TemplatePermissionsResponse response = _responseGenerator.createTemplatePermissionsResponse(accountNames, id, isAdmin);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : Account(com.cloud.user.Account) TemplatePermissionsResponse(com.cloud.api.response.TemplatePermissionsResponse)

Example 12 with Account

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

the class DeployVMCmd method create.

@Override
public void create() throws ResourceAllocationException {
    try {
        //Verify that all objects exist before passing them to the service
        Account owner = _accountService.getActiveAccountById(getEntityOwnerId());
        DataCenter zone = _configService.getZone(zoneId);
        if (zone == null) {
            throw new InvalidParameterValueException("Unable to find zone by id=" + zoneId);
        }
        ServiceOffering serviceOffering = _configService.getServiceOffering(serviceOfferingId);
        if (serviceOffering == null) {
            throw new InvalidParameterValueException("Unable to find service offering: " + serviceOfferingId);
        }
        VirtualMachineTemplate template = _templateService.getTemplate(templateId);
        // Make sure a valid template ID was specified
        if (template == null) {
            throw new InvalidParameterValueException("Unable to use template " + templateId);
        }
        if (diskOfferingId != null) {
            DiskOffering diskOffering = _configService.getDiskOffering(diskOfferingId);
            if (diskOffering == null) {
                throw new InvalidParameterValueException("Unable to find disk offering " + diskOfferingId);
            }
        }
        UserVm vm = null;
        if (getHypervisor() == HypervisorType.BareMetal) {
            vm = _bareMetalVmService.createVirtualMachine(this);
        } else {
            if (zone.getNetworkType() == NetworkType.Basic) {
                if (getNetworkIds() != null) {
                    throw new InvalidParameterValueException("Can't specify network Ids in Basic zone");
                } else {
                    vm = _userVmService.createBasicSecurityGroupVirtualMachine(zone, serviceOffering, template, getSecurityGroupIdList(), owner, name, displayName, diskOfferingId, size, group, getHypervisor(), userData, sshKeyPairName, getIpToNetworkMap(), ipAddress, keyboard);
                }
            } else {
                if (zone.isSecurityGroupEnabled()) {
                    vm = _userVmService.createAdvancedSecurityGroupVirtualMachine(zone, serviceOffering, template, getNetworkIds(), getSecurityGroupIdList(), owner, name, displayName, diskOfferingId, size, group, getHypervisor(), userData, sshKeyPairName, getIpToNetworkMap(), ipAddress, keyboard);
                } else {
                    if (getSecurityGroupIdList() != null && !getSecurityGroupIdList().isEmpty()) {
                        throw new InvalidParameterValueException("Can't create vm with security groups; security group feature is not enabled per zone");
                    }
                    vm = _userVmService.createAdvancedVirtualMachine(zone, serviceOffering, template, getNetworkIds(), owner, name, displayName, diskOfferingId, size, group, getHypervisor(), userData, sshKeyPairName, getIpToNetworkMap(), ipAddress, keyboard);
                }
            }
        }
        if (vm != null) {
            setEntityId(vm.getId());
        } else {
            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to deploy vm");
        }
    } catch (InsufficientCapacityException ex) {
        s_logger.info(ex);
        s_logger.trace(ex);
        throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
    } catch (ResourceUnavailableException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
    } catch (ConcurrentOperationException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
    }
}
Also used : Account(com.cloud.user.Account) UserVm(com.cloud.uservm.UserVm) DataCenter(com.cloud.dc.DataCenter) DiskOffering(com.cloud.offering.DiskOffering) VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) ServerApiException(com.cloud.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ServiceOffering(com.cloud.offering.ServiceOffering) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Example 13 with Account

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

the class EnableAccountCmd method getEntityOwnerId.

@Override
public long getEntityOwnerId() {
    Account account = _entityMgr.findById(Account.class, getId());
    if (account != null) {
        return account.getAccountId();
    }
    account = _accountService.getActiveAccountByName(getAccountName(), getDomainId());
    if (account != null) {
        return account.getAccountId();
    }
    // no account info given, parent this command to SYSTEM so ERROR events are tracked
    return Account.ACCOUNT_ID_SYSTEM;
}
Also used : Account(com.cloud.user.Account)

Example 14 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 15 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)

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