Search in sources :

Example 91 with UserVm

use of com.cloud.uservm.UserVm in project CloudStack-archive by CloudStack-extras.

the class AssignVMCmd method execute.

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

Example 92 with UserVm

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

the class DetachIsoCmdByAdmin method execute.

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

Example 93 with UserVm

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

the class UpdateVMAffinityGroupCmdByAdmin method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException {
    CallContext.current().setEventDetails("Vm Id: " + getId());
    UserVm result = _affinityGroupService.updateVMAffinityGroups(getId(), getAffinityGroupIdList());
    ArrayList<VMDetails> dc = new ArrayList<VMDetails>();
    dc.add(VMDetails.valueOf("affgrp"));
    EnumSet<VMDetails> details = EnumSet.copyOf(dc);
    if (result != null) {
        UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", details, result).get(0);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update vm's affinity groups");
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) VMDetails(org.apache.cloudstack.api.ApiConstants.VMDetails) ServerApiException(org.apache.cloudstack.api.ServerApiException) ArrayList(java.util.ArrayList) UserVmResponse(org.apache.cloudstack.api.response.UserVmResponse)

Example 94 with UserVm

use of com.cloud.uservm.UserVm 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 95 with UserVm

use of com.cloud.uservm.UserVm 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)

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