Permalink
Browse files

Merge branch 'master' of github.com:voldemort/voldemort

  • Loading branch information...
afeinberg committed May 26, 2010
2 parents aeb05f5 + 10b8628 commit ebcbd5c6020cfa953ee51176d7c45aeff5463a7c
@@ -71,6 +71,7 @@
* @param keypairId String representing keypair ID
* @param instanceType Instance type to launch
* @param instanceCount Number of instances to launch
+ * @param securityGroups Security groups to apply to instances (null for none)
*
* @return List of HostNamePair instances
*
@@ -80,7 +81,8 @@
public List<HostNamePair> createInstances(String ami,
String keypairId,
Ec2InstanceType instanceType,
- int instanceCount) throws Exception;
+ int instanceCount,
+ List<String> securityGroups) throws Exception;
/**
* Deletes the EC2 instances represented by the given external host names.
@@ -16,6 +16,7 @@
package voldemort.utils.app;
+import java.util.Arrays;
import java.util.List;
import joptsimple.OptionSet;
@@ -47,6 +48,8 @@ public void run(String[] args) throws Exception {
parser.accepts("secretkey", "Secret key (used instead of secretkeyfile)").withRequiredArg();
parser.accepts("secretkeyfile", "Secret key file (used instead of secretkey)")
.withRequiredArg();
+ parser.accepts("securitygroups", "Security groups to allow on instances (optional)")
+ .withRequiredArg();
parser.accepts("ami", "AMI").withRequiredArg();
parser.accepts("keypairid", "KeyPairID").withRequiredArg();
parser.accepts("instances", "Number of instances (default 1)")
@@ -65,6 +68,10 @@ public void run(String[] args) throws Exception {
String ami = getRequiredString(options, "ami");
String keypairId = getRequiredString(options, "keypairid");
int instanceCount = CmdUtils.valueOf(options, "instances", 1);
+ String securityGroups = CmdUtils.valueOf(options, "securitygroups", null);
+ List<String> securityGroupsList = (securityGroups != null)
+ ? Arrays.asList(securityGroups.split(","))
+ : null;
Ec2Connection.Ec2InstanceType instanceType = null;
try {
@@ -79,7 +86,8 @@ public void run(String[] args) throws Exception {
List<HostNamePair> hostNamePairs = ec2Connection.createInstances(ami,
keypairId,
instanceType,
- instanceCount);
+ instanceCount,
+ securityGroupsList);
StringBuilder s = new StringBuilder();
@@ -93,4 +101,4 @@ public void run(String[] args) throws Exception {
System.out.print(s);
}
-}
+}
@@ -86,12 +86,16 @@ public TypicaEc2Connection(String accessId, String secretKey, Ec2ConnectionListe
public List<HostNamePair> createInstances(String ami,
String keypairId,
Ec2Connection.Ec2InstanceType instanceType,
- int instanceCount) throws Exception {
+ int instanceCount,
+ List<String> securityGroups) throws Exception {
LaunchConfiguration launchConfiguration = new LaunchConfiguration(ami);
launchConfiguration.setInstanceType(InstanceType.valueOf(instanceType.name()));
launchConfiguration.setKeyName(keypairId);
launchConfiguration.setMinCount(instanceCount);
launchConfiguration.setMaxCount(instanceCount);
+ if (securityGroups != null && securityGroups.size() > 0) {
+ launchConfiguration.setSecurityGroup(securityGroups);
+ }
ReservationDescription reservationDescription = ec2.runInstances(launchConfiguration);
@@ -43,7 +43,7 @@
return ec2.createInstances(ec2Config.getAmi(),
ec2Config.getKeyPairId(),
Ec2Connection.Ec2InstanceType.DEFAULT,
- instanceCount);
+ instanceCount, null);
}

0 comments on commit ebcbd5c

Please sign in to comment.