bug 8493: Check for resource limit for manual snapshots.

This commit is contained in:
nit 2011-02-09 19:01:10 +05:30
parent 77719be46a
commit 82506ff8d0
2 changed files with 9 additions and 2 deletions

2
api/src/com/cloud/api/commands/CreateSnapshotCmd.java Normal file → Executable file
View File

@ -53,7 +53,7 @@ public class CreateSnapshotCmd extends BaseAsyncCreateCmd {
@Parameter(name=ApiConstants.VOLUME_ID, type=CommandType.LONG, required=true, description="The ID of the disk volume")
private Long volumeId;
@Parameter(name=ApiConstants.POLICY_ID, type=CommandType.LONG, description="polocy id of the snapshot, if this is null, then use MANUAL_POLICY.")
@Parameter(name=ApiConstants.POLICY_ID, type=CommandType.LONG, description="policy id of the snapshot, if this is null, then use MANUAL_POLICY.")
private Long policyId;
/////////////////////////////////////////////////////

View File

@ -234,7 +234,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
}
@Override
public SnapshotVO createSnapshotOnPrimary(VolumeVO volume, Long policyId, Long snapshotId) throws ResourceAllocationException {
public SnapshotVO createSnapshotOnPrimary(VolumeVO volume, Long policyId, Long snapshotId) {
SnapshotVO snapshot = _snapshotDao.findById(snapshotId);
if ( snapshot == null ) {
throw new CloudRuntimeException("Can not find snapshot " + snapshotId);
@ -323,6 +323,13 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
@Override @DB
public SnapshotVO createSnapshotImpl(Long volumeId, Long policyId, Long snapshotId) throws ResourceAllocationException {
VolumeVO v = _volsDao.findById(volumeId);
AccountVO account = _accountDao.findById(v.getAccountId());
if (_accountMgr.resourceLimitExceeded(account, ResourceType.snapshot)) {
ResourceAllocationException rae = new ResourceAllocationException("Maximum number of snapshots for account: " + account.getAccountName() + " has been exceeded.");
rae.setResourceType("snapshot");
throw rae;
}
if ( v != null && _volsDao.getHypervisorType(v.getId()).equals(HypervisorType.KVM)) {
/*KVM needs to lock on the vm of volume, because it takes snapshot on behalf of vm, not volume*/
UserVmVO uservm = _vmDao.findById(v.getInstanceId());