From 18a243e1d6a1e428e855ea254478baacc96732ee Mon Sep 17 00:00:00 2001 From: Nitin Date: Mon, 7 Nov 2011 18:30:24 +0530 Subject: [PATCH] bug 11428: Under VMware with current version, for snapshot related related operations, 1) if snapshot is originally created from root volume, allow only CreateTemplateCommand from snapshot 2) if snapshot is originally created from data volume, allow only CreateVolumeCommand from snapshot Reviewed by - Kishan status 11428: resolved fixed --- server/src/com/cloud/storage/StorageManagerImpl.java | 7 +++++++ server/src/com/cloud/vm/UserVmManagerImpl.java | 10 +++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index af160abdf48..cdc431eb7a0 100755 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -109,6 +109,7 @@ import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceInUseException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.exception.StorageUnavailableException; +import com.cloud.exception.UnsupportedServiceException; import com.cloud.host.Host; import com.cloud.host.HostVO; import com.cloud.host.Status; @@ -1712,6 +1713,12 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag throw new InvalidParameterValueException("unable to find a snapshot with id " + snapshotId + " for this account"); } } + + // bug #11428. Operation not supported if vmware and snapshots parent volume = ROOT + if(snapshotCheck.getHypervisorType() == HypervisorType.VMware + && ApiDBUtils.findVolumeById(snapshotCheck.getVolumeId()).getVolumeType() == Type.ROOT){ + throw new UnsupportedServiceException("operation not supported, snapshot with id " + snapshotId + " is created from ROOT volume"); + } } // Verify that zone exists diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index ae85cb91c94..ce0427dffcf 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -105,6 +105,7 @@ import com.cloud.exception.PermissionDeniedException; import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.exception.StorageUnavailableException; +import com.cloud.exception.UnsupportedServiceException; import com.cloud.exception.VirtualMachineMigrationException; import com.cloud.ha.HighAvailabilityManager; import com.cloud.host.Host; @@ -1394,6 +1395,8 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager hyperType = _volsDao.getHypervisorType(volumeId); } else { // create template from snapshot SnapshotVO snapshot = _snapshotDao.findById(snapshotId); + volume = _volsDao.findById(snapshot.getVolumeId()); + if (snapshot == null) { throw new InvalidParameterValueException("Failed to create private template record, unable to find snapshot " + snapshotId); } @@ -1401,11 +1404,16 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager if (snapshot.getStatus() != Snapshot.Status.BackedUp) { throw new InvalidParameterValueException("Snapshot id=" + snapshotId + " is not in " + Snapshot.Status.BackedUp + " state yet and can't be used for template creation"); } + + // bug #11428. Operation not supported if vmware and snapshots parent volume = ROOT + if(snapshot.getHypervisorType() == HypervisorType.VMware && volume.getVolumeType() == Type.DATADISK){ + throw new UnsupportedServiceException("operation not supported, snapshot with id " + snapshotId + " is created from Data Disk"); + } domainId = snapshot.getDomainId(); accountId = snapshot.getAccountId(); hyperType = snapshot.getHypervisorType(); - volume = _volsDao.findById(snapshot.getVolumeId()); + } if (!isAdmin) {