Skip to content

Commit 656ae10

Browse files
committed
CLOUDSTACK-9211: Support passing vRAM size to support 3D GPU on Vmware
1 parent ee2ccc4 commit 656ae10

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
import com.vmware.vim25.VirtualMachineRelocateSpec;
9595
import com.vmware.vim25.VirtualMachineRelocateSpecDiskLocator;
9696
import com.vmware.vim25.VirtualMachineRuntimeInfo;
97+
import com.vmware.vim25.VirtualMachineVideoCard;
9798
import com.vmware.vim25.VmwareDistributedVirtualSwitchVlanIdSpec;
9899

99100
import org.apache.cloudstack.storage.command.StorageSubSystemCommand;
@@ -1895,6 +1896,9 @@ protected StartAnswer execute(StartCommand cmd) {
18951896

18961897
postDiskConfigBeforeStart(vmMo, vmSpec, sortedDisks, ideControllerKey, scsiControllerKey, iqnToPath, hyperHost, context);
18971898

1899+
//Sets video card memory to the one provided in detail svga.vramSize (if provided), 64MB was always set before
1900+
postVideoCardMemoryConfigBeforeStart(vmMo, vmSpec);
1901+
18981902
//
18991903
// Power-on VM
19001904
//
@@ -1943,6 +1947,44 @@ protected StartAnswer execute(StartCommand cmd) {
19431947
}
19441948
}
19451949

1950+
private void postVideoCardMemoryConfigBeforeStart(VirtualMachineMO vmMo, VirtualMachineTO vmSpec) {
1951+
String paramVRamSize = "svga.vramSize";
1952+
if (vmSpec.getDetails().containsKey(paramVRamSize)){
1953+
String value = vmSpec.getDetails().get(paramVRamSize);
1954+
try {
1955+
long svgaVmramSize = Long.parseLong(value);
1956+
for (VirtualDevice device : vmMo.getAllDeviceList()){
1957+
if (device instanceof VirtualMachineVideoCard){
1958+
VirtualMachineVideoCard videoCard = (VirtualMachineVideoCard) device;
1959+
if (videoCard.getVideoRamSizeInKB().longValue() != svgaVmramSize){
1960+
s_logger.info("Video card memory was set " + videoCard.getVideoRamSizeInKB().longValue() + "kb instead of " + svgaVmramSize + "kb");
1961+
videoCard.setVideoRamSizeInKB(svgaVmramSize);
1962+
videoCard.setUseAutoDetect(false);
1963+
1964+
VirtualDeviceConfigSpec arrayVideoCardConfigSpecs = new VirtualDeviceConfigSpec();
1965+
arrayVideoCardConfigSpecs.setDevice(videoCard);
1966+
arrayVideoCardConfigSpecs.setOperation(VirtualDeviceConfigSpecOperation.EDIT);
1967+
1968+
VirtualMachineConfigSpec changeVideoCardSpecs = new VirtualMachineConfigSpec();
1969+
changeVideoCardSpecs.getDeviceChange().add(arrayVideoCardConfigSpecs);
1970+
1971+
boolean res = vmMo.configureVm(changeVideoCardSpecs);
1972+
if (res) {
1973+
s_logger.info("Video card memory successfully updated to " + svgaVmramSize + "kb");
1974+
}
1975+
}
1976+
}
1977+
}
1978+
}
1979+
catch (NumberFormatException e){
1980+
s_logger.error("Unexpected value, cannot parse " + value + " to long due to: " + e.getMessage());
1981+
}
1982+
catch (Exception e){
1983+
s_logger.error("Error while reconfiguring vm due to: " + e.getMessage());
1984+
}
1985+
}
1986+
}
1987+
19461988
private void tearDownVm(VirtualMachineMO vmMo) throws Exception{
19471989

19481990
if(vmMo == null) return;

0 commit comments

Comments
 (0)