@@ -1896,9 +1896,8 @@ protected StartAnswer execute(StartCommand cmd) {
18961896
18971897 postDiskConfigBeforeStart (vmMo , vmSpec , sortedDisks , ideControllerKey , scsiControllerKey , iqnToPath , hyperHost , context );
18981898
1899- //Sets video card memory to the one provided in detail svga.vramSize (if provided), 64MB was always set before
19001899 postVideoCardMemoryConfigBeforeStart (vmMo , vmSpec );
1901-
1900+
19021901 //
19031902 // Power-on VM
19041903 //
@@ -1947,42 +1946,57 @@ protected StartAnswer execute(StartCommand cmd) {
19471946 }
19481947 }
19491948
1949+ /**
1950+ * Sets video card memory to the one provided in detail svga.vramSize (if provided).
1951+ * 64MB was always set before.
1952+ * Size must be in KB.
1953+ * @param vmMo virtual machine mo
1954+ * @param vmSpec virtual machine specs
1955+ */
19501956 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- }
1957+ String paramVRamSize = "svga.vramSize" ;
1958+ if (vmSpec .getDetails ().containsKey (paramVRamSize )){
1959+ String value = vmSpec .getDetails ().get (paramVRamSize );
1960+ try {
1961+ long svgaVmramSize = Long .parseLong (value );
1962+ for (VirtualDevice device : vmMo .getAllDeviceList ()){
1963+ if (device instanceof VirtualMachineVideoCard ){
1964+ VirtualMachineVideoCard videoCard = (VirtualMachineVideoCard ) device ;
1965+ if (videoCard .getVideoRamSizeInKB ().longValue () != svgaVmramSize ){
1966+ s_logger .info ("Video card memory was set " + videoCard .getVideoRamSizeInKB ().longValue () + "kb instead of " + svgaVmramSize + "kb" );
1967+ boolean res = vmMo .configureVm (configSpecVideoCardNewVRamSize (videoCard , svgaVmramSize ));
1968+ if (res ) {
1969+ s_logger .info ("Video card memory successfully updated to " + svgaVmramSize + "kb" );
1970+ }
1971+ }
1972+ }
1973+ }
1974+ }
1975+ catch (NumberFormatException e ){
1976+ s_logger .error ("Unexpected value, cannot parse " + value + " to long due to: " + e .getMessage ());
1977+ }
1978+ catch (Exception e ){
1979+ s_logger .error ("Error while reconfiguring vm due to: " + e .getMessage ());
1980+ }
1981+ }
1982+ }
1983+
1984+ /**
1985+ * Returns a VirtualMachineConfigSpec to edit its svga vram size
1986+ * @param videoCard video card device to edit providing the svga vram size
1987+ * @param svgaVmramSize new svga vram size
1988+ */
1989+ private VirtualMachineConfigSpec configSpecVideoCardNewVRamSize (VirtualMachineVideoCard videoCard , long svgaVmramSize ){
1990+ videoCard .setVideoRamSizeInKB (svgaVmramSize );
1991+ videoCard .setUseAutoDetect (false );
1992+
1993+ VirtualDeviceConfigSpec arrayVideoCardConfigSpecs = new VirtualDeviceConfigSpec ();
1994+ arrayVideoCardConfigSpecs .setDevice (videoCard );
1995+ arrayVideoCardConfigSpecs .setOperation (VirtualDeviceConfigSpecOperation .EDIT );
1996+
1997+ VirtualMachineConfigSpec changeVideoCardSpecs = new VirtualMachineConfigSpec ();
1998+ changeVideoCardSpecs .getDeviceChange ().add (arrayVideoCardConfigSpecs );
1999+ return changeVideoCardSpecs ;
19862000 }
19872001
19882002 private void tearDownVm (VirtualMachineMO vmMo ) throws Exception {
0 commit comments