Skip to content

Commit 40f180d

Browse files
committed
server: return usage description with resource names and UUIDs
The usage record descriptions have CloudStack's internal integer IDs which makes it difficult for users to read their usages. This PRs introduces a new API boolean flag `oldformat` which when set to true would return the older description format, otherwise by default listUsageRecords will process and return description with names and UUIDs of resources. Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent 3e64285 commit 40f180d

4 files changed

Lines changed: 343 additions & 180 deletions

File tree

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ public class ApiConstants {
214214
public static final String OFFER_HA = "offerha";
215215
public static final String IS_SYSTEM_OFFERING = "issystem";
216216
public static final String IS_DEFAULT_USE = "defaultuse";
217+
public static final String OLD_FORMAT = "oldformat";
217218
public static final String OP = "op";
218219
public static final String OS_CATEGORY_ID = "oscategoryid";
219220
public static final String OS_TYPE_ID = "ostypeid";

api/src/main/java/org/apache/cloudstack/api/ResponseGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ List<TemplateResponse> createTemplateResponses(ResponseView view, VirtualMachine
435435

436436
UsageRecordResponse createUsageResponse(Usage usageRecord);
437437

438-
UsageRecordResponse createUsageResponse(Usage usageRecord, Map<String, Set<ResourceTagResponse>> resourceTagResponseMap);
438+
UsageRecordResponse createUsageResponse(Usage usageRecord, Map<String, Set<ResourceTagResponse>> resourceTagResponseMap, boolean oldFormat);
439439

440440
public Map<String, Set<ResourceTagResponse>> getUsageResourceTags();
441441

api/src/main/java/org/apache/cloudstack/api/command/admin/usage/ListUsageRecordsCmd.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.util.Map;
2323
import java.util.Set;
2424

25-
import com.cloud.utils.Pair;
2625
import org.apache.cloudstack.api.APICommand;
2726
import org.apache.cloudstack.api.ApiConstants;
2827
import org.apache.cloudstack.api.BaseCmd;
@@ -36,6 +35,8 @@
3635
import org.apache.cloudstack.api.response.UsageRecordResponse;
3736
import org.apache.cloudstack.usage.Usage;
3837

38+
import com.cloud.utils.Pair;
39+
3940
@APICommand(name = ListUsageRecordsCmd.APINAME,
4041
description = "Lists usage records for accounts",
4142
responseObject = UsageRecordResponse.class,
@@ -81,6 +82,10 @@ public class ListUsageRecordsCmd extends BaseListCmd {
8182
@Parameter(name = ApiConstants.INCLUDE_TAGS, type = CommandType.BOOLEAN, description = "Flag to enable display of Tags for a resource")
8283
private Boolean includeTags;
8384

85+
@Parameter(name = ApiConstants.OLD_FORMAT, type = CommandType.BOOLEAN, description = "Flag to enable description rendered in old format with no processing")
86+
private Boolean oldFormat;
87+
88+
8489
/////////////////////////////////////////////////////
8590
/////////////////// Accessors ///////////////////////
8691
/////////////////////////////////////////////////////
@@ -145,6 +150,9 @@ public void setUsageId(String usageId) {
145150
this.usageId = usageId;
146151
}
147152

153+
public boolean getOldFormat() {
154+
return oldFormat != null && oldFormat;
155+
}
148156

149157
/////////////////////////////////////////////////////
150158
/////////////// API Implementation///////////////////
@@ -167,7 +175,7 @@ public void execute() {
167175
resourceTagResponseMap = _responseGenerator.getUsageResourceTags();
168176
}
169177
for (Usage usageRecord : usageRecords.first()) {
170-
UsageRecordResponse usageResponse = _responseGenerator.createUsageResponse(usageRecord, resourceTagResponseMap);
178+
UsageRecordResponse usageResponse = _responseGenerator.createUsageResponse(usageRecord, resourceTagResponseMap, getOldFormat());
171179
usageResponse.setObjectName("usagerecord");
172180
usageResponses.add(usageResponse);
173181
}

0 commit comments

Comments
 (0)