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 91eaaa9163..f50a194a4e 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(); 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 fb7d739c9f..9dd5245035 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; 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 cfc3e8135a..02bc3f2975 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 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(); 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 0000000000..d69106d6ac --- /dev/null +++ b/providers/aws-ec2/src/test/resources/centos_marketplace_images.xml @@ -0,0 +1,38 @@ + + + 6104eee1-affd-49d7-92a0-516cab8a8ba6 + + + ami-061b1560 + aws-marketplace/CentOS Linux 7 x86_64 HVM EBS 1704_01-b7ee8a69-ee97-4a49-9e68-afaee216db2e-ami-d52f5bc3.4 + available + 679593333241 + true + + + aw0evgkw8e5c1q413zgy5pjce + marketplace + + + x86_64 + machine + aws-marketplace + CentOS Linux 7 x86_64 HVM EBS 1704_01-b7ee8a69-ee97-4a49-9e68-afaee216db2e-ami-d52f5bc3.4 + CentOS Linux 7 x86_64 HVM EBS 1704_01 + ebs + /dev/sda1 + + + /dev/sda1 + + snap-00f18f3f6413c7879 + 8 + false + + + + hvm + xen + + +