CLOUDSTACK-3336 AWSAPI - createVolume API with custom size should prefer a non-tagged custom sized disk offering first over a tagged offering

Changes:
For createVolume API with custom size the awsapi component chooses the custom size disk offering present on CloudStack, sice CS createVolume API needs an offering Id.

But if there are multiple custom size disk offerings, and some of the offerings have tags, awsapi should try to choose a non-tagged custom offering first. There is a reason for people to tag a disk offering and using that on every user API call may not be preferable.

If all disk offerings are tagged however, awsapi will choose one of them.
This commit is contained in:
Prachi Damle 2013-07-02 15:18:49 -07:00
parent f9de646c28
commit 6c9383bd76
2 changed files with 19 additions and 1 deletions

View File

@ -1184,14 +1184,23 @@ public class EC2Engine extends ManagerBase {
String snapshotId = request.getSnapshotId();
Long size = request.getSize();
String diskOfferingId = null;
String taggedDiskOffering = null;
if (snapshotId == null) {
List<CloudStackDiskOffering> disks = getApi().listDiskOfferings(null, null, null, null);
for (CloudStackDiskOffering offer : disks) {
if (offer.isCustomized()) {
if (offer.getTags() == null) {
diskOfferingId = offer.getId();
break;
} else {
taggedDiskOffering = offer.getId();
}
}
}
if (diskOfferingId == null) {
diskOfferingId = taggedDiskOffering;
}
if (diskOfferingId == null) throw new EC2ServiceException(ServerError.InternalError, "No Customize Disk Offering Found");
}

View File

@ -32,6 +32,8 @@ public class CloudStackDiskOffering {
private String created;
@SerializedName(ApiConstants.IS_CUSTOMIZED)
private boolean isCustomized;
@SerializedName(ApiConstants.TAGS)
private String tags;
/**
*
@ -80,4 +82,11 @@ public class CloudStackDiskOffering {
public boolean isCustomized() {
return isCustomized;
}
/**
* @return the tags
*/
public String getTags() {
return tags;
}
}