Skip to content

Commit 8b09620

Browse files
rafaelweingartneryadvr
authored andcommitted
CLOUDSTACK-10276: listVolumes not working when storage UUID is not a UUID (#2639)
When configuring a pre-setup primary storage we can enter the name-label of the storage that is going to be used by ACS and is already set up in the host. The problem is that we can use any String of characters there, and this String does not need to be a UUID. When listing volumes from a primary storage that has such conditions, the list will return all of the volumes in the cloud because the “API framework” will ignore that value as it is not a UUID type.
1 parent 02ece53 commit 8b09620

3 files changed

Lines changed: 153 additions & 272 deletions

File tree

api/src/org/apache/cloudstack/api/command/admin/volume/ListVolumesCmdByAdmin.java

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,50 +16,15 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.admin.volume;
1818

19-
import org.apache.log4j.Logger;
20-
21-
import org.apache.cloudstack.acl.RoleType;
2219
import org.apache.cloudstack.api.APICommand;
23-
import org.apache.cloudstack.api.ApiConstants;
24-
import org.apache.cloudstack.api.Parameter;
2520
import org.apache.cloudstack.api.ResponseObject.ResponseView;
2621
import org.apache.cloudstack.api.command.user.volume.ListVolumesCmd;
27-
import org.apache.cloudstack.api.response.PodResponse;
28-
import org.apache.cloudstack.api.response.StoragePoolResponse;
2922
import org.apache.cloudstack.api.response.VolumeResponse;
3023

3124
import com.cloud.storage.Volume;
3225

33-
34-
@APICommand(name = "listVolumes", description = "Lists all volumes.", responseObject = VolumeResponse.class, responseView = ResponseView.Full, entityType = {Volume.class},
35-
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
26+
@APICommand(name = "listVolumes", description = "Lists all volumes.", responseObject = VolumeResponse.class, responseView = ResponseView.Full, entityType = {
27+
Volume.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
3628
public class ListVolumesCmdByAdmin extends ListVolumesCmd {
37-
public static final Logger s_logger = Logger.getLogger(ListVolumesCmdByAdmin.class.getName());
38-
39-
@Parameter(name=ApiConstants.POD_ID, type=CommandType.UUID, entityType=PodResponse.class,
40-
description="the pod id the disk volume belongs to")
41-
private Long podId;
42-
43-
44-
@Parameter(name=ApiConstants.STORAGE_ID, type=CommandType.UUID, entityType=StoragePoolResponse.class,
45-
description="the ID of the storage pool, available to ROOT admin only", since="4.3", authorized = { RoleType.Admin })
46-
private Long storageId;
47-
48-
49-
/////////////////////////////////////////////////////
50-
/////////////////// Accessors ///////////////////////
51-
/////////////////////////////////////////////////////
52-
53-
54-
@Override
55-
public Long getPodId() {
56-
return podId;
57-
}
58-
59-
60-
@Override
61-
public Long getStorageId() {
62-
return storageId;
63-
}
6429

6530
}

api/src/org/apache/cloudstack/api/command/user/volume/ListVolumesCmd.java

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.user.volume;
1818

19-
import org.apache.log4j.Logger;
20-
2119
import java.util.List;
20+
2221
import org.apache.cloudstack.acl.RoleType;
2322
import org.apache.cloudstack.api.APICommand;
2423
import org.apache.cloudstack.api.ApiCommandJobType;
@@ -35,11 +34,12 @@
3534
import org.apache.cloudstack.api.response.UserVmResponse;
3635
import org.apache.cloudstack.api.response.VolumeResponse;
3736
import org.apache.cloudstack.api.response.ZoneResponse;
37+
import org.apache.log4j.Logger;
3838

3939
import com.cloud.storage.Volume;
4040

41-
@APICommand(name = "listVolumes", description = "Lists all volumes.", responseObject = VolumeResponse.class, responseView = ResponseView.Restricted, entityType = {Volume.class},
42-
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
41+
@APICommand(name = "listVolumes", description = "Lists all volumes.", responseObject = VolumeResponse.class, responseView = ResponseView.Restricted, entityType = {
42+
Volume.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
4343
public class ListVolumesCmd extends BaseListTaggedResourcesCmd {
4444
public static final Logger s_logger = Logger.getLogger(ListVolumesCmd.class.getName());
4545

@@ -55,7 +55,7 @@ public class ListVolumesCmd extends BaseListTaggedResourcesCmd {
5555
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = VolumeResponse.class, description = "the ID of the disk volume")
5656
private Long id;
5757

58-
@Parameter(name=ApiConstants.IDS, type=CommandType.LIST, collectionType=CommandType.UUID, entityType=VolumeResponse.class, description="the IDs of the volumes, mutually exclusive with id", since = "4.9")
58+
@Parameter(name = ApiConstants.IDS, type = CommandType.LIST, collectionType = CommandType.UUID, entityType = VolumeResponse.class, description = "the IDs of the volumes, mutually exclusive with id", since = "4.9")
5959
private List<Long> ids;
6060

6161
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "the name of the disk volume")
@@ -76,22 +76,15 @@ public class ListVolumesCmd extends BaseListTaggedResourcesCmd {
7676
@Parameter(name = ApiConstants.ZONE_ID, type = CommandType.UUID, entityType = ZoneResponse.class, description = "the ID of the availability zone")
7777
private Long zoneId;
7878

79-
@Parameter(name = ApiConstants.STORAGE_ID,
80-
type = CommandType.UUID,
81-
entityType = StoragePoolResponse.class,
82-
description = "the ID of the storage pool, available to ROOT admin only",
83-
since = "4.3",
84-
authorized = {RoleType.Admin})
85-
private Long storageId;
86-
87-
@Parameter(name = ApiConstants.DISK_OFFERING_ID,
88-
type = CommandType.UUID,
89-
entityType = DiskOfferingResponse.class,
90-
description = "list volumes by disk offering",
91-
since = "4.4")
79+
@Parameter(name = ApiConstants.STORAGE_ID, type = CommandType.STRING, entityType = StoragePoolResponse.class, description = "the ID of the storage pool, available to ROOT admin only", since = "4.3", authorized = {
80+
RoleType.Admin})
81+
private String storageId;
82+
83+
@Parameter(name = ApiConstants.DISK_OFFERING_ID, type = CommandType.UUID, entityType = DiskOfferingResponse.class, description = "list volumes by disk offering", since = "4.4")
9284
private Long diskOfferingId;
9385

94-
@Parameter(name = ApiConstants.DISPLAY_VOLUME, type = CommandType.BOOLEAN, description = "list resources by display flag; only ROOT admin is eligible to pass this parameter", since = "4.4", authorized = {RoleType.Admin})
86+
@Parameter(name = ApiConstants.DISPLAY_VOLUME, type = CommandType.BOOLEAN, description = "list resources by display flag; only ROOT admin is eligible to pass this parameter", since = "4.4", authorized = {
87+
RoleType.Admin})
9588
private Boolean display;
9689

9790
/////////////////////////////////////////////////////
@@ -134,7 +127,7 @@ public Long getZoneId() {
134127
return zoneId;
135128
}
136129

137-
public Long getStorageId() {
130+
public String getStorageId() {
138131
return storageId;
139132
}
140133

0 commit comments

Comments
 (0)