Search in sources :

Example 6 with VMStatus

use of org.ovirt.engine.core.common.businessentities.VMStatus in project ovirt-engine by oVirt.

the class SetVmTicketCommand method validate.

@Override
protected boolean validate() {
    // Check that the virtual machine exists:
    final VM vm = getVm();
    if (vm == null) {
        addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_VM_NOT_FOUND);
        return false;
    }
    if (!canRunActionOnNonManagedVm()) {
        return false;
    }
    // Check that the virtual machine is in state that allows connections
    // to the console:
    final VMStatus status = vm.getStatus();
    if (status != VMStatus.Up && status != VMStatus.Paused && status != VMStatus.PoweringUp && status != VMStatus.PoweringDown && status != VMStatus.RebootInProgress) {
        return failVmStatusIllegal();
    }
    // subjects:
    return true;
}
Also used : VM(org.ovirt.engine.core.common.businessentities.VM) VMStatus(org.ovirt.engine.core.common.businessentities.VMStatus)

Example 7 with VMStatus

use of org.ovirt.engine.core.common.businessentities.VMStatus in project ovirt-engine by oVirt.

the class RunVmCommand method runVm.

protected void runVm() {
    setActionReturnValue(VMStatus.Down);
    if (getVdsToRunOn()) {
        VMStatus status = null;
        try {
            acquireHostDevicesLock();
            if (connectLunDisks(getVdsId()) && updateCinderDisksConnections()) {
                if (!checkRequiredHostDevicesAvailability()) {
                    // (while the host-device lock wasn't being held) we need to bail here
                    throw new EngineException(EngineError.HOST_DEVICES_TAKEN_BY_OTHER_VM);
                } else {
                    status = createVm();
                    ExecutionHandler.setAsyncJob(getExecutionContext(), true);
                    markHostDevicesAsUsed();
                }
            }
        } catch (EngineException e) {
            // re-throw it. otherwise, continue (the vm will be down and a re-run will be triggered)
            switch(e.getErrorCode()) {
                // should never get here with errorCode = 'Done' though
                case Done:
                case exist:
                    cleanupPassthroughVnics();
                    reportCompleted();
                    throw e;
                // probably wrong xml format sent.
                case VDS_NETWORK_ERROR:
                case PROVIDER_FAILURE:
                case HOST_DEVICES_TAKEN_BY_OTHER_VM:
                    runningFailed();
                    throw e;
                default:
                    log.warn("Failed to run VM '{}': {}", getVmName(), e.getMessage());
            }
        } finally {
            releaseHostDevicesLock();
            freeLock();
        }
        setActionReturnValue(status);
        if (status != null && (status.isRunning() || status == VMStatus.RestoringState)) {
            setSucceeded(true);
        } else {
            // Try to rerun Vm on different vds no need to log the command because it is
            // being logged inside the rerun
            log.info("Trying to rerun VM '{}'", getVm().getName());
            setCommandShouldBeLogged(false);
            setSucceeded(true);
            rerun();
        }
    } else {
        runningFailed();
    }
}
Also used : EngineException(org.ovirt.engine.core.common.errors.EngineException) VMStatus(org.ovirt.engine.core.common.businessentities.VMStatus)

Example 8 with VMStatus

use of org.ovirt.engine.core.common.businessentities.VMStatus in project ovirt-engine by oVirt.

the class VmStatusCell method render.

@Override
public void render(Context context, VM vm, SafeHtmlBuilder sb, String id) {
    // Nothing to render if no vm is provided:
    if (vm == null) {
        return;
    }
    // Find the image corresponding to the status of the vm:
    VMStatus status = vm.getStatus();
    ImageResource statusImage;
    switch(status) {
        case Up:
            if (vm.isRunOnce()) {
                statusImage = resources.runOnceUpImage();
            } else {
                statusImage = resources.vmStatusRunning();
            }
            break;
        case SavingState:
            statusImage = resources.vmStatusWait();
            break;
        case RestoringState:
            statusImage = resources.vmStatusWait();
            break;
        case PoweringUp:
            statusImage = resources.vmStatusStarting();
            break;
        case PoweringDown:
            statusImage = resources.vmStatusPoweringDown();
            break;
        case RebootInProgress:
            statusImage = resources.rebootInProgress();
            break;
        case WaitForLaunch:
            statusImage = resources.waitForLaunch();
            break;
        case ImageLocked:
            statusImage = resources.vmStatusWait();
            break;
        case MigratingFrom:
        case MigratingTo:
            statusImage = resources.migrationImage();
            break;
        case Suspended:
            statusImage = resources.suspendedImage();
            break;
        case Paused:
            statusImage = resources.pauseImage();
            break;
        case Unknown:
        case Unassigned:
            statusImage = resources.questionMarkImage();
            break;
        case NotResponding:
            statusImage = resources.questionMarkImage();
            break;
        default:
            statusImage = resources.downStatusImage();
            break;
    }
    // Generate the HTML for status image
    SafeHtml statusImageHtml = SafeHtmlUtils.fromTrustedString(AbstractImagePrototype.create(statusImage).getHTML());
    if (vm.getLockInfo() != null && vm.getLockInfo().isExclusive()) {
        ImageResource lockImageResource = resources.vmLocked();
        // Get the image html
        AbstractImagePrototype imagePrototype = AbstractImagePrototype.create(lockImageResource);
        SafeHtml lockImageHtml = SafeHtmlUtils.fromTrustedString(imagePrototype.getHTML());
        statusImageHtml = templates.lockedStatusTemplate(lockImageHtml, statusImageHtml);
    }
    if (VmStatusColumn.needsAlert(vm)) {
        sb.append(templates.statusWithAlertTemplate(statusImageHtml, getAlertImageResource(vm), id, status.toString()));
    } else {
        sb.append(templates.statusTemplate(statusImageHtml, id, status.toString()));
    }
}
Also used : AbstractImagePrototype(com.google.gwt.user.client.ui.AbstractImagePrototype) ImageResource(com.google.gwt.resources.client.ImageResource) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) VMStatus(org.ovirt.engine.core.common.businessentities.VMStatus)

Aggregations

VMStatus (org.ovirt.engine.core.common.businessentities.VMStatus)8 VM (org.ovirt.engine.core.common.businessentities.VM)3 Field (java.lang.reflect.Field)2 PostConstruct (javax.annotation.PostConstruct)2 EditableVmField (org.ovirt.engine.core.common.businessentities.EditableVmField)2 VmBase (org.ovirt.engine.core.common.businessentities.VmBase)2 Guid (org.ovirt.engine.core.compat.Guid)2 ObjectIdentityChecker (org.ovirt.engine.core.utils.ObjectIdentityChecker)2 ImageResource (com.google.gwt.resources.client.ImageResource)1 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)1 AbstractImagePrototype (com.google.gwt.user.client.ui.AbstractImagePrototype)1 VmManagementParametersBase (org.ovirt.engine.core.common.action.VmManagementParametersBase)1 EditableDeviceOnVmStatusField (org.ovirt.engine.core.common.businessentities.EditableDeviceOnVmStatusField)1 EditableVmTemplateField (org.ovirt.engine.core.common.businessentities.EditableVmTemplateField)1 TransientField (org.ovirt.engine.core.common.businessentities.TransientField)1 VmDynamic (org.ovirt.engine.core.common.businessentities.VmDynamic)1 VmStatic (org.ovirt.engine.core.common.businessentities.VmStatic)1 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)1 EngineException (org.ovirt.engine.core.common.errors.EngineException)1