Fix restrictions on attach and restore VMs

This commit is contained in:
nvazquez 2020-10-08 14:48:20 -03:00 committed by Harikrishna Patnala
parent 3063b6cae5
commit dc4f913afa
2 changed files with 4 additions and 2 deletions

View File

@ -1501,8 +1501,9 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
UserVmVO vm = _userVmDao.findById(vmId);
VolumeVO exstingVolumeOfVm = null;
VMTemplateVO template = _templateDao.findById(vm.getTemplateId());
List<VolumeVO> rootVolumesOfVm = _volsDao.findByInstanceAndType(vmId, Volume.Type.ROOT);
if (rootVolumesOfVm.size() > 1) {
if (rootVolumesOfVm.size() > 1 && template != null && !template.isDeployAsIs()) {
throw new CloudRuntimeException("The VM " + vm.getHostName() + " has more than one ROOT volume and is in an invalid state.");
} else {
if (!rootVolumesOfVm.isEmpty()) {

View File

@ -6730,13 +6730,14 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
needRestart = true;
}
VMTemplateVO currentTemplate = _templateDao.findById(vm.getTemplateId());
List<VolumeVO> rootVols = _volsDao.findByInstanceAndType(vmId, Volume.Type.ROOT);
if (rootVols.isEmpty()) {
InvalidParameterValueException ex = new InvalidParameterValueException("Can not find root volume for VM " + vm.getUuid());
ex.addProxyObject(vm.getUuid(), "vmId");
throw ex;
}
if (rootVols.size() > 1) {
if (rootVols.size() > 1 && currentTemplate != null && !currentTemplate.isDeployAsIs()) {
InvalidParameterValueException ex = new InvalidParameterValueException("There are " + rootVols.size() + " root volumes for VM " + vm.getUuid());
ex.addProxyObject(vm.getUuid(), "vmId");
throw ex;