Skip to content

Commit

Permalink
[KVM] Add MV Settings for virtual GPU hardware type and memory (#5513)
Browse files Browse the repository at this point in the history
* KVM: Add MV Settings for virtual GPU hardware type and memory

* fix method createVideoDef argument in test package

* add available options for KVM virtual GPU hardware VM setting

* fix videoRam default value

* fix _videoRam is 0, it will use default provided by libvirt
  • Loading branch information
leolleeooleo committed Oct 4, 2021
1 parent 669ab73 commit 72a1c0e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
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(VmDetailConstants.VIDEO_HARDWARE)) {
videoHw = details.get(VmDetailConstants.VIDEO_HARDWARE);
}
if (details.containsKey(VmDetailConstants.VIDEO_RAM)) {
String value = details.get(VmDetailConstants.VIDEO_RAM);
videoRam = NumbersUtil.parseInt(value, videoRam);
}
}
return new VideoDef(videoHw, videoRam);
}

protected RngDef createRngDef() {
Expand Down
Expand Up @@ -1624,9 +1624,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

0 comments on commit 72a1c0e

Please sign in to comment.