Search in sources :

Example 36 with UserVm

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

the class UpdateVMCmd 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.Restricted, "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 37 with UserVm

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

the class UpgradeVMCmd 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.Restricted, "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 38 with UserVm

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

the class AutoScaleManagerImpl method createNewVM.

private long createNewVM(AutoScaleVmGroupVO asGroup) {
    AutoScaleVmProfileVO profileVo = _autoScaleVmProfileDao.findById(asGroup.getProfileId());
    long templateId = profileVo.getTemplateId();
    long serviceOfferingId = profileVo.getServiceOfferingId();
    if (templateId == -1) {
        return -1;
    }
    // create new VM into DB
    try {
        //Verify that all objects exist before passing them to the service
        Account owner = _accountService.getActiveAccountById(profileVo.getAccountId());
        DataCenter zone = _entityMgr.findById(DataCenter.class, profileVo.getZoneId());
        if (zone == null) {
            throw new InvalidParameterValueException("Unable to find zone by id=" + profileVo.getZoneId());
        }
        ServiceOffering serviceOffering = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
        if (serviceOffering == null) {
            throw new InvalidParameterValueException("Unable to find service offering: " + serviceOfferingId);
        }
        VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, templateId);
        // Make sure a valid template ID was specified
        if (template == null) {
            throw new InvalidParameterValueException("Unable to use template " + templateId);
        }
        if (!zone.isLocalStorageEnabled()) {
            if (serviceOffering.getUseLocalStorage()) {
                throw new InvalidParameterValueException("Zone is not configured to use local storage but service offering " + serviceOffering.getName() + " uses it");
            }
        }
        UserVm vm = null;
        IpAddresses addrs = new IpAddresses(null, null);
        if (zone.getNetworkType() == NetworkType.Basic) {
            vm = _userVmService.createBasicSecurityGroupVirtualMachine(zone, serviceOffering, template, null, owner, "autoScaleVm-" + asGroup.getId() + "-" + getCurrentTimeStampString(), "autoScaleVm-" + asGroup.getId() + "-" + getCurrentTimeStampString(), null, null, null, HypervisorType.XenServer, HTTPMethod.GET, null, null, null, null, true, null, null, null, null);
        } else {
            if (zone.isSecurityGroupEnabled()) {
                vm = _userVmService.createAdvancedSecurityGroupVirtualMachine(zone, serviceOffering, template, null, null, owner, "autoScaleVm-" + asGroup.getId() + "-" + getCurrentTimeStampString(), "autoScaleVm-" + asGroup.getId() + "-" + getCurrentTimeStampString(), null, null, null, HypervisorType.XenServer, HTTPMethod.GET, null, null, null, null, true, null, null, null, null);
            } else {
                vm = _userVmService.createAdvancedVirtualMachine(zone, serviceOffering, template, null, owner, "autoScaleVm-" + asGroup.getId() + "-" + getCurrentTimeStampString(), "autoScaleVm-" + asGroup.getId() + "-" + getCurrentTimeStampString(), null, null, null, HypervisorType.XenServer, HTTPMethod.GET, null, null, null, addrs, true, null, null, null, null);
            }
        }
        if (vm != null) {
            return vm.getId();
        } else {
            return -1;
        }
    } catch (InsufficientCapacityException ex) {
        s_logger.info(ex);
        s_logger.trace(ex.getMessage(), ex);
        throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
    } 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 (ResourceAllocationException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, ex.getMessage());
    }
}
Also used : Account(com.cloud.user.Account) VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) ServiceOffering(com.cloud.offering.ServiceOffering) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) IpAddresses(com.cloud.network.Network.IpAddresses) UserVm(com.cloud.uservm.UserVm) DataCenter(com.cloud.dc.DataCenter) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException)

Example 39 with UserVm

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

the class AttachIsoCmdByAdmin method execute.

@Override
public void execute() {
    CallContext.current().setEventDetails("Vm Id: " + getVirtualMachineId() + " ISO Id: " + getId());
    boolean result = _templateService.attachIso(id, virtualMachineId);
    if (result) {
        UserVm userVm = _responseGenerator.findUserVmById(virtualMachineId);
        if (userVm != null) {
            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 attach iso");
        }
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to attach iso");
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) ServerApiException(org.apache.cloudstack.api.ServerApiException) UserVmResponse(org.apache.cloudstack.api.response.UserVmResponse)

Example 40 with UserVm

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

the class CreateSnapshotFromVMSnapshotCmd method getVmId.

private Long getVmId() {
    VMSnapshot vmsnapshot = _entityMgr.findById(VMSnapshot.class, getVMSnapshotId());
    if (vmsnapshot == null) {
        throw new InvalidParameterValueException("Unable to find vm snapshot by id=" + getVMSnapshotId());
    }
    UserVm vm = _entityMgr.findById(UserVm.class, vmsnapshot.getVmId());
    if (vm == null) {
        throw new InvalidParameterValueException("Unable to find vm by vm snapshot id=" + getVMSnapshotId());
    }
    return vm.getId();
}
Also used : UserVm(com.cloud.uservm.UserVm) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) VMSnapshot(com.cloud.vm.snapshot.VMSnapshot)

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