|
94 | 94 | import com.vmware.vim25.VirtualMachineRelocateSpec; |
95 | 95 | import com.vmware.vim25.VirtualMachineRelocateSpecDiskLocator; |
96 | 96 | import com.vmware.vim25.VirtualMachineRuntimeInfo; |
| 97 | +import com.vmware.vim25.VirtualMachineVideoCard; |
97 | 98 | import com.vmware.vim25.VmwareDistributedVirtualSwitchVlanIdSpec; |
98 | 99 |
|
99 | 100 | import org.apache.cloudstack.storage.command.StorageSubSystemCommand; |
@@ -1895,6 +1896,9 @@ protected StartAnswer execute(StartCommand cmd) { |
1895 | 1896 |
|
1896 | 1897 | postDiskConfigBeforeStart(vmMo, vmSpec, sortedDisks, ideControllerKey, scsiControllerKey, iqnToPath, hyperHost, context); |
1897 | 1898 |
|
| 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 | + |
1898 | 1902 | // |
1899 | 1903 | // Power-on VM |
1900 | 1904 | // |
@@ -1943,6 +1947,44 @@ protected StartAnswer execute(StartCommand cmd) { |
1943 | 1947 | } |
1944 | 1948 | } |
1945 | 1949 |
|
| 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 | + |
1946 | 1988 | private void tearDownVm(VirtualMachineMO vmMo) throws Exception{ |
1947 | 1989 |
|
1948 | 1990 | if(vmMo == null) return; |
|
0 commit comments