Search in sources :

Example 1 with VmDeviceType

use of org.ovirt.engine.core.common.utils.VmDeviceType in project ovirt-engine by oVirt.

the class VmHandler method addDeviceUpdateOnNextRun.

private boolean addDeviceUpdateOnNextRun(Guid vmId, VmDeviceGeneralType generalType, VmDeviceType type, boolean readOnly, String name, Object key, Object value, List<VmDeviceUpdate> updates) {
    if (key != null) {
        VmDeviceGeneralType keyGeneralType = VmDeviceGeneralType.UNKNOWN;
        VmDeviceType keyType = VmDeviceType.UNKNOWN;
        if (key instanceof VmDeviceGeneralType) {
            keyGeneralType = (VmDeviceGeneralType) key;
        } else if (key instanceof VmDeviceType) {
            keyType = (VmDeviceType) key;
        } else if (key instanceof GraphicsType) {
            keyType = ((GraphicsType) key).getCorrespondingDeviceType();
        } else {
            log.warn("addDeviceUpdateOnNextRun: Unsupported map key type: " + key.getClass().getName());
            return false;
        }
        if (keyGeneralType != VmDeviceGeneralType.UNKNOWN) {
            generalType = keyGeneralType;
        }
        if (keyType != VmDeviceType.UNKNOWN) {
            type = keyType;
        }
    }
    // if device type is set to unknown, search by general type only
    // because some devices have more than one type, like sound can be ac97/ich6
    String typeName = type != VmDeviceType.UNKNOWN ? type.getName() : null;
    if (value == null) {
        if (vmDeviceUtils.vmDeviceChanged(vmId, generalType, typeName, false)) {
            updates.add(new VmDeviceUpdate(generalType, type, readOnly, name, false));
        }
    } else if (value instanceof Boolean) {
        if (vmDeviceUtils.vmDeviceChanged(vmId, generalType, typeName, (Boolean) value)) {
            updates.add(new VmDeviceUpdate(generalType, type, readOnly, name, (Boolean) value));
        }
    } else if (value instanceof VmDevice) {
        if (vmDeviceUtils.vmDeviceChanged(vmId, generalType, typeName, (VmDevice) value)) {
            updates.add(new VmDeviceUpdate(generalType, type, readOnly, name, (VmDevice) value));
        }
    } else if (value instanceof VmWatchdog) {
        if (vmDeviceUtils.vmDeviceChanged(vmId, generalType, typeName, ((VmWatchdog) value).getVmDevice())) {
            updates.add(new VmDeviceUpdate(generalType, type, readOnly, name, ((VmWatchdog) value).getVmDevice()));
        }
    } else {
        log.warn("addDeviceUpdateOnNextRun: Unsupported value type: " + value.getClass().getName());
        return false;
    }
    return true;
}
Also used : GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VmDeviceUpdate(org.ovirt.engine.core.common.utils.VmDeviceUpdate) VmDeviceType(org.ovirt.engine.core.common.utils.VmDeviceType) VmDeviceGeneralType(org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType) VmWatchdog(org.ovirt.engine.core.common.businessentities.VmWatchdog)

Example 2 with VmDeviceType

use of org.ovirt.engine.core.common.utils.VmDeviceType in project ovirt-engine by oVirt.

the class GetGraphicsDevicesMultipleQuery method mapDevices.

private void mapDevices(Map<Guid, List<GraphicsDevice>> result, VmDeviceType type, List<Guid> vmsIds) {
    log.debug("Retrieving graphics devices '{}' for '{}' vms", type.getName(), vmsIds.size());
    List<VmDevice> devicesList = vmDeviceDao.getVmDeviceByTypeAndDevice(vmsIds, VmDeviceGeneralType.GRAPHICS, type.getName(), getUserID(), getParameters().isFiltered());
    for (VmDevice device : devicesList) {
        result.computeIfAbsent(device.getVmId(), guid -> new ArrayList<>()).add(new GraphicsDevice(device));
    }
}
Also used : VmDeviceType(org.ovirt.engine.core.common.utils.VmDeviceType) GraphicsDevice(org.ovirt.engine.core.common.businessentities.GraphicsDevice) IdsQueryParameters(org.ovirt.engine.core.common.queries.IdsQueryParameters) Guid(org.ovirt.engine.core.compat.Guid) HashMap(java.util.HashMap) EngineContext(org.ovirt.engine.core.bll.context.EngineContext) ArrayList(java.util.ArrayList) VmDeviceGeneralType(org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType) Inject(javax.inject.Inject) List(java.util.List) Map(java.util.Map) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VmDeviceDao(org.ovirt.engine.core.dao.VmDeviceDao) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) GraphicsDevice(org.ovirt.engine.core.common.businessentities.GraphicsDevice) ArrayList(java.util.ArrayList)

Example 3 with VmDeviceType

use of org.ovirt.engine.core.common.utils.VmDeviceType in project ovirt-engine by oVirt.

the class VmHandler method autoSelectGraphicsDevice.

public void autoSelectGraphicsDevice(Guid srcEntityId, VmStatic parametersStaticData, Cluster cluster, Map<GraphicsType, GraphicsDevice> graphicsDevices, Version compatibilityVersion) {
    if (// if not set by user in params
    graphicsDevices.isEmpty() && cluster != null) {
        // and Cluster is known
        DisplayType defaultDisplayType = parametersStaticData.getDefaultDisplayType();
        int osId = parametersStaticData.getOsId();
        List<GraphicsType> sourceGraphics = vmDeviceUtils.getGraphicsTypesOfEntity(srcEntityId);
        // otherwise choose the first supported graphics device
        if (!vmValidationUtils.isGraphicsAndDisplaySupported(osId, compatibilityVersion, sourceGraphics, defaultDisplayType)) {
            GraphicsType defaultGraphicsType = null;
            List<Pair<GraphicsType, DisplayType>> pairs = osRepository.getGraphicsAndDisplays(osId, compatibilityVersion);
            for (Pair<GraphicsType, DisplayType> pair : pairs) {
                if (pair.getSecond().equals(defaultDisplayType)) {
                    defaultGraphicsType = pair.getFirst();
                    break;
                }
            }
            if (defaultGraphicsType != null) {
                for (GraphicsType graphicsType : GraphicsType.values()) {
                    // reset graphics devices
                    graphicsDevices.put(graphicsType, null);
                }
                VmDeviceType vmDisplayType = defaultGraphicsType.getCorrespondingDeviceType();
                GraphicsDevice defaultGraphicsDevice = new GraphicsDevice(vmDisplayType);
                graphicsDevices.put(defaultGraphicsType, defaultGraphicsDevice);
            }
        }
    }
}
Also used : GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) GraphicsDevice(org.ovirt.engine.core.common.businessentities.GraphicsDevice) DisplayType(org.ovirt.engine.core.common.businessentities.DisplayType) VmDeviceType(org.ovirt.engine.core.common.utils.VmDeviceType) Pair(org.ovirt.engine.core.common.utils.Pair)

Aggregations

VmDeviceType (org.ovirt.engine.core.common.utils.VmDeviceType)3 GraphicsDevice (org.ovirt.engine.core.common.businessentities.GraphicsDevice)2 GraphicsType (org.ovirt.engine.core.common.businessentities.GraphicsType)2 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)2 VmDeviceGeneralType (org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Inject (javax.inject.Inject)1 EngineContext (org.ovirt.engine.core.bll.context.EngineContext)1 DisplayType (org.ovirt.engine.core.common.businessentities.DisplayType)1 VmWatchdog (org.ovirt.engine.core.common.businessentities.VmWatchdog)1 IdsQueryParameters (org.ovirt.engine.core.common.queries.IdsQueryParameters)1 Pair (org.ovirt.engine.core.common.utils.Pair)1 VmDeviceUpdate (org.ovirt.engine.core.common.utils.VmDeviceUpdate)1 Guid (org.ovirt.engine.core.compat.Guid)1 VmDeviceDao (org.ovirt.engine.core.dao.VmDeviceDao)1