diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/EC2Client.java b/aws/core/src/main/java/org/jclouds/aws/ec2/EC2Client.java index fa5abff67f..556c9ac358 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/EC2Client.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/EC2Client.java @@ -38,6 +38,7 @@ import org.jclouds.aws.ec2.binders.BindInstanceIdsToIndexedFormParams; import org.jclouds.aws.ec2.binders.BindKeyNameToIndexedFormParams; import org.jclouds.aws.ec2.binders.BindUserIdGroupPairToSourceSecurityGroupFormParams; import org.jclouds.aws.ec2.domain.Image; +import org.jclouds.aws.ec2.domain.ImageAttribute; import org.jclouds.aws.ec2.domain.IpProtocol; import org.jclouds.aws.ec2.domain.KeyPair; import org.jclouds.aws.ec2.domain.Reservation; @@ -93,6 +94,27 @@ public interface EC2Client { @XMLResponseParser(DescribeImagesResponseHandler.class) Future> describeImages(DescribeImagesOptions... options); + /** + * Returns information about an attribute of an AMI. Only one attribute can be specified per + * call. + * + * @param imageId + * The ID of the AMI for which an attribute will be described + * @param attribute + * the attribute to describe + * @see #describeImages + * @see #modifyImageAttribute + * @see #resetImageAttribute + * @see + * @see DescribeImagesOptions + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "DescribeImageAttribute") + String describeImageAttribute(@FormParam("ImageId") String imageId, + @FormParam("Attribute") ImageAttribute attribute); + /** * Returns information about instances that you own. *

diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/domain/ImageAttribute.java b/aws/core/src/main/java/org/jclouds/aws/ec2/domain/ImageAttribute.java new file mode 100644 index 0000000000..973d4e98a9 --- /dev/null +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/domain/ImageAttribute.java @@ -0,0 +1,84 @@ +package org.jclouds.aws.ec2.domain; + +import org.jclouds.aws.ec2.EC2Client; + +/** + * + * An attribute of an AMI. + * + * @author Adrian Cole + * @see EC2Client#modifyImageAttribute + * @see EC2Client#resetImageAttribute + * @see EC2Client#describeImageAttribute + * + */ +public enum ImageAttribute { + + /** + * the product code associated with the AMI. + */ + PRODUCT_CODES, + + /** + * the ID of the RAM disk associated with the AMI. + */ + RAMDISK, + + /** + * the ID of the kernel associated with the AMI. + */ + KERNEL, + /** + * the launch permissions of the AMI. + */ + LAUNCH_PERMISSION, + /** + * the operating system platform. + */ + PLATFORM, + /** + * the mapping that defines native device names to use when exposing virtual devices. + */ + BLOCK_DEVICE_MAPPING; + public String value() { + switch (this) { + case PRODUCT_CODES: + return "productCodes"; + case RAMDISK: + return "ramdisk"; + case KERNEL: + return "kernel"; + case LAUNCH_PERMISSION: + return "launchPermission"; + case PLATFORM: + return "platform"; + case BLOCK_DEVICE_MAPPING: + return "blockDeviceMapping"; + default: + throw new IllegalArgumentException("unmapped attribute: " + super.name()); + } + } + + @Override + public String toString() { + return value(); + } + + public static ImageAttribute fromValue(String attribute) { + if ("productCodes".equals(attribute)) + return PRODUCT_CODES; + else if ("ramdisk".equals(attribute)) + return RAMDISK; + else if ("kernel".equals(attribute)) + return KERNEL; + else if ("launchPermission".equals(attribute)) + return LAUNCH_PERMISSION; + else if ("platform".equals(attribute)) + return PLATFORM; + else if ("blockDeviceMapping".equals(attribute)) + return BLOCK_DEVICE_MAPPING; + else + throw new IllegalArgumentException("unmapped attribute: " + attribute); + } + +} \ No newline at end of file diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/EC2ClientLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/EC2ClientLiveTest.java index e0baff989a..0010e3e145 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/EC2ClientLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/EC2ClientLiveTest.java @@ -35,6 +35,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import org.jclouds.aws.ec2.domain.Image; +import org.jclouds.aws.ec2.domain.ImageAttribute; import org.jclouds.aws.ec2.domain.IpPermission; import org.jclouds.aws.ec2.domain.IpProtocol; import org.jclouds.aws.ec2.domain.KeyPair; @@ -58,6 +59,7 @@ public class EC2ClientLiveTest { private EC2Client client; private String user; + private String imageId = "ami-d7fe1fbe"; @BeforeGroups(groups = { "live" }) public void setupClient() throws InterruptedException, ExecutionException, TimeoutException { @@ -84,6 +86,25 @@ public class EC2ClientLiveTest { assertEquals(iterator.next().getImageId(), id2); } + @Test(dependsOnMethods = "testDescribeImages", enabled=false) + void testDescribeImageAttribute() throws InterruptedException, ExecutionException, + TimeoutException { + SortedSet oneResult = client.describeImages(imageIds(imageId)).get(30, + TimeUnit.SECONDS); + @SuppressWarnings("unused") + Image expects = oneResult.last(); + + System.out.println(client.describeImageAttribute(imageId, ImageAttribute.PRODUCT_CODES)); + + System.out.println(client.describeImageAttribute(imageId, ImageAttribute.PRODUCT_CODES)); + System.out.println(client.describeImageAttribute(imageId, ImageAttribute.RAMDISK)); + System.out.println(client.describeImageAttribute(imageId, ImageAttribute.KERNEL)); + System.out.println(client.describeImageAttribute(imageId, ImageAttribute.PLATFORM)); + System.out.println(client.describeImageAttribute(imageId, ImageAttribute.LAUNCH_PERMISSION)); + System.out.println(client + .describeImageAttribute(imageId, ImageAttribute.BLOCK_DEVICE_MAPPING)); + } + @Test void testDescribeInstances() throws InterruptedException, ExecutionException, TimeoutException { SortedSet allResults = client.describeInstances().get(30, TimeUnit.SECONDS); diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/EC2ClientTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/EC2ClientTest.java index c5cb2a5851..f7dd052ac3 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/EC2ClientTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/EC2ClientTest.java @@ -31,6 +31,7 @@ import java.lang.reflect.Array; import java.lang.reflect.Method; import java.net.URI; +import org.jclouds.aws.ec2.domain.ImageAttribute; import org.jclouds.aws.ec2.domain.IpProtocol; import org.jclouds.aws.ec2.domain.UserIdGroupPair; import org.jclouds.aws.ec2.filters.FormSigner; @@ -46,6 +47,7 @@ import org.jclouds.aws.ec2.xml.RunInstancesResponseHandler; import org.jclouds.aws.ec2.xml.TerminateInstancesResponseHandler; import org.jclouds.aws.reference.AWSConstants; import org.jclouds.http.functions.ParseSax; +import org.jclouds.http.functions.ReturnStringIf200; import org.jclouds.http.functions.ReturnVoidIf2xx; import org.jclouds.logging.Logger; import org.jclouds.logging.Logger.LoggerFactory; @@ -112,6 +114,30 @@ public class EC2ClientTest extends RestClientTest { checkFilters(httpMethod); } + public void testDescribeImageAttribute() throws SecurityException, NoSuchMethodException, + IOException { + Method method = EC2Client.class.getMethod("describeImageAttribute", String.class, + ImageAttribute.class); + GeneratedHttpRequest httpMethod = processor.createRequest(method, "imageId", + ImageAttribute.BLOCK_DEVICE_MAPPING); + + assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1"); + assertHeadersEqual(httpMethod, + "Content-Length: 93\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.amazonaws.com\n"); + assertEntityEquals(httpMethod, + "Version=2009-08-15&Action=DescribeImageAttribute&ImageId=imageId&Attribute=blockDeviceMapping"); + filter.filter(httpMethod); + assertEntityEquals( + httpMethod, + "Action=DescribeImageAttribute&Attribute=blockDeviceMapping&ImageId=imageId&Signature=IiyxXwoOmpLiPC%2BbfBdqJwE758bvbs8kXCL71FefStY%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Version=2009-08-15&AWSAccessKeyId=user"); + + assertResponseParserClassEquals(method, httpMethod, ReturnStringIf200.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(httpMethod); + } + public void testDescribeInstances() throws SecurityException, NoSuchMethodException, IOException { Method method = EC2Client.class.getMethod("describeInstances", Array.newInstance( String.class, 0).getClass()); diff --git a/aws/core/src/test/resources/log4j.xml b/aws/core/src/test/resources/log4j.xml index 3be65a2ae2..cd798738c6 100644 --- a/aws/core/src/test/resources/log4j.xml +++ b/aws/core/src/test/resources/log4j.xml @@ -1,37 +1,35 @@ - + http://www.apache.org/licenses/LICENSE-2.0 Unless required by + applicable law or agreed to in writing, software distributed + under the License is distributed on an "AS IS" BASIS, WITHOUT + WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions + and limitations under the License. + ==================================================================== + --> - + + debug="false"> @@ -48,68 +46,68 @@ - - - - + + + + - - + + - + - - - + + + - - - - - - - + + + + + + + - - - - - + - - + + + + + + - - + + - - - - - - + + + + + + + \ No newline at end of file