diff --git a/api/src/com/cloud/storage/VolumeApiService.java b/api/src/com/cloud/storage/VolumeApiService.java index 5487a4bf9b2..a9e02ecce6e 100644 --- a/api/src/com/cloud/storage/VolumeApiService.java +++ b/api/src/com/cloud/storage/VolumeApiService.java @@ -80,7 +80,7 @@ public interface VolumeApiService { 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); diff --git a/api/src/com/cloud/storage/snapshot/SnapshotApiService.java b/api/src/com/cloud/storage/snapshot/SnapshotApiService.java index 0300980edb6..a86ef37b452 100644 --- a/api/src/com/cloud/storage/snapshot/SnapshotApiService.java +++ b/api/src/com/cloud/storage/snapshot/SnapshotApiService.java @@ -86,7 +86,7 @@ public interface SnapshotApiService { 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 diff --git a/api/src/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotCmd.java b/api/src/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotCmd.java index df7fe8296bc..473730597bb 100644 --- a/api/src/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotCmd.java @@ -74,6 +74,9 @@ public class CreateSnapshotCmd extends BaseAsyncCreateCmd { @Parameter(name = ApiConstants.SNAPSHOT_QUIESCEVM, type = CommandType.BOOLEAN, required = false, description = "quiesce vm if true") private Boolean quiescevm; + @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "the name of the snapshot") + private String snapshotName; + private String syncObjectType = BaseAsyncCmd.snapshotHostSyncObject; // /////////////////////////////////////////////////// @@ -100,6 +103,10 @@ public class CreateSnapshotCmd extends BaseAsyncCreateCmd { return volumeId; } + public String getSnapshotName() { + return snapshotName; + } + public Long getPolicyId() { if (policyId != null) { return policyId; @@ -169,7 +176,7 @@ public class CreateSnapshotCmd extends BaseAsyncCreateCmd { @Override public void create() throws ResourceAllocationException { - Snapshot snapshot = _volumeService.allocSnapshot(getVolumeId(), getPolicyId()); + Snapshot snapshot = _volumeService.allocSnapshot(getVolumeId(), getPolicyId(), getSnapshotName()); if (snapshot != null) { setEntityId(snapshot.getId()); setEntityUuid(snapshot.getUuid()); diff --git a/server/src/com/cloud/storage/VolumeApiServiceImpl.java b/server/src/com/cloud/storage/VolumeApiServiceImpl.java index 4343c4b1376..9132f42921f 100644 --- a/server/src/com/cloud/storage/VolumeApiServiceImpl.java +++ b/server/src/com/cloud/storage/VolumeApiServiceImpl.java @@ -1929,7 +1929,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic @Override @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(); 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"); } - return snapshotMgr.allocSnapshot(volumeId, policyId); + return snapshotMgr.allocSnapshot(volumeId, policyId, snapshotName); } @Override diff --git a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java index 04a04891689..b224beb0902 100644 --- a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java +++ b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java @@ -1092,7 +1092,7 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager, } @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(); VolumeInfo volume = volFactory.getVolume(volumeId); supportedByHypervisor(volume); @@ -1125,7 +1125,8 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager, if (vmInstance != null) { vmDisplayName = vmInstance.getHostName(); } - String snapshotName = vmDisplayName + "_" + volume.getName() + "_" + timeString; + if (snapshotName == null) + snapshotName = vmDisplayName + "_" + volume.getName() + "_" + timeString; HypervisorType hypervisorType = HypervisorType.None; StoragePoolVO storagePool = _storagePoolDao.findById(volume.getDataStore().getId()); diff --git a/ui/scripts/storage.js b/ui/scripts/storage.js index 31562660f90..57f8640ee0b 100644 --- a/ui/scripts/storage.js +++ b/ui/scripts/storage.js @@ -597,12 +597,25 @@ else return true; } + }, + name: { + label: 'label.name', } } }, 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({ - url: createURL("createSnapshot&volumeid=" + args.context.volumes[0].id + "&quiescevm=" + (args.data.quiescevm=='on')), + url: createURL("createSnapshot"), + data: data, dataType: "json", async: true, success: function(json) {