mirror of https://github.com/apache/jclouds.git
Issue 354: new amazon linux is default for ec2; 64bit and uses yum packaging
This commit is contained in:
parent
69417755cd
commit
ccbe1c56f1
|
@ -45,8 +45,8 @@ public class EC2PropertiesBuilder extends PropertiesBuilder {
|
|||
properties.setProperty(PROPERTY_ENDPOINT, "https://ec2.us-east-1.amazonaws.com");
|
||||
properties.setProperty(PROPERTY_API_VERSION, EC2AsyncClient.VERSION);
|
||||
properties.setProperty(PROPERTY_ELB_ENDPOINT, "https://elasticloadbalancing.us-east-1.amazonaws.com");
|
||||
// alestic, canonical, and rightscale
|
||||
properties.setProperty(PROPERTY_EC2_AMI_OWNERS, "063491364108,099720109477,411009282317");
|
||||
// amazon, alestic, canonical, and rightscale
|
||||
properties.setProperty(PROPERTY_EC2_AMI_OWNERS, "137112412989,063491364108,099720109477,411009282317");
|
||||
// amis that work with the cluster instances
|
||||
properties.setProperty(PROPERTY_EC2_CC_AMIs, "us-east-1/ami-7ea24a17");
|
||||
// auth fail sometimes happens in EC2, as the rc.local script that injects the
|
||||
|
|
|
@ -24,8 +24,8 @@ import static com.google.common.collect.Maps.newLinkedHashMap;
|
|||
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
|
||||
import static org.jclouds.aws.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS;
|
||||
import static org.jclouds.aws.ec2.reference.EC2Constants.PROPERTY_EC2_CC_AMIs;
|
||||
import static org.jclouds.compute.domain.OsFamily.AMZN_LINUX;
|
||||
import static org.jclouds.compute.domain.OsFamily.CENTOS;
|
||||
import static org.jclouds.compute.domain.OsFamily.UBUNTU;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Map;
|
||||
|
@ -165,8 +165,8 @@ public class EC2ComputeServiceContextModule extends BaseComputeServiceContextMod
|
|||
@Override
|
||||
protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) {
|
||||
String region = injector.getInstance(Key.get(String.class, Region.class));
|
||||
return "Eucalyptus".equals(region) ? template.osFamily(CENTOS).smallest() : template.osFamily(UBUNTU)
|
||||
.osVersionMatches("10.04").os64Bit(true).osDescriptionMatches(".*ubuntu-images.*");
|
||||
return "Eucalyptus".equals(region) ? template.osFamily(CENTOS).smallest() : template.osFamily(AMZN_LINUX)
|
||||
.os64Bit(true);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
|
|
@ -61,6 +61,11 @@ public class ImageParser implements Function<org.jclouds.aws.ec2.domain.Image, I
|
|||
@Resource
|
||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
// 137112412989/amzn-ami-0.9.7-beta.i386-ebs
|
||||
// 137112412989/amzn-ami-0.9.7-beta.x86_64-ebs
|
||||
// amzn-ami-us-east-1/amzn-ami-0.9.7-beta.x86_64.manifest.xml
|
||||
// amzn-ami-us-east-1/amzn-ami-0.9.7-beta.i386.manifest.xml
|
||||
public static final Pattern AMZN_PATTERN = Pattern.compile(".*/amzn-ami-(.*)\\.(i386|x86_64)(-ebs|\\.manifest.xml)?");
|
||||
|
||||
public static final Pattern CANONICAL_PATTERN = Pattern.compile(".*/([^-]*)-([^-]*)-.*-(.*)(\\.manifest.xml)?");
|
||||
|
||||
|
@ -108,9 +113,14 @@ public class ImageParser implements Function<org.jclouds.aws.ec2.domain.Image, I
|
|||
boolean is64Bit = from.getArchitecture() == Architecture.X86_64;
|
||||
try {
|
||||
Matcher matcher = getMatcherAndFind(from.getImageLocation());
|
||||
osFamily = OsFamily.fromValue(matcher.group(1));
|
||||
osVersion = parseVersionOrReturnEmptyString(osFamily, matcher.group(2));
|
||||
version = matcher.group(3).replace(".manifest.xml", "");
|
||||
if (matcher.pattern() == AMZN_PATTERN) {
|
||||
osFamily = OsFamily.AMZN_LINUX;
|
||||
version = osVersion = matcher.group(1);
|
||||
} else {
|
||||
osFamily = OsFamily.fromValue(matcher.group(1));
|
||||
osVersion = parseVersionOrReturnEmptyString(osFamily, matcher.group(2));
|
||||
version = matcher.group(3).replace(".manifest.xml", "");
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
logger.debug("<< didn't match os(%s)", from.getImageLocation());
|
||||
} catch (NoSuchElementException e) {
|
||||
|
@ -147,7 +157,7 @@ public class ImageParser implements Function<org.jclouds.aws.ec2.domain.Image, I
|
|||
* if no configured matcher matches the manifest.
|
||||
*/
|
||||
private Matcher getMatcherAndFind(String manifest) {
|
||||
for (Pattern pattern : new Pattern[] { CANONICAL_PATTERN, RIGHTIMAGE_PATTERN, RIGHTSCALE_PATTERN }) {
|
||||
for (Pattern pattern : new Pattern[] { AMZN_PATTERN, CANONICAL_PATTERN, RIGHTIMAGE_PATTERN, RIGHTSCALE_PATTERN }) {
|
||||
Matcher matcher = pattern.matcher(manifest);
|
||||
if (matcher.find())
|
||||
return matcher;
|
||||
|
|
|
@ -36,19 +36,18 @@ public class EC2PopulateDefaultLoginCredentialsForImageStrategy implements
|
|||
|
||||
@Override
|
||||
public Credentials execute(Object resourceToAuthenticate) {
|
||||
if (resourceToAuthenticate == null)
|
||||
return new Credentials("root", null);
|
||||
|
||||
checkArgument(resourceToAuthenticate instanceof Image, "Resource must be an image (for EC2)");
|
||||
Image image = (Image) resourceToAuthenticate;
|
||||
|
||||
Credentials credentials;
|
||||
// canonical/alestic images use the ubuntu user to login
|
||||
if (image != null && image.getImageOwnerId().matches("063491364108|099720109477"))
|
||||
credentials = new Credentials("ubuntu", null);
|
||||
else
|
||||
credentials = new Credentials("root", null);
|
||||
|
||||
Credentials credentials = new Credentials("root", null);
|
||||
if (resourceToAuthenticate != null) {
|
||||
checkArgument(resourceToAuthenticate instanceof Image, "Resource must be an image (for EC2)");
|
||||
Image image = (Image) resourceToAuthenticate;
|
||||
// canonical/alestic images use the ubuntu user to login
|
||||
if (image.getImageOwnerId().matches("063491364108|099720109477")) {
|
||||
credentials = new Credentials("ubuntu", null);
|
||||
// http://aws.typepad.com/aws/2010/09/introducing-amazon-linux-ami.html
|
||||
} else if (image.getImageOwnerId().equals("137112412989")) {
|
||||
credentials = new Credentials("ec2-user", null);
|
||||
}
|
||||
}
|
||||
return credentials;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
|
|||
protected void assertDefaultWorks() {
|
||||
Template defaultTemplate = client.templateBuilder().build();
|
||||
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
|
||||
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
|
||||
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.AMZN_LINUX);
|
||||
assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,6 @@ import org.testng.annotations.BeforeGroups;
|
|||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -83,7 +82,7 @@ public class EC2TemplateBuilderLiveTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testTemplateBuilder() throws IOException {
|
||||
public void testDefaultTemplateBuilder() throws IOException {
|
||||
ComputeServiceContext newContext = null;
|
||||
try {
|
||||
newContext = new ComputeServiceContextFactory().createContext("ec2", user, password,
|
||||
|
@ -91,18 +90,13 @@ public class EC2TemplateBuilderLiveTest {
|
|||
|
||||
Template defaultTemplate = newContext.getComputeService().templateBuilder().build();
|
||||
assert (defaultTemplate.getImage().getProviderId().startsWith("ami-")) : defaultTemplate;
|
||||
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "10.04");
|
||||
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "0.9.7-beta");
|
||||
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
|
||||
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
|
||||
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.AMZN_LINUX);
|
||||
assertEquals(defaultTemplate.getImage().getUserMetadata().get("rootDeviceType"), "ebs");
|
||||
assertEquals(defaultTemplate.getLocation().getId(), "us-east-1");
|
||||
assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
|
||||
newContext.getComputeService().templateBuilder()
|
||||
.imageId(Iterables.get(newContext.getComputeService().listImages(), 0).getId()).build();
|
||||
newContext.getComputeService().templateBuilder().osFamily(OsFamily.UBUNTU).smallest().os64Bit(false)
|
||||
.imageId("us-east-1/ami-7e28ca17").build();
|
||||
newContext.getComputeService().templateBuilder().osFamily(OsFamily.UBUNTU).smallest().os64Bit(false)
|
||||
.imageId("us-east-1/ami-bb709dd2").build();
|
||||
|
||||
} finally {
|
||||
if (newContext != null)
|
||||
newContext.close();
|
||||
|
|
|
@ -314,6 +314,87 @@ public class ImageParserTest extends BaseEC2HandlerTest {
|
|||
|
||||
}
|
||||
|
||||
public void testParseAmznmage() {
|
||||
InputStream is = getClass().getResourceAsStream("/ec2/amzn_images.xml");
|
||||
|
||||
Set<Image> result = parseImages(is);
|
||||
assertEquals(result.size(), 4);
|
||||
ImageParser parser = new ImageParser(new EC2PopulateDefaultLoginCredentialsForImageStrategy(), Suppliers
|
||||
.<Set<? extends Location>> ofInstance(ImmutableSet.<Location> of(defaultLocation)), Suppliers
|
||||
.ofInstance(defaultLocation));
|
||||
|
||||
org.jclouds.compute.domain.Image image = parser.apply(Iterables.get(result, 0));
|
||||
|
||||
assertEquals(image.getOperatingSystem().is64Bit(), false);
|
||||
assertEquals(image.getDescription(), "Amazon");
|
||||
assertEquals(image.getId(), "us-east-1/ami-82e4b5c7");
|
||||
assertEquals(image.getProviderId(), "ami-82e4b5c7");
|
||||
assertEquals(image.getLocation(), defaultLocation);
|
||||
assertEquals(image.getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getVersion(), "0.9.7-beta");
|
||||
assertEquals(image.getOperatingSystem().getArch(), "paravirtual");
|
||||
assertEquals(image.getOperatingSystem().getDescription(), "137112412989/amzn-ami-0.9.7-beta.i386-ebs");
|
||||
assertEquals(image.getOperatingSystem().getFamily(), OsFamily.AMZN_LINUX);
|
||||
assertEquals(image.getUserMetadata(), ImmutableMap.<String, String> of("owner", "137112412989", "rootDeviceType",
|
||||
"ebs"));
|
||||
assertEquals(image.getVersion(), "0.9.7-beta");
|
||||
|
||||
image = parser.apply(Iterables.get(result, 1));
|
||||
|
||||
assertEquals(image.getOperatingSystem().is64Bit(), true);
|
||||
assertEquals(image.getDescription(), "Amazon");
|
||||
assertEquals(image.getId(), "us-east-1/ami-8ce4b5c9");
|
||||
assertEquals(image.getProviderId(), "ami-8ce4b5c9");
|
||||
assertEquals(image.getLocation(), defaultLocation);
|
||||
assertEquals(image.getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getVersion(), "0.9.7-beta");
|
||||
assertEquals(image.getOperatingSystem().getArch(), "paravirtual");
|
||||
assertEquals(image.getOperatingSystem().getDescription(), "137112412989/amzn-ami-0.9.7-beta.x86_64-ebs");
|
||||
assertEquals(image.getOperatingSystem().getFamily(), OsFamily.AMZN_LINUX);
|
||||
assertEquals(image.getUserMetadata(), ImmutableMap.<String, String> of("owner", "137112412989", "rootDeviceType",
|
||||
"ebs"));
|
||||
assertEquals(image.getVersion(), "0.9.7-beta");
|
||||
|
||||
image = parser.apply(Iterables.get(result, 2));
|
||||
|
||||
assertEquals(image.getOperatingSystem().is64Bit(), false);
|
||||
assertEquals(image.getDescription(), "Amazon Linux AMI i386 S3");
|
||||
assertEquals(image.getId(), "us-east-1/ami-f0e4b5b5");
|
||||
assertEquals(image.getProviderId(), "ami-f0e4b5b5");
|
||||
assertEquals(image.getLocation(), defaultLocation);
|
||||
assertEquals(image.getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getVersion(), "0.9.7-beta");
|
||||
assertEquals(image.getOperatingSystem().getArch(), "paravirtual");
|
||||
assertEquals(image.getOperatingSystem().getDescription(), "amzn-ami-us-west-1/amzn-ami-0.9.7-beta.i386.manifest.xml");
|
||||
assertEquals(image.getOperatingSystem().getFamily(), OsFamily.AMZN_LINUX);
|
||||
assertEquals(image.getUserMetadata(), ImmutableMap.<String, String> of("owner", "137112412989", "rootDeviceType",
|
||||
"instance-store"));
|
||||
assertEquals(image.getVersion(), "0.9.7-beta");
|
||||
|
||||
image = parser.apply(Iterables.get(result, 3));
|
||||
|
||||
assertEquals(image.getOperatingSystem().is64Bit(), true);
|
||||
assertEquals(image.getDescription(), "Amazon Linux AMI x86_64 S3");
|
||||
assertEquals(image.getId(), "us-east-1/ami-f2e4b5b7");
|
||||
assertEquals(image.getProviderId(), "ami-f2e4b5b7");
|
||||
assertEquals(image.getLocation(), defaultLocation);
|
||||
assertEquals(image.getName(), null);
|
||||
|
||||
assertEquals(image.getOperatingSystem().getName(), null);
|
||||
assertEquals(image.getOperatingSystem().getVersion(), "0.9.7-beta");
|
||||
assertEquals(image.getOperatingSystem().getArch(), "paravirtual");
|
||||
assertEquals(image.getOperatingSystem().getDescription(), "amzn-ami-us-west-1/amzn-ami-0.9.7-beta.x86_64.manifest.xml");
|
||||
assertEquals(image.getOperatingSystem().getFamily(), OsFamily.AMZN_LINUX);
|
||||
assertEquals(image.getUserMetadata(), ImmutableMap.<String, String> of("owner", "137112412989", "rootDeviceType",
|
||||
"instance-store"));
|
||||
assertEquals(image.getVersion(), "0.9.7-beta");
|
||||
|
||||
|
||||
}
|
||||
|
||||
private Set<Image> parseImages(InputStream is) {
|
||||
DescribeImagesResponseHandler handler = injector.getInstance(DescribeImagesResponseHandler.class);
|
||||
addDefaultRegionToHandler(handler);
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
<?xml version="1.0"?>
|
||||
<DescribeImagesResponse xmlns="http://ec2.amazonaws.com/doc/2009-11-30/">
|
||||
<requestId>6104eee1-affd-49d7-92a0-516cab8a8ba6</requestId>
|
||||
<imagesSet>
|
||||
<item>
|
||||
<imageId>ami-82e4b5c7</imageId>
|
||||
<imageLocation>137112412989/amzn-ami-0.9.7-beta.i386-ebs</imageLocation>
|
||||
<imageState>available</imageState>
|
||||
<imageOwnerId>137112412989</imageOwnerId>
|
||||
<isPublic>true</isPublic>
|
||||
<architecture>i386</architecture>
|
||||
<imageType>machine</imageType>
|
||||
<kernelId>aki-99a0f1dc</kernelId>
|
||||
<name>amzn-ami-0.9.7-beta.i386-ebs</name>
|
||||
<description>Amazon</description>
|
||||
<rootDeviceType>ebs</rootDeviceType>
|
||||
<rootDeviceName>/dev/sda1</rootDeviceName>
|
||||
<blockDeviceMapping>
|
||||
<item>
|
||||
<deviceName>/dev/sda1</deviceName>
|
||||
<ebs>
|
||||
<snapshotId>snap-e98b7b82</snapshotId>
|
||||
<volumeSize>10</volumeSize>
|
||||
<deleteOnTermination>true</deleteOnTermination>
|
||||
</ebs>
|
||||
</item>
|
||||
</blockDeviceMapping>
|
||||
<virtualizationType>paravirtual</virtualizationType>
|
||||
</item>
|
||||
<item>
|
||||
<imageId>ami-8ce4b5c9</imageId>
|
||||
<imageLocation>137112412989/amzn-ami-0.9.7-beta.x86_64-ebs</imageLocation>
|
||||
<imageState>available</imageState>
|
||||
<imageOwnerId>137112412989</imageOwnerId>
|
||||
<isPublic>true</isPublic>
|
||||
<architecture>x86_64</architecture>
|
||||
<imageType>machine</imageType>
|
||||
<kernelId>aki-9ba0f1de</kernelId>
|
||||
<name>amzn-ami-0.9.7-beta.x86_64-ebs</name>
|
||||
<description>Amazon</description>
|
||||
<rootDeviceType>ebs</rootDeviceType>
|
||||
<rootDeviceName>/dev/sda1</rootDeviceName>
|
||||
<blockDeviceMapping>
|
||||
<item>
|
||||
<deviceName>/dev/sda1</deviceName>
|
||||
<ebs>
|
||||
<snapshotId>snap-8d8b7be6</snapshotId>
|
||||
<volumeSize>10</volumeSize>
|
||||
<deleteOnTermination>true</deleteOnTermination>
|
||||
</ebs>
|
||||
</item>
|
||||
</blockDeviceMapping>
|
||||
<virtualizationType>paravirtual</virtualizationType>
|
||||
</item>
|
||||
<item>
|
||||
<imageId>ami-f0e4b5b5</imageId>
|
||||
<imageLocation>amzn-ami-us-west-1/amzn-ami-0.9.7-beta.i386.manifest.xml</imageLocation>
|
||||
<imageState>available</imageState>
|
||||
<imageOwnerId>137112412989</imageOwnerId>
|
||||
<isPublic>true</isPublic>
|
||||
<architecture>i386</architecture>
|
||||
<imageType>machine</imageType>
|
||||
<kernelId>aki-99a0f1dc</kernelId>
|
||||
<name>amzn-ami-0.9.7-beta.i386-S3</name>
|
||||
<description>Amazon Linux AMI i386 S3</description>
|
||||
<rootDeviceType>instance-store</rootDeviceType>
|
||||
<blockDeviceMapping/>
|
||||
<virtualizationType>paravirtual</virtualizationType>
|
||||
</item>
|
||||
<item>
|
||||
<imageId>ami-f2e4b5b7</imageId>
|
||||
<imageLocation>amzn-ami-us-west-1/amzn-ami-0.9.7-beta.x86_64.manifest.xml</imageLocation>
|
||||
<imageState>available</imageState>
|
||||
<imageOwnerId>137112412989</imageOwnerId>
|
||||
<isPublic>true</isPublic>
|
||||
<architecture>x86_64</architecture>
|
||||
<imageType>machine</imageType>
|
||||
<kernelId>aki-9ba0f1de</kernelId>
|
||||
<name>amzn-ami-0.9.7-beta.x86_64-S3</name>
|
||||
<description>Amazon Linux AMI x86_64 S3</description>
|
||||
<rootDeviceType>instance-store</rootDeviceType>
|
||||
<blockDeviceMapping/>
|
||||
<virtualizationType>paravirtual</virtualizationType>
|
||||
</item>
|
||||
</imagesSet>
|
||||
</DescribeImagesResponse>
|
|
@ -30,7 +30,11 @@ import com.google.common.base.CaseFormat;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
public enum OsFamily {
|
||||
UNKNOWN, AIX, ARCH, CENTOS, DARWIN, DEBIAN, ESX, FEDORA, FREEBSD, GENTOO, HPUX, LINUX, MANDRIVA, NETBSD,
|
||||
UNKNOWN, AIX, ARCH, CENTOS, DARWIN, DEBIAN, ESX, FEDORA, FREEBSD, GENTOO, HPUX, LINUX,
|
||||
/**
|
||||
* @see <a href="http://aws.amazon.com/amazon-linux-ami/">amazon linux ami</a>
|
||||
*/
|
||||
AMZN_LINUX, MANDRIVA, NETBSD,
|
||||
/**
|
||||
*
|
||||
* Oracle Enterprise Linux
|
||||
|
|
|
@ -103,6 +103,7 @@ public class OperatingSystemPredicates {
|
|||
if (os.getFamily() != null) {
|
||||
switch (os.getFamily()) {
|
||||
case CENTOS:
|
||||
case AMZN_LINUX:
|
||||
case FEDORA:
|
||||
case RHEL:
|
||||
return true;
|
||||
|
|
|
@ -97,6 +97,10 @@ public class OperatingSystemPredicatesTest {
|
|||
assert supportsYum().apply(new OperatingSystem(OsFamily.CENTOS, null, "", null, "description", false));
|
||||
}
|
||||
|
||||
public void testAmzTypeSupportsYum() {
|
||||
assert supportsYum().apply(new OperatingSystem(OsFamily.AMZN_LINUX, null, "", null, "description", false));
|
||||
}
|
||||
|
||||
public void testRhelTypeSupportsYum() {
|
||||
assert supportsYum().apply(new OperatingSystem(OsFamily.RHEL, null, "", null, "description", false));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue