Search in sources :

Example 6 with VmDevice

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

the class VmDevicesMonitoring method buildNewVmDevice.

/**
 * Builds a new device structure for the device recognized by libvirt.
 */
private VmDevice buildNewVmDevice(Guid vmId, Map device, String logicalName) {
    String typeName = (String) device.get(VdsProperties.Type);
    String deviceName = (String) device.get(VdsProperties.Device);
    // do not allow null or empty device or type values
    if (StringUtils.isEmpty(typeName) || StringUtils.isEmpty(deviceName)) {
        log.error("Empty or NULL values were passed for a VM '{}' device, Device is skipped", vmId);
        return null;
    }
    String address = device.get(VdsProperties.Address).toString();
    String alias = StringUtils.defaultString((String) device.get(VdsProperties.Alias));
    Map<String, Object> specParams = (Map<String, Object>) device.get(VdsProperties.SpecParams);
    specParams = specParams != null ? specParams : new HashMap<>();
    Guid newDeviceId = Guid.newGuid();
    VmDeviceId id = new VmDeviceId(newDeviceId, vmId);
    Object deviceReadonlyValue = device.get(VdsProperties.ReadOnly);
    boolean isReadOnly = deviceReadonlyValue != null && Boolean.getBoolean(deviceReadonlyValue.toString());
    VmDevice newDevice = new VmDevice(id, VmDeviceGeneralType.forValue(typeName), deviceName, address, specParams, false, true, isReadOnly, alias, null, null, logicalName);
    if (VmDeviceCommonUtils.isMemory(newDevice)) {
        fixMemorySpecParamsTypes(newDevice);
    }
    log.debug("New device was marked for adding to VM '{}' Device : '{}'", vmId, newDevice);
    return newDevice;
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Guid(org.ovirt.engine.core.compat.Guid) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Example 7 with VmDevice

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

the class VmDevicesConverter method parseBalloon.

private Map<String, Object> parseBalloon(XmlDocument document, List<VmDevice> devices) {
    VmDevice dbDevice = filterDevice(devices, VmDeviceGeneralType.BALLOON);
    if (dbDevice == null) {
        return Collections.emptyMap();
    }
    XmlNode node = document.selectSingleNode("//*/memballoon");
    if (node == null) {
        return Collections.emptyMap();
    }
    Map<String, Object> result = new HashMap<>();
    result.put(VdsProperties.Device, "memballoon");
    result.put(VdsProperties.DeviceId, dbDevice.getDeviceId().toString());
    result.put(VdsProperties.Address, parseAddress(node));
    result.put(VdsProperties.Alias, parseAlias(node));
    result.put(VdsProperties.SpecParams, dbDevice.getSpecParams());
    return result;
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) HashMap(java.util.HashMap)

Example 8 with VmDevice

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

the class VmDevicesConverter method parseInterfaces.

private List<Map<String, Object>> parseInterfaces(XmlDocument document, List<VmDevice> devices, Guid vmId, MemoizingSupplier<Map<Map<String, String>, HostDevice>> addressToHostDeviceSupplier) {
    List<VmDevice> dbDevices = filterDevices(devices, VmDeviceGeneralType.INTERFACE);
    Map<Guid, VmDevice> devIdToDbDev = dbDevices.stream().collect(Collectors.toMap(device -> device.getDeviceId(), device -> device));
    List<VmNetworkInterface> dbInterfaces = vmNetworkInterfaceDao.getAllForVm(vmId);
    List<Map<String, Object>> result = new ArrayList<>();
    for (XmlNode node : selectNodes(document, VmDeviceGeneralType.INTERFACE)) {
        String type = parseAttribute(node, TYPE);
        Map<String, Object> dev = new HashMap<>();
        if (VmDeviceType.HOST_DEVICE.getName().equals(type)) {
            dev.put(VdsProperties.HostDev, getHostDeviceName(node, addressToHostDeviceSupplier));
        }
        dev.put(VdsProperties.Type, VmDeviceGeneralType.INTERFACE.getValue());
        dev.put(VdsProperties.Device, type);
        dev.put(VdsProperties.Address, parseAddress(node));
        dev.put(VdsProperties.Alias, parseAlias(node));
        String macAddress = parseMacAddress(node);
        // MAC address is a unique identifier of network interface devices
        VmDevice dbDev = correlate(dev, dbDevices, device -> {
            VmNetworkInterface dbInterface = dbInterfaces.stream().filter(iface -> iface.getMacAddress().equalsIgnoreCase(macAddress)).findFirst().orElse(null);
            return dbInterface != null ? devIdToDbDev.get(dbInterface.getId()) : null;
        });
        if (dbDev == null) {
            log.warn("unmanaged network interface with mac address '{}' is ignored", macAddress);
            continue;
        }
        dev.put(VdsProperties.DeviceId, dbDev.getDeviceId().toString());
        dev.put(VdsProperties.SpecParams, dbDev.getSpecParams());
        result.add(dev);
    }
    return result;
}
Also used : VmDeviceType(org.ovirt.engine.core.common.utils.VmDeviceType) Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) DiskLunMapDao(org.ovirt.engine.core.dao.DiskLunMapDao) Guid(org.ovirt.engine.core.compat.Guid) XmlNamespaceManager(org.ovirt.engine.core.utils.ovf.xml.XmlNamespaceManager) UsbControllerModel(org.ovirt.engine.core.common.businessentities.UsbControllerModel) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) XmlAttribute(org.ovirt.engine.core.utils.ovf.xml.XmlAttribute) LibvirtVmXmlBuilder(org.ovirt.engine.core.vdsbroker.builder.vminfo.LibvirtVmXmlBuilder) Singleton(javax.inject.Singleton) Function(java.util.function.Function) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) DiskLunMap(org.ovirt.engine.core.common.businessentities.storage.DiskLunMap) ArrayList(java.util.ArrayList) VmDeviceGeneralType(org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType) Inject(javax.inject.Inject) DiskImageDao(org.ovirt.engine.core.dao.DiskImageDao) Map(java.util.Map) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VdsProperties(org.ovirt.engine.core.vdsbroker.vdsbroker.VdsProperties) VmDeviceDao(org.ovirt.engine.core.dao.VmDeviceDao) VmNetworkInterfaceDao(org.ovirt.engine.core.dao.network.VmNetworkInterfaceDao) MemoizingSupplier(org.ovirt.engine.core.utils.MemoizingSupplier) Logger(org.slf4j.Logger) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) XmlDocument(org.ovirt.engine.core.utils.ovf.xml.XmlDocument) HostDeviceDao(org.ovirt.engine.core.dao.HostDeviceDao) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice) List(java.util.List) SPEC_PARAM_NODE(org.ovirt.engine.core.common.utils.VmDeviceCommonUtils.SPEC_PARAM_NODE) SPEC_PARAM_SIZE(org.ovirt.engine.core.common.utils.VmDeviceCommonUtils.SPEC_PARAM_SIZE) Optional(java.util.Optional) Comparator(java.util.Comparator) Collections(java.util.Collections) XmlNodeList(org.ovirt.engine.core.utils.ovf.xml.XmlNodeList) XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) HashMap(java.util.HashMap) DiskLunMap(org.ovirt.engine.core.common.businessentities.storage.DiskLunMap) Map(java.util.Map)

Example 9 with VmDevice

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

the class VmDevicesConverter method parseManagedHostDevices.

/**
 * This method processes managed host devices (those that are set by the engine).
 * That means that the device should already exist in the database and can be correlated
 * with one of the devices of the host. Host devices that were designed to be added as
 * unmanaged devices, like mdev devices, are handled separately.
 */
private List<Map<String, Object>> parseManagedHostDevices(XmlDocument document, List<VmDevice> devices, Guid hostId, MemoizingSupplier<Map<Map<String, String>, HostDevice>> addressToHostDeviceSupplier) {
    List<VmDevice> dbDevices = filterDevices(devices, VmDeviceGeneralType.HOSTDEV);
    if (dbDevices.isEmpty()) {
        return Collections.emptyList();
    }
    List<Map<String, Object>> result = new ArrayList<>();
    for (XmlNode node : document.selectNodes("//*/hostdev")) {
        Map<String, String> hostAddress = parseHostAddress(node);
        if (hostAddress == null) {
            continue;
        }
        HostDevice hostDevice = addressToHostDeviceSupplier.get().get(hostAddress);
        if (hostDevice == null) {
            // unmanaged
            continue;
        }
        Map<String, Object> dev = new HashMap<>();
        dev.put(VdsProperties.Address, parseAddress(node));
        dev.put(VdsProperties.Type, VmDeviceGeneralType.HOSTDEV.getValue());
        dev.put(VdsProperties.Alias, parseAlias(node));
        dev.put(VdsProperties.Device, hostDevice.getDeviceName());
        VmDevice dbDev = correlate(dev, dbDevices, device -> dbDevices.stream().filter(d -> d.getDevice().equals(hostDevice.getDeviceName())).findFirst().orElse(null));
        if (dbDev == null) {
            log.warn("VM host device '{}' does not exist in the database, thus ignored", hostDevice.getDeviceName());
            continue;
        }
        dev.put(VdsProperties.DeviceId, dbDev.getDeviceId().toString());
        dev.put(VdsProperties.SpecParams, dbDev.getSpecParams());
        result.add(dev);
    }
    return result;
}
Also used : VmDeviceType(org.ovirt.engine.core.common.utils.VmDeviceType) Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) DiskLunMapDao(org.ovirt.engine.core.dao.DiskLunMapDao) Guid(org.ovirt.engine.core.compat.Guid) XmlNamespaceManager(org.ovirt.engine.core.utils.ovf.xml.XmlNamespaceManager) UsbControllerModel(org.ovirt.engine.core.common.businessentities.UsbControllerModel) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) XmlAttribute(org.ovirt.engine.core.utils.ovf.xml.XmlAttribute) LibvirtVmXmlBuilder(org.ovirt.engine.core.vdsbroker.builder.vminfo.LibvirtVmXmlBuilder) Singleton(javax.inject.Singleton) Function(java.util.function.Function) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) DiskLunMap(org.ovirt.engine.core.common.businessentities.storage.DiskLunMap) ArrayList(java.util.ArrayList) VmDeviceGeneralType(org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType) Inject(javax.inject.Inject) DiskImageDao(org.ovirt.engine.core.dao.DiskImageDao) Map(java.util.Map) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VdsProperties(org.ovirt.engine.core.vdsbroker.vdsbroker.VdsProperties) VmDeviceDao(org.ovirt.engine.core.dao.VmDeviceDao) VmNetworkInterfaceDao(org.ovirt.engine.core.dao.network.VmNetworkInterfaceDao) MemoizingSupplier(org.ovirt.engine.core.utils.MemoizingSupplier) Logger(org.slf4j.Logger) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) XmlDocument(org.ovirt.engine.core.utils.ovf.xml.XmlDocument) HostDeviceDao(org.ovirt.engine.core.dao.HostDeviceDao) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice) List(java.util.List) SPEC_PARAM_NODE(org.ovirt.engine.core.common.utils.VmDeviceCommonUtils.SPEC_PARAM_NODE) SPEC_PARAM_SIZE(org.ovirt.engine.core.common.utils.VmDeviceCommonUtils.SPEC_PARAM_SIZE) Optional(java.util.Optional) Comparator(java.util.Comparator) Collections(java.util.Collections) XmlNodeList(org.ovirt.engine.core.utils.ovf.xml.XmlNodeList) XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) HashMap(java.util.HashMap) DiskLunMap(org.ovirt.engine.core.common.businessentities.storage.DiskLunMap) Map(java.util.Map)

Example 10 with VmDevice

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

the class VmModelBehaviorBase method updateGraphics.

protected void updateGraphics(Guid id) {
    Frontend.getInstance().runQuery(QueryType.GetGraphicsDevices, new IdQueryParameters(id), new AsyncQuery<QueryReturnValue>(returnValue -> {
        List<VmDevice> graphicsVmDevs = returnValue.getReturnValue();
        List<GraphicsType> graphicsTypes = new ArrayList<>();
        for (VmDevice graphicsVmDev : graphicsVmDevs) {
            graphicsTypes.add(GraphicsType.fromString(graphicsVmDev.getDevice()));
        }
        boolean hasSpiceAndVnc = graphicsTypes.size() == 2 && graphicsTypes.containsAll(Arrays.asList(GraphicsType.SPICE, GraphicsType.VNC));
        boolean canBeSelected = getModel().getGraphicsType().getItems().contains(UnitVmModel.GraphicsTypes.SPICE_AND_VNC);
        if (hasSpiceAndVnc && canBeSelected) {
            getModel().getGraphicsType().setSelectedItem(UnitVmModel.GraphicsTypes.SPICE_AND_VNC);
        } else if (graphicsVmDevs.size() == 1) {
            GraphicsType type = GraphicsType.fromString(graphicsVmDevs.get(0).getDevice());
            getModel().getGraphicsType().setSelectedItem(UnitVmModel.GraphicsTypes.fromGraphicsType(type));
        }
    }));
}
Also used : UsbPolicy(org.ovirt.engine.core.common.businessentities.UsbPolicy) TemplateWithVersion(org.ovirt.engine.ui.uicommonweb.models.templates.TemplateWithVersion) Arrays(java.util.Arrays) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) VmType(org.ovirt.engine.core.common.businessentities.VmType) InstanceType(org.ovirt.engine.core.common.businessentities.InstanceType) DiskByDiskAliasComparator(org.ovirt.engine.core.common.businessentities.comparators.DiskByDiskAliasComparator) Event(org.ovirt.engine.ui.uicompat.Event) ImagesDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.ImagesDataProvider) VmNumaSupportModel(org.ovirt.engine.ui.uicommonweb.models.hosts.numa.VmNumaSupportModel) QuotaEnforcementTypeEnum(org.ovirt.engine.core.common.businessentities.QuotaEnforcementTypeEnum) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) Map(java.util.Map) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) ConstantsManager(org.ovirt.engine.ui.uicompat.ConstantsManager) AsyncQuery(org.ovirt.engine.ui.frontend.AsyncQuery) Version(org.ovirt.engine.core.compat.Version) EventArgs(org.ovirt.engine.ui.uicompat.EventArgs) AsyncDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider) StorageType(org.ovirt.engine.core.common.businessentities.storage.StorageType) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) DiskStorageType(org.ovirt.engine.core.common.businessentities.storage.DiskStorageType) VmNumaNode(org.ovirt.engine.core.common.businessentities.VmNumaNode) Collection(java.util.Collection) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) ListModel(org.ovirt.engine.ui.uicommonweb.models.ListModel) Set(java.util.Set) I18NNameValidation(org.ovirt.engine.ui.uicommonweb.validation.I18NNameValidation) StringHelper(org.ovirt.engine.core.compat.StringHelper) VolumeType(org.ovirt.engine.core.common.businessentities.storage.VolumeType) List(java.util.List) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) RepoImage(org.ovirt.engine.core.common.businessentities.storage.RepoImage) LatestVmTemplate(org.ovirt.engine.ui.uicommonweb.models.templates.LatestVmTemplate) GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) QueryType(org.ovirt.engine.core.common.queries.QueryType) ArchitectureType(org.ovirt.engine.core.common.businessentities.ArchitectureType) TimeZoneType(org.ovirt.engine.core.common.TimeZoneType) Guid(org.ovirt.engine.core.compat.Guid) ServerCpu(org.ovirt.engine.core.common.businessentities.ServerCpu) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) IEventListener(org.ovirt.engine.ui.uicompat.IEventListener) HashMap(java.util.HashMap) StorageDomainStatus(org.ovirt.engine.core.common.businessentities.StorageDomainStatus) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) ExistingBlankTemplateModelBehavior(org.ovirt.engine.ui.uicommonweb.models.templates.ExistingBlankTemplateModelBehavior) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) AsyncCallback(org.ovirt.engine.ui.frontend.AsyncCallback) HashSet(java.util.HashSet) CpuProfile(org.ovirt.engine.core.common.businessentities.profiles.CpuProfile) Frontend(org.ovirt.engine.ui.frontend.Frontend) NumaSupportModel(org.ovirt.engine.ui.uicommonweb.models.hosts.numa.NumaSupportModel) InstanceTypeManager(org.ovirt.engine.ui.uicommonweb.models.vms.instancetypes.InstanceTypeManager) UIMessages(org.ovirt.engine.ui.uicompat.UIMessages) NameableComparator(org.ovirt.engine.core.common.businessentities.comparators.NameableComparator) Linq(org.ovirt.engine.ui.uicommonweb.Linq) BuilderExecutor(org.ovirt.engine.ui.uicommonweb.builders.BuilderExecutor) IValidation(org.ovirt.engine.ui.uicommonweb.validation.IValidation) ConfigValues(org.ovirt.engine.core.common.config.ConfigValues) Quota(org.ovirt.engine.core.common.businessentities.Quota) VmCommonUtils(org.ovirt.engine.core.common.utils.VmCommonUtils) VM(org.ovirt.engine.core.common.businessentities.VM) UIConstants(org.ovirt.engine.ui.uicompat.UIConstants) ActionGroup(org.ovirt.engine.core.common.businessentities.ActionGroup) MigrationSupport(org.ovirt.engine.core.common.businessentities.MigrationSupport) Collections(java.util.Collections) VDS(org.ovirt.engine.core.common.businessentities.VDS) GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)170 HashMap (java.util.HashMap)59 Guid (org.ovirt.engine.core.compat.Guid)53 VmDeviceId (org.ovirt.engine.core.common.businessentities.VmDeviceId)48 ArrayList (java.util.ArrayList)34 Map (java.util.Map)33 VM (org.ovirt.engine.core.common.businessentities.VM)29 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)28 List (java.util.List)26 GraphicsType (org.ovirt.engine.core.common.businessentities.GraphicsType)21 VmDeviceGeneralType (org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType)21 VmDeviceType (org.ovirt.engine.core.common.utils.VmDeviceType)20 Collections (java.util.Collections)19 Test (org.junit.Test)19 Collectors (java.util.stream.Collectors)18 Arrays (java.util.Arrays)17 Optional (java.util.Optional)17 StringUtils (org.apache.commons.lang.StringUtils)17 HostDevice (org.ovirt.engine.core.common.businessentities.HostDevice)17 Inject (javax.inject.Inject)16