Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting all DisplayType's via API #857

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading