Added support for RunInstances parameter PrivateIpAddress on EC2

This commit is contained in:
Nikolay Sokolov 2015-02-06 15:26:51 +03:00 committed by Ignasi Barrera
parent dce4cd29ec
commit 5b4ac5f186
5 changed files with 65 additions and 2 deletions

View File

@ -85,6 +85,8 @@ public class AWSEC2TemplateOptions extends EC2TemplateOptions implements Cloneab
eTo.spotPrice(getSpotPrice()); eTo.spotPrice(getSpotPrice());
if (getSpotOptions() != null) if (getSpotOptions() != null)
eTo.spotOptions(getSpotOptions()); eTo.spotOptions(getSpotOptions());
if (getPrivateIpAddress() != null)
eTo.privateIpAddress(getPrivateIpAddress());
} }
} }
@ -97,6 +99,7 @@ public class AWSEC2TemplateOptions extends EC2TemplateOptions implements Cloneab
private Set<String> groupIds = ImmutableSet.of(); private Set<String> groupIds = ImmutableSet.of();
private String iamInstanceProfileArn; private String iamInstanceProfileArn;
private String iamInstanceProfileName; private String iamInstanceProfileName;
private String privateIpAddress;
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
@ -110,13 +113,14 @@ public class AWSEC2TemplateOptions extends EC2TemplateOptions implements Cloneab
&& equal(this.noPlacementGroup, that.noPlacementGroup) && equal(this.subnetId, that.subnetId) && equal(this.noPlacementGroup, that.noPlacementGroup) && equal(this.subnetId, that.subnetId)
&& equal(this.spotPrice, that.spotPrice) && equal(this.spotOptions, that.spotOptions) && equal(this.spotPrice, that.spotPrice) && equal(this.spotOptions, that.spotOptions)
&& equal(this.groupIds, that.groupIds) && equal(this.iamInstanceProfileArn, that.iamInstanceProfileArn) && equal(this.groupIds, that.groupIds) && equal(this.iamInstanceProfileArn, that.iamInstanceProfileArn)
&& equal(this.iamInstanceProfileName, that.iamInstanceProfileName); && equal(this.iamInstanceProfileName, that.iamInstanceProfileName)
&& equal(this.privateIpAddress, that.privateIpAddress);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hashCode(super.hashCode(), monitoringEnabled, placementGroup, noPlacementGroup, subnetId, return Objects.hashCode(super.hashCode(), monitoringEnabled, placementGroup, noPlacementGroup, subnetId,
spotPrice, spotOptions, groupIds, iamInstanceProfileArn, iamInstanceProfileName); spotPrice, spotOptions, groupIds, iamInstanceProfileArn, iamInstanceProfileName, privateIpAddress);
} }
@Override @Override
@ -135,6 +139,7 @@ public class AWSEC2TemplateOptions extends EC2TemplateOptions implements Cloneab
toString.add("groupIds", groupIds); toString.add("groupIds", groupIds);
toString.add("iamInstanceProfileArn", iamInstanceProfileArn); toString.add("iamInstanceProfileArn", iamInstanceProfileArn);
toString.add("iamInstanceProfileName", iamInstanceProfileName); toString.add("iamInstanceProfileName", iamInstanceProfileName);
toString.add("privateIpAddress", privateIpAddress);
return toString; return toString;
} }
@ -195,6 +200,11 @@ public class AWSEC2TemplateOptions extends EC2TemplateOptions implements Cloneab
return this; return this;
} }
public AWSEC2TemplateOptions privateIpAddress(String address) {
this.privateIpAddress = checkNotNull(emptyToNull(address), "address must be defined");
return this;
}
/** /**
* Specifies the maximum spot price to use * Specifies the maximum spot price to use
*/ */
@ -442,6 +452,11 @@ public class AWSEC2TemplateOptions extends EC2TemplateOptions implements Cloneab
return options.iamInstanceProfileName(name); return options.iamInstanceProfileName(name);
} }
public static AWSEC2TemplateOptions privateIpAddress(String address) {
AWSEC2TemplateOptions options = new AWSEC2TemplateOptions();
return options.privateIpAddress(address);
}
/** /**
* @see AWSEC2TemplateOptions#spotPrice * @see AWSEC2TemplateOptions#spotPrice
*/ */
@ -788,4 +803,8 @@ public class AWSEC2TemplateOptions extends EC2TemplateOptions implements Cloneab
public String getIAMInstanceProfileName() { public String getIAMInstanceProfileName() {
return iamInstanceProfileName; return iamInstanceProfileName;
} }
public String getPrivateIpAddress() {
return privateIpAddress;
}
} }

View File

@ -92,6 +92,8 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions
instanceOptions.withIAMInstanceProfileArn(awsTemplateOptions.getIAMInstanceProfileArn()); instanceOptions.withIAMInstanceProfileArn(awsTemplateOptions.getIAMInstanceProfileArn());
if (awsTemplateOptions.getIAMInstanceProfileName() != null) if (awsTemplateOptions.getIAMInstanceProfileName() != null)
instanceOptions.withIAMInstanceProfileName(awsTemplateOptions.getIAMInstanceProfileName()); instanceOptions.withIAMInstanceProfileName(awsTemplateOptions.getIAMInstanceProfileName());
if (awsTemplateOptions.getPrivateIpAddress() != null)
instanceOptions.withPrivateIpAddress(awsTemplateOptions.getPrivateIpAddress());
return instanceOptions; return instanceOptions;
} }

View File

@ -114,6 +114,16 @@ public class AWSRunInstancesOptions extends RunInstancesOptions {
return this; return this;
} }
/**
* The primary IP address for VPC instance. You must specify a value from the IP address range of the subnet.
*
* @see org.jclouds.aws.ec2.domain.AWSRunningInstance#getPrivateIpAddress()
*/
public AWSRunInstancesOptions withPrivateIpAddress(String address) {
formParameters.put("PrivateIpAddress", checkNotNull(address, "address"));
return this;
}
public static class Builder extends RunInstancesOptions.Builder { public static class Builder extends RunInstancesOptions.Builder {
/** /**
@ -220,6 +230,14 @@ public class AWSRunInstancesOptions extends RunInstancesOptions {
return options.withBlockDeviceMappings(mappings); return options.withBlockDeviceMappings(mappings);
} }
/**
* @see AWSRunInstancesOptions#withPrivateIpAddress(String)
*/
public static AWSRunInstancesOptions withPrivateIpAdress(String address) {
AWSRunInstancesOptions options = new AWSRunInstancesOptions();
return options.withPrivateIpAddress(address);
}
} }
@Override @Override

View File

@ -25,6 +25,7 @@ import static org.jclouds.aws.ec2.compute.AWSEC2TemplateOptions.Builder.inboundP
import static org.jclouds.aws.ec2.compute.AWSEC2TemplateOptions.Builder.installPrivateKey; import static org.jclouds.aws.ec2.compute.AWSEC2TemplateOptions.Builder.installPrivateKey;
import static org.jclouds.aws.ec2.compute.AWSEC2TemplateOptions.Builder.keyPair; import static org.jclouds.aws.ec2.compute.AWSEC2TemplateOptions.Builder.keyPair;
import static org.jclouds.aws.ec2.compute.AWSEC2TemplateOptions.Builder.noKeyPair; import static org.jclouds.aws.ec2.compute.AWSEC2TemplateOptions.Builder.noKeyPair;
import static org.jclouds.aws.ec2.compute.AWSEC2TemplateOptions.Builder.privateIpAddress;
import static org.jclouds.aws.ec2.compute.AWSEC2TemplateOptions.Builder.securityGroupIds; import static org.jclouds.aws.ec2.compute.AWSEC2TemplateOptions.Builder.securityGroupIds;
import static org.jclouds.aws.ec2.compute.AWSEC2TemplateOptions.Builder.securityGroups; import static org.jclouds.aws.ec2.compute.AWSEC2TemplateOptions.Builder.securityGroups;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
@ -413,4 +414,15 @@ public class AWSEC2TemplateOptionsTest {
public void testIAMInstanceProfileNameNPE() { public void testIAMInstanceProfileNameNPE() {
iamInstanceProfileName(null); iamInstanceProfileName(null);
} }
@Test
public void testPrivateIpAddressStatic() {
AWSEC2TemplateOptions options = privateIpAddress("10.0.0.1");
assertEquals(options.getPrivateIpAddress(), "10.0.0.1");
}
@Test(expectedExceptions = NullPointerException.class)
public void testPrivateIpAddressNPE() {
privateIpAddress(null);
}
} }

View File

@ -23,6 +23,7 @@ import static org.jclouds.aws.ec2.options.AWSRunInstancesOptions.Builder.withIAM
import static org.jclouds.aws.ec2.options.AWSRunInstancesOptions.Builder.withIAMInstanceProfileName; import static org.jclouds.aws.ec2.options.AWSRunInstancesOptions.Builder.withIAMInstanceProfileName;
import static org.jclouds.aws.ec2.options.AWSRunInstancesOptions.Builder.withKernelId; import static org.jclouds.aws.ec2.options.AWSRunInstancesOptions.Builder.withKernelId;
import static org.jclouds.aws.ec2.options.AWSRunInstancesOptions.Builder.withKeyName; import static org.jclouds.aws.ec2.options.AWSRunInstancesOptions.Builder.withKeyName;
import static org.jclouds.aws.ec2.options.AWSRunInstancesOptions.Builder.withPrivateIpAdress;
import static org.jclouds.aws.ec2.options.AWSRunInstancesOptions.Builder.withRamdisk; import static org.jclouds.aws.ec2.options.AWSRunInstancesOptions.Builder.withRamdisk;
import static org.jclouds.aws.ec2.options.AWSRunInstancesOptions.Builder.withSecurityGroup; import static org.jclouds.aws.ec2.options.AWSRunInstancesOptions.Builder.withSecurityGroup;
import static org.jclouds.aws.ec2.options.AWSRunInstancesOptions.Builder.withSecurityGroupId; import static org.jclouds.aws.ec2.options.AWSRunInstancesOptions.Builder.withSecurityGroupId;
@ -371,4 +372,15 @@ public class AWSRunInstancesOptionsTest {
withBlockDeviceMappings(null); withBlockDeviceMappings(null);
} }
@Test
public void testWithPrivateIpAddressStatic() {
AWSRunInstancesOptions options = withPrivateIpAdress("10.0.0.1");
assertEquals(options.buildFormParameters().get("PrivateIpAddress"), ImmutableList.of("10.0.0.1"));
}
@Test(expectedExceptions = NullPointerException.class)
public void testWithPrivateIpAddressStaticNPE() {
withPrivateIpAdress(null);
}
} }