Search in sources :

Example 21 with UserVmResponse

use of org.apache.cloudstack.api.response.UserVmResponse in project cloudstack by apache.

the class UpdateVMCmdByAdmin method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException {
    CallContext.current().setEventDetails("Vm Id: " + getId());
    UserVm result = _userVmService.updateVirtualMachine(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 update vm");
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) ServerApiException(org.apache.cloudstack.api.ServerApiException) UserVmResponse(org.apache.cloudstack.api.response.UserVmResponse)

Example 22 with UserVmResponse

use of org.apache.cloudstack.api.response.UserVmResponse in project cloudstack by apache.

the class ListLoadBalancerRuleInstancesCmdByAdmin method execute.

@Override
public void execute() {
    Pair<List<? extends UserVm>, List<String>> vmServiceMap = _lbService.listLoadBalancerInstances(this);
    List<? extends UserVm> result = vmServiceMap.first();
    List<String> serviceStates = vmServiceMap.second();
    if (!isListLbVmip()) {
        // list lb instances
        ListResponse<UserVmResponse> response = new ListResponse<UserVmResponse>();
        List<UserVmResponse> vmResponses = new ArrayList<UserVmResponse>();
        if (result != null) {
            vmResponses = _responseGenerator.createUserVmResponse(ResponseView.Restricted, "loadbalancerruleinstance", result.toArray(new UserVm[result.size()]));
            for (int i = 0; i < result.size(); i++) {
                vmResponses.get(i).setServiceState(serviceStates.get(i));
            }
        }
        response.setResponses(vmResponses);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        ListResponse<LoadBalancerRuleVmMapResponse> lbRes = new ListResponse<LoadBalancerRuleVmMapResponse>();
        List<UserVmResponse> vmResponses = new ArrayList<UserVmResponse>();
        List<LoadBalancerRuleVmMapResponse> listlbVmRes = new ArrayList<LoadBalancerRuleVmMapResponse>();
        if (result != null) {
            vmResponses = _responseGenerator.createUserVmResponse(ResponseView.Full, "loadbalancerruleinstance", result.toArray(new UserVm[result.size()]));
            List<String> ipaddr = null;
            for (int i = 0; i < result.size(); i++) {
                LoadBalancerRuleVmMapResponse lbRuleVmIpResponse = new LoadBalancerRuleVmMapResponse();
                vmResponses.get(i).setServiceState(serviceStates.get(i));
                lbRuleVmIpResponse.setUserVmResponse(vmResponses.get(i));
                //get vm id from the uuid
                VirtualMachine lbvm = _entityMgr.findByUuid(VirtualMachine.class, vmResponses.get(i).getId());
                lbRuleVmIpResponse.setIpAddr(_lbService.listLbVmIpAddress(getId(), lbvm.getId()));
                lbRuleVmIpResponse.setObjectName("lbrulevmidip");
                listlbVmRes.add(lbRuleVmIpResponse);
            }
        }
        lbRes.setResponseName(getCommandName());
        lbRes.setResponses(listlbVmRes);
        setResponseObject(lbRes);
    }
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) LoadBalancerRuleVmMapResponse(org.apache.cloudstack.api.response.LoadBalancerRuleVmMapResponse) UserVmResponse(org.apache.cloudstack.api.response.UserVmResponse) UserVm(com.cloud.uservm.UserVm) List(java.util.List) ArrayList(java.util.ArrayList) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 23 with UserVmResponse

use of org.apache.cloudstack.api.response.UserVmResponse 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 24 with UserVmResponse

use of org.apache.cloudstack.api.response.UserVmResponse 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 25 with UserVmResponse

use of org.apache.cloudstack.api.response.UserVmResponse 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)

Aggregations

UserVmResponse (org.apache.cloudstack.api.response.UserVmResponse)56 UserVm (com.cloud.uservm.UserVm)49 ServerApiException (org.apache.cloudstack.api.ServerApiException)43 ArrayList (java.util.ArrayList)19 VMDetails (org.apache.cloudstack.api.ApiConstants.VMDetails)12 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)8 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)7 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)7 Account (com.cloud.user.Account)7 UserVmJoinVO (com.cloud.api.query.vo.UserVmJoinVO)6 VirtualMachine (com.cloud.vm.VirtualMachine)6 List (java.util.List)5 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)4 InsufficientServerCapacityException (com.cloud.exception.InsufficientServerCapacityException)4 ManagementServerException (com.cloud.exception.ManagementServerException)4 VirtualMachineMigrationException (com.cloud.exception.VirtualMachineMigrationException)4 Host (com.cloud.host.Host)4 ServiceOffering (com.cloud.offering.ServiceOffering)4 DiskOfferingVO (com.cloud.storage.DiskOfferingVO)4 ResponseView (org.apache.cloudstack.api.ResponseObject.ResponseView)4