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). Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/4b437402 Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/4b437402 Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/4b437402 Branch: refs/heads/2.0.x Commit: 4b4374025f75d0f590eeb5b6c7f34d0fc7413db5 Parents: 4dbba81 Author: Richard Downer <[email protected]> Authored: Thu Nov 2 20:48:13 2017 +0000 Committer: Ignasi Barrera <[email protected]> Committed: Fri Nov 3 12:35:42 2017 +0100 ---------------------------------------------------------------------- ...DefaultLoginCredentialsForImageStrategy.java | 5 +++ .../strategy/AWSEC2ReviseParsedImage.java | 6 ++-- .../compute/strategy/AWSEC2ImageParserTest.java | 24 +++++++++++++ .../resources/centos_marketplace_images.xml | 38 ++++++++++++++++++++ 4 files changed, 71 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jclouds/blob/4b437402/apis/ec2/src/main/java/org/jclouds/ec2/compute/strategy/EC2PopulateDefaultLoginCredentialsForImageStrategy.java ---------------------------------------------------------------------- diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/compute/strategy/EC2PopulateDefaultLoginCredentialsForImageStrategy.java b/apis/ec2/src/main/java/org/jclouds/ec2/compute/strategy/EC2PopulateDefaultLoginCredentialsForImageStrategy.java index 91eaaa9..f50a194 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/compute/strategy/EC2PopulateDefaultLoginCredentialsForImageStrategy.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/compute/strategy/EC2PopulateDefaultLoginCredentialsForImageStrategy.java @@ -53,10 +53,13 @@ public class EC2PopulateDefaultLoginCredentialsForImageStrategy extends ReturnCr Builder credentials = LoginCredentials.builder().user("root"); if (resourceToAuthenticate != null) { String owner = null; + String name = null; if (resourceToAuthenticate instanceof Image) { owner = Image.class.cast(resourceToAuthenticate).getImageOwnerId(); + name = Image.class.cast(resourceToAuthenticate).getName(); } else if (resourceToAuthenticate instanceof org.jclouds.compute.domain.Image) { 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)"); // 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 } else if (owner.equals("137112412989")) { credentials.user("ec2-user"); + } else if (owner.equals("679593333241") && name != null && name.startsWith("CentOS")) { + credentials.user("centos"); } } return credentials.build(); http://git-wip-us.apache.org/repos/asf/jclouds/blob/4b437402/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2ReviseParsedImage.java ---------------------------------------------------------------------- diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2ReviseParsedImage.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2ReviseParsedImage.java index fb7d739..9dd5245 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2ReviseParsedImage.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2ReviseParsedImage.java @@ -51,6 +51,8 @@ public class AWSEC2ReviseParsedImage implements ReviseParsedImage { // 1111111 22222222222 3333333333 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)?"); // 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. */ private Matcher getMatcherAndFind(String manifest) { - for (Pattern pattern : new Pattern[] { AMZN_PATTERN, AMAZON_PATTERN, AMAZON_WINDOWS_PATTERN, CANONICAL_PATTERN, - RIGHTIMAGE_PATTERN, RIGHTSCALE_PATTERN }) { + for (Pattern pattern : new Pattern[] { AMZN_PATTERN, AMAZON_PATTERN, AMAZON_WINDOWS_PATTERN, + CENTOS_MARKETPLACE_PATTERN, CANONICAL_PATTERN, RIGHTIMAGE_PATTERN, RIGHTSCALE_PATTERN }) { Matcher matcher = pattern.matcher(manifest); if (matcher.find()) return matcher; http://git-wip-us.apache.org/repos/asf/jclouds/blob/4b437402/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2ImageParserTest.java ---------------------------------------------------------------------- diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2ImageParserTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2ImageParserTest.java index cfc3e81..02bc3f2 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2ImageParserTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2ImageParserTest.java @@ -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") .description("us-east-1").build(); http://git-wip-us.apache.org/repos/asf/jclouds/blob/4b437402/providers/aws-ec2/src/test/resources/centos_marketplace_images.xml ---------------------------------------------------------------------- diff --git a/providers/aws-ec2/src/test/resources/centos_marketplace_images.xml b/providers/aws-ec2/src/test/resources/centos_marketplace_images.xml new file mode 100644 index 0000000..d69106d --- /dev/null +++ b/providers/aws-ec2/src/test/resources/centos_marketplace_images.xml @@ -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>
