From d53c3f07989151217a951547c9cbde63b91eddf5 Mon Sep 17 00:00:00 2001 From: Nitin Date: Thu, 15 Sep 2011 15:53:31 +0530 Subject: [PATCH] bug 11051: Listing Secondary Storage - also show the total and used storage. Listing Storage pools show the realtime storage stats and correctly populate the allocated storage. --- .../api/response/StoragePoolResponse.java | 13 ++++++++++- .../src/com/cloud/api/ApiResponseHelper.java | 22 +++++++++++-------- 2 files changed, 25 insertions(+), 10 deletions(-) mode change 100644 => 100755 api/src/com/cloud/api/response/StoragePoolResponse.java diff --git a/api/src/com/cloud/api/response/StoragePoolResponse.java b/api/src/com/cloud/api/response/StoragePoolResponse.java old mode 100644 new mode 100755 index abfaf8db9d0..a1639408ac3 --- a/api/src/com/cloud/api/response/StoragePoolResponse.java +++ b/api/src/com/cloud/api/response/StoragePoolResponse.java @@ -66,6 +66,9 @@ public class StoragePoolResponse extends BaseResponse { @SerializedName("disksizeallocated") @Param(description="the host's currently allocated disk size") private Long diskSizeAllocated; + + @SerializedName("disksizeused") @Param(description="the host's currently used disk size") + private Long diskSizeUsed; @SerializedName("tags") @Param(description="the tags for the storage pool") private String tags; @@ -216,7 +219,15 @@ public class StoragePoolResponse extends BaseResponse { this.diskSizeAllocated = diskSizeAllocated; } - public String getTags() { + public Long getDiskSizeUsed() { + return diskSizeUsed; + } + + public void setDiskSizeUsed(Long diskSizeUsed) { + this.diskSizeUsed = diskSizeUsed; + } + + public String getTags() { return tags; } diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index dfdafdacf2c..11cc5fb9fb7 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -578,6 +578,12 @@ public class ApiResponseHelper implements ResponseGenerator { } + }else if (host.getType() == Host.Type.SecondaryStorage){ + StorageStats secStorageStats = ApiDBUtils.getSecondaryStorageStatistics(host.getId()); + if (secStorageStats != null){ + hostResponse.setDiskSizeTotal(secStorageStats.getCapacityBytes()); + hostResponse.setDiskSizeAllocated(secStorageStats.getByteUsed()); + } } if (host.getClusterId() != null) { @@ -938,16 +944,14 @@ public class ApiResponseHelper implements ResponseGenerator { StorageStats stats = ApiDBUtils.getStoragePoolStatistics(pool.getId()); Long capacity = pool.getCapacityBytes(); - Long available = pool.getAvailableBytes(); - Long used = capacity - available; - - if (stats != null) { - used = stats.getByteUsed(); - available = capacity - used; - } - + long allocatedSize = ApiDBUtils.getStorageCapacitybyPool(pool.getId(),Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED); poolResponse.setDiskSizeTotal(pool.getCapacityBytes()); - poolResponse.setDiskSizeAllocated(used); + poolResponse.setDiskSizeAllocated(allocatedSize); + + if (stats != null) { + Long used = stats.getByteUsed(); + poolResponse.setDiskSizeUsed(used); + } if (pool.getClusterId() != null) { ClusterVO cluster = ApiDBUtils.findClusterById(pool.getClusterId());