Search in sources :

Example 1 with VmDeviceGeneralType

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

the class DevicePropertiesUtils method init.

/**
 * Loads device custom properties definition
 *
 * @throws InitializationException
 *             if an error occured during device custom properties definition loading
 */
public void init() throws InitializationException {
    try {
        Set<Version> versions = getSupportedClusterLevels();
        String devicePropertiesStr;
        deviceProperties = new HashMap<>();
        for (Version version : versions) {
            // load device properties
            devicePropertiesStr = getCustomDeviceProperties(version);
            deviceProperties.put(version, new EnumMap<>(VmDeviceGeneralType.class));
            Matcher typeMatcher = devicePropSplitPattern.matcher(devicePropertiesStr);
            while (typeMatcher.find()) {
                String dcpStr = typeMatcher.group();
                // device type definition starts with "{type="
                int start = TYPE_PREFIX_LEN;
                int end = dcpStr.length() - 1;
                if (dcpStr.endsWith(PROPERTIES_DELIMETER)) {
                    // remove trailing ;
                    end--;
                }
                dcpStr = dcpStr.substring(start, end);
                int idx = dcpStr.indexOf(PROPERTIES_DELIMETER);
                VmDeviceGeneralType type = VmDeviceGeneralType.forValue(dcpStr.substring(0, idx));
                // properties definition for device starts with ";prop={"
                String propStr = dcpStr.substring(idx + PROP_PREFIX_LEN, dcpStr.length() - 1);
                Map<String, String> props = new HashMap<>();
                parsePropertiesRegex(propStr, props);
                deviceProperties.get(version).put(type, props);
            }
        }
    } catch (Exception ex) {
        throw new InitializationException(ex);
    }
}
Also used : Version(org.ovirt.engine.core.compat.Version) Matcher(java.util.regex.Matcher) HashMap(java.util.HashMap) VmDeviceGeneralType(org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType) InitializationException(org.ovirt.engine.core.common.utils.exceptions.InitializationException) InitializationException(org.ovirt.engine.core.common.utils.exceptions.InitializationException)

Example 2 with VmDeviceGeneralType

use of org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType 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 3 with VmDeviceGeneralType

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

the class OvfReader method readOtherHardwareItem.

private VmDevice readOtherHardwareItem(XmlNode node) {
    boolean managed = false;
    if (selectSingleNode(node, VMD_TYPE, _xmlNS) != null && StringUtils.isNotEmpty(selectSingleNode(node, VMD_TYPE, _xmlNS).innerText)) {
        VmDeviceGeneralType type = VmDeviceGeneralType.forValue(String.valueOf(selectSingleNode(node, VMD_TYPE, _xmlNS).innerText));
        String device = selectSingleNode(node, VMD_DEVICE, _xmlNS).innerText;
        // special devices are treated as managed devices but still have the OTHER OVF ResourceType
        managed = VmDeviceCommonUtils.isSpecialDevice(device, type);
    }
    return managed ? readManagedVmDevice(node, Guid.newGuid()) : readUnmanagedVmDevice(node, Guid.newGuid());
}
Also used : VmDeviceGeneralType(org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType)

Aggregations

VmDeviceGeneralType (org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType)3 HashMap (java.util.HashMap)1 Matcher (java.util.regex.Matcher)1 GraphicsType (org.ovirt.engine.core.common.businessentities.GraphicsType)1 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)1 VmWatchdog (org.ovirt.engine.core.common.businessentities.VmWatchdog)1 VmDeviceType (org.ovirt.engine.core.common.utils.VmDeviceType)1 VmDeviceUpdate (org.ovirt.engine.core.common.utils.VmDeviceUpdate)1 InitializationException (org.ovirt.engine.core.common.utils.exceptions.InitializationException)1 Version (org.ovirt.engine.core.compat.Version)1