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();
}
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;
}
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;
}
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;
}
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);
}
Aggregations