Fix NPE when using baremetal template

Template size is NULL for baremetal, which caused NPE when unboxing
This commit is contained in:
Sheng Yang 2013-06-21 17:15:50 -07:00
parent 64c5266ec5
commit db97bb8e89
1 changed files with 6 additions and 1 deletions

View File

@ -2450,7 +2450,12 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use
// check if account/domain is with in resource limits to create a new vm
boolean isIso = Storage.ImageFormat.ISO == template.getFormat();
long size = _templateDao.findById(template.getId()).getSize();
// For baremetal, size can be null
Long tmp = _templateDao.findById(template.getId()).getSize();
long size = 0;
if (tmp != null) {
size = tmp;
}
if (diskOfferingId != null) {
size += _diskOfferingDao.findById(diskOfferingId).getDiskSize();
}