Skip to content

Commit 2ccea13

Browse files
nathanejohnsonyadvr
authored andcommitted
CLOUDSTACK-10056: Fix vm details usage (#2248)
Fix bug where disk controller specified via vm details throws a NumberFormatException, since "scsi" is not a number.
1 parent c7a55eb commit 2ccea13

3 files changed

Lines changed: 14 additions & 4 deletions

File tree

api/src/com/cloud/vm/VmDetailConstants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@ public interface VmDetailConstants {
2424
public static final String HYPERVISOR_TOOLS_VERSION = "hypervisortoolsversion";
2525
public static final String DATA_DISK_CONTROLLER = "dataDiskController";
2626
public static final String SVGA_VRAM_SIZE = "svga.vramSize";
27+
public static final String CPU_NUMBER = "cpuNumber";
28+
public static final String CPU_SPEED = "cpuSpeed";
29+
public static final String MEMORY = "memory";
2730
}

server/src/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3619,8 +3619,14 @@ public UserVmVO doInTransaction(TransactionStatus status) throws InsufficientCap
36193619

36203620
_vmDao.persist(vm);
36213621
for (String key : customParameters.keySet()) {
3622-
//handle double byte strings.
3623-
vm.setDetail(key, Integer.toString(Integer.parseInt(customParameters.get(key))));
3622+
if( key.equalsIgnoreCase(VmDetailConstants.CPU_NUMBER) ||
3623+
key.equalsIgnoreCase(VmDetailConstants.CPU_SPEED) ||
3624+
key.equalsIgnoreCase(VmDetailConstants.MEMORY)) {
3625+
// handle double byte strings.
3626+
vm.setDetail(key, Integer.toString(Integer.parseInt(customParameters.get(key))));
3627+
} else {
3628+
vm.setDetail(key, customParameters.get(key));
3629+
}
36243630
}
36253631
vm.setDetail("deployvm", "true");
36263632
_vmDao.saveDetails(vm);
@@ -4587,7 +4593,7 @@ public UserVm createVirtualMachine(DeployVMCmd cmd) throws InsufficientCapacityE
45874593

45884594
if(!serviceOffering.isDynamic()) {
45894595
for(String detail: cmd.getDetails().keySet()) {
4590-
if(detail.equalsIgnoreCase("cpuNumber") || detail.equalsIgnoreCase("cpuSpeed") || detail.equalsIgnoreCase("memory")) {
4596+
if(detail.equalsIgnoreCase(VmDetailConstants.CPU_NUMBER) || detail.equalsIgnoreCase(VmDetailConstants.CPU_SPEED) || detail.equalsIgnoreCase(VmDetailConstants.MEMORY)) {
45914597
throw new InvalidParameterValueException("cpuNumber or cpuSpeed or memory should not be specified for static service offering");
45924598
}
45934599
}

server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
import com.cloud.vm.UserVmDetailVO;
103103
import com.cloud.vm.UserVmManager;
104104
import com.cloud.vm.UserVmVO;
105+
import com.cloud.vm.VmDetailConstants;
105106
import com.cloud.vm.VMInstanceVO;
106107
import com.cloud.vm.VirtualMachine;
107108
import com.cloud.vm.VirtualMachine.State;
@@ -413,7 +414,7 @@ protected void addSupportForCustomServiceOffering(long vmId, long serviceOfferin
413414
List<UserVmDetailVO> vmDetails = _userVmDetailsDao.listDetails(vmId);
414415
List<VMSnapshotDetailsVO> vmSnapshotDetails = new ArrayList<VMSnapshotDetailsVO>();
415416
for (UserVmDetailVO detail : vmDetails) {
416-
if(detail.getName().equalsIgnoreCase("cpuNumber") || detail.getName().equalsIgnoreCase("cpuSpeed") || detail.getName().equalsIgnoreCase("memory")) {
417+
if(detail.getName().equalsIgnoreCase(VmDetailConstants.CPU_NUMBER) || detail.getName().equalsIgnoreCase(VmDetailConstants.CPU_SPEED) || detail.getName().equalsIgnoreCase(VmDetailConstants.MEMORY)) {
417418
vmSnapshotDetails.add(new VMSnapshotDetailsVO(vmSnapshotId, detail.getName(), detail.getValue(), detail.isDisplay()));
418419
}
419420
}

0 commit comments

Comments
 (0)