Add snapshotName parameter in CreateSnapshotCmd

This commit is contained in:
Wei Zhou 2014-12-04 15:29:39 +01:00
parent 4608053ed7
commit fc1a09ff49
6 changed files with 29 additions and 8 deletions

View File

@ -80,7 +80,7 @@ public interface VolumeApiService {
Snapshot takeSnapshot(Long volumeId, Long policyId, Long snapshotId, Account account, boolean quiescevm) throws ResourceAllocationException; Snapshot takeSnapshot(Long volumeId, Long policyId, Long snapshotId, Account account, boolean quiescevm) throws ResourceAllocationException;
Snapshot allocSnapshot(Long volumeId, Long policyId) throws ResourceAllocationException; Snapshot allocSnapshot(Long volumeId, Long policyId, String snapshotName) throws ResourceAllocationException;
Volume updateVolume(long volumeId, String path, String state, Long storageId, Boolean displayVolume, String customId, long owner, String chainInfo); Volume updateVolume(long volumeId, String path, String state, Long storageId, Boolean displayVolume, String customId, long owner, String chainInfo);

View File

@ -86,7 +86,7 @@ public interface SnapshotApiService {
boolean deleteSnapshotPolicies(DeleteSnapshotPoliciesCmd cmd); boolean deleteSnapshotPolicies(DeleteSnapshotPoliciesCmd cmd);
Snapshot allocSnapshot(Long volumeId, Long policyId) throws ResourceAllocationException; Snapshot allocSnapshot(Long volumeId, Long policyId, String snapshotName) throws ResourceAllocationException;
/** /**
* Create a snapshot of a volume * Create a snapshot of a volume

View File

@ -74,6 +74,9 @@ public class CreateSnapshotCmd extends BaseAsyncCreateCmd {
@Parameter(name = ApiConstants.SNAPSHOT_QUIESCEVM, type = CommandType.BOOLEAN, required = false, description = "quiesce vm if true") @Parameter(name = ApiConstants.SNAPSHOT_QUIESCEVM, type = CommandType.BOOLEAN, required = false, description = "quiesce vm if true")
private Boolean quiescevm; private Boolean quiescevm;
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "the name of the snapshot")
private String snapshotName;
private String syncObjectType = BaseAsyncCmd.snapshotHostSyncObject; private String syncObjectType = BaseAsyncCmd.snapshotHostSyncObject;
// /////////////////////////////////////////////////// // ///////////////////////////////////////////////////
@ -100,6 +103,10 @@ public class CreateSnapshotCmd extends BaseAsyncCreateCmd {
return volumeId; return volumeId;
} }
public String getSnapshotName() {
return snapshotName;
}
public Long getPolicyId() { public Long getPolicyId() {
if (policyId != null) { if (policyId != null) {
return policyId; return policyId;
@ -169,7 +176,7 @@ public class CreateSnapshotCmd extends BaseAsyncCreateCmd {
@Override @Override
public void create() throws ResourceAllocationException { public void create() throws ResourceAllocationException {
Snapshot snapshot = _volumeService.allocSnapshot(getVolumeId(), getPolicyId()); Snapshot snapshot = _volumeService.allocSnapshot(getVolumeId(), getPolicyId(), getSnapshotName());
if (snapshot != null) { if (snapshot != null) {
setEntityId(snapshot.getId()); setEntityId(snapshot.getId());
setEntityUuid(snapshot.getUuid()); setEntityUuid(snapshot.getUuid());

View File

@ -1929,7 +1929,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
@Override @Override
@ActionEvent(eventType = EventTypes.EVENT_SNAPSHOT_CREATE, eventDescription = "allocating snapshot", create = true) @ActionEvent(eventType = EventTypes.EVENT_SNAPSHOT_CREATE, eventDescription = "allocating snapshot", create = true)
public Snapshot allocSnapshot(Long volumeId, Long policyId) throws ResourceAllocationException { public Snapshot allocSnapshot(Long volumeId, Long policyId, String snapshotName) throws ResourceAllocationException {
Account caller = CallContext.current().getCallingAccount(); Account caller = CallContext.current().getCallingAccount();
VolumeInfo volume = volFactory.getVolume(volumeId); VolumeInfo volume = volFactory.getVolume(volumeId);
@ -1972,7 +1972,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
throw new InvalidParameterValueException("VolumeId: " + volumeId + " please attach this volume to a VM before create snapshot for it"); throw new InvalidParameterValueException("VolumeId: " + volumeId + " please attach this volume to a VM before create snapshot for it");
} }
return snapshotMgr.allocSnapshot(volumeId, policyId); return snapshotMgr.allocSnapshot(volumeId, policyId, snapshotName);
} }
@Override @Override

View File

@ -1092,7 +1092,7 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
} }
@Override @Override
public Snapshot allocSnapshot(Long volumeId, Long policyId) throws ResourceAllocationException { public Snapshot allocSnapshot(Long volumeId, Long policyId, String snapshotName) throws ResourceAllocationException {
Account caller = CallContext.current().getCallingAccount(); Account caller = CallContext.current().getCallingAccount();
VolumeInfo volume = volFactory.getVolume(volumeId); VolumeInfo volume = volFactory.getVolume(volumeId);
supportedByHypervisor(volume); supportedByHypervisor(volume);
@ -1125,7 +1125,8 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
if (vmInstance != null) { if (vmInstance != null) {
vmDisplayName = vmInstance.getHostName(); vmDisplayName = vmInstance.getHostName();
} }
String snapshotName = vmDisplayName + "_" + volume.getName() + "_" + timeString; if (snapshotName == null)
snapshotName = vmDisplayName + "_" + volume.getName() + "_" + timeString;
HypervisorType hypervisorType = HypervisorType.None; HypervisorType hypervisorType = HypervisorType.None;
StoragePoolVO storagePool = _storagePoolDao.findById(volume.getDataStore().getId()); StoragePoolVO storagePool = _storagePoolDao.findById(volume.getDataStore().getId());

View File

@ -597,12 +597,25 @@
else else
return true; return true;
} }
},
name: {
label: 'label.name',
} }
} }
}, },
action: function(args) { action: function(args) {
var data = {
volumeId: args.context.volumes[0].id,
quiescevm: (args.data.quiescevm == 'on' ? true: false)
};
if (args.data.name != null && args.data.name.length > 0) {
$.extend(data, {
name: args.data.name
});
}
$.ajax({ $.ajax({
url: createURL("createSnapshot&volumeid=" + args.context.volumes[0].id + "&quiescevm=" + (args.data.quiescevm=='on')), url: createURL("createSnapshot"),
data: data,
dataType: "json", dataType: "json",
async: true, async: true,
success: function(json) { success: function(json) {