|
86 | 86 | import org.apache.cloudstack.storage.command.DettachCommand; |
87 | 87 | import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; |
88 | 88 | import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; |
| 89 | +import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao; |
| 90 | +import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO; |
89 | 91 |
|
90 | 92 | import com.cloud.agent.AgentManager; |
91 | 93 | import com.cloud.agent.api.Answer; |
|
273 | 275 | import com.cloud.vm.dao.UserVmDao; |
274 | 276 | import com.cloud.vm.dao.UserVmDetailsDao; |
275 | 277 | import com.cloud.vm.dao.VMInstanceDao; |
276 | | -import com.cloud.vm.snapshot.VMSnapshot; |
277 | 278 | import com.cloud.vm.snapshot.VMSnapshotManager; |
278 | 279 | import com.cloud.vm.snapshot.VMSnapshotVO; |
279 | 280 | import com.cloud.vm.snapshot.dao.VMSnapshotDao; |
@@ -817,6 +818,12 @@ public UserVm upgradeVirtualMachine(UpgradeVMCmd cmd) throws ResourceAllocationE |
817 | 818 | + "; make sure the virtual machine is stopped"); |
818 | 819 | } |
819 | 820 |
|
| 821 | + // If target VM has associated VM snapshots then don't allow upgrading of VM |
| 822 | + List<VMSnapshotVO> vmSnapshots = _vmSnapshotDao.findByVm(vmId); |
| 823 | + if (vmSnapshots.size() > 0) { |
| 824 | + throw new InvalidParameterValueException("Unable to change service offering for VM, please remove VM snapshots before changing service offering of VM"); |
| 825 | + } |
| 826 | + |
820 | 827 | _accountMgr.checkAccess(caller, null, true, vmInstance); |
821 | 828 |
|
822 | 829 | // Check resource limits for CPU and Memory. |
@@ -844,19 +851,6 @@ public UserVm upgradeVirtualMachine(UpgradeVMCmd cmd) throws ResourceAllocationE |
844 | 851 | // Check that the specified service offering ID is valid |
845 | 852 | _itMgr.checkIfCanUpgrade(vmInstance, newServiceOffering); |
846 | 853 |
|
847 | | - // remove diskAndMemory VM snapshots |
848 | | - List<VMSnapshotVO> vmSnapshots = _vmSnapshotDao.findByVm(vmId); |
849 | | - for (VMSnapshotVO vmSnapshotVO : vmSnapshots) { |
850 | | - if (vmSnapshotVO.getType() == VMSnapshot.Type.DiskAndMemory) { |
851 | | - if (!_vmSnapshotMgr.deleteAllVMSnapshots(vmId, VMSnapshot.Type.DiskAndMemory)) { |
852 | | - String errMsg = "Failed to remove VM snapshot during upgrading, snapshot id " + vmSnapshotVO.getId(); |
853 | | - s_logger.debug(errMsg); |
854 | | - throw new CloudRuntimeException(errMsg); |
855 | | - } |
856 | | - |
857 | | - } |
858 | | - } |
859 | | - |
860 | 854 | _itMgr.upgradeVmDb(vmId, svcOffId); |
861 | 855 | if (newServiceOffering.isDynamic()) { |
862 | 856 | //save the custom values to the database. |
@@ -957,19 +951,6 @@ private UserVm upgradeStoppedVirtualMachine(Long vmId, Long svcOffId, Map<String |
957 | 951 | // Check that the specified service offering ID is valid |
958 | 952 | _itMgr.checkIfCanUpgrade(vmInstance, newServiceOffering); |
959 | 953 |
|
960 | | - // remove diskAndMemory VM snapshots |
961 | | - List<VMSnapshotVO> vmSnapshots = _vmSnapshotDao.findByVm(vmId); |
962 | | - for (VMSnapshotVO vmSnapshotVO : vmSnapshots) { |
963 | | - if (vmSnapshotVO.getType() == VMSnapshot.Type.DiskAndMemory) { |
964 | | - if (!_vmSnapshotMgr.deleteAllVMSnapshots(vmId, VMSnapshot.Type.DiskAndMemory)) { |
965 | | - String errMsg = "Failed to remove VM snapshot during upgrading, snapshot id " + vmSnapshotVO.getId(); |
966 | | - s_logger.debug(errMsg); |
967 | | - throw new CloudRuntimeException(errMsg); |
968 | | - } |
969 | | - |
970 | | - } |
971 | | - } |
972 | | - |
973 | 954 | _itMgr.upgradeVmDb(vmId, svcOffId); |
974 | 955 | if (newServiceOffering.isDynamic()) { |
975 | 956 | //save the custom values to the database. |
@@ -1007,6 +988,12 @@ public UserVm addNicToVirtualMachine(AddNicToVMCmd cmd) throws InvalidParameterV |
1007 | 988 | if (vmInstance == null) { |
1008 | 989 | throw new InvalidParameterValueException("unable to find a virtual machine with id " + vmId); |
1009 | 990 | } |
| 991 | + |
| 992 | + // Check that Vm does not have VM Snapshots |
| 993 | + if (_vmSnapshotDao.findByVm(vmId).size() > 0) { |
| 994 | + throw new InvalidParameterValueException("NIC cannot be added to VM with VM Snapshots"); |
| 995 | + } |
| 996 | + |
1010 | 997 | NetworkVO network = _networkDao.findById(networkId); |
1011 | 998 | if (network == null) { |
1012 | 999 | throw new InvalidParameterValueException("unable to find a network with id " + networkId); |
@@ -1091,6 +1078,12 @@ public UserVm removeNicFromVirtualMachine(RemoveNicFromVMCmd cmd) throws Invalid |
1091 | 1078 | if (vmInstance == null) { |
1092 | 1079 | throw new InvalidParameterValueException("Unable to find a virtual machine with id " + vmId); |
1093 | 1080 | } |
| 1081 | + |
| 1082 | + // Check that Vm does not have VM Snapshots |
| 1083 | + if (_vmSnapshotDao.findByVm(vmId).size() > 0) { |
| 1084 | + throw new InvalidParameterValueException("NIC cannot be removed from VM with VM Snapshots"); |
| 1085 | + } |
| 1086 | + |
1094 | 1087 | NicVO nic = _nicDao.findById(nicId); |
1095 | 1088 | if (nic == null) { |
1096 | 1089 | throw new InvalidParameterValueException("Unable to find a nic with id " + nicId); |
@@ -1157,6 +1150,12 @@ public UserVm updateDefaultNicForVirtualMachine(UpdateDefaultNicForVMCmd cmd) th |
1157 | 1150 | if (vmInstance == null) { |
1158 | 1151 | throw new InvalidParameterValueException("unable to find a virtual machine with id " + vmId); |
1159 | 1152 | } |
| 1153 | + |
| 1154 | + // Check that Vm does not have VM Snapshots |
| 1155 | + if (_vmSnapshotDao.findByVm(vmId).size() > 0) { |
| 1156 | + throw new InvalidParameterValueException("NIC cannot be updated for VM with VM Snapshots"); |
| 1157 | + } |
| 1158 | + |
1160 | 1159 | NicVO nic = _nicDao.findById(nicId); |
1161 | 1160 | if (nic == null) { |
1162 | 1161 | throw new InvalidParameterValueException("unable to find a nic with id " + nicId); |
@@ -1329,6 +1328,14 @@ public boolean upgradeVirtualMachine(Long vmId, Long newServiceOfferingId, Map<S |
1329 | 1328 | // Verify input parameters |
1330 | 1329 | VMInstanceVO vmInstance = _vmInstanceDao.findById(vmId); |
1331 | 1330 |
|
| 1331 | + if (vmInstance != null) { |
| 1332 | + // If target VM has associated VM snapshots then don't allow upgrading of VM |
| 1333 | + List<VMSnapshotVO> vmSnapshots = _vmSnapshotDao.findByVm(vmId); |
| 1334 | + if (vmSnapshots.size() > 0) { |
| 1335 | + throw new InvalidParameterValueException("Unable to scale VM, please remove VM snapshots before scaling VM"); |
| 1336 | + } |
| 1337 | + } |
| 1338 | + |
1332 | 1339 | if (vmInstance.getState().equals(State.Stopped)) { |
1333 | 1340 | upgradeStoppedVirtualMachine(vmId, newServiceOfferingId, customParameters); |
1334 | 1341 | return true; |
@@ -3830,6 +3837,11 @@ public VirtualMachine vmStorageMigration(Long vmId, StoragePool destPool) { |
3830 | 3837 | throw new InvalidParameterValueException("Data disks attached to the vm, can not migrate. Need to dettach data disks at first"); |
3831 | 3838 | } |
3832 | 3839 |
|
| 3840 | + // Check that Vm does not have VM Snapshots |
| 3841 | + if (_vmSnapshotDao.findByVm(vmId).size() > 0) { |
| 3842 | + throw new InvalidParameterValueException("VM's disk cannot be migrated, please remove all the VM Snapshots for this VM"); |
| 3843 | + } |
| 3844 | + |
3833 | 3845 | HypervisorType destHypervisorType = destPool.getHypervisor(); |
3834 | 3846 | if (destHypervisorType == null) { |
3835 | 3847 | destHypervisorType = _clusterDao.findById( |
@@ -4248,6 +4260,11 @@ public VirtualMachine migrateVirtualMachineWithVolume(Long vmId, Host destinatio |
4248 | 4260 | + destinationHost.getResourceState()); |
4249 | 4261 | } |
4250 | 4262 |
|
| 4263 | + // Check that Vm does not have VM Snapshots |
| 4264 | + if (_vmSnapshotDao.findByVm(vmId).size() > 0) { |
| 4265 | + throw new InvalidParameterValueException("VM with VM Snapshots cannot be migrated with storage, please remove all VM snapshots"); |
| 4266 | + } |
| 4267 | + |
4251 | 4268 | List<VolumeVO> vmVolumes = _volsDao.findUsableVolumesForInstance(vm.getId()); |
4252 | 4269 | Map<Long, Long> volToPoolObjectMap = new HashMap<Long, Long>(); |
4253 | 4270 | if (!isVMUsingLocalStorage(vm) && destinationHost.getClusterId().equals(srcHost.getClusterId())) { |
@@ -4714,8 +4731,8 @@ public UserVm restoreVMInternal(Account caller, UserVmVO vm, Long newTemplateId) |
4714 | 4731 |
|
4715 | 4732 | // If target VM has associated VM snapshots then don't allow restore of VM |
4716 | 4733 | List<VMSnapshotVO> vmSnapshots = _vmSnapshotDao.findByVm(vmId); |
4717 | | - if (vmSnapshots.size() > 0 && vm.getHypervisorType() == HypervisorType.VMware) { |
4718 | | - throw new InvalidParameterValueException("Unable to restore VM, please specify a VM that does not have VM snapshots"); |
| 4734 | + if (vmSnapshots.size() > 0) { |
| 4735 | + throw new InvalidParameterValueException("Unable to restore VM, please remove VM snapshots before restoring VM"); |
4719 | 4736 | } |
4720 | 4737 |
|
4721 | 4738 | VMTemplateVO template = null; |
|
0 commit comments