|
35 | 35 | import javax.inject.Inject; |
36 | 36 | import javax.naming.ConfigurationException; |
37 | 37 |
|
38 | | -import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao; |
39 | | -import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO; |
40 | 38 | import org.apache.commons.codec.binary.Base64; |
41 | 39 | import org.apache.log4j.Logger; |
42 | 40 |
|
|
89 | 87 | import org.apache.cloudstack.storage.command.DettachCommand; |
90 | 88 | import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; |
91 | 89 | import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; |
| 90 | +import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao; |
| 91 | +import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO; |
92 | 92 |
|
93 | 93 | import com.cloud.agent.AgentManager; |
94 | 94 | import com.cloud.agent.api.Answer; |
|
276 | 276 | import com.cloud.vm.dao.UserVmDao; |
277 | 277 | import com.cloud.vm.dao.UserVmDetailsDao; |
278 | 278 | import com.cloud.vm.dao.VMInstanceDao; |
279 | | -import com.cloud.vm.snapshot.VMSnapshot; |
280 | 279 | import com.cloud.vm.snapshot.VMSnapshotManager; |
281 | 280 | import com.cloud.vm.snapshot.VMSnapshotVO; |
282 | 281 | import com.cloud.vm.snapshot.dao.VMSnapshotDao; |
@@ -822,6 +821,12 @@ public UserVm upgradeVirtualMachine(UpgradeVMCmd cmd) throws ResourceAllocationE |
822 | 821 | + "; make sure the virtual machine is stopped"); |
823 | 822 | } |
824 | 823 |
|
| 824 | + // If target VM has associated VM snapshots then don't allow upgrading of VM |
| 825 | + List<VMSnapshotVO> vmSnapshots = _vmSnapshotDao.findByVm(vmId); |
| 826 | + if (vmSnapshots.size() > 0) { |
| 827 | + throw new InvalidParameterValueException("Unable to change service offering for VM, please remove VM snapshots before changing service offering of VM"); |
| 828 | + } |
| 829 | + |
825 | 830 | _accountMgr.checkAccess(caller, null, true, vmInstance); |
826 | 831 |
|
827 | 832 | // Check resource limits for CPU and Memory. |
@@ -849,19 +854,6 @@ public UserVm upgradeVirtualMachine(UpgradeVMCmd cmd) throws ResourceAllocationE |
849 | 854 | // Check that the specified service offering ID is valid |
850 | 855 | _itMgr.checkIfCanUpgrade(vmInstance, newServiceOffering); |
851 | 856 |
|
852 | | - // remove diskAndMemory VM snapshots |
853 | | - List<VMSnapshotVO> vmSnapshots = _vmSnapshotDao.findByVm(vmId); |
854 | | - for (VMSnapshotVO vmSnapshotVO : vmSnapshots) { |
855 | | - if (vmSnapshotVO.getType() == VMSnapshot.Type.DiskAndMemory) { |
856 | | - if (!_vmSnapshotMgr.deleteAllVMSnapshots(vmId, VMSnapshot.Type.DiskAndMemory)) { |
857 | | - String errMsg = "Failed to remove VM snapshot during upgrading, snapshot id " + vmSnapshotVO.getId(); |
858 | | - s_logger.debug(errMsg); |
859 | | - throw new CloudRuntimeException(errMsg); |
860 | | - } |
861 | | - |
862 | | - } |
863 | | - } |
864 | | - |
865 | 857 | _itMgr.upgradeVmDb(vmId, svcOffId); |
866 | 858 | if (newServiceOffering.isDynamic()) { |
867 | 859 | //save the custom values to the database. |
@@ -962,19 +954,6 @@ private UserVm upgradeStoppedVirtualMachine(Long vmId, Long svcOffId, Map<String |
962 | 954 | // Check that the specified service offering ID is valid |
963 | 955 | _itMgr.checkIfCanUpgrade(vmInstance, newServiceOffering); |
964 | 956 |
|
965 | | - // remove diskAndMemory VM snapshots |
966 | | - List<VMSnapshotVO> vmSnapshots = _vmSnapshotDao.findByVm(vmId); |
967 | | - for (VMSnapshotVO vmSnapshotVO : vmSnapshots) { |
968 | | - if (vmSnapshotVO.getType() == VMSnapshot.Type.DiskAndMemory) { |
969 | | - if (!_vmSnapshotMgr.deleteAllVMSnapshots(vmId, VMSnapshot.Type.DiskAndMemory)) { |
970 | | - String errMsg = "Failed to remove VM snapshot during upgrading, snapshot id " + vmSnapshotVO.getId(); |
971 | | - s_logger.debug(errMsg); |
972 | | - throw new CloudRuntimeException(errMsg); |
973 | | - } |
974 | | - |
975 | | - } |
976 | | - } |
977 | | - |
978 | 957 | _itMgr.upgradeVmDb(vmId, svcOffId); |
979 | 958 | if (newServiceOffering.isDynamic()) { |
980 | 959 | //save the custom values to the database. |
@@ -1012,6 +991,12 @@ public UserVm addNicToVirtualMachine(AddNicToVMCmd cmd) throws InvalidParameterV |
1012 | 991 | if (vmInstance == null) { |
1013 | 992 | throw new InvalidParameterValueException("unable to find a virtual machine with id " + vmId); |
1014 | 993 | } |
| 994 | + |
| 995 | + // Check that Vm does not have VM Snapshots |
| 996 | + if (_vmSnapshotDao.findByVm(vmId).size() > 0) { |
| 997 | + throw new InvalidParameterValueException("NIC cannot be added to VM with VM Snapshots"); |
| 998 | + } |
| 999 | + |
1015 | 1000 | NetworkVO network = _networkDao.findById(networkId); |
1016 | 1001 | if (network == null) { |
1017 | 1002 | throw new InvalidParameterValueException("unable to find a network with id " + networkId); |
@@ -1096,6 +1081,12 @@ public UserVm removeNicFromVirtualMachine(RemoveNicFromVMCmd cmd) throws Invalid |
1096 | 1081 | if (vmInstance == null) { |
1097 | 1082 | throw new InvalidParameterValueException("unable to find a virtual machine with id " + vmId); |
1098 | 1083 | } |
| 1084 | + |
| 1085 | + // Check that Vm does not have VM Snapshots |
| 1086 | + if (_vmSnapshotDao.findByVm(vmId).size() > 0) { |
| 1087 | + throw new InvalidParameterValueException("NIC cannot be removed from VM with VM Snapshots"); |
| 1088 | + } |
| 1089 | + |
1099 | 1090 | NicVO nic = _nicDao.findById(nicId); |
1100 | 1091 | if (nic == null) { |
1101 | 1092 | throw new InvalidParameterValueException("unable to find a nic with id " + nicId); |
@@ -1153,6 +1144,12 @@ public UserVm updateDefaultNicForVirtualMachine(UpdateDefaultNicForVMCmd cmd) th |
1153 | 1144 | if (vmInstance == null) { |
1154 | 1145 | throw new InvalidParameterValueException("unable to find a virtual machine with id " + vmId); |
1155 | 1146 | } |
| 1147 | + |
| 1148 | + // Check that Vm does not have VM Snapshots |
| 1149 | + if (_vmSnapshotDao.findByVm(vmId).size() > 0) { |
| 1150 | + throw new InvalidParameterValueException("NIC cannot be updated for VM with VM Snapshots"); |
| 1151 | + } |
| 1152 | + |
1156 | 1153 | NicVO nic = _nicDao.findById(nicId); |
1157 | 1154 | if (nic == null) { |
1158 | 1155 | throw new InvalidParameterValueException("unable to find a nic with id " + nicId); |
@@ -1325,6 +1322,14 @@ public boolean upgradeVirtualMachine(Long vmId, Long newServiceOfferingId, Map<S |
1325 | 1322 | // Verify input parameters |
1326 | 1323 | VMInstanceVO vmInstance = _vmInstanceDao.findById(vmId); |
1327 | 1324 |
|
| 1325 | + if (vmInstance != null) { |
| 1326 | + // If target VM has associated VM snapshots then don't allow upgrading of VM |
| 1327 | + List<VMSnapshotVO> vmSnapshots = _vmSnapshotDao.findByVm(vmId); |
| 1328 | + if (vmSnapshots.size() > 0) { |
| 1329 | + throw new InvalidParameterValueException("Unable to scale VM, please remove VM snapshots before scaling VM"); |
| 1330 | + } |
| 1331 | + } |
| 1332 | + |
1328 | 1333 | if (vmInstance.getState().equals(State.Stopped)) { |
1329 | 1334 | upgradeStoppedVirtualMachine(vmId, newServiceOfferingId, customParameters); |
1330 | 1335 | return true; |
@@ -3813,6 +3818,11 @@ public VirtualMachine vmStorageMigration(Long vmId, StoragePool destPool) { |
3813 | 3818 | throw new InvalidParameterValueException("Data disks attached to the vm, can not migrate. Need to dettach data disks at first"); |
3814 | 3819 | } |
3815 | 3820 |
|
| 3821 | + // Check that Vm does not have VM Snapshots |
| 3822 | + if (_vmSnapshotDao.findByVm(vmId).size() > 0) { |
| 3823 | + throw new InvalidParameterValueException("VM's disk cannot be migrated, please remove all the VM Snapshots for this VM"); |
| 3824 | + } |
| 3825 | + |
3816 | 3826 | HypervisorType destHypervisorType = destPool.getHypervisor(); |
3817 | 3827 | if (destHypervisorType == null) { |
3818 | 3828 | destHypervisorType = _clusterDao.findById( |
@@ -4231,6 +4241,11 @@ public VirtualMachine migrateVirtualMachineWithVolume(Long vmId, Host destinatio |
4231 | 4241 | + destinationHost.getResourceState()); |
4232 | 4242 | } |
4233 | 4243 |
|
| 4244 | + // Check that Vm does not have VM Snapshots |
| 4245 | + if (_vmSnapshotDao.findByVm(vmId).size() > 0) { |
| 4246 | + throw new InvalidParameterValueException("VM with VM Snapshots cannot be migrated with storage, please remove all VM snapshots"); |
| 4247 | + } |
| 4248 | + |
4234 | 4249 | List<VolumeVO> vmVolumes = _volsDao.findUsableVolumesForInstance(vm.getId()); |
4235 | 4250 | Map<Long, Long> volToPoolObjectMap = new HashMap<Long, Long>(); |
4236 | 4251 | if (!isVMUsingLocalStorage(vm) && destinationHost.getClusterId().equals(srcHost.getClusterId())) { |
@@ -4697,8 +4712,8 @@ public UserVm restoreVMInternal(Account caller, UserVmVO vm, Long newTemplateId) |
4697 | 4712 |
|
4698 | 4713 | // If target VM has associated VM snapshots then don't allow restore of VM |
4699 | 4714 | List<VMSnapshotVO> vmSnapshots = _vmSnapshotDao.findByVm(vmId); |
4700 | | - if (vmSnapshots.size() > 0 && vm.getHypervisorType() == HypervisorType.VMware) { |
4701 | | - throw new InvalidParameterValueException("Unable to restore VM, please specify a VM that does not have VM snapshots"); |
| 4715 | + if (vmSnapshots.size() > 0) { |
| 4716 | + throw new InvalidParameterValueException("Unable to restore VM, please remove VM snapshots before restoring VM"); |
4702 | 4717 | } |
4703 | 4718 |
|
4704 | 4719 | VMTemplateVO template = null; |
|
0 commit comments