Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/src/main/java/com/cloud/storage/VolumeApiService.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Snapshot takeSnapshot(Long volumeId, Long policyId, Long snapshotId, Account acc

Snapshot allocSnapshot(Long volumeId, Long policyId, String snapshotName, Snapshot.LocationType locationType) 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, String name);

/**
* Extracts the volume to a particular location.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,33 @@ public class UpdateVolumeCmd extends BaseAsyncCustomIdCmd implements UserCmd {
@Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType=VolumeResponse.class, description="the ID of the disk volume")
private Long id;

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

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

@Parameter(name = ApiConstants.STORAGE_ID,
type = CommandType.UUID,
entityType = StoragePoolResponse.class,
description = "Destination storage pool UUID for the volume",
since = "4.3")
since = "4.3", authorized = {RoleType.Admin})
private Long storageId;

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

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

@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "new name of the volume", since = "4.16")
private String name;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
Expand Down Expand Up @@ -103,6 +106,11 @@ public Boolean getDisplayVolume() {
public String getChainInfo() {
return chainInfo;
}

public String getName() {
return name;
}

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
Expand Down Expand Up @@ -150,14 +158,19 @@ public String getEventDescription() {
if (getState() != null) {
desc.append(", state " + getState());
}

if (getName() != null) {
desc.append(", name " + getName());
}

return desc.toString();
}

@Override
public void execute() {
CallContext.current().setEventDetails("Volume Id: " + this._uuidMgr.getUuid(Volume.class, getId()));
Volume result = _volumeService.updateVolume(getId(), getPath(), getState(), getStorageId(), getDisplayVolume(),
getCustomId(), getEntityOwnerId(), getChainInfo());
getCustomId(), getEntityOwnerId(), getChainInfo(), getName());
if (result != null) {
VolumeResponse response = _responseGenerator.createVolumeResponse(getResponseView(), result);
response.setResponseName(getCommandName());
Expand Down
14 changes: 13 additions & 1 deletion server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1857,8 +1857,16 @@ public Volume attachVolumeToVM(Long vmId, Long volumeId, Long deviceId) {

@Override
@ActionEvent(eventType = EventTypes.EVENT_VOLUME_UPDATE, eventDescription = "updating volume", async = true)
public Volume updateVolume(long volumeId, String path, String state, Long storageId, Boolean displayVolume, String customId, long entityOwnerId, String chainInfo) {
public Volume updateVolume(long volumeId, String path, String state, Long storageId, Boolean displayVolume,
String customId, long entityOwnerId, String chainInfo, String name) {

Account caller = CallContext.current().getCallingAccount();
if (!_accountMgr.isRootAdmin(caller.getId())) {
if (path != null || state != null || storageId != null || displayVolume != null || customId != null || chainInfo != null) {
throw new InvalidParameterValueException("The domain admin and normal user are not allowed to update volume except volume name");
}
}

VolumeVO volume = _volsDao.findById(volumeId);

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

if (name != null) {
volume.setName(name);
}

updateDisplay(volume, displayVolume);

_volsDao.update(volumeId, volume);
Expand Down
15 changes: 15 additions & 0 deletions ui/src/config/section/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,21 @@ export default {
['Running', 'Stopped', 'Destroyed'].includes(record.vmstate)
}
},
{
api: 'updateVolume',
icon: 'edit',
label: 'label.edit',
dataView: true,
args: ['name'],
mapping: {
account: {
value: (record) => { return record.account }
},
domainid: {
value: (record) => { return record.domainid }
}
}
},
{
api: 'createSnapshot',
icon: 'camera',
Expand Down