From 6c9383bd76500e38f6737db814bc2d7aae131a2c Mon Sep 17 00:00:00 2001 From: Prachi Damle Date: Tue, 2 Jul 2013 15:18:49 -0700 Subject: [PATCH] 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. --- .../com/cloud/bridge/service/core/ec2/EC2Engine.java | 11 ++++++++++- .../cloud/stack/models/CloudStackDiskOffering.java | 9 +++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/awsapi/src/com/cloud/bridge/service/core/ec2/EC2Engine.java b/awsapi/src/com/cloud/bridge/service/core/ec2/EC2Engine.java index 15ed9083f84..715c83eeb4d 100644 --- a/awsapi/src/com/cloud/bridge/service/core/ec2/EC2Engine.java +++ b/awsapi/src/com/cloud/bridge/service/core/ec2/EC2Engine.java @@ -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 disks = getApi().listDiskOfferings(null, null, null, null); for (CloudStackDiskOffering offer : disks) { if (offer.isCustomized()) { - diskOfferingId = offer.getId(); + 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"); } diff --git a/awsapi/src/com/cloud/stack/models/CloudStackDiskOffering.java b/awsapi/src/com/cloud/stack/models/CloudStackDiskOffering.java index 308941c7ef6..6e1b98e871a 100644 --- a/awsapi/src/com/cloud/stack/models/CloudStackDiskOffering.java +++ b/awsapi/src/com/cloud/stack/models/CloudStackDiskOffering.java @@ -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; + } }