mirror of https://github.com/apache/jclouds.git
Issue 249: switch to use group, not key, for tag lookups; prefix jclouds created groups and keys with jclouds#tag so that we can differentiate what we've created from what the user has
This commit is contained in:
parent
6c14ae1831
commit
25fd278ecf
|
@ -48,6 +48,7 @@ import org.jclouds.compute.strategy.RebootNodeStrategy;
|
|||
import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy;
|
||||
import org.jclouds.compute.util.ComputeUtils;
|
||||
import org.jclouds.domain.Location;
|
||||
import static org.jclouds.util.Utils.*;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
|
@ -88,19 +89,21 @@ public class EC2ComputeService extends BaseComputeService {
|
|||
}
|
||||
|
||||
private void deleteSecurityGroup(String region, String tag) {
|
||||
if (ec2Client.getSecurityGroupServices().describeSecurityGroupsInRegion(region, tag).size() > 0) {
|
||||
logger.debug(">> deleting securityGroup(%s)", tag);
|
||||
ec2Client.getSecurityGroupServices().deleteSecurityGroupInRegion(region, tag);
|
||||
checkNotEmpty(tag, "tag");
|
||||
String group = "jclouds#" + tag;
|
||||
if (ec2Client.getSecurityGroupServices().describeSecurityGroupsInRegion(region, group).size() > 0) {
|
||||
logger.debug(">> deleting securityGroup(%s)", group);
|
||||
ec2Client.getSecurityGroupServices().deleteSecurityGroupInRegion(region, group);
|
||||
securityGroupMap.remove(new PortsRegionTag(region, tag, null)); // TODO: test this clear
|
||||
// happens
|
||||
logger.debug("<< deleted securityGroup(%s)", tag);
|
||||
logger.debug("<< deleted securityGroup(%s)", group);
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteKeyPair(String region, String tag) {
|
||||
for (KeyPair keyPair : ec2Client.getKeyPairServices().describeKeyPairsInRegion(region)) {
|
||||
if (keyPair.getKeyName().matches(tag + "-[0-9]+")) {
|
||||
logger.debug(">> deleting keyPair(%s)", tag);
|
||||
if (keyPair.getKeyName().matches("jclouds#" + tag + "-[0-9]+")) {
|
||||
logger.debug(">> deleting keyPair(%s)", keyPair.getKeyName());
|
||||
ec2Client.getKeyPairServices().deleteKeyPairInRegion(region, keyPair.getKeyName());
|
||||
credentialsMap.remove(new RegionTag(region, keyPair.getKeyName())); // TODO: test this
|
||||
// clear happens
|
||||
|
|
|
@ -66,7 +66,7 @@ public class CreateNewKeyPair implements Function<RegionTag, KeyPair> {
|
|||
while (keyPair == null) {
|
||||
try {
|
||||
keyPair = ec2Client.getKeyPairServices().createKeyPairInRegion(region,
|
||||
tag + "-" + new SecureRandom().nextInt(100));
|
||||
"jclouds#" + tag + "-" + new SecureRandom().nextInt(100));
|
||||
logger.debug("<< created keyPair(%s)", keyPair.getKeyName());
|
||||
} catch (AWSResponseException e) {
|
||||
if (!e.getError().getCode().equals("InvalidKeyPair.Duplicate")) {
|
||||
|
|
|
@ -114,11 +114,29 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
|
|||
String name = null; // user doesn't determine a node name;
|
||||
URI uri = null; // no uri to get rest access to host info
|
||||
|
||||
String tag = String.format("NOTAG-%s", instance.getId());// default
|
||||
try {
|
||||
tag = Iterables.getOnlyElement(
|
||||
Iterables.filter(instance.getGroupIds(), new Predicate<String>() {
|
||||
|
||||
@Override
|
||||
public boolean apply(String input) {
|
||||
return input.startsWith("jclouds#");
|
||||
}
|
||||
|
||||
})).substring(8);
|
||||
} catch (NoSuchElementException e) {
|
||||
logger
|
||||
.warn("no tag parsed from %s's groups: %s", instance.getId(), instance
|
||||
.getGroupIds());
|
||||
} catch (IllegalArgumentException e) {
|
||||
logger.warn("too many groups match %s; %s's groups: %s", "jclouds#", instance.getId(),
|
||||
instance.getGroupIds());
|
||||
}
|
||||
|
||||
Credentials credentials = null;// default if no keypair exists
|
||||
String tag = String.format("NOTAG-%s", instance.getId());// default if no keypair exists
|
||||
|
||||
if (instance.getKeyName() != null) {
|
||||
tag = instance.getKeyName().replaceAll("-[0-9]+", "");
|
||||
credentials = new Credentials(getLoginAccountFor(instance), getPrivateKeyOrNull(instance,
|
||||
tag));
|
||||
}
|
||||
|
|
|
@ -139,7 +139,8 @@ public class EC2RunNodesAndAddToSetStrategy implements RunNodesAndAddToSetStrate
|
|||
credentialsMap.put(new RegionTag(region, keyPair.getKeyName()), keyPair);
|
||||
|
||||
TemplateOptions options = template.getOptions();
|
||||
PortsRegionTag portsRegionTag = new PortsRegionTag(region, tag, options.getInboundPorts());
|
||||
String group = "jclouds#" +tag;
|
||||
PortsRegionTag portsRegionTag = new PortsRegionTag(region, group, options.getInboundPorts());
|
||||
if (!securityGroupMap.containsKey(portsRegionTag)) {
|
||||
securityGroupMap.put(portsRegionTag, createSecurityGroupIfNeeded.apply(portsRegionTag));
|
||||
}
|
||||
|
@ -148,10 +149,10 @@ public class EC2RunNodesAndAddToSetStrategy implements RunNodesAndAddToSetStrate
|
|||
.debug(
|
||||
">> running %d instance region(%s) zone(%s) ami(%s) type(%s) keyPair(%s) securityGroup(%s)",
|
||||
count, region, zone, template.getImage().getId(),
|
||||
ec2Size.getInstanceType(), tag, tag);
|
||||
ec2Size.getInstanceType(), keyPair.getKeyName(), group);
|
||||
RunInstancesOptions instanceOptions = withKeyName(keyPair.getKeyName())// key
|
||||
.asType(ec2Size.getInstanceType())// instance size
|
||||
.withSecurityGroup(tag)// group I created above
|
||||
.withSecurityGroup(group)// group I created above
|
||||
.withAdditionalInfo(tag);
|
||||
|
||||
Reservation reservation = ec2Client.getInstanceServices().runInstancesInRegion(region, zone,
|
||||
|
|
|
@ -27,7 +27,9 @@ import java.util.Set;
|
|||
|
||||
import org.jclouds.aws.ec2.domain.Attachment.Status;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.inject.internal.Nullable;
|
||||
|
||||
/**
|
||||
|
@ -45,7 +47,7 @@ public class RunningInstance implements Comparable<RunningInstance> {
|
|||
private final boolean deleteOnTermination;
|
||||
|
||||
public EbsBlockDevice(String volumeId, Status attachmentStatus, Date attachTime,
|
||||
boolean deleteOnTermination) {
|
||||
boolean deleteOnTermination) {
|
||||
super();
|
||||
this.volumeId = volumeId;
|
||||
this.attachmentStatus = attachmentStatus;
|
||||
|
@ -116,6 +118,8 @@ public class RunningInstance implements Comparable<RunningInstance> {
|
|||
}
|
||||
|
||||
private final String region;
|
||||
private final Set<String> groupIds = Sets.newLinkedHashSet();
|
||||
|
||||
private final String amiLaunchIndex;
|
||||
@Nullable
|
||||
private final String dnsName;
|
||||
|
@ -156,15 +160,17 @@ public class RunningInstance implements Comparable<RunningInstance> {
|
|||
return (this == o) ? 0 : getId().compareTo(o.getId());
|
||||
}
|
||||
|
||||
public RunningInstance(String region, @Nullable String amiLaunchIndex, @Nullable String dnsName,
|
||||
String imageId, String instanceId, InstanceState instanceState,
|
||||
String instanceType, @Nullable InetAddress ipAddress, @Nullable String kernelId,
|
||||
@Nullable String keyName, Date launchTime, boolean monitoring,
|
||||
String availabilityZone, @Nullable String platform,
|
||||
@Nullable String privateDnsName, @Nullable InetAddress privateIpAddress,
|
||||
Set<String> productCodes, @Nullable String ramdiskId, @Nullable String reason,
|
||||
@Nullable String subnetId, @Nullable String vpcId, RootDeviceType rootDeviceType,
|
||||
@Nullable String rootDeviceName, Map<String, EbsBlockDevice> ebsBlockDevices) {
|
||||
public RunningInstance(String region, Iterable<String> groupIds,
|
||||
@Nullable String amiLaunchIndex, @Nullable String dnsName, String imageId,
|
||||
String instanceId, InstanceState instanceState, String instanceType,
|
||||
@Nullable InetAddress ipAddress, @Nullable String kernelId, @Nullable String keyName,
|
||||
Date launchTime, boolean monitoring, String availabilityZone,
|
||||
@Nullable String platform, @Nullable String privateDnsName,
|
||||
@Nullable InetAddress privateIpAddress, Set<String> productCodes,
|
||||
@Nullable String ramdiskId, @Nullable String reason, @Nullable String subnetId,
|
||||
@Nullable String vpcId, RootDeviceType rootDeviceType, @Nullable String rootDeviceName,
|
||||
Map<String, EbsBlockDevice> ebsBlockDevices) {
|
||||
Iterables.addAll(this.groupIds, checkNotNull(groupIds, "groupIds"));
|
||||
this.region = checkNotNull(region, "region");
|
||||
this.amiLaunchIndex = amiLaunchIndex; // nullable on runinstances.
|
||||
this.dnsName = dnsName; // nullable on runinstances.
|
||||
|
@ -359,6 +365,13 @@ public class RunningInstance implements Comparable<RunningInstance> {
|
|||
return ebsBlockDevices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Names of the security groups.
|
||||
*/
|
||||
public Set<String> getGroupIds() {
|
||||
return groupIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
|
@ -367,6 +380,7 @@ public class RunningInstance implements Comparable<RunningInstance> {
|
|||
result = prime * result + ((availabilityZone == null) ? 0 : availabilityZone.hashCode());
|
||||
result = prime * result + ((dnsName == null) ? 0 : dnsName.hashCode());
|
||||
result = prime * result + ((ebsBlockDevices == null) ? 0 : ebsBlockDevices.hashCode());
|
||||
result = prime * result + ((groupIds == null) ? 0 : groupIds.hashCode());
|
||||
result = prime * result + ((imageId == null) ? 0 : imageId.hashCode());
|
||||
result = prime * result + ((instanceId == null) ? 0 : instanceId.hashCode());
|
||||
result = prime * result + ((instanceState == null) ? 0 : instanceState.hashCode());
|
||||
|
@ -417,6 +431,11 @@ public class RunningInstance implements Comparable<RunningInstance> {
|
|||
return false;
|
||||
} else if (!ebsBlockDevices.equals(other.ebsBlockDevices))
|
||||
return false;
|
||||
if (groupIds == null) {
|
||||
if (other.groupIds != null)
|
||||
return false;
|
||||
} else if (!groupIds.equals(other.groupIds))
|
||||
return false;
|
||||
if (imageId == null) {
|
||||
if (other.imageId != null)
|
||||
return false;
|
||||
|
@ -511,15 +530,15 @@ public class RunningInstance implements Comparable<RunningInstance> {
|
|||
public String toString() {
|
||||
return "RunningInstance [amiLaunchIndex=" + amiLaunchIndex + ", availabilityZone="
|
||||
+ availabilityZone + ", dnsName=" + dnsName + ", ebsBlockDevices=" + ebsBlockDevices
|
||||
+ ", imageId=" + imageId + ", instanceId=" + instanceId + ", instanceState="
|
||||
+ instanceState + ", instanceType=" + instanceType + ", ipAddress=" + ipAddress
|
||||
+ ", kernelId=" + kernelId + ", keyName=" + keyName + ", launchTime=" + launchTime
|
||||
+ ", monitoring=" + monitoring + ", platform=" + platform + ", privateDnsName="
|
||||
+ privateDnsName + ", privateIpAddress=" + privateIpAddress + ", productCodes="
|
||||
+ productCodes + ", ramdiskId=" + ramdiskId + ", reason=" + reason + ", region="
|
||||
+ region + ", rootDeviceName=" + rootDeviceName + ", rootDeviceType="
|
||||
+ rootDeviceType + ", subnetId=" + subnetId + ", vpcId=" + vpcId + "]";
|
||||
+ ", groupIds=" + groupIds + ", imageId=" + imageId + ", instanceId=" + instanceId
|
||||
+ ", instanceState=" + instanceState + ", instanceType=" + instanceType
|
||||
+ ", ipAddress=" + ipAddress + ", kernelId=" + kernelId + ", keyName=" + keyName
|
||||
+ ", launchTime=" + launchTime + ", monitoring=" + monitoring + ", platform="
|
||||
+ platform + ", privateDnsName=" + privateDnsName + ", privateIpAddress="
|
||||
+ privateIpAddress + ", productCodes=" + productCodes + ", ramdiskId=" + ramdiskId
|
||||
+ ", reason=" + reason + ", region=" + region + ", rootDeviceName=" + rootDeviceName
|
||||
+ ", rootDeviceType=" + rootDeviceType + ", subnetId=" + subnetId + ", vpcId="
|
||||
+ vpcId + "]";
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -208,11 +208,11 @@ public abstract class BaseReservationHandler<T> extends HandlerWithResult<T> {
|
|||
String region = EC2Utils.findRegionInArgsOrNull(request);
|
||||
if (region == null)
|
||||
region = defaultRegion;
|
||||
instances.add(new RunningInstance(region, amiLaunchIndex, dnsName, imageId, instanceId,
|
||||
instanceState, instanceType, ipAddress, kernelId, keyName, launchTime,
|
||||
monitoring, availabilityZone, platform, privateDnsName, privateIpAddress,
|
||||
productCodes, ramdiskId, reason, subnetId, vpcId, rootDeviceType, rootDeviceName,
|
||||
ebsBlockDevices));
|
||||
instances.add(new RunningInstance(region, groupIds, amiLaunchIndex, dnsName, imageId,
|
||||
instanceId, instanceState, instanceType, ipAddress, kernelId, keyName,
|
||||
launchTime, monitoring, availabilityZone, platform, privateDnsName,
|
||||
privateIpAddress, productCodes, ramdiskId, reason, subnetId, vpcId,
|
||||
rootDeviceType, rootDeviceName, ebsBlockDevices));
|
||||
this.amiLaunchIndex = null;
|
||||
this.dnsName = null;
|
||||
this.imageId = null;
|
||||
|
|
|
@ -55,10 +55,9 @@ import com.google.common.collect.ImmutableSet;
|
|||
*/
|
||||
@Test(groups = "unit", testName = "ec2.RunningInstanceToNodeMetadataTest")
|
||||
public class RunningInstanceToNodeMetadataTest {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testApplyWithNoKeyPairCreatesTagOfIdPrefixedByTagAndNullCredentials()
|
||||
public void testApplyWithNoSecurityGroupCreatesTagOfIdPrefixedByTagAndNullCredentials()
|
||||
throws UnknownHostException {
|
||||
AMIClient amiClient = createMock(AMIClient.class);
|
||||
Map<RegionTag, KeyPair> credentialsMap = createMock(Map.class);
|
||||
|
@ -73,6 +72,7 @@ public class RunningInstanceToNodeMetadataTest {
|
|||
RunningInstance instance = createMock(RunningInstance.class);
|
||||
|
||||
expect(instance.getId()).andReturn("id").atLeastOnce();
|
||||
expect(instance.getGroupIds()).andReturn(ImmutableSet.<String> of()).atLeastOnce();
|
||||
expect(instance.getKeyName()).andReturn(null).atLeastOnce();
|
||||
expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
||||
|
||||
|
@ -114,7 +114,64 @@ public class RunningInstanceToNodeMetadataTest {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testApplyWithKeyPairCreatesTagOfParsedKeyPairAndCredentialsBasedOnIt()
|
||||
public void testApplyWithNoKeyPairCreatesTagOfParsedSecurityGroupAndNullCredentials()
|
||||
throws UnknownHostException {
|
||||
AMIClient amiClient = createMock(AMIClient.class);
|
||||
Map<RegionTag, KeyPair> credentialsMap = createMock(Map.class);
|
||||
org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
||||
|
||||
Set<org.jclouds.compute.domain.Image> images = ImmutableSet
|
||||
.<org.jclouds.compute.domain.Image> of(jcImage);
|
||||
|
||||
Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
|
||||
Set<Location> locations = ImmutableSet.<Location> of(location);
|
||||
PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
|
||||
RunningInstance instance = createMock(RunningInstance.class);
|
||||
|
||||
expect(instance.getId()).andReturn("id").atLeastOnce();
|
||||
expect(instance.getGroupIds()).andReturn(ImmutableSet.of("jclouds#tag")).atLeastOnce();
|
||||
expect(instance.getKeyName()).andReturn(null).atLeastOnce();
|
||||
expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
||||
|
||||
expect(instance.getIpAddress()).andReturn(
|
||||
InetAddress.getByAddress(new byte[] { 12, 10, 10, 1 }));
|
||||
expect(instance.getPrivateIpAddress()).andReturn(
|
||||
InetAddress.getByAddress(new byte[] { 10, 10, 10, 1 }));
|
||||
|
||||
expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce();
|
||||
|
||||
expect(instance.getImageId()).andReturn("imageId").atLeastOnce();
|
||||
expect(jcImage.getId()).andReturn("imageId").atLeastOnce();
|
||||
expect(jcImage.getLocation()).andReturn(location).atLeastOnce();
|
||||
|
||||
expect(instance.getInstanceType()).andReturn(InstanceType.C1_XLARGE).atLeastOnce();
|
||||
|
||||
replay(jcImage);
|
||||
replay(amiClient);
|
||||
replay(credentialsMap);
|
||||
replay(credentialProvider);
|
||||
replay(instance);
|
||||
|
||||
RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(amiClient,
|
||||
credentialsMap, credentialProvider, images, locations,
|
||||
new RunningInstanceToStorageMappingUnix());
|
||||
|
||||
NodeMetadata metadata = parser.apply(instance);
|
||||
assertEquals(metadata.getLocation(), locations.iterator().next());
|
||||
assertEquals(metadata.getImage(), jcImage);
|
||||
assertEquals(metadata.getTag(), "tag");
|
||||
assertEquals(metadata.getCredentials(), null);
|
||||
|
||||
verify(jcImage);
|
||||
verify(amiClient);
|
||||
verify(credentialsMap);
|
||||
verify(credentialProvider);
|
||||
verify(instance);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testApplyWithKeyPairCreatesTagOfParsedSecurityGroupAndCredentialsBasedOnIt()
|
||||
throws UnknownHostException {
|
||||
AMIClient amiClient = createMock(AMIClient.class);
|
||||
Map<RegionTag, KeyPair> credentialsMap = createMock(Map.class);
|
||||
|
@ -124,7 +181,8 @@ public class RunningInstanceToNodeMetadataTest {
|
|||
Image image = createMock(Image.class);
|
||||
|
||||
expect(instance.getId()).andReturn("id").atLeastOnce();
|
||||
expect(instance.getKeyName()).andReturn("keyName-100").atLeastOnce();
|
||||
expect(instance.getGroupIds()).andReturn(ImmutableSet.of("jclouds#tag")).atLeastOnce();
|
||||
expect(instance.getKeyName()).andReturn("jclouds#keyName").atLeastOnce();
|
||||
expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
||||
|
||||
Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
|
||||
|
@ -149,8 +207,8 @@ public class RunningInstanceToNodeMetadataTest {
|
|||
|
||||
expect(credentialProvider.execute(image)).andReturn(new Credentials("user", "pass"));
|
||||
|
||||
expect(credentialsMap.get(new RegionTag(Region.US_EAST_1, "keyName-100"))).andReturn(
|
||||
new KeyPair(Region.US_EAST_1, "keyName-100", "keyFingerprint", "pass"));
|
||||
expect(credentialsMap.get(new RegionTag(Region.US_EAST_1, "jclouds#keyName"))).andReturn(
|
||||
new KeyPair(Region.US_EAST_1, "jclouds#keyName", "keyFingerprint", "pass"));
|
||||
|
||||
expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce();
|
||||
|
||||
|
@ -168,7 +226,7 @@ public class RunningInstanceToNodeMetadataTest {
|
|||
|
||||
NodeMetadata metadata = parser.apply(instance);
|
||||
|
||||
assertEquals(metadata.getTag(), "keyName");
|
||||
assertEquals(metadata.getTag(), "tag");
|
||||
assertEquals(metadata.getLocation(), location);
|
||||
assertEquals(metadata.getImage(), jcImage);
|
||||
|
||||
|
@ -182,4 +240,74 @@ public class RunningInstanceToNodeMetadataTest {
|
|||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testApplyWithTwoSecurityGroups()
|
||||
throws UnknownHostException {
|
||||
AMIClient amiClient = createMock(AMIClient.class);
|
||||
Map<RegionTag, KeyPair> credentialsMap = createMock(Map.class);
|
||||
|
||||
PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
|
||||
RunningInstance instance = createMock(RunningInstance.class);
|
||||
Image image = createMock(Image.class);
|
||||
|
||||
expect(instance.getId()).andReturn("id").atLeastOnce();
|
||||
expect(instance.getGroupIds()).andReturn(ImmutableSet.of("jclouds#tag","jclouds#tag2")).atLeastOnce();
|
||||
expect(instance.getKeyName()).andReturn("jclouds#keyName").atLeastOnce();
|
||||
expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
|
||||
|
||||
Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null);
|
||||
Set<Location> locations = ImmutableSet.<Location> of(location);
|
||||
org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
|
||||
Set<org.jclouds.compute.domain.Image> images = ImmutableSet
|
||||
.<org.jclouds.compute.domain.Image> of(jcImage);
|
||||
|
||||
expect(instance.getIpAddress()).andReturn(
|
||||
InetAddress.getByAddress(new byte[] { 12, 10, 10, 1 }));
|
||||
expect(instance.getPrivateIpAddress()).andReturn(
|
||||
InetAddress.getByAddress(new byte[] { 10, 10, 10, 1 }));
|
||||
|
||||
expect(instance.getRegion()).andReturn(Region.US_EAST_1).atLeastOnce();
|
||||
|
||||
expect(instance.getImageId()).andReturn("imageId").atLeastOnce();
|
||||
expect(jcImage.getId()).andReturn("imageId").atLeastOnce();
|
||||
expect(jcImage.getLocation()).andReturn(location).atLeastOnce();
|
||||
|
||||
expect(amiClient.describeImagesInRegion(Region.US_EAST_1, imageIds("imageId"))).andReturn(
|
||||
ImmutableSet.<Image> of(image));
|
||||
|
||||
expect(credentialProvider.execute(image)).andReturn(new Credentials("user", "pass"));
|
||||
|
||||
expect(credentialsMap.get(new RegionTag(Region.US_EAST_1, "jclouds#keyName"))).andReturn(
|
||||
new KeyPair(Region.US_EAST_1, "jclouds#keyName", "keyFingerprint", "pass"));
|
||||
|
||||
expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce();
|
||||
|
||||
expect(instance.getInstanceType()).andReturn(InstanceType.C1_XLARGE).atLeastOnce();
|
||||
|
||||
replay(amiClient);
|
||||
replay(credentialsMap);
|
||||
replay(credentialProvider);
|
||||
replay(instance);
|
||||
replay(jcImage);
|
||||
|
||||
RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(amiClient,
|
||||
credentialsMap, credentialProvider, images, locations,
|
||||
new RunningInstanceToStorageMappingUnix());
|
||||
|
||||
NodeMetadata metadata = parser.apply(instance);
|
||||
|
||||
assertEquals(metadata.getTag(), "NOTAG-id");
|
||||
assertEquals(metadata.getLocation(), location);
|
||||
assertEquals(metadata.getImage(), jcImage);
|
||||
|
||||
assertEquals(metadata.getCredentials(), new Credentials("user", "pass"));
|
||||
|
||||
verify(jcImage);
|
||||
verify(amiClient);
|
||||
verify(credentialsMap);
|
||||
verify(credentialProvider);
|
||||
verify(instance);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,7 +70,8 @@ public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest {
|
|||
Set<Reservation> contents = Sets.newTreeSet();
|
||||
|
||||
contents.add(new Reservation(defaultRegion, ImmutableSet.of("adriancole.ec2ingress"),
|
||||
ImmutableSet.of(new RunningInstance(defaultRegion, "0",
|
||||
ImmutableSet.of(new RunningInstance(defaultRegion, ImmutableSet
|
||||
.of("adriancole.ec2ingress"), "0",
|
||||
"ec2-174-129-81-68.compute-1.amazonaws.com", "ami-1fd73376", "i-0799056f",
|
||||
InstanceState.RUNNING, InstanceType.M1_SMALL, InetAddress
|
||||
.getByName("174.129.81.68"), "aki-a71cf9ce", "adriancole.ec21",
|
||||
|
@ -92,17 +93,19 @@ public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest {
|
|||
Set<Reservation> contents = Sets.newTreeSet();
|
||||
|
||||
contents.add(new Reservation(defaultRegion, ImmutableSet.of("default"), ImmutableSet.of(
|
||||
new RunningInstance(defaultRegion, "23", "ec2-72-44-33-4.compute-1.amazonaws.com",
|
||||
"ami-6ea54007", "i-28a64341", InstanceState.RUNNING, InstanceType.M1_LARGE,
|
||||
(InetAddress) null, "aki-ba3adfd3", "example-key-name", dateService
|
||||
new RunningInstance(defaultRegion, ImmutableSet.of("default"), "23",
|
||||
"ec2-72-44-33-4.compute-1.amazonaws.com", "ami-6ea54007", "i-28a64341",
|
||||
InstanceState.RUNNING, InstanceType.M1_LARGE, (InetAddress) null,
|
||||
"aki-ba3adfd3", "example-key-name", dateService
|
||||
.iso8601DateParse("2007-08-07T11:54:42.000Z"), false,
|
||||
AvailabilityZone.US_EAST_1B, null, "10-251-50-132.ec2.internal", null,
|
||||
ImmutableSet.of("774F4FF8"), "ari-badbad00", null, null, null,
|
||||
RootDeviceType.INSTANCE_STORE, null, ImmutableMap
|
||||
.<String, EbsBlockDevice> of()), new RunningInstance(
|
||||
defaultRegion, "23", "ec2-72-44-33-6.compute-1.amazonaws.com",
|
||||
"ami-6ea54007", "i-28a64435", InstanceState.RUNNING, InstanceType.M1_LARGE,
|
||||
(InetAddress) null, "aki-ba3adfd3", "example-key-name", dateService
|
||||
defaultRegion, ImmutableSet.of("default"), "23",
|
||||
"ec2-72-44-33-6.compute-1.amazonaws.com", "ami-6ea54007", "i-28a64435",
|
||||
InstanceState.RUNNING, InstanceType.M1_LARGE, (InetAddress) null,
|
||||
"aki-ba3adfd3", "example-key-name", dateService
|
||||
.iso8601DateParse("2007-08-07T11:54:42.000Z"), false,
|
||||
AvailabilityZone.US_EAST_1B, null, "10-251-50-134.ec2.internal", null,
|
||||
ImmutableSet.of("774F4FF8"), "ari-badbad00", null, null, null,
|
||||
|
@ -121,7 +124,8 @@ public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest {
|
|||
Set<Reservation> contents = Sets.newTreeSet();
|
||||
|
||||
contents.add(new Reservation(defaultRegion, ImmutableSet.of("adriancole.ec2ebsingress"),
|
||||
ImmutableSet.of(new RunningInstance(defaultRegion, "0",
|
||||
ImmutableSet.of(new RunningInstance(defaultRegion, ImmutableSet
|
||||
.of("adriancole.ec2ebsingress"), "0",
|
||||
"ec2-75-101-203-146.compute-1.amazonaws.com", "ami-849875ed", "i-e564438d",
|
||||
InstanceState.RUNNING, InstanceType.M1_SMALL, InetAddress
|
||||
.getByName("75.101.203.146"), "aki-a71cf9ce",
|
||||
|
|
|
@ -67,25 +67,25 @@ public class RunInstancesResponseHandlerTest extends BaseEC2HandlerTest {
|
|||
InputStream is = getClass().getResourceAsStream("/ec2/run_instances.xml");
|
||||
|
||||
Reservation expected = new Reservation(defaultRegion, ImmutableSortedSet.of("default"),
|
||||
ImmutableSet.of(new RunningInstance(defaultRegion, "0", null, "ami-60a54009",
|
||||
"i-2ba64342", InstanceState.PENDING, InstanceType.M1_SMALL,
|
||||
ImmutableSet.of(new RunningInstance(defaultRegion, ImmutableSortedSet.of("default"),
|
||||
"0", null, "ami-60a54009", "i-2ba64342", InstanceState.PENDING,
|
||||
InstanceType.M1_SMALL, (InetAddress) null, null, "example-key-name",
|
||||
dateService.iso8601DateParse("2007-08-07T11:51:50.000Z"), true,
|
||||
AvailabilityZone.US_EAST_1B, null, null, (InetAddress) null, Sets
|
||||
.<String> newTreeSet(), null, null, null, null,
|
||||
RootDeviceType.INSTANCE_STORE, null, ImmutableMap
|
||||
.<String, EbsBlockDevice> of()), new RunningInstance(
|
||||
defaultRegion, ImmutableSortedSet.of("default"), "1", null, "ami-60a54009",
|
||||
"i-2bc64242", InstanceState.PENDING, InstanceType.M1_SMALL,
|
||||
(InetAddress) null, null, "example-key-name", dateService
|
||||
.iso8601DateParse("2007-08-07T11:51:50.000Z"), true,
|
||||
AvailabilityZone.US_EAST_1B, null, null, (InetAddress) null, Sets
|
||||
.<String> newTreeSet(), null, null, null, null,
|
||||
RootDeviceType.INSTANCE_STORE, null, ImmutableMap
|
||||
.<String, EbsBlockDevice> of()), new RunningInstance(
|
||||
defaultRegion, "1", null, "ami-60a54009", "i-2bc64242",
|
||||
InstanceState.PENDING, InstanceType.M1_SMALL, (InetAddress) null, null,
|
||||
"example-key-name", dateService
|
||||
.iso8601DateParse("2007-08-07T11:51:50.000Z"), true,
|
||||
AvailabilityZone.US_EAST_1B, null, null, (InetAddress) null, Sets
|
||||
.<String> newTreeSet(), null, null, null, null,
|
||||
RootDeviceType.INSTANCE_STORE, null, ImmutableMap
|
||||
.<String, EbsBlockDevice> of()), new RunningInstance(
|
||||
defaultRegion, "2", null, "ami-60a54009", "i-2be64332",
|
||||
InstanceState.PENDING, InstanceType.M1_SMALL, (InetAddress) null, null,
|
||||
"example-key-name", dateService
|
||||
defaultRegion, ImmutableSortedSet.of("default"), "2", null, "ami-60a54009",
|
||||
"i-2be64332", InstanceState.PENDING, InstanceType.M1_SMALL,
|
||||
(InetAddress) null, null, "example-key-name", dateService
|
||||
.iso8601DateParse("2007-08-07T11:51:50.000Z"), true,
|
||||
AvailabilityZone.US_EAST_1B, null, null, (InetAddress) null, Sets
|
||||
.<String> newTreeSet(), null, null, null, null,
|
||||
|
|
Loading…
Reference in New Issue