CLOUDSTACK-7962: VM Snaptshot should add check for root volume status also (cherry picked from commit 690a5ded358fe6f4d8671f497049f510d4894b1e) Signed-off-by: Rohit Yadav <[email protected]>
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/f88a34da Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/f88a34da Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/f88a34da Branch: refs/heads/4.5 Commit: f88a34dabe1f3a18cd508e31fdc1da8077866a27 Parents: b77cbea Author: Saksham Srivastava <[email protected]> Authored: Fri Nov 21 17:28:06 2014 +0530 Committer: Rohit Yadav <[email protected]> Committed: Tue Jan 20 11:29:59 2015 +0530 ---------------------------------------------------------------------- .../com/cloud/vm/snapshot/VMSnapshotManagerImpl.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f88a34da/server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java b/server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java index e7df088..0268727 100644 --- a/server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java +++ b/server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java @@ -29,7 +29,6 @@ import javax.naming.ConfigurationException; import org.apache.log4j.Logger; import org.springframework.stereotype.Component; - import org.apache.cloudstack.api.command.user.vmsnapshot.ListVMSnapshotCmd; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.engine.subsystem.api.storage.StorageStrategyFactory; @@ -62,6 +61,7 @@ import com.cloud.projects.Project.ListProjectResourcesCriteria; import com.cloud.service.dao.ServiceOfferingDetailsDao; import com.cloud.storage.Snapshot; import com.cloud.storage.SnapshotVO; +import com.cloud.storage.Volume.Type; import com.cloud.storage.VolumeVO; import com.cloud.storage.dao.GuestOSDao; import com.cloud.storage.dao.SnapshotDao; @@ -413,6 +413,17 @@ public class VMSnapshotManagerImpl extends ManagerBase implements VMSnapshotMana if (userVm == null) { throw new InvalidParameterValueException("Create vm to snapshot failed due to vm: " + vmId + " is not found"); } + + List<VolumeVO> volumeVos = _volumeDao.findByInstanceAndType(vmId, Type.ROOT); + if(volumeVos == null ||volumeVos.isEmpty()) { + throw new CloudRuntimeException("Create vm to snapshot failed due to no root disk found"); + } + + VolumeVO rootVolume = volumeVos.get(0); + if(!rootVolume.getState().equals(State.Running)) { + throw new CloudRuntimeException("Create vm to snapshot failed due to vm: " + vmId + " has root disk in " + rootVolume.getState() + " state"); + } + VMSnapshotVO vmSnapshot = _vmSnapshotDao.findById(vmSnapshotId); if (vmSnapshot == null) { throw new CloudRuntimeException("VM snapshot id: " + vmSnapshotId + " can not be found");
