Search in sources :

Example 41 with UserVm

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

the class StartVMCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException {
    try {
        UserContext.current().setEventDetails("Vm Id: " + getId());
        UserVm result;
        if (_userVmService.getHypervisorTypeOfUserVM(getId()) == HypervisorType.BareMetal) {
            result = _bareMetalVmService.startVirtualMachine(this);
        } else {
            result = _userVmService.startVirtualMachine(this);
        }
        if (result != null) {
            UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0);
            response.setResponseName(getCommandName());
            this.setResponseObject(response);
        } else {
            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to start a vm");
        }
    } catch (ConcurrentOperationException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
    } catch (StorageUnavailableException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
    } catch (ExecutionException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) ServerApiException(com.cloud.api.ServerApiException) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) ExecutionException(com.cloud.utils.exception.ExecutionException) UserVmResponse(com.cloud.api.response.UserVmResponse) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Example 42 with UserVm

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

the class ResetVMPasswordCmd method execute.

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

Example 43 with UserVm

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

the class RestoreVMCmd method execute.

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

Example 44 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 45 with UserVm

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

the class LoadBalancingRulesManagerImpl method getLbInstances.

@Override
public Map<Ip, UserVm> getLbInstances(long lbId) {
    Map<Ip, UserVm> dstList = new HashMap<Ip, UserVm>();
    List<LoadBalancerVMMapVO> lbVmMaps = _lb2VmMapDao.listByLoadBalancerId(lbId);
    LoadBalancerVO lb = _lbDao.findById(lbId);
    for (LoadBalancerVMMapVO lbVmMap : lbVmMaps) {
        UserVm vm = _vmDao.findById(lbVmMap.getInstanceId());
        Nic nic = _nicDao.findByInstanceIdAndNetworkIdIncludingRemoved(lb.getNetworkId(), vm.getId());
        Ip ip = new Ip(nic.getIPv4Address());
        dstList.put(ip, vm);
    }
    return dstList;
}
Also used : UserVm(com.cloud.uservm.UserVm) HashMap(java.util.HashMap) Ip(com.cloud.utils.net.Ip) PublicIp(com.cloud.network.addr.PublicIp) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) Nic(com.cloud.vm.Nic) LoadBalancerVMMapVO(com.cloud.network.dao.LoadBalancerVMMapVO)

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