Issue 29: started on image attributes

git-svn-id: http://jclouds.googlecode.com/svn/trunk@2258 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-11-12 06:22:44 +00:00
parent f8377f3adc
commit 7dca745375
5 changed files with 218 additions and 67 deletions

View File

@ -38,6 +38,7 @@ import org.jclouds.aws.ec2.binders.BindInstanceIdsToIndexedFormParams;
import org.jclouds.aws.ec2.binders.BindKeyNameToIndexedFormParams; import org.jclouds.aws.ec2.binders.BindKeyNameToIndexedFormParams;
import org.jclouds.aws.ec2.binders.BindUserIdGroupPairToSourceSecurityGroupFormParams; import org.jclouds.aws.ec2.binders.BindUserIdGroupPairToSourceSecurityGroupFormParams;
import org.jclouds.aws.ec2.domain.Image; 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.IpProtocol;
import org.jclouds.aws.ec2.domain.KeyPair; import org.jclouds.aws.ec2.domain.KeyPair;
import org.jclouds.aws.ec2.domain.Reservation; import org.jclouds.aws.ec2.domain.Reservation;
@ -93,6 +94,27 @@ public interface EC2Client {
@XMLResponseParser(DescribeImagesResponseHandler.class) @XMLResponseParser(DescribeImagesResponseHandler.class)
Future<? extends SortedSet<Image>> describeImages(DescribeImagesOptions... options); Future<? extends SortedSet<Image>> 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 <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeImageAttribute.html"
* />
* @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. * Returns information about instances that you own.
* <p/> * <p/>

View File

@ -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);
}
}

View File

@ -35,6 +35,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import org.jclouds.aws.ec2.domain.Image; 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.IpPermission;
import org.jclouds.aws.ec2.domain.IpProtocol; import org.jclouds.aws.ec2.domain.IpProtocol;
import org.jclouds.aws.ec2.domain.KeyPair; import org.jclouds.aws.ec2.domain.KeyPair;
@ -58,6 +59,7 @@ public class EC2ClientLiveTest {
private EC2Client client; private EC2Client client;
private String user; private String user;
private String imageId = "ami-d7fe1fbe";
@BeforeGroups(groups = { "live" }) @BeforeGroups(groups = { "live" })
public void setupClient() throws InterruptedException, ExecutionException, TimeoutException { public void setupClient() throws InterruptedException, ExecutionException, TimeoutException {
@ -84,6 +86,25 @@ public class EC2ClientLiveTest {
assertEquals(iterator.next().getImageId(), id2); assertEquals(iterator.next().getImageId(), id2);
} }
@Test(dependsOnMethods = "testDescribeImages", enabled=false)
void testDescribeImageAttribute() throws InterruptedException, ExecutionException,
TimeoutException {
SortedSet<Image> 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 @Test
void testDescribeInstances() throws InterruptedException, ExecutionException, TimeoutException { void testDescribeInstances() throws InterruptedException, ExecutionException, TimeoutException {
SortedSet<Reservation> allResults = client.describeInstances().get(30, TimeUnit.SECONDS); SortedSet<Reservation> allResults = client.describeInstances().get(30, TimeUnit.SECONDS);

View File

@ -31,6 +31,7 @@ import java.lang.reflect.Array;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.URI; import java.net.URI;
import org.jclouds.aws.ec2.domain.ImageAttribute;
import org.jclouds.aws.ec2.domain.IpProtocol; import org.jclouds.aws.ec2.domain.IpProtocol;
import org.jclouds.aws.ec2.domain.UserIdGroupPair; import org.jclouds.aws.ec2.domain.UserIdGroupPair;
import org.jclouds.aws.ec2.filters.FormSigner; 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.ec2.xml.TerminateInstancesResponseHandler;
import org.jclouds.aws.reference.AWSConstants; import org.jclouds.aws.reference.AWSConstants;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ReturnStringIf200;
import org.jclouds.http.functions.ReturnVoidIf2xx; import org.jclouds.http.functions.ReturnVoidIf2xx;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.logging.Logger.LoggerFactory;
@ -112,6 +114,30 @@ public class EC2ClientTest extends RestClientTest<EC2Client> {
checkFilters(httpMethod); checkFilters(httpMethod);
} }
public void testDescribeImageAttribute() throws SecurityException, NoSuchMethodException,
IOException {
Method method = EC2Client.class.getMethod("describeImageAttribute", String.class,
ImageAttribute.class);
GeneratedHttpRequest<EC2Client> 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 { public void testDescribeInstances() throws SecurityException, NoSuchMethodException, IOException {
Method method = EC2Client.class.getMethod("describeInstances", Array.newInstance( Method method = EC2Client.class.getMethod("describeInstances", Array.newInstance(
String.class, 0).getClass()); String.class, 0).getClass());

View File

@ -1,37 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- <!--
Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com> Copyright (C) 2009 Cloud Conscious, LLC.
<info@cloudconscious.com>
==================================================================== ====================================================================
Licensed to the Apache Software Foundation (ASF) under one Licensed to the Apache Software Foundation (ASF) under one or
or more contributor license agreements. See the NOTICE file more contributor license agreements. See the NOTICE file
distributed with this work for additional information distributed with this work for additional information regarding
regarding copyright ownership. The ASF licenses this file copyright ownership. The ASF licenses this file to you under the
to you under the Apache License, Version 2.0 (the Apache License, Version 2.0 (the "License"); you may not use
"License"); you may not use this file except in compliance this file except in compliance with the License. You may obtain
with the License. You may obtain a copy of the License at a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0 Unless required by
applicable law or agreed to in writing, software distributed
Unless required by applicable law or agreed to in writing, under the License is distributed on an "AS IS" BASIS, WITHOUT
software distributed under the License is distributed on an WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY See the License for the specific language governing permissions
KIND, either express or implied. See the License for the and limitations under the License.
specific language governing permissions and limitations ====================================================================
under the License. -->
====================================================================
-->
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<!-- <!--
For more configuration infromation and examples see the Apache Log4j For more configuration infromation and examples see the Apache
website: http://logging.apache.org/log4j/ Log4j website: http://logging.apache.org/log4j/
--> -->
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
debug="false"> debug="false">
<!-- A time/date based rolling appender --> <!-- A time/date based rolling appender -->
<appender name="WIREFILE" class="org.apache.log4j.DailyRollingFileAppender"> <appender name="WIREFILE" class="org.apache.log4j.DailyRollingFileAppender">
@ -48,68 +46,68 @@
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" /> <param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
<!-- <!--
The full pattern: Date MS Priority [Category] (Thread:NDC) Message\n The full pattern: Date MS Priority [Category]
<param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x) (Thread:NDC) Message\n <param name="ConversionPattern"
%m%n"/> value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
--> -->
</layout> </layout>
</appender> </appender>
<!-- A time/date based rolling appender --> <!-- A time/date based rolling appender -->
<appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender"> <appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="target/test-data/jclouds.log" /> <param name="File" value="target/test-data/jclouds.log" />
<param name="Append" value="true" /> <param name="Append" value="true" />
<!-- Rollover at midnight each day --> <!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd" /> <param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="TRACE" /> <param name="Threshold" value="TRACE" />
<layout class="org.apache.log4j.PatternLayout"> <layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n --> <!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" /> <param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
<!-- <!--
The full pattern: Date MS Priority [Category] (Thread:NDC) Message\n The full pattern: Date MS Priority [Category]
<param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x) (Thread:NDC) Message\n <param name="ConversionPattern"
%m%n"/> value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
--> -->
</layout> </layout>
</appender> </appender>
<appender name="ASYNC" class="org.apache.log4j.AsyncAppender"> <appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="FILE" /> <appender-ref ref="FILE" />
</appender> </appender>
<appender name="ASYNCWIRE" class="org.apache.log4j.AsyncAppender"> <appender name="ASYNCWIRE" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="WIREFILE" /> <appender-ref ref="WIREFILE" />
</appender> </appender>
<!-- ================ -->
<!-- Limit categories -->
<!-- ================ -->
<category name="org.jclouds"> <!-- ================ -->
<priority value="DEBUG" /> <!-- Limit categories -->
<!-- ================ -->
<category name="org.jclouds">
<priority value="DEBUG" />
<appender-ref ref="ASYNC" /> <appender-ref ref="ASYNC" />
</category> </category>
<category name="jclouds.http.headers"> <category name="jclouds.http.headers">
<priority value="DEBUG" /> <priority value="DEBUG" />
<appender-ref ref="ASYNCWIRE" /> <appender-ref ref="ASYNCWIRE" />
</category><!-- </category>
<category name="jclouds.http.wire"> <category name="jclouds.http.wire">
<priority value="DEBUG" /> <priority value="DEBUG" />
<appender-ref ref="ASYNCWIRE" /> <appender-ref ref="ASYNCWIRE" />
</category> </category>
--><!-- ======================= -->
<!-- Setup the Root category -->
<!-- ======================= -->
<root> <!-- ======================= -->
<priority value="WARN" /> <!-- Setup the Root category -->
</root> <!-- ======================= -->
<root>
<priority value="WARN" />
</root>
</log4j:configuration> </log4j:configuration>