|
60 | 60 | import javax.xml.parsers.DocumentBuilder; |
61 | 61 | import javax.xml.parsers.ParserConfigurationException; |
62 | 62 |
|
| 63 | +import com.cloud.storage.SnapshotPolicyVO; |
| 64 | +import com.cloud.storage.dao.SnapshotPolicyDao; |
63 | 65 | import org.apache.cloudstack.acl.ControlledEntity; |
64 | 66 | import org.apache.cloudstack.acl.ControlledEntity.ACLType; |
65 | 67 | import org.apache.cloudstack.acl.SecurityChecker.AccessType; |
|
103 | 105 | import org.apache.cloudstack.api.command.user.volume.ChangeOfferingForVolumeCmd; |
104 | 106 | import org.apache.cloudstack.api.command.user.volume.ResizeVolumeCmd; |
105 | 107 | import org.apache.cloudstack.backup.BackupManager; |
| 108 | +import org.apache.cloudstack.backup.BackupScheduleVO; |
106 | 109 | import org.apache.cloudstack.backup.BackupVO; |
107 | 110 | import org.apache.cloudstack.backup.dao.BackupDao; |
| 111 | +import org.apache.cloudstack.backup.dao.BackupScheduleDao; |
108 | 112 | import org.apache.cloudstack.context.CallContext; |
109 | 113 | import org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntity; |
110 | 114 | import org.apache.cloudstack.engine.cloud.entity.api.db.dao.VMNetworkMapDao; |
@@ -607,6 +611,10 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir |
607 | 611 | ReservationDao reservationDao; |
608 | 612 | @Inject |
609 | 613 | ResourceLimitService resourceLimitService; |
| 614 | + @Inject |
| 615 | + SnapshotPolicyDao snapshotPolicyDao; |
| 616 | + @Inject |
| 617 | + BackupScheduleDao backupScheduleDao; |
610 | 618 |
|
611 | 619 | @Inject |
612 | 620 | private StatsCollector statsCollector; |
@@ -8043,6 +8051,9 @@ protected void executeStepsToChangeOwnershipOfVm(AssignVMCmd cmd, Account caller |
8043 | 8051 |
|
8044 | 8052 | updateVolumesOwner(volumes, oldAccount, newAccount, newAccountId); |
8045 | 8053 |
|
| 8054 | + updateSnapshotPolicyOwnership(volumes, newAccount); |
| 8055 | + updateBackupScheduleOwnership(vm, newAccount); |
| 8056 | + |
8046 | 8057 | try { |
8047 | 8058 | updateVmNetwork(cmd, caller, vm, newAccount, template); |
8048 | 8059 | } catch (InsufficientCapacityException | ResourceAllocationException e) { |
@@ -8517,6 +8528,36 @@ protected void addAdditionalNetworksToVm(UserVmVO vm, Account newAccount, List<L |
8517 | 8528 | } |
8518 | 8529 | } |
8519 | 8530 |
|
| 8531 | + protected void updateSnapshotPolicyOwnership(List<VolumeVO> volumes, Account newAccount) { |
| 8532 | + logger.debug("Updating snapshot policy ownership for volumes of VM being assigned to account [{}]", newAccount); |
| 8533 | + |
| 8534 | + for (VolumeVO volume : volumes) { |
| 8535 | + List<SnapshotPolicyVO> snapshotPolicies = snapshotPolicyDao.listByVolumeId(volume.getId()); |
| 8536 | + for (SnapshotPolicyVO policy : snapshotPolicies) { |
| 8537 | + logger.trace("Updating snapshot policy [{}] ownership from account [{}] to account [{}]", |
| 8538 | + policy.getId(), policy.getAccountId(), newAccount.getAccountId()); |
| 8539 | + |
| 8540 | + policy.setAccountId(newAccount.getAccountId()); |
| 8541 | + policy.setDomainId(newAccount.getDomainId()); |
| 8542 | + snapshotPolicyDao.update(policy.getId(), policy); |
| 8543 | + } |
| 8544 | + } |
| 8545 | + } |
| 8546 | + |
| 8547 | + protected void updateBackupScheduleOwnership(UserVmVO vm, Account newAccount) { |
| 8548 | + logger.debug("Updating backup schedule ownership for VM [{}] being assigned to account [{}]", vm, newAccount); |
| 8549 | + |
| 8550 | + List<BackupScheduleVO> backupSchedules = backupScheduleDao.listByVM(vm.getId()); |
| 8551 | + for (BackupScheduleVO schedule : backupSchedules) { |
| 8552 | + logger.trace("Updating backup schedule [{}] ownership from account [{}] to account [{}]", |
| 8553 | + schedule.getId(), schedule.getAccountId(), newAccount.getAccountId()); |
| 8554 | + |
| 8555 | + schedule.setAccountId(newAccount.getAccountId()); |
| 8556 | + schedule.setDomainId(newAccount.getDomainId()); |
| 8557 | + backupScheduleDao.update(schedule.getId(), schedule); |
| 8558 | + } |
| 8559 | + } |
| 8560 | + |
8520 | 8561 | /** |
8521 | 8562 | * Attempts to create a network suitable for the creation of a VM ({@link NetworkOrchestrationService#createGuestNetwork}). |
8522 | 8563 | * If no physical network is found, throws a {@link InvalidParameterValueException}. |
|
0 commit comments