fixed ec2 to work with alestic amis

This commit is contained in:
Adrian Cole 2010-04-05 20:06:57 -07:00
parent 9837bfd3ba
commit 736e85da6b
1 changed files with 17 additions and 1 deletions

View File

@ -10,8 +10,11 @@ import javax.inject.Singleton;
import org.jclouds.aws.ec2.compute.domain.KeyPairCredentials;
import org.jclouds.aws.ec2.compute.domain.RegionTag;
import org.jclouds.aws.ec2.domain.Image;
import org.jclouds.aws.ec2.domain.InstanceState;
import org.jclouds.aws.ec2.domain.RunningInstance;
import org.jclouds.aws.ec2.options.DescribeImagesOptions;
import org.jclouds.aws.ec2.services.AMIClient;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.internal.NodeMetadataImpl;
@ -20,6 +23,7 @@ import org.jclouds.domain.Credentials;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
@Singleton
public class RunningInstanceToNodeMetadata implements Function<RunningInstance, NodeMetadata> {
@ -27,10 +31,14 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
.<InstanceState, NodeState> builder().put(InstanceState.PENDING, NodeState.PENDING)
.put(InstanceState.RUNNING, NodeState.RUNNING).put(InstanceState.SHUTTING_DOWN,
NodeState.PENDING).put(InstanceState.TERMINATED, NodeState.TERMINATED).build();
private final AMIClient amiClient;
private final Map<RegionTag, KeyPairCredentials> credentialsMap;
@Inject
public RunningInstanceToNodeMetadata(Map<RegionTag, KeyPairCredentials> credentialsMap) {
public RunningInstanceToNodeMetadata(AMIClient amiClient,
Map<RegionTag, KeyPairCredentials> credentialsMap) {
this.amiClient = amiClient;
this.credentialsMap = credentialsMap;
}
@ -47,6 +55,14 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
Credentials credentials = credentialsMap.containsKey(new RegionTag(from.getRegion(), tag)) ? credentialsMap
.get(new RegionTag(from.getRegion(), tag))
: null;
Image image = Iterables.getOnlyElement(amiClient.describeImagesInRegion(from.getRegion(),
DescribeImagesOptions.Builder.imageIds(from.getImageId())));
// canonical/alestic images use the ubuntu user to login
// TODO: add this as a property of image
if (credentials != null && image.getImageOwnerId().equals("063491364108"))
credentials = new Credentials("ubuntu", credentials.key);
String locationId = from.getAvailabilityZone().toString();
Map<String, String> extra = ImmutableMap.<String, String> of();
return new NodeMetadataImpl(id, name, locationId, uri, userMetadata, tag, state,