Skip to content

Commit ee01522

Browse files
authored
Allow users to update volume name (#4618)
Provide an api support to update volume name by all users
1 parent d23a995 commit ee01522

File tree

4 files changed

+47
-7
lines changed

4 files changed

+47
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ Snapshot takeSnapshot(Long volumeId, Long policyId, Long snapshotId, Account acc
9999

100100
Snapshot allocSnapshot(Long volumeId, Long policyId, String snapshotName, Snapshot.LocationType locationType) throws ResourceAllocationException;
101101

102-
Volume updateVolume(long volumeId, String path, String state, Long storageId, Boolean displayVolume, String customId, long owner, String chainInfo);
102+
Volume updateVolume(long volumeId, String path, String state, Long storageId, Boolean displayVolume, String customId, long owner, String chainInfo, String name);
103103

104104
/**
105105
* Extracts the volume to a particular location.

api/src/main/java/org/apache/cloudstack/api/command/user/volume/UpdateVolumeCmd.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,30 +52,33 @@ public class UpdateVolumeCmd extends BaseAsyncCustomIdCmd implements UserCmd {
5252
@Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType=VolumeResponse.class, description="the ID of the disk volume")
5353
private Long id;
5454

55-
@Parameter(name = ApiConstants.PATH, type = CommandType.STRING, description = "The path of the volume")
55+
@Parameter(name = ApiConstants.PATH, type = CommandType.STRING, description = "The path of the volume", authorized = {RoleType.Admin})
5656
private String path;
5757

5858
@Parameter(name = ApiConstants.CHAIN_INFO,
5959
type = CommandType.STRING,
6060
description = "The chain info of the volume",
61-
since = "4.4")
61+
since = "4.4", authorized = {RoleType.Admin})
6262
private String chainInfo;
6363

6464
@Parameter(name = ApiConstants.STORAGE_ID,
6565
type = CommandType.UUID,
6666
entityType = StoragePoolResponse.class,
6767
description = "Destination storage pool UUID for the volume",
68-
since = "4.3")
68+
since = "4.3", authorized = {RoleType.Admin})
6969
private Long storageId;
7070

71-
@Parameter(name = ApiConstants.STATE, type = CommandType.STRING, description = "The state of the volume", since = "4.3")
71+
@Parameter(name = ApiConstants.STATE, type = CommandType.STRING, description = "The state of the volume", since = "4.3", authorized = {RoleType.Admin})
7272
private String state;
7373

7474
@Parameter(name = ApiConstants.DISPLAY_VOLUME,
7575
type = CommandType.BOOLEAN,
7676
description = "an optional field, whether to the display the volume to the end user or not.", authorized = {RoleType.Admin})
7777
private Boolean displayVolume;
7878

79+
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "new name of the volume", since = "4.16")
80+
private String name;
81+
7982
/////////////////////////////////////////////////////
8083
/////////////////// Accessors ///////////////////////
8184
/////////////////////////////////////////////////////
@@ -103,6 +106,11 @@ public Boolean getDisplayVolume() {
103106
public String getChainInfo() {
104107
return chainInfo;
105108
}
109+
110+
public String getName() {
111+
return name;
112+
}
113+
106114
/////////////////////////////////////////////////////
107115
/////////////// API Implementation///////////////////
108116
/////////////////////////////////////////////////////
@@ -150,14 +158,19 @@ public String getEventDescription() {
150158
if (getState() != null) {
151159
desc.append(", state " + getState());
152160
}
161+
162+
if (getName() != null) {
163+
desc.append(", name " + getName());
164+
}
165+
153166
return desc.toString();
154167
}
155168

156169
@Override
157170
public void execute() {
158171
CallContext.current().setEventDetails("Volume Id: " + this._uuidMgr.getUuid(Volume.class, getId()));
159172
Volume result = _volumeService.updateVolume(getId(), getPath(), getState(), getStorageId(), getDisplayVolume(),
160-
getCustomId(), getEntityOwnerId(), getChainInfo());
173+
getCustomId(), getEntityOwnerId(), getChainInfo(), getName());
161174
if (result != null) {
162175
VolumeResponse response = _responseGenerator.createVolumeResponse(getResponseView(), result);
163176
response.setResponseName(getCommandName());

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1857,8 +1857,16 @@ public Volume attachVolumeToVM(Long vmId, Long volumeId, Long deviceId) {
18571857

18581858
@Override
18591859
@ActionEvent(eventType = EventTypes.EVENT_VOLUME_UPDATE, eventDescription = "updating volume", async = true)
1860-
public Volume updateVolume(long volumeId, String path, String state, Long storageId, Boolean displayVolume, String customId, long entityOwnerId, String chainInfo) {
1860+
public Volume updateVolume(long volumeId, String path, String state, Long storageId, Boolean displayVolume,
1861+
String customId, long entityOwnerId, String chainInfo, String name) {
1862+
18611863
Account caller = CallContext.current().getCallingAccount();
1864+
if (!_accountMgr.isRootAdmin(caller.getId())) {
1865+
if (path != null || state != null || storageId != null || displayVolume != null || customId != null || chainInfo != null) {
1866+
throw new InvalidParameterValueException("The domain admin and normal user are not allowed to update volume except volume name");
1867+
}
1868+
}
1869+
18621870
VolumeVO volume = _volsDao.findById(volumeId);
18631871

18641872
if (volume == null) {
@@ -1903,6 +1911,10 @@ public Volume updateVolume(long volumeId, String path, String state, Long storag
19031911
volume.setUuid(customId);
19041912
}
19051913

1914+
if (name != null) {
1915+
volume.setName(name);
1916+
}
1917+
19061918
updateDisplay(volume, displayVolume);
19071919

19081920
_volsDao.update(volumeId, volume);

ui/src/config/section/storage.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,21 @@ export default {
115115
['Running', 'Stopped', 'Destroyed'].includes(record.vmstate)
116116
}
117117
},
118+
{
119+
api: 'updateVolume',
120+
icon: 'edit',
121+
label: 'label.edit',
122+
dataView: true,
123+
args: ['name'],
124+
mapping: {
125+
account: {
126+
value: (record) => { return record.account }
127+
},
128+
domainid: {
129+
value: (record) => { return record.domainid }
130+
}
131+
}
132+
},
118133
{
119134
api: 'createSnapshot',
120135
icon: 'camera',

0 commit comments

Comments
 (0)