mirror of https://github.com/apache/jclouds.git
Recognise CentOS images on AWS Marketplace
CentOS’ officially-supported AMIs are hosted on the AWS Marketplace. This adds support for those images, recognising the AMI naming convention and ensuring the OS metadata is parsed correctly and the correct SSH login name is used. There is no change to the default jclouds configuration and the official CentOS images will not be detected by default. To use these images, you must alter the ami-query properties to include searching the “AWS Marketplace”, which has an owner ID of 679593333241. You must also manually log on to the AWS Marketplace, select your chosen CentOS image, and “subscribe” to it (you can do this by proceeding as if to launch an image, but stopping after you have agreed to the subscription and before launching).
This commit is contained in:
parent
045f1e9527
commit
98c289721c
|
@ -53,10 +53,13 @@ public class EC2PopulateDefaultLoginCredentialsForImageStrategy extends ReturnCr
|
||||||
Builder credentials = LoginCredentials.builder().user("root");
|
Builder credentials = LoginCredentials.builder().user("root");
|
||||||
if (resourceToAuthenticate != null) {
|
if (resourceToAuthenticate != null) {
|
||||||
String owner = null;
|
String owner = null;
|
||||||
|
String name = null;
|
||||||
if (resourceToAuthenticate instanceof Image) {
|
if (resourceToAuthenticate instanceof Image) {
|
||||||
owner = Image.class.cast(resourceToAuthenticate).getImageOwnerId();
|
owner = Image.class.cast(resourceToAuthenticate).getImageOwnerId();
|
||||||
|
name = Image.class.cast(resourceToAuthenticate).getName();
|
||||||
} else if (resourceToAuthenticate instanceof org.jclouds.compute.domain.Image) {
|
} else if (resourceToAuthenticate instanceof org.jclouds.compute.domain.Image) {
|
||||||
owner = org.jclouds.compute.domain.Image.class.cast(resourceToAuthenticate).getUserMetadata().get("owner");
|
owner = org.jclouds.compute.domain.Image.class.cast(resourceToAuthenticate).getUserMetadata().get("owner");
|
||||||
|
name = org.jclouds.compute.domain.Image.class.cast(resourceToAuthenticate).getUserMetadata().get("name");
|
||||||
}
|
}
|
||||||
checkArgument(owner != null, "Resource must be an image (for EC2)");
|
checkArgument(owner != null, "Resource must be an image (for EC2)");
|
||||||
// canonical/alestic images use the ubuntu user to login
|
// canonical/alestic images use the ubuntu user to login
|
||||||
|
@ -65,6 +68,8 @@ public class EC2PopulateDefaultLoginCredentialsForImageStrategy extends ReturnCr
|
||||||
// http://typepad.com/2010/09/introducing-amazon-linux-ami.html
|
// http://typepad.com/2010/09/introducing-amazon-linux-ami.html
|
||||||
} else if (owner.equals("137112412989")) {
|
} else if (owner.equals("137112412989")) {
|
||||||
credentials.user("ec2-user");
|
credentials.user("ec2-user");
|
||||||
|
} else if (owner.equals("679593333241") && name != null && name.startsWith("CentOS")) {
|
||||||
|
credentials.user("centos");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return credentials.build();
|
return credentials.build();
|
||||||
|
|
|
@ -51,6 +51,8 @@ public class AWSEC2ReviseParsedImage implements ReviseParsedImage {
|
||||||
// 1111111 22222222222 3333333333
|
// 1111111 22222222222 3333333333
|
||||||
public static final Pattern AMAZON_WINDOWS_PATTERN = Pattern.compile(".*/(Windows)_Server-([^-]*-[^-]*)-.*-([^-]*)(\\.manifest.xml)?");
|
public static final Pattern AMAZON_WINDOWS_PATTERN = Pattern.compile(".*/(Windows)_Server-([^-]*-[^-]*)-.*-([^-]*)(\\.manifest.xml)?");
|
||||||
|
|
||||||
|
public static final Pattern CENTOS_MARKETPLACE_PATTERN = Pattern.compile(".*/(CentOS) Linux ([^ ]*) (.*)(\\.manifest.xml)?");
|
||||||
|
|
||||||
public static final Pattern CANONICAL_PATTERN = Pattern.compile(".*/([^-]*)-([^-]*)-.*-(.*)(\\.manifest.xml)?");
|
public static final Pattern CANONICAL_PATTERN = Pattern.compile(".*/([^-]*)-([^-]*)-.*-(.*)(\\.manifest.xml)?");
|
||||||
|
|
||||||
// ex rightscale-us-east/CentOS_5.4_x64_v4.4.10.manifest.xml
|
// ex rightscale-us-east/CentOS_5.4_x64_v4.4.10.manifest.xml
|
||||||
|
@ -105,8 +107,8 @@ public class AWSEC2ReviseParsedImage implements ReviseParsedImage {
|
||||||
* if no configured matcher matches the manifest.
|
* if no configured matcher matches the manifest.
|
||||||
*/
|
*/
|
||||||
private Matcher getMatcherAndFind(String manifest) {
|
private Matcher getMatcherAndFind(String manifest) {
|
||||||
for (Pattern pattern : new Pattern[] { AMZN_PATTERN, AMAZON_PATTERN, AMAZON_WINDOWS_PATTERN, CANONICAL_PATTERN,
|
for (Pattern pattern : new Pattern[] { AMZN_PATTERN, AMAZON_PATTERN, AMAZON_WINDOWS_PATTERN,
|
||||||
RIGHTIMAGE_PATTERN, RIGHTSCALE_PATTERN }) {
|
CENTOS_MARKETPLACE_PATTERN, CANONICAL_PATTERN, RIGHTIMAGE_PATTERN, RIGHTSCALE_PATTERN }) {
|
||||||
Matcher matcher = pattern.matcher(manifest);
|
Matcher matcher = pattern.matcher(manifest);
|
||||||
if (matcher.find())
|
if (matcher.find())
|
||||||
return matcher;
|
return matcher;
|
||||||
|
|
|
@ -229,6 +229,30 @@ public class AWSEC2ImageParserTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testParseCentOsOnMarketplaceImage() {
|
||||||
|
|
||||||
|
Set<org.jclouds.compute.domain.Image> result = convertImages("/centos_marketplace_images.xml");
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
Iterables.get(result, 0),
|
||||||
|
new ImageBuilder()
|
||||||
|
.name("CentOS Linux 7 x86_64 HVM EBS 1704_01-b7ee8a69-ee97-4a49-9e68-afaee216db2e-ami-d52f5bc3.4")
|
||||||
|
.operatingSystem(
|
||||||
|
new OperatingSystem.Builder().family(OsFamily.CENTOS).arch("x86_64")
|
||||||
|
.version("7").description("aws-marketplace/CentOS Linux 7 x86_64 HVM EBS 1704_01-b7ee8a69-ee97-4a49-9e68-afaee216db2e-ami-d52f5bc3.4")
|
||||||
|
.is64Bit(true).build()).description("CentOS Linux 7 x86_64 HVM EBS 1704_01")
|
||||||
|
.defaultCredentials(LoginCredentials.builder().user("centos").build()).id("us-east-1/ami-061b1560")
|
||||||
|
.providerId("ami-061b1560").location(defaultLocation).version("7")
|
||||||
|
.userMetadata(ImmutableMap.of(
|
||||||
|
"owner", "679593333241",
|
||||||
|
"rootDeviceType", "ebs",
|
||||||
|
"virtualizationType", "hvm",
|
||||||
|
"hypervisor", "xen"))
|
||||||
|
.status(org.jclouds.compute.domain.Image.Status.AVAILABLE).build());
|
||||||
|
assertEquals(Iterables.get(result, 0).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
static Location defaultLocation = new LocationBuilder().scope(LocationScope.REGION).id("us-east-1")
|
static Location defaultLocation = new LocationBuilder().scope(LocationScope.REGION).id("us-east-1")
|
||||||
.description("us-east-1").build();
|
.description("us-east-1").build();
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
<?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-061b1560</imageId>
|
||||||
|
<imageLocation>aws-marketplace/CentOS Linux 7 x86_64 HVM EBS 1704_01-b7ee8a69-ee97-4a49-9e68-afaee216db2e-ami-d52f5bc3.4</imageLocation>
|
||||||
|
<imageState>available</imageState>
|
||||||
|
<imageOwnerId>679593333241</imageOwnerId>
|
||||||
|
<isPublic>true</isPublic>
|
||||||
|
<productCodes>
|
||||||
|
<item>
|
||||||
|
<productCode>aw0evgkw8e5c1q413zgy5pjce</productCode>
|
||||||
|
<type>marketplace</type>
|
||||||
|
</item>
|
||||||
|
</productCodes>
|
||||||
|
<architecture>x86_64</architecture>
|
||||||
|
<imageType>machine</imageType>
|
||||||
|
<imageOwnerAlias>aws-marketplace</imageOwnerAlias>
|
||||||
|
<name>CentOS Linux 7 x86_64 HVM EBS 1704_01-b7ee8a69-ee97-4a49-9e68-afaee216db2e-ami-d52f5bc3.4</name>
|
||||||
|
<description>CentOS Linux 7 x86_64 HVM EBS 1704_01</description>
|
||||||
|
<rootDeviceType>ebs</rootDeviceType>
|
||||||
|
<rootDeviceName>/dev/sda1</rootDeviceName>
|
||||||
|
<blockDeviceMapping>
|
||||||
|
<item>
|
||||||
|
<deviceName>/dev/sda1</deviceName>
|
||||||
|
<ebs>
|
||||||
|
<snapshotId>snap-00f18f3f6413c7879</snapshotId>
|
||||||
|
<volumeSize>8</volumeSize>
|
||||||
|
<deleteOnTermination>false</deleteOnTermination>
|
||||||
|
</ebs>
|
||||||
|
</item>
|
||||||
|
</blockDeviceMapping>
|
||||||
|
<virtualizationType>hvm</virtualizationType>
|
||||||
|
<hypervisor>xen</hypervisor>
|
||||||
|
</item>
|
||||||
|
</imagesSet>
|
||||||
|
</DescribeImagesResponse>
|
Loading…
Reference in New Issue