Skip to content

Commit 4fcebfc

Browse files
committed
CLOUDSTACK-9211: Refactor vm vram size setter method
1 parent 448b43f commit 4fcebfc

File tree

1 file changed

+33
-13
lines changed

1 file changed

+33
-13
lines changed

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

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1959,18 +1959,7 @@ private void postVideoCardMemoryConfigBeforeStart(VirtualMachineMO vmMo, Virtual
19591959
String value = vmSpec.getDetails().get(paramVRamSize);
19601960
try {
19611961
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-
}
1962+
setNewVRamSizeVmVideoCard(vmMo, svgaVmramSize);
19741963
}
19751964
catch (NumberFormatException e){
19761965
s_logger.error("Unexpected value, cannot parse " + value + " to long due to: " + e.getMessage());
@@ -1981,10 +1970,41 @@ private void postVideoCardMemoryConfigBeforeStart(VirtualMachineMO vmMo, Virtual
19811970
}
19821971
}
19831972

1973+
/**
1974+
* Search for vm video card iterating through vm device list
1975+
* @param vmMo virtual machine mo
1976+
* @param svgaVmramSize new svga vram size (in KB)
1977+
*/
1978+
private void setNewVRamSizeVmVideoCard(VirtualMachineMO vmMo, long svgaVmramSize) throws Exception {
1979+
for (VirtualDevice device : vmMo.getAllDeviceList()){
1980+
if (device instanceof VirtualMachineVideoCard){
1981+
VirtualMachineVideoCard videoCard = (VirtualMachineVideoCard) device;
1982+
modifyVmVideoCardVRamSize(videoCard, vmMo, svgaVmramSize);
1983+
}
1984+
}
1985+
}
1986+
1987+
/**
1988+
* Modifies vm vram size if it was set to a different size to the one provided in svga.vramSize (user_vm_details or template_vm_details)
1989+
* @param videoCard vm's video card device
1990+
* @param vmMo virtual machine mo
1991+
* @param svgaVmramSize new svga vram size (in KB)
1992+
*/
1993+
private void modifyVmVideoCardVRamSize(VirtualMachineVideoCard videoCard, VirtualMachineMO vmMo, long svgaVmramSize) throws Exception {
1994+
if (videoCard.getVideoRamSizeInKB().longValue() != svgaVmramSize){
1995+
s_logger.info("Video card memory was set " + videoCard.getVideoRamSizeInKB().longValue() + "kb instead of " + svgaVmramSize + "kb");
1996+
VirtualMachineConfigSpec newSizeSpecs = configSpecVideoCardNewVRamSize(videoCard, svgaVmramSize);
1997+
boolean res = vmMo.configureVm(newSizeSpecs);
1998+
if (res) {
1999+
s_logger.info("Video card memory successfully updated to " + svgaVmramSize + "kb");
2000+
}
2001+
}
2002+
}
2003+
19842004
/**
19852005
* Returns a VirtualMachineConfigSpec to edit its svga vram size
19862006
* @param videoCard video card device to edit providing the svga vram size
1987-
* @param svgaVmramSize new svga vram size
2007+
* @param svgaVmramSize new svga vram size (in KB)
19882008
*/
19892009
private VirtualMachineConfigSpec configSpecVideoCardNewVRamSize(VirtualMachineVideoCard videoCard, long svgaVmramSize){
19902010
videoCard.setVideoRamSizeInKB(svgaVmramSize);

0 commit comments

Comments
 (0)