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 e411580ec3..b525c29ef2 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 SmartOS */ @@ -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 predicateOnShouldPrioritise(final boolean prioritise) { + return new Predicate() { + @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); + } } 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 b9333a597d..1d1cf95f2f 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; }