You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by na...@apache.org on 2017/11/03 11:52:56 UTC

[1/2] jclouds git commit: JCLOUDS-1351: improve OS Family parsing

Repository: jclouds
Updated Branches:
  refs/heads/2.0.x 79aa09dd1 -> 4b4374025


JCLOUDS-1351: improve OS Family parsing

Modifies OsFamily to have two tiers of known OSes, so that generic OS
names such as “Linux” cannot end up taking priority over more specific
OS names. This fixes the case where “CentOS Linux” was detected as LINUX
and not CENTOS.

Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/4dbba815
Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/4dbba815
Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/4dbba815

Branch: refs/heads/2.0.x
Commit: 4dbba815caa77ad44d7e8d75fde1692a6810d862
Parents: 79aa09d
Author: Richard Downer <ri...@apache.org>
Authored: Thu Nov 2 20:46:01 2017 +0000
Committer: Ignasi Barrera <na...@apache.org>
Committed: Fri Nov 3 12:35:39 2017 +0100

----------------------------------------------------------------------
 .../org/jclouds/compute/domain/OsFamily.java    | 38 +++++++++++++++++++-
 .../compute/util/ComputeServiceUtils.java       | 10 +++++-
 2 files changed, 46 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds/blob/4dbba815/compute/src/main/java/org/jclouds/compute/domain/OsFamily.java
----------------------------------------------------------------------
diff --git a/compute/src/main/java/org/jclouds/compute/domain/OsFamily.java b/compute/src/main/java/org/jclouds/compute/domain/OsFamily.java
index e411580..b525c29 100644
--- a/compute/src/main/java/org/jclouds/compute/domain/OsFamily.java
+++ b/compute/src/main/java/org/jclouds/compute/domain/OsFamily.java
@@ -21,11 +21,16 @@ import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.base.CaseFormat.LOWER_HYPHEN;
 import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE;
 
+import java.util.Arrays;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.FluentIterable;
+
 /**
  * Running Operating system
  */
 public enum OsFamily {
-   UNRECOGNIZED, AIX, ALPINE, ARCH, CENTOS, DARWIN, DEBIAN, ESX, FEDORA, FREEBSD, GENTOO, HPUX, LINUX, COREOS, 
+   UNRECOGNIZED(false), AIX, ALPINE, ARCH, CENTOS, DARWIN, DEBIAN, ESX, FEDORA, FREEBSD, GENTOO, HPUX, LINUX(false), COREOS,
    /**
     * @see <a href="http://smartos.org">SmartOS</a>
     */
@@ -48,6 +53,16 @@ public enum OsFamily {
     */
    GCEL, SIGAR, SLACKWARE, SOLARIS, SUSE, TURBOLINUX, CLOUD_LINUX, UBUNTU, WINDOWS;
 
+   private final boolean prioritise;
+
+   OsFamily() {
+      this.prioritise = true;
+   }
+
+   OsFamily(boolean prioritise) {
+      this.prioritise = prioritise;
+   }
+
    public String value() {
       return UPPER_UNDERSCORE.to(LOWER_HYPHEN, name());
    }
@@ -57,6 +72,10 @@ public enum OsFamily {
       return value();
    }
 
+   public boolean shouldPrioritise() {
+      return prioritise;
+   }
+
    public static OsFamily fromValue(String osFamily) {
       try {
          return valueOf(LOWER_HYPHEN.to(UPPER_UNDERSCORE, checkNotNull(osFamily, "osFamily")));
@@ -64,4 +83,21 @@ public enum OsFamily {
          return UNRECOGNIZED;
       }
    }
+
+   private static Predicate<OsFamily> predicateOnShouldPrioritise(final boolean prioritise) {
+      return new Predicate<OsFamily>() {
+         @Override
+         public boolean apply(OsFamily osFamily) {
+            return osFamily.shouldPrioritise() == prioritise;
+         }
+      };
+   }
+
+   public static OsFamily[] proritisedValues() {
+      return FluentIterable.from(Arrays.asList(values())).filter(predicateOnShouldPrioritise(true)).toArray(OsFamily.class);
+   }
+
+   public static OsFamily[] nonProritisedValues() {
+      return FluentIterable.from(Arrays.asList(values())).filter(predicateOnShouldPrioritise(false)).toArray(OsFamily.class);
+   }
 }

http://git-wip-us.apache.org/repos/asf/jclouds/blob/4dbba815/compute/src/main/java/org/jclouds/compute/util/ComputeServiceUtils.java
----------------------------------------------------------------------
diff --git a/compute/src/main/java/org/jclouds/compute/util/ComputeServiceUtils.java b/compute/src/main/java/org/jclouds/compute/util/ComputeServiceUtils.java
index b9333a5..1d1cf95 100644
--- a/compute/src/main/java/org/jclouds/compute/util/ComputeServiceUtils.java
+++ b/compute/src/main/java/org/jclouds/compute/util/ComputeServiceUtils.java
@@ -140,7 +140,15 @@ public class ComputeServiceUtils {
 
    public static org.jclouds.compute.domain.OsFamily parseOsFamilyOrUnrecognized(String in) {
       org.jclouds.compute.domain.OsFamily myOs = null;
-      for (org.jclouds.compute.domain.OsFamily os : org.jclouds.compute.domain.OsFamily.values()) {
+      for (org.jclouds.compute.domain.OsFamily os : org.jclouds.compute.domain.OsFamily.proritisedValues()) {
+         if (in.toLowerCase().replaceAll("\\s", "").indexOf(os.toString()) != -1) {
+            myOs = os;
+         }
+      }
+      if (myOs != null) {
+         return myOs;
+      }
+      for (org.jclouds.compute.domain.OsFamily os : org.jclouds.compute.domain.OsFamily.nonProritisedValues()) {
          if (in.toLowerCase().replaceAll("\\s", "").indexOf(os.toString()) != -1) {
             myOs = os;
          }


[2/2] jclouds git commit: Recognise CentOS images on AWS Marketplace

Posted by na...@apache.org.
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 <ri...@apache.org>
Authored: Thu Nov 2 20:48:13 2017 +0000
Committer: Ignasi Barrera <na...@apache.org>
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>