Search in sources :

Example 26 with UserVm

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

the class AssignVMCmd method execute.

@Override
public void execute() {
    try {
        UserVm userVm = _userVmService.moveVMToUser(this);
        if (userVm == null) {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm");
        }
        UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", userVm).get(0);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } catch (InvalidParameterValueException e) {
        e.printStackTrace();
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm " + e.getMessage());
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) UserVmResponse(org.apache.cloudstack.api.response.UserVmResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException)

Example 27 with UserVm

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

the class DestroyVMCmdByAdmin method execute.

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

Example 28 with UserVm

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

the class ExpungeVMCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, ConcurrentOperationException {
    CallContext.current().setEventDetails("Vm Id: " + getId());
    try {
        UserVm result = _userVmService.expungeVm(this.getId());
        if (result != null) {
            SuccessResponse response = new SuccessResponse(getCommandName());
            setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to expunge vm");
        }
    } catch (InvalidParameterValueException ipve) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ipve.getMessage());
    } catch (CloudRuntimeException cre) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, cre.getMessage());
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) SuccessResponse(org.apache.cloudstack.api.response.SuccessResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 29 with UserVm

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

the class UpgradeVMCmdByAdmin method execute.

@Override
public void execute() throws ResourceAllocationException {
    CallContext.current().setEventDetails("Vm Id: " + getId());
    ServiceOffering serviceOffering = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
    if (serviceOffering == null) {
        throw new InvalidParameterValueException("Unable to find service offering: " + serviceOfferingId);
    }
    UserVm result = _userVmService.upgradeVirtualMachine(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 upgrade vm");
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) ServerApiException(org.apache.cloudstack.api.ServerApiException) ServiceOffering(com.cloud.offering.ServiceOffering) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) UserVmResponse(org.apache.cloudstack.api.response.UserVmResponse)

Example 30 with UserVm

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

the class RevertToVMSnapshotCmdByAdmin method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException, ConcurrentOperationException {
    CallContext.current().setEventDetails("vmsnapshot id: " + getVmSnapShotId());
    UserVm result = _vmSnapshotService.revertToSnapshot(getVmSnapShotId());
    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 revert VM snapshot");
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) ServerApiException(org.apache.cloudstack.api.ServerApiException) UserVmResponse(org.apache.cloudstack.api.response.UserVmResponse)

Aggregations

UserVm (com.cloud.uservm.UserVm)98 ServerApiException (org.apache.cloudstack.api.ServerApiException)45 UserVmResponse (org.apache.cloudstack.api.response.UserVmResponse)45 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)20 ArrayList (java.util.ArrayList)19 ServerApiException (com.cloud.api.ServerApiException)15 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)15 UserVmResponse (com.cloud.api.response.UserVmResponse)14 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)14 Network (com.cloud.network.Network)13 Account (com.cloud.user.Account)10 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)9 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)9 VMDetails (org.apache.cloudstack.api.ApiConstants.VMDetails)9 Test (org.junit.Test)9 DataCenter (com.cloud.dc.DataCenter)6 ManagementServerException (com.cloud.exception.ManagementServerException)6 VirtualMachineMigrationException (com.cloud.exception.VirtualMachineMigrationException)6 DB (com.cloud.utils.db.DB)6 TransactionStatus (com.cloud.utils.db.TransactionStatus)6