Allow for arbitrary disk offering details to be saved/displayed (#174)

* Allow for arbitrary disk offering details to be saved/displayed
* Update api/src/main/java/org/apache/cloudstack/api/response/DiskOfferingResponse.java
This commit is contained in:
Marcus Sorensen 2022-06-17 10:07:50 -06:00 committed by GitHub
parent dcf68b272e
commit edaa1cbfed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 8 deletions

View File

@ -17,6 +17,7 @@
package org.apache.cloudstack.api.response;
import java.util.Date;
import java.util.Map;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseResponseWithAnnotations;
@ -155,6 +156,10 @@ public class DiskOfferingResponse extends BaseResponseWithAnnotations {
@Param(description = "the vsphere storage policy tagged to the disk offering in case of VMware", since = "4.15")
private String vsphereStoragePolicy;
@SerializedName(ApiConstants.DETAILS)
@Param(description = "additional key/value details tied with this disk offering", since = "4.16.1")
private Map<String, String> details;
public Boolean getDisplayOffering() {
return displayOffering;
}
@ -363,4 +368,8 @@ public class DiskOfferingResponse extends BaseResponseWithAnnotations {
public void setVsphereStoragePolicy(String vsphereStoragePolicy) {
this.vsphereStoragePolicy = vsphereStoragePolicy;
}
public void setDetails(Map<String, String> details) {
this.details = details;
}
}

View File

@ -131,6 +131,7 @@ public class DiskOfferingJoinDaoImpl extends GenericDaoBase<DiskOfferingJoinVO,
diskOfferingResponse.setCacheMode(offering.getCacheMode());
diskOfferingResponse.setObjectName("diskoffering");
Map<String, String> offeringDetails = ApiDBUtils.getResourceDetails(offering.getId(), ResourceTag.ResourceObjectType.DiskOffering);
diskOfferingResponse.setDetails(offeringDetails);
if (offeringDetails != null && !offeringDetails.isEmpty()) {
String vsphereStoragePolicyId = offeringDetails.get(ApiConstants.STORAGE_POLICY);
if (vsphereStoragePolicyId != null) {

View File

@ -3364,14 +3364,11 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
detailsVO.add(new DiskOfferingDetailVO(offering.getId(), ApiConstants.ZONE_ID, String.valueOf(zoneId), false));
}
}
if (details != null && !details.isEmpty()) {
// Support disk offering details for below parameters
if (details.containsKey(Volume.BANDWIDTH_LIMIT_IN_MBPS)) {
detailsVO.add(new DiskOfferingDetailVO(offering.getId(), Volume.BANDWIDTH_LIMIT_IN_MBPS, details.get(Volume.BANDWIDTH_LIMIT_IN_MBPS), false));
}
if (details.containsKey(Volume.IOPS_LIMIT)) {
detailsVO.add(new DiskOfferingDetailVO(offering.getId(), Volume.IOPS_LIMIT, details.get(Volume.IOPS_LIMIT), false));
}
if (MapUtils.isNotEmpty(details)) {
details.forEach((key, value) -> {
boolean displayDetail = !key.equals(Volume.BANDWIDTH_LIMIT_IN_MBPS) && !key.equals(Volume.IOPS_LIMIT);
detailsVO.add(new DiskOfferingDetailVO(offering.getId(), key, value, displayDetail));
});
}
if (storagePolicyID != null) {
detailsVO.add(new DiskOfferingDetailVO(offering.getId(), ApiConstants.STORAGE_POLICY, String.valueOf(storagePolicyID), false));