server: Fix null pointer exception in restore VM (#8930)

This commit is contained in:
Vishesh 2024-04-22 22:51:16 +05:30 committed by GitHub
parent 21182dabcd
commit c081f60427
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 1 deletions

View File

@ -7699,8 +7699,19 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
}
_accountMgr.checkAccess(caller, null, true, vm);
VMTemplateVO template;
if (newTemplateId != null) {
template = _templateDao.findById(newTemplateId);
if (template == null) {
throw new InvalidParameterValueException("Cannot find template with ID " + newTemplateId);
}
} else {
template = _templateDao.findById(vm.getTemplateId());
if (template == null) {
throw new InvalidParameterValueException("Cannot find template linked with VM");
}
}
DiskOffering diskOffering = rootDiskOfferingId != null ? validateAndGetDiskOffering(rootDiskOfferingId, vm, caller) : null;
VMTemplateVO template = _templateDao.findById(newTemplateId);
if (template.getSize() != null) {
String rootDiskSize = details.get(VmDetailConstants.ROOT_DISK_SIZE);
Long templateSize = template.getSize();