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

kvm: add VM Settings for virtual GPU hardware type and memory #5513

Merged
merged 8 commits into from Oct 4, 2021
4 changes: 4 additions & 0 deletions api/src/main/java/com/cloud/vm/VmDetailConstants.java
Expand Up @@ -40,6 +40,10 @@ public interface VmDetailConstants {
String KVM_VNC_PORT = "kvm.vnc.port";
String KVM_VNC_ADDRESS = "kvm.vnc.address";

// KVM specific, custom virtual GPU hardware
String VIDEO_HARDWARE = "video.hardware";
String VIDEO_RAM = "video.ram";

// Mac OSX guest specific (internal)
String SMC_PRESENT = "smc.present";
String FIRMWARE = "firmware";
Expand Down
Expand Up @@ -2427,7 +2427,7 @@ protected DevicesDef createDevicesDef(VirtualMachineTO vmTO, GuestDef guest, int

devices.addDevice(createChannelDef(vmTO));
devices.addDevice(createWatchDogDef());
devices.addDevice(createVideoDef());
devices.addDevice(createVideoDef(vmTO));
devices.addDevice(createConsoleDef());
devices.addDevice(createGraphicDef(vmTO));
devices.addDevice(createTabletInputDef());
Expand Down Expand Up @@ -2488,8 +2488,20 @@ protected ConsoleDef createConsoleDef() {
return new ConsoleDef(PTY, null, null, (short)0);
}

protected VideoDef createVideoDef() {
return new VideoDef(_videoHw, _videoRam);
protected VideoDef createVideoDef(VirtualMachineTO vmTO) {
Map<String, String> details = vmTO.getDetails();
String videoHw = _videoHw;
int videoRam = _videoRam;
if (details != null) {
if (details.containsKey(VideoDef.VIDEO_MODEL)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (details.containsKey(VideoDef.VIDEO_MODEL)) {
if (details.containsKey(VmDetailConstants.VIDEO_HARDWARE)) {

can use the same constants defined in VmDetailConstants.

videoHw = details.get(VideoDef.VIDEO_MODEL);
}
if (details.containsKey(VideoDef.VIDEO_RAM)) {
String value = details.get(VideoDef.VIDEO_RAM);
sureshanaparti marked this conversation as resolved.
Show resolved Hide resolved
videoRam = NumbersUtil.parseInt(value, videoRam);
}
}
return new VideoDef(videoHw, videoRam);
}

protected RngDef createRngDef() {
Expand Down
Expand Up @@ -1613,6 +1613,10 @@ public String toString() {
}

public static class VideoDef {

public static final String VIDEO_MODEL = "video.hardware";
public static final String VIDEO_RAM = "video.ram";
sureshanaparti marked this conversation as resolved.
Show resolved Hide resolved

private String _videoModel;
private int _videoRam;

Expand All @@ -1624,9 +1628,13 @@ public VideoDef(String videoModel, int videoRam) {
@Override
public String toString() {
StringBuilder videoBuilder = new StringBuilder();
if (_videoModel != null && !_videoModel.isEmpty() && _videoRam != 0){
if (_videoModel != null && !_videoModel.isEmpty()){
videoBuilder.append("<video>\n");
videoBuilder.append("<model type='" + _videoModel + "' vram='" + _videoRam + "'/>\n");
if (_videoRam != 0) {
videoBuilder.append("<model type='" + _videoModel + "' vram='" + _videoRam + "'/>\n");
} else {
videoBuilder.append("<model type='" + _videoModel + "'/>\n");
}
videoBuilder.append("</video>\n");
return videoBuilder.toString();
}
Expand Down
Expand Up @@ -627,7 +627,7 @@ public void testCreateVideoDef() {
libvirtComputingResourceSpy._videoRam = 200;
libvirtComputingResourceSpy._videoHw = "vGPU";

VideoDef videoDef = libvirtComputingResourceSpy.createVideoDef();
VideoDef videoDef = libvirtComputingResourceSpy.createVideoDef(to);
Document domainDoc = parse(videoDef.toString());
assertXpath(domainDoc, "/video/model/@type", "vGPU");
assertXpath(domainDoc, "/video/model/@vram", "200");
Expand Down
Expand Up @@ -3879,6 +3879,8 @@ private void fillVMOrTemplateDetailOptions(final Map<String, List<String>> optio

if (HypervisorType.KVM.equals(hypervisorType)) {
options.put(VmDetailConstants.ROOT_DISK_CONTROLLER, Arrays.asList("osdefault", "ide", "scsi", "virtio"));
options.put(VmDetailConstants.VIDEO_HARDWARE, Arrays.asList("cirrus", "vga", "qxl", "virtio"));
options.put(VmDetailConstants.VIDEO_RAM, Collections.emptyList());
}

if (HypervisorType.VMware.equals(hypervisorType)) {
Expand Down