Skip to content

Commit 81c5afd

Browse files
committed
Allow users to update volume name
Provide an api support to update volume name by all users Can be done both through api and UI
1 parent 366785a commit 81c5afd

4 files changed

Lines changed: 57 additions & 7 deletions

File tree

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
@@ -1763,7 +1763,15 @@ public Volume attachVolumeToVM(Long vmId, Long volumeId, Long deviceId) {
17631763

17641764
@Override
17651765
@ActionEvent(eventType = EventTypes.EVENT_VOLUME_UPDATE, eventDescription = "updating volume", async = true)
1766-
public Volume updateVolume(long volumeId, String path, String state, Long storageId, Boolean displayVolume, String customId, long entityOwnerId, String chainInfo) {
1766+
public Volume updateVolume(long volumeId, String path, String state, Long storageId, Boolean displayVolume,
1767+
String customId, long entityOwnerId, String chainInfo, String name) {
1768+
1769+
Account caller = CallContext.current().getCallingAccount();
1770+
if (!_accountMgr.isRootAdmin(caller.getId())) {
1771+
if (path != null || state != null || storageId != null || displayVolume != null || customId != null || chainInfo != null) {
1772+
throw new InvalidParameterValueException("The domain admin and normal user are not allowed to update volume except volume name");
1773+
}
1774+
}
17671775

17681776
VolumeVO volume = _volsDao.findById(volumeId);
17691777

@@ -1806,6 +1814,10 @@ public Volume updateVolume(long volumeId, String path, String state, Long storag
18061814
volume.setUuid(customId);
18071815
}
18081816

1817+
if (name != null) {
1818+
volume.setName(name);
1819+
}
1820+
18091821
updateDisplay(volume, displayVolume);
18101822

18111823
_volsDao.update(volumeId, volume);

ui/legacy/scripts/storage.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,6 +1573,30 @@
15731573
}
15741574
},
15751575

1576+
edit: {
1577+
label: 'label.edit',
1578+
action: function(args) {
1579+
var data = {
1580+
id: args.context.volumes[0].id,
1581+
};
1582+
if (args.data.name != args.context.volumes[0].name) {
1583+
$.extend(data, {
1584+
name: args.data.name
1585+
});
1586+
}
1587+
$.ajax({
1588+
url: createURL('updateVolume'),
1589+
data: data,
1590+
success: function(json) {
1591+
var item = json.updatevolumeresponse.volume;
1592+
args.response.success({
1593+
data: item
1594+
});
1595+
}
1596+
});
1597+
}
1598+
},
1599+
15761600
resize: {
15771601
label: 'label.action.resize.volume',
15781602
messages: {
@@ -3181,6 +3205,7 @@
31813205
}
31823206
}
31833207

3208+
allowedActions.push("edit");
31843209
return allowedActions;
31853210
};
31863211

0 commit comments

Comments
 (0)