Swift; create template from snapshot

This commit is contained in:
anthony 2011-10-21 17:32:48 -07:00
parent 3067a9d2db
commit 19df7ed8af
3 changed files with 18 additions and 12 deletions

View File

@ -20,6 +20,7 @@ package com.cloud.storage.snapshot;
import java.util.List;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.host.HostVO;
import com.cloud.storage.SnapshotPolicyVO;
import com.cloud.storage.SnapshotVO;
import com.cloud.storage.VolumeVO;
@ -131,6 +132,8 @@ public interface SnapshotManager {
void downloadSnapshotsFromSwift(SnapshotVO ss);
HostVO getSecondaryStorageHost(SnapshotVO snapshot);
String getSecondaryStorageURL(SnapshotVO snapshot);
void deleteSnapshotsForVolume (String secondaryStoragePoolUrl, Long dcId, Long accountId, Long volumeId );

View File

@ -811,17 +811,22 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
return true;
}
@Override
public String getSecondaryStorageURL(SnapshotVO snapshot) {
HostVO secHost = null;
@Override
public HostVO getSecondaryStorageHost(SnapshotVO snapshot) {
HostVO secHost = null;
if( snapshot.getSwiftId() == null ) {
secHost = _hostDao.findById(snapshot.getSecHostId());
} else {
Long dcId = snapshot.getDataCenterId();
secHost = _storageMgr.getSecondaryStorageHost(dcId);
}
return secHost;
}
@Override
public String getSecondaryStorageURL(SnapshotVO snapshot) {
HostVO secHost = getSecondaryStorageHost(snapshot);
if (secHost != null) {
return secHost.getStorageUrl();
}

View File

@ -1437,12 +1437,8 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
throw new CloudRuntimeException("Unable to find Snapshot for Id " + snapshotId);
}
zoneId = snapshot.getDataCenterId();
secondaryStorageHost = _hostDao.findById(snapshot.getSecHostId());
if (secondaryStorageHost == null) {
throw new CloudRuntimeException("Secondary storage " + snapshot.getSecHostId() + " doesn't exist");
}
secondaryStorageURL = secondaryStorageHost.getStorageUrl();
secondaryStorageHost = _snapshotMgr.getSecondaryStorageHost(snapshot);
secondaryStorageURL = _snapshotMgr.getSecondaryStorageURL(snapshot);
String name = command.getTemplateName();
String backupSnapshotUUID = snapshot.getBackupSnapshotId();
if (backupSnapshotUUID == null) {
@ -1600,10 +1596,12 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
Transaction txn = Transaction.currentTxn();
txn.start();
// Remove the template record
_templateDao.remove(templateId);
_templateDao.expunge(templateId);
// decrement resource count
_resourceLimitMgr.decrementResourceCount(accountId, ResourceType.template);
if (accountId != null) {
_resourceLimitMgr.decrementResourceCount(accountId, ResourceType.template);
}
txn.commit();
}
}