Search in sources :

Example 96 with UserVm

use of com.cloud.uservm.UserVm in project cloudstack by apache.

the class ResetVMPasswordCmdByAdmin method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException {
    password = _mgr.generateRandomPassword();
    CallContext.current().setEventDetails("Vm Id: " + getId());
    UserVm result = _userVmService.resetVMPassword(this, password);
    if (result != null) {
        UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", result).get(0);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to reset vm password");
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) ServerApiException(org.apache.cloudstack.api.ServerApiException) UserVmResponse(org.apache.cloudstack.api.response.UserVmResponse)

Example 97 with UserVm

use of com.cloud.uservm.UserVm in project cloudstack by apache.

the class ResetVMSSHKeyCmdByAdmin method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException {
    CallContext.current().setEventDetails("Vm Id: " + getId());
    UserVm result = _userVmService.resetVMSSHKey(this);
    if (result != null) {
        UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", result).get(0);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to reset vm SSHKey");
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) ServerApiException(org.apache.cloudstack.api.ServerApiException) UserVmResponse(org.apache.cloudstack.api.response.UserVmResponse)

Example 98 with UserVm

use of com.cloud.uservm.UserVm in project cloudstack by apache.

the class RestoreVMCmdByAdmin method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    UserVm result;
    CallContext.current().setEventDetails("Vm Id: " + getVmId());
    result = _userVmService.restoreVM(this);
    if (result != null) {
        UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", result).get(0);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to restore vm " + getVmId());
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) ServerApiException(org.apache.cloudstack.api.ServerApiException) UserVmResponse(org.apache.cloudstack.api.response.UserVmResponse)

Example 99 with UserVm

use of com.cloud.uservm.UserVm in project cloudstack by apache.

the class ScaleVMCmdByAdmin method execute.

@Override
public void execute() {
    UserVm result;
    try {
        result = _userVmService.upgradeVirtualMachine(this);
    } catch (ResourceUnavailableException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
    } catch (ConcurrentOperationException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    } catch (ManagementServerException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    } catch (VirtualMachineMigrationException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    }
    if (result != null) {
        List<UserVmResponse> responseList = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", result);
        UserVmResponse response = responseList.get(0);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to scale vm");
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) ServerApiException(org.apache.cloudstack.api.ServerApiException) ManagementServerException(com.cloud.exception.ManagementServerException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) VirtualMachineMigrationException(com.cloud.exception.VirtualMachineMigrationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) UserVmResponse(org.apache.cloudstack.api.response.UserVmResponse)

Example 100 with UserVm

use of com.cloud.uservm.UserVm in project cloudstack by apache.

the class StartVMCmdByAdmin method execute.

@Override
public void execute() throws ResourceUnavailableException, ResourceAllocationException {
    try {
        CallContext.current().setEventDetails("Vm Id: " + getId());
        UserVm result;
        result = _userVmService.startVirtualMachine(this);
        if (result != null) {
            UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", result).get(0);
            response.setResponseName(getCommandName());
            setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to start a vm");
        }
    } catch (ConcurrentOperationException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    } catch (StorageUnavailableException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
    } catch (ExecutionException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    } catch (InsufficientCapacityException ex) {
        StringBuilder message = new StringBuilder(ex.getMessage());
        if (ex instanceof InsufficientServerCapacityException) {
            if (((InsufficientServerCapacityException) ex).isAffinityApplied()) {
                message.append(", Please check the affinity groups provided, there may not be sufficient capacity to follow them");
            }
        }
        s_logger.info(ex);
        s_logger.info(message.toString(), ex);
        throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, message.toString());
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) ServerApiException(org.apache.cloudstack.api.ServerApiException) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) InsufficientServerCapacityException(com.cloud.exception.InsufficientServerCapacityException) ExecutionException(com.cloud.utils.exception.ExecutionException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) UserVmResponse(org.apache.cloudstack.api.response.UserVmResponse) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Aggregations

UserVm (com.cloud.uservm.UserVm)196 ServerApiException (com.cloud.api.ServerApiException)59 UserVmResponse (com.cloud.api.response.UserVmResponse)59 ArrayList (java.util.ArrayList)54 ServerApiException (org.apache.cloudstack.api.ServerApiException)48 UserVmResponse (org.apache.cloudstack.api.response.UserVmResponse)47 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)32 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)30 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)28 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)28 Network (com.cloud.network.Network)26 Account (com.cloud.user.Account)22 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)21 ManagementServerException (com.cloud.exception.ManagementServerException)21 HashMap (java.util.HashMap)16 ServiceOffering (com.cloud.offering.ServiceOffering)15 DataCenter (com.cloud.dc.DataCenter)14 List (java.util.List)14 ActionEvent (com.cloud.event.ActionEvent)12 VirtualMachineMigrationException (com.cloud.exception.VirtualMachineMigrationException)12