You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by nv...@apache.org on 2021/08/19 14:56:58 UTC

[cloudstack] branch main updated: Allow users to update volume name (#4618)

This is an automated email from the ASF dual-hosted git repository.

nvazquez pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/main by this push:
     new ee01522  Allow users to update volume name (#4618)
ee01522 is described below

commit ee01522d3fb3cb241a7882afeeec3ef2f65459f1
Author: Rakesh <ra...@gmail.com>
AuthorDate: Thu Aug 19 16:56:35 2021 +0200

    Allow users to update volume name (#4618)
    
    Provide an api support to update volume name by all users
---
 .../java/com/cloud/storage/VolumeApiService.java   |  2 +-
 .../api/command/user/volume/UpdateVolumeCmd.java   | 23 +++++++++++++++++-----
 .../com/cloud/storage/VolumeApiServiceImpl.java    | 14 ++++++++++++-
 ui/src/config/section/storage.js                   | 15 ++++++++++++++
 4 files changed, 47 insertions(+), 7 deletions(-)

diff --git a/api/src/main/java/com/cloud/storage/VolumeApiService.java b/api/src/main/java/com/cloud/storage/VolumeApiService.java
index 5c41301..6087ece 100644
--- a/api/src/main/java/com/cloud/storage/VolumeApiService.java
+++ b/api/src/main/java/com/cloud/storage/VolumeApiService.java
@@ -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.
diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/UpdateVolumeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/UpdateVolumeCmd.java
index 71fb576..345221e 100644
--- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/UpdateVolumeCmd.java
+++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/UpdateVolumeCmd.java
@@ -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());
diff --git a/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java b/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java
index 019af67..2c38bbf 100644
--- a/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java
+++ b/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java
@@ -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);
diff --git a/ui/src/config/section/storage.js b/ui/src/config/section/storage.js
index f22d702..3eb50b6 100644
--- a/ui/src/config/section/storage.js
+++ b/ui/src/config/section/storage.js
@@ -116,6 +116,21 @@ export default {
           }
         },
         {
+          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',
           docHelp: 'adminguide/storage.html#working-with-volume-snapshots',