Skip to content

Commit 1574f3a

Browse files
committed
Error out vm expunge from destroyvmCmd if it has a backup offering with backups.
1 parent 4997056 commit 1574f3a

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@
5757
import org.apache.cloudstack.api.command.admin.vm.MigrateVMCmd;
5858
import org.apache.cloudstack.api.command.admin.volume.MigrateVolumeCmdByAdmin;
5959
import org.apache.cloudstack.api.command.user.volume.MigrateVolumeCmd;
60+
import org.apache.cloudstack.backup.Backup;
6061
import org.apache.cloudstack.backup.BackupManager;
62+
import org.apache.cloudstack.backup.dao.BackupDao;
6163
import org.apache.cloudstack.ca.CAManager;
6264
import org.apache.cloudstack.context.CallContext;
6365
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
@@ -412,6 +414,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
412414
VmWorkJobDao vmWorkJobDao;
413415
@Inject
414416
BackupManager backupManager;
417+
@Inject
418+
BackupDao backupDao;
415419

416420
private SingleCache<List<Long>> vmIdsInProgressCache;
417421

@@ -2345,6 +2349,17 @@ public void doInTransactionWithoutResult(final TransactionStatus status) throws
23452349
throw new CloudRuntimeException("Unable to destroy " + vm);
23462350
} else {
23472351
if (expunge) {
2352+
if (vm.getBackupOfferingId() != null) {
2353+
List<Backup> backupsForVm = backupDao.listByVmId(vm.getDataCenterId(), vm.getId());
2354+
if (CollectionUtils.isEmpty(backupsForVm)) {
2355+
backupManager.removeVMFromBackupOffering(vm.getId(), true);
2356+
} else {
2357+
throw new CloudRuntimeException(String.format("This VM [uuid: %s, name: %s] has a "
2358+
+ "Backup Offering [id: %s, external id: %s] with %s backups. Please, remove the backup offering "
2359+
+ "before proceeding to VM exclusion!", vm.getUuid(), vm.getInstanceName(), vm.getBackupOfferingId(),
2360+
vm.getBackupExternalId(), backupsForVm.size()));
2361+
}
2362+
}
23482363
if (!stateTransitTo(vm, VirtualMachine.Event.ExpungeOperation, vm.getHostId())) {
23492364
logger.debug("Unable to expunge the vm because it is not in the correct state: {}", vm);
23502365
throw new CloudRuntimeException("Unable to expunge " + vm);

packaging/el8/cloud.spec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ Requires: ipset
115115
Requires: perl
116116
Requires: rsync
117117
Requires: cifs-utils
118-
Requires: ceph-common
119118
Requires: (python3-libvirt or python3-libvirt-python)
120119
Requires: (qemu-img or qemu-tools)
121120
Requires: qemu-kvm

0 commit comments

Comments
 (0)