Search in sources :

Example 41 with ServerApiException

use of com.cloud.api.ServerApiException in project CloudStack-archive by CloudStack-extras.

the class DestroyVMCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, ConcurrentOperationException {
    UserContext.current().setEventDetails("Vm Id: " + getId());
    UserVm result;
    if (_userVmService.getHypervisorTypeOfUserVM(getId()) == HypervisorType.BareMetal) {
        result = _bareMetalVmService.destroyVm(this);
    } else {
        result = _userVmService.destroyVm(this);
    }
    if (result != null) {
        UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0);
        response.setResponseName("virtualmachine");
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to destroy vm");
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) ServerApiException(com.cloud.api.ServerApiException) UserVmResponse(com.cloud.api.response.UserVmResponse)

Example 42 with ServerApiException

use of com.cloud.api.ServerApiException in project CloudStack-archive by CloudStack-extras.

the class DetachIsoCmd method execute.

@Override
public void execute() {
    boolean result = _templateService.detachIso(virtualMachineId);
    if (result) {
        UserVm userVm = _entityMgr.findById(UserVm.class, virtualMachineId);
        UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", userVm).get(0);
        response.setResponseName(DeployVMCmd.getResultObjectName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to detach iso");
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) ServerApiException(com.cloud.api.ServerApiException) UserVmResponse(com.cloud.api.response.UserVmResponse)

Example 43 with ServerApiException

use of com.cloud.api.ServerApiException in project CloudStack-archive by CloudStack-extras.

the class DisassociateIPAddrCmd method execute.

@Override
public void execute() throws InsufficientAddressCapacityException {
    UserContext.current().setEventDetails("Ip Id: " + getIpAddressId());
    boolean result = _networkService.disassociateIpAddress(id);
    if (result) {
        SuccessResponse response = new SuccessResponse(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to disassociate ip address");
    }
}
Also used : SuccessResponse(com.cloud.api.response.SuccessResponse) ServerApiException(com.cloud.api.ServerApiException)

Example 44 with ServerApiException

use of com.cloud.api.ServerApiException 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 45 with ServerApiException

use of com.cloud.api.ServerApiException in project CloudStack-archive by CloudStack-extras.

the class EnableStaticNatCmd method execute.

@Override
public void execute() throws ResourceUnavailableException {
    try {
        boolean result = _rulesService.enableStaticNat(ipAddressId, virtualMachineId, false);
        if (result) {
            SuccessResponse response = new SuccessResponse(getCommandName());
            this.setResponseObject(response);
        } else {
            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to enable static nat");
        }
    } catch (NetworkRuleConflictException ex) {
        s_logger.info("Network rule conflict: " + ex.getMessage());
        s_logger.trace("Network Rule Conflict: ", ex);
        throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage());
    }
}
Also used : SuccessResponse(com.cloud.api.response.SuccessResponse) ServerApiException(com.cloud.api.ServerApiException) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException)

Aggregations

ServerApiException (com.cloud.api.ServerApiException)170 SuccessResponse (com.cloud.api.response.SuccessResponse)46 UserVm (com.cloud.uservm.UserVm)15 UserVmResponse (com.cloud.api.response.UserVmResponse)14 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)12 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)12 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)12 Account (com.cloud.user.Account)9 Host (com.cloud.host.Host)8 VirtualMachineTemplate (com.cloud.template.VirtualMachineTemplate)8 ListResponse (com.cloud.api.response.ListResponse)7 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)7 HostResponse (com.cloud.api.response.HostResponse)6 TemplateResponse (com.cloud.api.response.TemplateResponse)6 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)6 AccountResponse (com.cloud.api.response.AccountResponse)5 SystemVmResponse (com.cloud.api.response.SystemVmResponse)5 UserResponse (com.cloud.api.response.UserResponse)5 VolumeResponse (com.cloud.api.response.VolumeResponse)5 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)5