Allow users to update volume name (#4618)

Provide an api support to update volume name by all users
This commit is contained in:
Rakesh 2021-08-19 16:56:35 +02:00 committed by GitHub
parent d23a9954e8
commit ee01522d3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 7 deletions

View File

@ -99,7 +99,7 @@ public interface VolumeApiService {
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.

View File

@ -52,23 +52,23 @@ 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,
@ -76,6 +76,9 @@ public class UpdateVolumeCmd extends BaseAsyncCustomIdCmd implements UserCmd {
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 ///////////////////////
/////////////////////////////////////////////////////
@ -103,6 +106,11 @@ public class UpdateVolumeCmd extends BaseAsyncCustomIdCmd implements UserCmd {
public String getChainInfo() {
return chainInfo;
}
public String getName() {
return name;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@ -150,6 +158,11 @@ public class UpdateVolumeCmd extends BaseAsyncCustomIdCmd implements UserCmd {
if (getState() != null) {
desc.append(", state " + getState());
}
if (getName() != null) {
desc.append(", name " + getName());
}
return desc.toString();
}
@ -157,7 +170,7 @@ public class UpdateVolumeCmd extends BaseAsyncCustomIdCmd implements UserCmd {
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());

View File

@ -1857,8 +1857,16 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
@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) {
@ -1903,6 +1911,10 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
volume.setUuid(customId);
}
if (name != null) {
volume.setName(name);
}
updateDisplay(volume, displayVolume);
_volsDao.update(volumeId, volume);

View File

@ -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',