Search in sources :

Example 16 with GraphicsType

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

the class LibvirtVmXmlBuilder method writeGraphics.

private void writeGraphics(VmDevice device) {
    GraphicsType graphicsType = GraphicsType.fromString(device.getDevice());
    if (graphicsType == null) {
        log.error("Unsupported graphics type: {}", device.getDevice());
        return;
    }
    // <graphics type='spice' port='5900' tlsPort='5901' autoport='yes'
    // listen='0' keymap='en-us'
    // passwdValidTo='1970-01-01T00:00:01'>
    // <listen type='address' address='0'/>
    // <clipboard copypaste='no'/>
    // </graphics>
    // or:
    // <graphics type='vnc' port='5900' autoport='yes' listen='0'
    // keymap='en-us' passwdValidTo='1970-01-01T00:00:01'>
    // <listen type='address' address='0'/>
    // </graphics>
    writer.writeStartElement("graphics");
    writer.writeAttributeString("type", device.getDevice());
    writer.writeAttributeString("port", String.valueOf(LIBVIRT_PORT_AUTOSELECT));
    writer.writeAttributeString("autoport", "yes");
    // TODO: defaultMode
    writer.writeAttributeString("passwd", "*****");
    writer.writeAttributeString("passwdValidTo", "1970-01-01T00:00:01");
    Network displayNetwork = vmInfoBuildUtils.getDisplayNetwork(vm);
    if (displayNetwork == null) {
        writer.writeAttributeString("listen", "0");
    }
    switch(graphicsType) {
        case SPICE:
            writer.writeAttributeString("tlsPort", String.valueOf(LIBVIRT_PORT_AUTOSELECT));
            if (!vm.isSpiceFileTransferEnabled()) {
                writer.writeStartElement("filetransfer");
                writer.writeAttributeString("enable", "no");
                writer.writeEndElement();
            }
            if (!vm.isSpiceCopyPasteEnabled()) {
                writer.writeStartElement("clipboard");
                writer.writeAttributeString("copypaste", "no");
                writer.writeEndElement();
            }
            if ((boolean) Config.getValue(ConfigValues.SSLEnabled)) {
                String channels = Config.getValue(ConfigValues.SpiceSecureChannels, vm.getCompatibilityVersion().toString());
                adjustSpiceSecureChannels(channels.split(",")).forEach(channel -> {
                    writer.writeStartElement("channel");
                    writer.writeAttributeString("name", channel);
                    writer.writeAttributeString("mode", "secure");
                    writer.writeEndElement();
                });
            }
            break;
        case VNC:
            writer.writeAttributeString("keymap", vm.getDynamicData().getVncKeyboardLayout() != null ? vm.getDynamicData().getVncKeyboardLayout() : vm.getDefaultVncKeyboardLayout() != null ? vm.getDefaultVncKeyboardLayout() : Config.getValue(ConfigValues.VncKeyboardLayout));
            break;
    }
    if (displayNetwork != null) {
        writer.writeStartElement("listen");
        String displayIp = (String) device.getSpecParams().get("displayIp");
        if (displayIp == null) {
            writer.writeAttributeString("type", "network");
            writer.writeAttributeString("network", String.format("vdsm-%s", displayNetwork.getName()));
        } else {
            writer.writeAttributeString("type", "address");
            writer.writeAttributeString("address", displayIp);
        }
        writer.writeEndElement();
    }
    writer.writeEndElement();
}
Also used : GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) Network(org.ovirt.engine.core.common.businessentities.network.Network)

Example 17 with GraphicsType

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

the class BackendVmGraphicsConsolesResource method list.

@Override
public GraphicsConsoles list() {
    GraphicsConsoles consoles = new GraphicsConsoles();
    Map<GraphicsType, GraphicsInfo> graphicsTypeToGraphicsInfo;
    VM entity = loadEntity();
    boolean current = ParametersHelper.getBooleanParameter(httpHeaders, uriInfo, CURRENT, true, false);
    if (current) {
        // from entity dynamic (e.g. what is now present on the VM
        graphicsTypeToGraphicsInfo = extractGraphicsInofs(entity);
    } else {
        // from devices (e.g. what is configured on the VM)
        List<GraphicsType> graphicsTypes = DisplayHelper.getGraphicsTypesForEntity(this, guid, true);
        graphicsTypeToGraphicsInfo = new EnumMap<>(GraphicsType.class);
        for (GraphicsType type : graphicsTypes) {
            graphicsTypeToGraphicsInfo.put(type, null);
        }
    }
    for (Map.Entry<GraphicsType, GraphicsInfo> graphicsInfo : graphicsTypeToGraphicsInfo.entrySet()) {
        consoles.getGraphicsConsoles().add(addLinks(populate(VmMapper.map(graphicsInfo, null), entity)));
    }
    return consoles;
}
Also used : GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) GraphicsConsoles(org.ovirt.engine.api.model.GraphicsConsoles) VM(org.ovirt.engine.core.common.businessentities.VM) GraphicsInfo(org.ovirt.engine.core.common.businessentities.GraphicsInfo) EnumMap(java.util.EnumMap) Map(java.util.Map)

Example 18 with GraphicsType

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

the class LibvirtVmXmlBuilder method overrideDevicesForRunOnce.

private List<VmDevice> overrideDevicesForRunOnce(List<VmDevice> devices) {
    if (!vm.isRunOnce()) {
        return devices;
    }
    // video device handling
    DisplayType displayType = vm.getDefaultDisplayType();
    if (displayType != null) {
        // remove existing video device
        devices = devices.stream().filter(dev -> dev.getType() != VmDeviceGeneralType.VIDEO).collect(Collectors.toList());
        // add new video device
        if (displayType != DisplayType.none) {
            devices.add(vmInfoBuildUtils.createVideoDeviceByDisplayType(displayType, vm.getId()));
        }
    }
    // graphics device handling
    if (displayType == DisplayType.none || (vm.getGraphicsInfos() != null && !vm.getGraphicsInfos().isEmpty())) {
        // remove existing graphics devices
        devices = devices.stream().filter(dev -> dev.getType() != VmDeviceGeneralType.GRAPHICS).collect(Collectors.toList());
        if (displayType != DisplayType.none) {
            // add new graphics devices
            Map<GraphicsType, GraphicsInfo> infos = vm.getGraphicsInfos();
            Map<String, Object> specParamsFromVm = new HashMap<>();
            vmInfoBuildUtils.addVmGraphicsOptions(infos, specParamsFromVm, vm);
            devices.addAll(vmInfoBuildUtils.createGraphicsDevices(infos, specParamsFromVm, vm.getId()));
        }
    }
    // the user may specify floppy path while there is no device in the database
    if (!StringUtils.isEmpty(vm.getFloppyPath()) && devices.stream().noneMatch(dev -> dev.getDevice().equals(VmDeviceType.FLOPPY.getName()))) {
        devices.add(vmInfoBuildUtils.createFloppyDevice(vm));
    }
    return devices;
}
Also used : GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) VmType(org.ovirt.engine.core.common.businessentities.VmType) PropagateErrors(org.ovirt.engine.core.common.businessentities.storage.PropagateErrors) VmInterfaceType(org.ovirt.engine.core.common.businessentities.network.VmInterfaceType) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk) LoggerFactory(org.slf4j.LoggerFactory) GraphicsInfo(org.ovirt.engine.core.common.businessentities.GraphicsInfo) VmCpuCountHelper(org.ovirt.engine.core.common.utils.VmCpuCountHelper) XmlTextWriter(org.ovirt.engine.core.utils.ovf.xml.XmlTextWriter) HugePageUtils(org.ovirt.engine.core.common.utils.HugePageUtils) ChipsetType(org.ovirt.engine.core.common.businessentities.ChipsetType) VmDeviceCommonUtils(org.ovirt.engine.core.common.utils.VmDeviceCommonUtils) Map(java.util.Map) VdsNumaNode(org.ovirt.engine.core.common.businessentities.VdsNumaNode) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) StringMapUtils(org.ovirt.engine.core.utils.StringMapUtils) VmDeviceCommonUtils.updateVmDevicesBootOrder(org.ovirt.engine.core.common.utils.VmDeviceCommonUtils.updateVmDevicesBootOrder) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic) VdsStatistics(org.ovirt.engine.core.common.businessentities.VdsStatistics) Version(org.ovirt.engine.core.compat.Version) MemoizingSupplier(org.ovirt.engine.core.utils.MemoizingSupplier) DisplayType(org.ovirt.engine.core.common.businessentities.DisplayType) NetworkFilter(org.ovirt.engine.core.common.businessentities.network.NetworkFilter) DiskStorageType(org.ovirt.engine.core.common.businessentities.storage.DiskStorageType) VmNumaNode(org.ovirt.engine.core.common.businessentities.VmNumaNode) Collection(java.util.Collection) VmPayload(org.ovirt.engine.core.common.businessentities.VmPayload) Set(java.util.Set) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice) List(java.util.List) Stream(java.util.stream.Stream) DiskInterface(org.ovirt.engine.core.common.businessentities.storage.DiskInterface) Entry(java.util.Map.Entry) Optional(java.util.Optional) GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) NumaSettingFactory(org.ovirt.engine.core.vdsbroker.vdsbroker.NumaSettingFactory) FeatureSupported(org.ovirt.engine.core.common.FeatureSupported) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId) VmDeviceType(org.ovirt.engine.core.common.utils.VmDeviceType) ArchitectureType(org.ovirt.engine.core.common.businessentities.ArchitectureType) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) Guid(org.ovirt.engine.core.compat.Guid) HashMap(java.util.HashMap) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) NetworkUtils(org.ovirt.engine.core.utils.NetworkUtils) ArrayList(java.util.ArrayList) VmDeviceGeneralType(org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType) VmPropertiesUtils(org.ovirt.engine.core.common.utils.customprop.VmPropertiesUtils) HashSet(java.util.HashSet) ArchStrategyFactory(org.ovirt.engine.core.utils.archstrategy.ArchStrategyFactory) VdsProperties(org.ovirt.engine.core.vdsbroker.vdsbroker.VdsProperties) HugePage(org.ovirt.engine.core.common.businessentities.HugePage) Network(org.ovirt.engine.core.common.businessentities.network.Network) VolumeFormat(org.ovirt.engine.core.common.businessentities.storage.VolumeFormat) Pair(org.ovirt.engine.core.common.utils.Pair) Config(org.ovirt.engine.core.common.config.Config) Logger(org.slf4j.Logger) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) VmHostDevice(org.ovirt.engine.core.common.businessentities.VmHostDevice) VnicProfile(org.ovirt.engine.core.common.businessentities.network.VnicProfile) ConfigValues(org.ovirt.engine.core.common.config.ConfigValues) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) VM(org.ovirt.engine.core.common.businessentities.VM) NumaTuneMode(org.ovirt.engine.core.common.businessentities.NumaTuneMode) GetControllerIndices(org.ovirt.engine.core.vdsbroker.architecture.GetControllerIndices) IoTuneUtils.ioTuneListFrom(org.ovirt.engine.core.vdsbroker.vdsbroker.IoTuneUtils.ioTuneListFrom) Comparator(java.util.Comparator) Collections(java.util.Collections) StorageQos(org.ovirt.engine.core.common.businessentities.qos.StorageQos) DisplayType(org.ovirt.engine.core.common.businessentities.DisplayType) HashMap(java.util.HashMap) GraphicsInfo(org.ovirt.engine.core.common.businessentities.GraphicsInfo)

Example 19 with GraphicsType

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

the class VmInfoBuildUtils method createGraphicsDevices.

public List<VmDevice> createGraphicsDevices(Map<GraphicsType, GraphicsInfo> graphicsInfos, Map<String, Object> extraSpecParams, Guid vmId) {
    final Comparator<GraphicsType> spiceLastComparator = ComparatorUtils.sortLast(GraphicsType.SPICE);
    final List<Entry<GraphicsType, GraphicsInfo>> sortedGraphicsInfos = graphicsInfos.entrySet().stream().sorted(Comparator.comparing(Entry::getKey, spiceLastComparator)).collect(Collectors.toList());
    List<VmDevice> result = new ArrayList<>();
    for (Entry<GraphicsType, GraphicsInfo> graphicsInfo : sortedGraphicsInfos) {
        VmDevice device = new VmDevice();
        device.setId(new VmDeviceId(Guid.newGuid(), vmId));
        device.setType(VmDeviceGeneralType.GRAPHICS);
        device.setDevice(graphicsInfo.getKey().name().toLowerCase());
        device.setPlugged(true);
        device.setAddress("");
        if (extraSpecParams != null) {
            device.setSpecParams(extraSpecParams);
        }
        result.add(device);
    }
    return result;
}
Also used : GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) Entry(java.util.Map.Entry) ArrayList(java.util.ArrayList) GraphicsInfo(org.ovirt.engine.core.common.businessentities.GraphicsInfo) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Example 20 with GraphicsType

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

the class VmInfoBuilderImpl method deriveDisplayTypeLegacy.

/**
 * Derives display type from vm configuration, used with legacy vdsm.
 *
 * @return either "vnc" or "qxl" string or null if the vm is headless
 */
private String deriveDisplayTypeLegacy() {
    List<VmDevice> vmDevices = vmDeviceDao.getVmDeviceByVmIdAndType(vm.getId(), VmDeviceGeneralType.GRAPHICS);
    if (vmDevices.isEmpty()) {
        return null;
    } else if (vmDevices.size() == 2) {
        // we have spice & vnc together, we prioritize SPICE
        return VdsProperties.QXL;
    }
    GraphicsType deviceType = GraphicsType.fromString(vmDevices.get(0).getDevice());
    return graphicsTypeToLegacyDisplayType(deviceType);
}
Also used : GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice)

Aggregations

GraphicsType (org.ovirt.engine.core.common.businessentities.GraphicsType)31 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)13 GraphicsDevice (org.ovirt.engine.core.common.businessentities.GraphicsDevice)12 HashSet (java.util.HashSet)8 DisplayType (org.ovirt.engine.core.common.businessentities.DisplayType)8 ArrayList (java.util.ArrayList)7 Map (java.util.Map)6 GraphicsInfo (org.ovirt.engine.core.common.businessentities.GraphicsInfo)6 Guid (org.ovirt.engine.core.compat.Guid)6 HashMap (java.util.HashMap)5 List (java.util.List)5 Set (java.util.Set)5 VM (org.ovirt.engine.core.common.businessentities.VM)5 VmDeviceId (org.ovirt.engine.core.common.businessentities.VmDeviceId)5 VmRngDevice (org.ovirt.engine.core.common.businessentities.VmRngDevice)5 Collection (java.util.Collection)4 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)4 VmWatchdog (org.ovirt.engine.core.common.businessentities.VmWatchdog)4 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)4 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)4