Search in sources :

Example 56 with UserVmVO

use of com.cloud.vm.UserVmVO in project cloudstack by apache.

the class VolumeApiServiceImpl method updateMissingRootDiskController.

public void updateMissingRootDiskController(final VMInstanceVO vm, final String rootVolChainInfo) {
    if (vm == null || !VirtualMachine.Type.User.equals(vm.getType()) || StringUtils.isEmpty(rootVolChainInfo)) {
        return;
    }
    String rootDiskController = null;
    try {
        final VirtualMachineDiskInfo infoInChain = _gson.fromJson(rootVolChainInfo, VirtualMachineDiskInfo.class);
        if (infoInChain != null) {
            rootDiskController = infoInChain.getControllerFromDeviceBusName();
        }
        final UserVmVO userVmVo = _userVmDao.findById(vm.getId());
        if ((rootDiskController != null) && (!rootDiskController.isEmpty())) {
            _userVmDao.loadDetails(userVmVo);
            _userVmMgr.persistDeviceBusInfo(userVmVo, rootDiskController);
        }
    } catch (JsonParseException e) {
        s_logger.debug("Error parsing chain info json: " + e.getMessage());
    }
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) VirtualMachineDiskInfo(org.apache.cloudstack.utils.volume.VirtualMachineDiskInfo) JsonParseException(com.google.gson.JsonParseException)

Example 57 with UserVmVO

use of com.cloud.vm.UserVmVO in project cloudstack by apache.

the class VolumeApiServiceImpl method validateVolumeReadyStateAndHypervisorChecks.

private void validateVolumeReadyStateAndHypervisorChecks(VolumeVO volume, long currentSize, Long newSize) {
    // checking if there are any ongoing snapshots on the volume which is to be resized
    List<SnapshotVO> ongoingSnapshots = _snapshotDao.listByStatus(volume.getId(), Snapshot.State.Creating, Snapshot.State.CreatedOnPrimary, Snapshot.State.BackingUp);
    if (ongoingSnapshots.size() > 0) {
        throw new CloudRuntimeException("There is/are unbacked up snapshot(s) on this volume, resize volume is not permitted, please try again later.");
    }
    /* Only works for KVM/XenServer/VMware (or "Any") for now, and volumes with 'None' since they're just allocated in DB */
    HypervisorType hypervisorType = _volsDao.getHypervisorType(volume.getId());
    if (hypervisorType != HypervisorType.KVM && hypervisorType != HypervisorType.XenServer && hypervisorType != HypervisorType.VMware && hypervisorType != HypervisorType.Any && hypervisorType != HypervisorType.None) {
        throw new InvalidParameterValueException("Hypervisor " + hypervisorType + " does not support volume resize");
    }
    if (volume.getState() != Volume.State.Ready && volume.getState() != Volume.State.Allocated) {
        throw new InvalidParameterValueException("Volume should be in ready or allocated state before attempting a resize. Volume " + volume.getUuid() + " is in state " + volume.getState() + ".");
    }
    if (hypervisorType.equals(HypervisorType.VMware) && newSize < currentSize) {
        throw new InvalidParameterValueException("VMware doesn't support shrinking volume from larger size: " + currentSize + " GB to a smaller size: " + newSize + " GB");
    }
    UserVmVO userVm = _userVmDao.findById(volume.getInstanceId());
    if (userVm != null) {
        if (volume.getVolumeType().equals(Volume.Type.ROOT) && userVm.getPowerState() != VirtualMachine.PowerState.PowerOff && hypervisorType == HypervisorType.VMware) {
            s_logger.error(" For ROOT volume resize VM should be in Power Off state.");
            throw new InvalidParameterValueException("VM current state is : " + userVm.getPowerState() + ". But VM should be in " + VirtualMachine.PowerState.PowerOff + " state.");
        }
    }
}
Also used : HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) UserVmVO(com.cloud.vm.UserVmVO) VMSnapshotVO(com.cloud.vm.snapshot.VMSnapshotVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 58 with UserVmVO

use of com.cloud.vm.UserVmVO in project cloudstack by apache.

the class StatsCollector method cleanUpVirtualMachineStats.

/**
 * Removes stats of virtual machines that are not running from memory.
 */
protected void cleanUpVirtualMachineStats() {
    List<Long> allRunningVmIds = new ArrayList<Long>();
    for (UserVmVO vm : _userVmDao.listAllRunning()) {
        allRunningVmIds.add(vm.getId());
    }
    List<Long> vmIdsToRemoveStats = new ArrayList<Long>(_VmStats.keySet());
    vmIdsToRemoveStats.removeAll(allRunningVmIds);
    for (Long vmId : vmIdsToRemoveStats) {
        removeVirtualMachineStats(vmId);
    }
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) ArrayList(java.util.ArrayList)

Example 59 with UserVmVO

use of com.cloud.vm.UserVmVO in project cloudstack by apache.

the class AdvancedNetworkVisitor method visit.

@Override
public boolean visit(final DhcpEntryRules dhcp) throws ResourceUnavailableException {
    final VirtualRouter router = dhcp.getRouter();
    final Commands commands = new Commands(Command.OnError.Stop);
    final NicVO nicVo = dhcp.getNicVo();
    final UserVmVO userVM = dhcp.getUserVM();
    final boolean remove = dhcp.isRemove();
    _commandSetupHelper.createDhcpEntryCommand(router, userVM, nicVo, remove, commands);
    return _networkGeneralHelper.sendCommandsToRouter(router, commands);
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) Commands(com.cloud.agent.manager.Commands) NicVO(com.cloud.vm.NicVO) VirtualRouter(com.cloud.network.router.VirtualRouter)

Example 60 with UserVmVO

use of com.cloud.vm.UserVmVO in project cloudstack by apache.

the class BasicNetworkVisitor method visit.

@Override
public boolean visit(final UserdataPwdRules userdata) throws ResourceUnavailableException {
    final VirtualRouter router = userdata.getRouter();
    final Commands commands = new Commands(Command.OnError.Stop);
    final VirtualMachineProfile profile = userdata.getProfile();
    final NicVO nicVo = userdata.getNicVo();
    final UserVmVO userVM = userdata.getUserVM();
    final DeployDestination destination = userdata.getDestination();
    if (router.getPodIdToDeployIn().longValue() == destination.getPod().getId()) {
        _commandSetupHelper.createPasswordCommand(router, profile, nicVo, commands);
        _commandSetupHelper.createVmDataCommand(router, userVM, nicVo, userVM.getDetail("SSH.PublicKey"), commands);
        return _networkGeneralHelper.sendCommandsToRouter(router, commands);
    }
    return true;
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) DeployDestination(com.cloud.deploy.DeployDestination) Commands(com.cloud.agent.manager.Commands) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) NicVO(com.cloud.vm.NicVO) VirtualRouter(com.cloud.network.router.VirtualRouter)

Aggregations

UserVmVO (com.cloud.vm.UserVmVO)190 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)79 Account (com.cloud.user.Account)50 ArrayList (java.util.ArrayList)45 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)39 HostVO (com.cloud.host.HostVO)34 VMSnapshotVO (com.cloud.vm.snapshot.VMSnapshotVO)33 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)31 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)30 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)28 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)25 VolumeVO (com.cloud.storage.VolumeVO)25 VMInstanceVO (com.cloud.vm.VMInstanceVO)24 ActionEvent (com.cloud.event.ActionEvent)23 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)22 GuestOSVO (com.cloud.storage.GuestOSVO)20 HashMap (java.util.HashMap)19 ConfigurationException (javax.naming.ConfigurationException)19 Test (org.junit.Test)19 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)18