fix for multiple security groups in ec2

This commit is contained in:
Alex Yarmula 2010-03-16 16:55:19 -07:00
parent d0dd757cfb
commit a7d73a2d64
2 changed files with 27 additions and 12 deletions

View File

@ -37,7 +37,7 @@ import org.jclouds.encryption.internal.Base64;
* EC2Client connection = // get connection
* ListenableFuture<ReservationInfo> instances = connection.runInstances(executableBy("123125").imageIds(1000, 1004));
* <code>
*
*
* @author Adrian Cole
* @see <a
* href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-form-RunInstances.html"
@ -59,13 +59,22 @@ public class RunInstancesOptions extends BaseEC2RequestOptions {
}
/**
* Name of the security group.
* Attach multiple security groups
*/
public RunInstancesOptions withSecurityGroup(String securityGroup) {
formParameters.put("SecurityGroup", checkNotNull(securityGroup, "securityGroup"));
public RunInstancesOptions withSecurityGroups(String... securityGroups) {
indexFormValuesWithPrefix("SecurityGroup", securityGroups);
return this;
}
/**
* Attaches a single security group. Multiple calls to this method
* won't add more groups.
* @param securityGroup name of an existing security group
*/
public RunInstancesOptions withSecurityGroup(String securityGroup) {
return withSecurityGroups(securityGroup);
}
String getSecurityGroup() {
return getFirstFormOrNull("SecurityGroup");
}

View File

@ -30,6 +30,9 @@ import javax.inject.Singleton;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.EC2;
import org.jclouds.aws.ec2.EC2AsyncClient;
import org.jclouds.aws.ec2.EC2Client;
import org.jclouds.aws.ec2.EC2ContextFactory;
import org.jclouds.aws.ec2.domain.AvailabilityZone;
import org.jclouds.aws.ec2.domain.BlockDeviceMapping;
import org.jclouds.aws.ec2.domain.InstanceType;
@ -53,6 +56,7 @@ import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.logging.Logger;
import org.jclouds.logging.Logger.LoggerFactory;
import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Jsr330;
@ -157,15 +161,17 @@ public class InstanceAsyncClientTest extends RestClientTest<InstanceAsyncClient>
RunInstancesOptions.class, 0).getClass());
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method,
Region.EU_WEST_1, AvailabilityZone.EU_WEST_1A, "ami-voo", 1, 5,
new RunInstancesOptions().withKernelId("kernelId").enableMonitoring());
new RunInstancesOptions().withKernelId("kernelId").enableMonitoring().
withSecurityGroups("group1", "group2"));
assertRequestLineEquals(httpMethod, "POST https://ec2.eu-west-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(
httpMethod,
"Content-Length: 164\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.eu-west-1.amazonaws.com\n");
assertPayloadEquals(
httpMethod,
"Version=2009-11-30&Action=RunInstances&ImageId=ami-voo&MinCount=1&MaxCount=5&KernelId=kernelId&Monitoring.Enabled=true&SecurityGroup.1=group1&SecurityGroup.2=group2&Placement.AvailabilityZone=eu-west-1a");
assertRequestLineEquals(httpMethod, "POST https://ec2.eu-west-1.amazonaws.com/ HTTP/1.1");
assertHeadersEqual(
httpMethod,
"Content-Length: 118\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.eu-west-1.amazonaws.com\n");
assertPayloadEquals(
httpMethod,
"Version=2009-11-30&Action=RunInstances&ImageId=ami-voo&MinCount=1&MaxCount=5&KernelId=kernelId&Monitoring.Enabled=true&Placement.AvailabilityZone=eu-west-1a");
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertSaxResponseParserClassEquals(method, RunInstancesResponseHandler.class);