Skip to content

Commit

Permalink
Allow setting DisplayType via API
Browse files Browse the repository at this point in the history
This change allows to set the DisplayType via the API.
And also prefers VNC over SPICE as SPICE is deprecated.

Signed-off-by: Jean-Louis Dupond <jean-louis@dupond.be>
  • Loading branch information
dupondje authored and sandrobonazzola committed Jul 10, 2024
1 parent 1043c13 commit 9dbe9b1
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public static void setGraphicsToParams(Display display, HasGraphicsDevices param
/**
* Sets static display info (derived from graphics device) to the Template.
* Serves for BC purposes as VM can have more graphics devices, but old restapi allows us to set only one.
* If there are multiple graphics, SPICE is preferred.
* If there are multiple graphics, VNC is preferred.
*/
public static void adjustDisplayData(BackendResource res, Template template) {
adjustDisplayDataInternal(res, template, null, false);
Expand All @@ -107,7 +107,7 @@ public static void adjustDisplayData(BackendResource res, Template template) {
/**
* Sets static display info (derived from graphics device) to the VM.
* Serves for BC purposes as VM can have more graphics devices, but old restapi allows us to set only one.
* If there are multiple graphics, SPICE is preferred.
* If there are multiple graphics, VNC is preferred.
*/
public static void adjustDisplayData(BackendResource res, Vm vm, boolean nextRun) {
adjustDisplayData(res, vm, null, nextRun);
Expand All @@ -126,10 +126,10 @@ private static void adjustDisplayDataInternal(BackendResource backendResource, B
List<GraphicsType> graphicsTypes = getGraphicsTypesForEntity(backendResource,
new Guid(res.getId()), vmsGraphicsDevices, nextRun);

if (graphicsTypes.contains(GraphicsType.SPICE)) {
display.setType(DisplayType.SPICE);
} else if (graphicsTypes.contains(GraphicsType.VNC)) {
if (graphicsTypes.contains(GraphicsType.VNC)) {
display.setType(DisplayType.VNC);
} else if (graphicsTypes.contains(GraphicsType.SPICE)) {
display.setType(DisplayType.SPICE);
} else {
resetDisplay(res);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,54 @@ public static DisplayType map(GraphicsType graphicsType, DisplayType displayType
public static GraphicsType map(DisplayType displayType, GraphicsType graphicsType) {
switch (displayType) {
case SPICE:
case QXL:
return GraphicsType.SPICE;
case VNC:
case CIRRUS:
case VGA:
case BOCHS:
return GraphicsType.VNC;
default:
return null;
}
}

@Mapping(from = org.ovirt.engine.core.common.businessentities.DisplayType.class, to = DisplayType.class)
public static DisplayType mapDisplay(org.ovirt.engine.core.common.businessentities.DisplayType displayType, DisplayType disType) {
switch (displayType) {
case cirrus:
return DisplayType.CIRRUS;
case qxl:
return DisplayType.QXL;
case vga:
return DisplayType.VGA;
case bochs:
return DisplayType.BOCHS;
case none:
return DisplayType.NONE;
default:
return null;
}
}

@Mapping(from = DisplayType.class, to = org.ovirt.engine.core.common.businessentities.DisplayType.class)
public static org.ovirt.engine.core.common.businessentities.DisplayType mapDisplay(DisplayType displayType, org.ovirt.engine.core.common.businessentities.DisplayType disType) {
switch (displayType) {
case CIRRUS:
return org.ovirt.engine.core.common.businessentities.DisplayType.cirrus;
case QXL:
return org.ovirt.engine.core.common.businessentities.DisplayType.qxl;
case VGA:
return org.ovirt.engine.core.common.businessentities.DisplayType.vga;
case BOCHS:
return org.ovirt.engine.core.common.businessentities.DisplayType.bochs;
case NONE:
return org.ovirt.engine.core.common.businessentities.DisplayType.none;
default:
return null;
}
}

@Mapping(from = VmTemplate.class, to = Display.class)
public static Display map(VmTemplate vmTemplate, Display display) {
Display result = (display == null)
Expand Down Expand Up @@ -74,34 +114,21 @@ public static void fillDisplayInParams(Vm vm, RunVmOnceParams params) {
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:
case bochs:
graphics.add(GraphicsType.VNC);
break;
}
params.setRunOnceGraphics(graphics);
Set<GraphicsType> graphics = new HashSet<>();
switch (displayType) {
case SPICE:
case QXL:
graphics.add(GraphicsType.SPICE);
break;
case VNC:
case VGA:
case CIRRUS:
case BOCHS:
graphics.add(GraphicsType.VNC);
break;
}
params.setRunOnceGraphics(graphics);
}
}
}

@Mapping(from = DisplayType.class, to = org.ovirt.engine.core.common.businessentities.DisplayType.class)
public static org.ovirt.engine.core.common.businessentities.DisplayType mapDisplayType(DisplayType type, org.ovirt.engine.core.common.businessentities.DisplayType incoming) {
switch (type) {
case VNC:
return org.ovirt.engine.core.common.businessentities.DisplayType.vga;
case SPICE:
return org.ovirt.engine.core.common.businessentities.DisplayType.qxl;
default:
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected static void mapCommonModelToEntity(org.ovirt.engine.core.common.busine
}
if (model.isSetDisplay()) {
if (model.getDisplay().isSetType()) {
entity.setDefaultDisplayType(null); // let backend decide which video device to use
entity.setDefaultDisplayType(DisplayMapper.mapDisplay(model.getDisplay().getType(), null));
}
if (model.getDisplay().isSetMonitors()) {
entity.setNumOfMonitors(model.getDisplay().getMonitors());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,9 @@ public static Vm map(org.ovirt.engine.core.common.businessentities.VM entity, Vm
model.setRunOnce(entity.isRunOnce());
org.ovirt.engine.core.common.businessentities.GraphicsType graphicsType = deriveGraphicsType(entity.getGraphicsInfos());
if (graphicsType != null) {
model.getDisplay().setType(DisplayMapper.map(graphicsType, null));
if (!model.getDisplay().isSetType()) {
model.getDisplay().setType(DisplayMapper.map(graphicsType, null));
}

GraphicsInfo graphicsInfo = entity.getGraphicsInfos().get(graphicsType);
model.getDisplay().setAddress(graphicsInfo == null ? null : graphicsInfo.getIp());
Expand Down

0 comments on commit 9dbe9b1

Please sign in to comment.