use of org.ovirt.engine.core.common.businessentities.GraphicsType in project ovirt-engine by oVirt.
the class ImportUtils method getCompatibleGraphics.
private GraphicsDevice getCompatibleGraphics(VmDeviceType videoDeviceType, Version clusterVersion, VmBase vmBase) {
GraphicsDevice graphicsDevice = null;
GraphicsType compatibleType = null;
for (Pair<GraphicsType, DisplayType> graphicsDisplayPair : osRepository.getGraphicsAndDisplays(vmBase.getOsId(), clusterVersion)) {
if (graphicsDisplayPair.getSecond().getDefaultVmDeviceType() == videoDeviceType) {
compatibleType = graphicsDisplayPair.getFirst();
// previously to spice+vnc, QXL was only used by spice, so prefer spice if available
if (videoDeviceType == VmDeviceType.QXL && compatibleType == GraphicsType.SPICE) {
break;
}
}
}
if (compatibleType != null) {
graphicsDevice = new GraphicsDevice(compatibleType.getCorrespondingDeviceType());
graphicsDevice.setId(new VmDeviceId(Guid.newGuid(), vmBase.getId()));
}
return graphicsDevice;
}
use of org.ovirt.engine.core.common.businessentities.GraphicsType 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;
}
use of org.ovirt.engine.core.common.businessentities.GraphicsType in project ovirt-engine by oVirt.
the class VmHandler method autoSelectDefaultDisplayType.
/**
* Automatic selection of display type based on its graphics types in parameters.
* This method preserves backward compatibility for REST API - legacy REST API doesn't allow to set display and
* graphics separately.
*/
public void autoSelectDefaultDisplayType(Guid srcEntityId, VmBase parametersStaticData, Cluster cluster, Map<GraphicsType, GraphicsDevice> graphicsDevices) {
if (parametersStaticData.getOsId() == OsRepository.AUTO_SELECT_OS) {
return;
}
List<Pair<GraphicsType, DisplayType>> graphicsAndDisplays = osRepository.getGraphicsAndDisplays(parametersStaticData.getOsId(), CompatibilityVersionUtils.getEffective(parametersStaticData, cluster));
if (parametersStaticData.getDefaultDisplayType() != null && (parametersStaticData.getDefaultDisplayType() == DisplayType.none || isDisplayTypeSupported(parametersStaticData.getDefaultDisplayType(), graphicsAndDisplays))) {
return;
}
DisplayType defaultDisplayType = null;
// map holding display type -> set of supported graphics types for this display type
Map<DisplayType, Set<GraphicsType>> displayGraphicsSupport = new LinkedHashMap<>();
for (Pair<GraphicsType, DisplayType> graphicsAndDisplay : graphicsAndDisplays) {
DisplayType display = graphicsAndDisplay.getSecond();
if (!displayGraphicsSupport.containsKey(display)) {
displayGraphicsSupport.put(display, new HashSet<>());
}
displayGraphicsSupport.get(display).add(graphicsAndDisplay.getFirst());
}
for (Map.Entry<DisplayType, Set<GraphicsType>> entry : displayGraphicsSupport.entrySet()) {
final List<GraphicsType> graphicsTypes = vmDeviceUtils.getGraphicsTypesOfEntity(srcEntityId);
final Set<GraphicsType> resultingVmGraphics = getResultingVmGraphics(graphicsTypes, graphicsDevices);
if (entry.getValue().containsAll(resultingVmGraphics)) {
defaultDisplayType = entry.getKey();
break;
}
}
if (defaultDisplayType == null) {
if (!displayGraphicsSupport.isEmpty()) {
// when not found otherwise, let's take osinfo's record as the default
Map.Entry<DisplayType, Set<GraphicsType>> entry = displayGraphicsSupport.entrySet().iterator().next();
defaultDisplayType = entry.getKey();
} else {
// no osinfo record
defaultDisplayType = DisplayType.qxl;
}
}
parametersStaticData.setDefaultDisplayType(defaultDisplayType);
}
use of org.ovirt.engine.core.common.businessentities.GraphicsType in project ovirt-engine by oVirt.
the class VmDeviceUtils method copyVmDevices.
/**
* Copy devices from the given VmDevice list to the destination VM/VmBase.
*/
public void copyVmDevices(Guid srcId, Guid dstId, VmBase srcVmBase, VmBase dstVmBase, List<VmDevice> srcDevices, Map<Guid, Guid> srcDeviceIdToDstDeviceIdMapping, boolean isSoundEnabled, boolean isConsoleEnabled, Boolean isVirtioScsiEnabled, boolean isBalloonEnabled, Set<GraphicsType> graphicsToSkip, boolean copySnapshotDevices, boolean copyHostDevices, Version versionToUpdateRngDeviceWith) {
if (graphicsToSkip == null) {
graphicsToSkip = Collections.emptySet();
}
String dstCdPath = dstVmBase.getIsoPath();
boolean dstIsVm = !(dstVmBase instanceof VmTemplate);
boolean hasCd = hasCdDevice(dstVmBase.getId());
boolean hasSound = false;
boolean hasConsole = false;
boolean hasVirtioScsi = false;
boolean hasBalloon = false;
boolean hasRng = hasRngDevice(dstId);
Cluster cluster = null;
if (dstVmBase.getClusterId() != null) {
cluster = clusterDao.get(dstVmBase.getClusterId());
}
for (VmDevice device : srcDevices) {
if (device.getSnapshotId() != null && !copySnapshotDevices) {
continue;
}
Guid deviceId = Guid.newGuid();
Map<String, Object> specParams = new HashMap<>();
switch(device.getType()) {
case DISK:
if (VmDeviceType.DISK.getName().equals(device.getDevice())) {
if (srcDeviceIdToDstDeviceIdMapping.containsKey(device.getDeviceId())) {
deviceId = srcDeviceIdToDstDeviceIdMapping.get(device.getDeviceId());
}
} else if (VmDeviceType.CDROM.getName().equals(device.getDevice())) {
if (!hasCd) {
hasCd = true;
// check here is source VM had CD (VM from snapshot)
String srcCdPath = (String) device.getSpecParams().get(VdsProperties.Path);
specParams.putAll(getCdDeviceSpecParams(srcCdPath, dstCdPath));
} else {
// CD already exists
continue;
}
}
break;
case INTERFACE:
if (srcDeviceIdToDstDeviceIdMapping.containsKey(device.getDeviceId())) {
deviceId = srcDeviceIdToDstDeviceIdMapping.get(device.getDeviceId());
}
break;
case CONTROLLER:
if (VmDeviceType.USB.getName().equals(device.getDevice())) {
specParams = device.getSpecParams();
} else if (VmDeviceType.VIRTIOSCSI.getName().equals(device.getDevice())) {
hasVirtioScsi = true;
if (Boolean.FALSE.equals(isVirtioScsiEnabled)) {
continue;
}
}
break;
case VIDEO:
if (dstIsVm) {
// to the new Vm params.
continue;
}
specParams.putAll(getVideoDeviceSpecParams(dstVmBase));
break;
case BALLOON:
if (!isBalloonEnabled) {
continue;
}
hasBalloon = true;
specParams.putAll(getMemoryBalloonSpecParams());
break;
case SMARTCARD:
specParams.putAll(getSmartcardDeviceSpecParams());
break;
case WATCHDOG:
specParams.putAll(device.getSpecParams());
break;
case RNG:
if (hasRng) {
continue;
}
if (!new VirtIoRngValidator().canAddRngDevice(cluster, new VmRngDevice(device)).isValid()) {
continue;
}
final VmRngDevice rngDevice = new VmRngDevice(device);
if (versionToUpdateRngDeviceWith != null) {
rngDevice.updateSourceByVersion(versionToUpdateRngDeviceWith);
}
specParams.putAll(rngDevice.getSpecParams());
break;
case CONSOLE:
if (!isConsoleEnabled) {
continue;
}
specParams.putAll(device.getSpecParams());
hasConsole = true;
break;
case SOUND:
if (!isSoundEnabled) {
continue;
}
hasSound = true;
break;
case GRAPHICS:
GraphicsType type = GraphicsType.fromVmDeviceType(VmDeviceType.getByName(device.getDevice()));
// OR if we already have it
if (graphicsToSkip.contains(type) || hasGraphicsDevice(dstId, GraphicsType.fromString(device.getDevice()))) {
continue;
}
break;
case HOSTDEV:
if (!copyHostDevices) {
continue;
}
specParams.putAll(device.getSpecParams());
break;
default:
break;
}
device.setId(new VmDeviceId(deviceId, dstId));
device.setSpecParams(specParams);
vmDeviceDao.save(device);
}
if (!hasCd) {
addCdDevice(dstId, dstCdPath);
}
updateUsbSlots(srcVmBase, dstVmBase, () -> clusterDao.get(dstVmBase.getClusterId()));
if (isSoundEnabled && !hasSound) {
if (dstIsVm) {
addSoundDevice(dstVmBase);
} else {
addSoundDevice(dstVmBase.getId(), dstVmBase.getOsId(), cluster != null ? cluster.getCompatibilityVersion() : null);
}
}
if (isConsoleEnabled && !hasConsole) {
addConsoleDevice(dstId);
}
if (Boolean.TRUE.equals(isVirtioScsiEnabled) && !hasVirtioScsi) {
addVirtioScsiController(dstVmBase, getVmCompatibilityVersion(dstVmBase));
}
if (isBalloonEnabled && !hasBalloon) {
addMemoryBalloon(dstId);
}
if (dstIsVm) {
addVideoDevices(dstVmBase, getNeededNumberOfVideoDevices(dstVmBase));
}
}
use of org.ovirt.engine.core.common.businessentities.GraphicsType in project ovirt-engine by oVirt.
the class DisplayMapper method fillDisplayInParams.
/**
* For backwards compatibility. Derives graphics type (backend) from display (rest).
*/
public static void fillDisplayInParams(Vm vm, RunVmOnceParams params) {
if (params == null) {
return;
}
if (vm.isSetDisplay() && vm.getDisplay().isSetType()) {
DisplayType displayType = vm.getDisplay().getType();
if (displayType != null) {
org.ovirt.engine.core.common.businessentities.DisplayType display = mapDisplayType(displayType, null);
if (display != null) {
Set<GraphicsType> graphics = new HashSet<>();
switch(display) {
case qxl:
graphics.add(GraphicsType.SPICE);
break;
case vga:
case cirrus:
graphics.add(GraphicsType.VNC);
break;
}
params.setRunOnceGraphics(graphics);
}
}
}
}
Aggregations