Block remove of VM which has backup offering (#5457)

Co-authored-by: SadiJr <sadi@scclouds.com.br>
This commit is contained in:
SadiJr 2022-02-17 05:17:53 -03:00 committed by GitHub
parent d82cd5569a
commit 478e24493e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 0 deletions

View File

@ -2364,6 +2364,11 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
List<Backup> backupsForVm = backupDao.listByVmId(vm.getDataCenterId(), vm.getId());
if (CollectionUtils.isEmpty(backupsForVm)) {
backupManager.removeVMFromBackupOffering(vm.getId(), true);
} else {
throw new CloudRuntimeException(String.format("This VM [uuid: %s, name: %s] has a "
+ "Backup Offering [id: %s, external id: %s] with %s backups. Please, remove the backup offering "
+ "before proceeding to VM exclusion!", vm.getUuid(), vm.getInstanceName(), vm.getBackupOfferingId(),
vm.getBackupExternalId(), backupsForVm.size()));
}
}