mirror of https://github.com/apache/jclouds.git
Issue 29: added create image
git-svn-id: http://jclouds.googlecode.com/svn/trunk@2521 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
parent
8819816e50
commit
36662a2dc8
|
@ -39,7 +39,7 @@ import org.jclouds.aws.ec2.options.internal.BaseEC2RequestOptions;
|
|||
* import static org.jclouds.aws.ec2.options.DescribeImagesOptions.Builder.*
|
||||
* <p/>
|
||||
* EC2Client connection = // get connection
|
||||
* Future<SortedSet<ImageMetadata>> images = connection.describeImages(executableBy("123125").imageIds(1000, 1004));
|
||||
* Future<SortedSet<ImageMetadata>> images = connection.getAMIServices().describeImages(executableBy("123125").imageIds(1000, 1004));
|
||||
* <code>
|
||||
*
|
||||
* @author Adrian Cole
|
||||
|
|
|
@ -37,6 +37,7 @@ import org.jclouds.aws.ec2.EC2;
|
|||
import org.jclouds.aws.ec2.domain.Image;
|
||||
import org.jclouds.aws.ec2.domain.ImageAttribute;
|
||||
import org.jclouds.aws.ec2.filters.FormSigner;
|
||||
import org.jclouds.aws.ec2.options.CreateImageOptions;
|
||||
import org.jclouds.aws.ec2.options.DescribeImagesOptions;
|
||||
import org.jclouds.aws.ec2.xml.DescribeImagesResponseHandler;
|
||||
import org.jclouds.rest.annotations.Endpoint;
|
||||
|
@ -46,7 +47,7 @@ import org.jclouds.rest.annotations.VirtualHost;
|
|||
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||
|
||||
/**
|
||||
* Provides access to EC2 via their REST API.
|
||||
* Provides access to AMI Services.
|
||||
* <p/>
|
||||
*
|
||||
* @author Adrian Cole
|
||||
|
@ -58,7 +59,7 @@ import org.jclouds.rest.annotations.XMLResponseParser;
|
|||
public interface AMIAsyncClient {
|
||||
|
||||
/**
|
||||
* @see BaseEC2Client#describeImages
|
||||
* @see AMIClient#describeImages
|
||||
*/
|
||||
@POST
|
||||
@Path("/")
|
||||
|
@ -67,11 +68,20 @@ public interface AMIAsyncClient {
|
|||
Future<? extends SortedSet<Image>> describeImages(DescribeImagesOptions... options);
|
||||
|
||||
/**
|
||||
* @see BaseEC2Client#describeImages
|
||||
* @see AMIClient#describeImages
|
||||
*/
|
||||
@POST
|
||||
@Path("/")
|
||||
@FormParams(keys = ACTION, values = "DescribeImageAttribute")
|
||||
Future<String> describeImageAttribute(@FormParam("ImageId") String imageId,
|
||||
@FormParam("Attribute") ImageAttribute attribute);
|
||||
|
||||
/**
|
||||
* @see AMIClient#createImage
|
||||
*/
|
||||
@POST
|
||||
@Path("/")
|
||||
@FormParams(keys = ACTION, values = "CreateImage")
|
||||
Future<String> createImage(@FormParam("Name") String name,
|
||||
@FormParam("InstanceId") String instanceId, CreateImageOptions... options);
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
import org.jclouds.aws.ec2.domain.Image;
|
||||
import org.jclouds.aws.ec2.domain.ImageAttribute;
|
||||
import org.jclouds.aws.ec2.options.CreateImageOptions;
|
||||
import org.jclouds.aws.ec2.options.DescribeImagesOptions;
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
|
||||
|
@ -46,7 +47,7 @@ public interface AMIClient {
|
|||
* private images that you own, and private images owned by other users for which you have
|
||||
* explicit launch permissions.
|
||||
*
|
||||
* @see #describeInstances
|
||||
* @see InstanceClient#describeInstances
|
||||
* @see #describeImageAttribute
|
||||
* @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeImages.html"
|
||||
* />
|
||||
|
@ -72,4 +73,19 @@ public interface AMIClient {
|
|||
*/
|
||||
String describeImageAttribute(String imageId, ImageAttribute attribute);
|
||||
|
||||
/**
|
||||
* Creates an AMI that uses an Amazon EBS root device from a "running" or "stopped" instance.
|
||||
*
|
||||
* @param name The name of the AMI that was provided during image creation. 3-128 alphanumeric characters, parenthesis (()), commas (,), slashes (/), dashes (-), or underscores(_)
|
||||
* @param instanceId The ID of the instance.
|
||||
* @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeImages.html"
|
||||
* />
|
||||
* @see CreateImageOptions
|
||||
* @see InstanceClient#runInstances
|
||||
* @see InstanceClient#describeInstances
|
||||
* @see InstanceClient#terminateInstances
|
||||
* @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreateImage.html"
|
||||
* />
|
||||
*/
|
||||
String createImage(String name, String instanceId, CreateImageOptions... options);
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ import java.net.URI;
|
|||
import org.jclouds.aws.ec2.EC2;
|
||||
import org.jclouds.aws.ec2.domain.ImageAttribute;
|
||||
import org.jclouds.aws.ec2.filters.FormSigner;
|
||||
import org.jclouds.aws.ec2.options.CreateImageOptions;
|
||||
import org.jclouds.aws.ec2.options.DescribeImagesOptions;
|
||||
import org.jclouds.aws.ec2.xml.DescribeImagesResponseHandler;
|
||||
import org.jclouds.aws.reference.AWSConstants;
|
||||
|
@ -62,6 +63,52 @@ import com.google.inject.TypeLiteral;
|
|||
@Test(groups = "unit", testName = "ec2.AMIAsyncClientTest")
|
||||
public class AMIAsyncClientTest extends RestClientTest<AMIAsyncClient> {
|
||||
|
||||
public void testCreateImage() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AMIAsyncClient.class.getMethod("createImage", String.class, String.class,
|
||||
Array.newInstance(CreateImageOptions.class, 0).getClass());
|
||||
GeneratedHttpRequest<AMIAsyncClient> httpMethod = processor.createRequest(method, "name",
|
||||
"instanceId");
|
||||
|
||||
assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod,
|
||||
"Content-Length: 69\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.amazonaws.com\n");
|
||||
assertPayloadEquals(httpMethod,
|
||||
"Version=2009-11-30&Action=CreateImage&Name=name&InstanceId=instanceId");
|
||||
filter.filter(httpMethod);
|
||||
assertPayloadEquals(
|
||||
httpMethod,
|
||||
"Action=CreateImage&InstanceId=instanceId&Name=name&Signature=DPCvwvxdNmWXHfiIB%2BRy%2F4gJDAruu6i8dQVirzkFGOU%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2009-11-08T15%3A54%3A08.897Z&Version=2009-11-30&AWSAccessKeyId=user");
|
||||
|
||||
assertResponseParserClassEquals(method, httpMethod, ReturnStringIf200.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
public void testCreateImageOptions() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = AMIAsyncClient.class.getMethod("createImage", String.class, String.class,
|
||||
Array.newInstance(CreateImageOptions.class, 0).getClass());
|
||||
GeneratedHttpRequest<AMIAsyncClient> httpMethod = processor.createRequest(method, "name",
|
||||
"instanceId", new CreateImageOptions().withDescription("description").noReboot());
|
||||
|
||||
assertRequestLineEquals(httpMethod, "POST https://ec2.amazonaws.com/ HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod,
|
||||
"Content-Length: 107\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.amazonaws.com\n");
|
||||
assertPayloadEquals(
|
||||
httpMethod,
|
||||
"Version=2009-11-30&Action=CreateImage&Name=name&InstanceId=instanceId&Description=description&NoReboot=true");
|
||||
|
||||
assertResponseParserClassEquals(method, httpMethod, ReturnStringIf200.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
// assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
// assertSaxResponseParserClassEquals(method, CreateImageResponseHandler.class);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
public void testDescribeImages() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AMIAsyncClient.class.getMethod("describeImages", Array.newInstance(
|
||||
DescribeImagesOptions.class, 0).getClass());
|
||||
|
|
Loading…
Reference in New Issue