Skip to content

Commit fc1a09f

Browse files
committed
Add snapshotName parameter in CreateSnapshotCmd
1 parent 4608053 commit fc1a09f

6 files changed

Lines changed: 29 additions & 8 deletions

File tree

api/src/com/cloud/storage/VolumeApiService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public interface VolumeApiService {
8080

8181
Snapshot takeSnapshot(Long volumeId, Long policyId, Long snapshotId, Account account, boolean quiescevm) throws ResourceAllocationException;
8282

83-
Snapshot allocSnapshot(Long volumeId, Long policyId) throws ResourceAllocationException;
83+
Snapshot allocSnapshot(Long volumeId, Long policyId, String snapshotName) throws ResourceAllocationException;
8484

8585
Volume updateVolume(long volumeId, String path, String state, Long storageId, Boolean displayVolume, String customId, long owner, String chainInfo);
8686

api/src/com/cloud/storage/snapshot/SnapshotApiService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public interface SnapshotApiService {
8686

8787
boolean deleteSnapshotPolicies(DeleteSnapshotPoliciesCmd cmd);
8888

89-
Snapshot allocSnapshot(Long volumeId, Long policyId) throws ResourceAllocationException;
89+
Snapshot allocSnapshot(Long volumeId, Long policyId, String snapshotName) throws ResourceAllocationException;
9090

9191
/**
9292
* Create a snapshot of a volume

api/src/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotCmd.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ public class CreateSnapshotCmd extends BaseAsyncCreateCmd {
7474
@Parameter(name = ApiConstants.SNAPSHOT_QUIESCEVM, type = CommandType.BOOLEAN, required = false, description = "quiesce vm if true")
7575
private Boolean quiescevm;
7676

77+
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "the name of the snapshot")
78+
private String snapshotName;
79+
7780
private String syncObjectType = BaseAsyncCmd.snapshotHostSyncObject;
7881

7982
// ///////////////////////////////////////////////////
@@ -100,6 +103,10 @@ public Long getVolumeId() {
100103
return volumeId;
101104
}
102105

106+
public String getSnapshotName() {
107+
return snapshotName;
108+
}
109+
103110
public Long getPolicyId() {
104111
if (policyId != null) {
105112
return policyId;
@@ -169,7 +176,7 @@ public ApiCommandJobType getInstanceType() {
169176

170177
@Override
171178
public void create() throws ResourceAllocationException {
172-
Snapshot snapshot = _volumeService.allocSnapshot(getVolumeId(), getPolicyId());
179+
Snapshot snapshot = _volumeService.allocSnapshot(getVolumeId(), getPolicyId(), getSnapshotName());
173180
if (snapshot != null) {
174181
setEntityId(snapshot.getId());
175182
setEntityUuid(snapshot.getUuid());

server/src/com/cloud/storage/VolumeApiServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1929,7 +1929,7 @@ private Snapshot orchestrateTakeVolumeSnapshot(Long volumeId, Long policyId, Lon
19291929

19301930
@Override
19311931
@ActionEvent(eventType = EventTypes.EVENT_SNAPSHOT_CREATE, eventDescription = "allocating snapshot", create = true)
1932-
public Snapshot allocSnapshot(Long volumeId, Long policyId) throws ResourceAllocationException {
1932+
public Snapshot allocSnapshot(Long volumeId, Long policyId, String snapshotName) throws ResourceAllocationException {
19331933
Account caller = CallContext.current().getCallingAccount();
19341934

19351935
VolumeInfo volume = volFactory.getVolume(volumeId);
@@ -1972,7 +1972,7 @@ public Snapshot allocSnapshot(Long volumeId, Long policyId) throws ResourceAlloc
19721972
throw new InvalidParameterValueException("VolumeId: " + volumeId + " please attach this volume to a VM before create snapshot for it");
19731973
}
19741974

1975-
return snapshotMgr.allocSnapshot(volumeId, policyId);
1975+
return snapshotMgr.allocSnapshot(volumeId, policyId, snapshotName);
19761976
}
19771977

19781978
@Override

server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ public boolean canOperateOnVolume(Volume volume) {
10921092
}
10931093

10941094
@Override
1095-
public Snapshot allocSnapshot(Long volumeId, Long policyId) throws ResourceAllocationException {
1095+
public Snapshot allocSnapshot(Long volumeId, Long policyId, String snapshotName) throws ResourceAllocationException {
10961096
Account caller = CallContext.current().getCallingAccount();
10971097
VolumeInfo volume = volFactory.getVolume(volumeId);
10981098
supportedByHypervisor(volume);
@@ -1125,7 +1125,8 @@ public Snapshot allocSnapshot(Long volumeId, Long policyId) throws ResourceAlloc
11251125
if (vmInstance != null) {
11261126
vmDisplayName = vmInstance.getHostName();
11271127
}
1128-
String snapshotName = vmDisplayName + "_" + volume.getName() + "_" + timeString;
1128+
if (snapshotName == null)
1129+
snapshotName = vmDisplayName + "_" + volume.getName() + "_" + timeString;
11291130

11301131
HypervisorType hypervisorType = HypervisorType.None;
11311132
StoragePoolVO storagePool = _storagePoolDao.findById(volume.getDataStore().getId());

ui/scripts/storage.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,12 +597,25 @@
597597
else
598598
return true;
599599
}
600+
},
601+
name: {
602+
label: 'label.name',
600603
}
601604
}
602605
},
603606
action: function(args) {
607+
var data = {
608+
volumeId: args.context.volumes[0].id,
609+
quiescevm: (args.data.quiescevm == 'on' ? true: false)
610+
};
611+
if (args.data.name != null && args.data.name.length > 0) {
612+
$.extend(data, {
613+
name: args.data.name
614+
});
615+
}
604616
$.ajax({
605-
url: createURL("createSnapshot&volumeid=" + args.context.volumes[0].id + "&quiescevm=" + (args.data.quiescevm=='on')),
617+
url: createURL("createSnapshot"),
618+
data: data,
606619
dataType: "json",
607620
async: true,
608621
success: function(json) {

0 commit comments

Comments
 (0)