Repository: jclouds Updated Branches: refs/heads/master 1d4cb6c39 -> d905adebe
Improve OS detection and SSH configuration in Packet Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/d905adeb Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/d905adeb Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/d905adeb Branch: refs/heads/master Commit: d905adebe1108bd5570059f5bab0655ecd78cc63 Parents: 1d4cb6c Author: Ignasi Barrera <[email protected]> Authored: Thu Jun 8 12:26:11 2017 +0200 Committer: El del tallat <[email protected]> Committed: Mon Jun 12 08:29:51 2017 +0200 ---------------------------------------------------------------------- .../org/jclouds/compute/domain/OsFamily.java | 2 +- .../PacketComputeServiceContextModule.java | 4 +- .../functions/OperatingSystemToImage.java | 48 ++++++++++++-- .../org/jclouds/packet/domain/ActionType.java | 39 ----------- .../org/jclouds/packet/domain/Distribution.java | 68 -------------------- 5 files changed, 48 insertions(+), 113 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jclouds/blob/d905adeb/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 121e18d..e411580 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/OsFamily.java +++ b/compute/src/main/java/org/jclouds/compute/domain/OsFamily.java @@ -25,7 +25,7 @@ import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE; * Running Operating system */ public enum OsFamily { - UNRECOGNIZED, AIX, ARCH, CENTOS, DARWIN, DEBIAN, ESX, FEDORA, FREEBSD, GENTOO, HPUX, LINUX, COREOS, + UNRECOGNIZED, AIX, ALPINE, ARCH, CENTOS, DARWIN, DEBIAN, ESX, FEDORA, FREEBSD, GENTOO, HPUX, LINUX, COREOS, /** * @see <a href="http://smartos.org">SmartOS</a> */ http://git-wip-us.apache.org/repos/asf/jclouds/blob/d905adeb/providers/packet/src/main/java/org/jclouds/packet/compute/config/PacketComputeServiceContextModule.java ---------------------------------------------------------------------- diff --git a/providers/packet/src/main/java/org/jclouds/packet/compute/config/PacketComputeServiceContextModule.java b/providers/packet/src/main/java/org/jclouds/packet/compute/config/PacketComputeServiceContextModule.java index 0a64f43..920870b 100644 --- a/providers/packet/src/main/java/org/jclouds/packet/compute/config/PacketComputeServiceContextModule.java +++ b/providers/packet/src/main/java/org/jclouds/packet/compute/config/PacketComputeServiceContextModule.java @@ -21,6 +21,8 @@ import org.jclouds.compute.config.ComputeServiceAdapterContextModule; import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.functions.NodeAndTemplateOptionsToStatement; +import org.jclouds.compute.functions.NodeAndTemplateOptionsToStatementWithoutPublicKey; import org.jclouds.compute.options.TemplateOptions; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet; @@ -58,7 +60,6 @@ import static org.jclouds.util.Predicates2.retry; public class PacketComputeServiceContextModule extends ComputeServiceAdapterContextModule<Device, Plan, OperatingSystem, Facility> { - @SuppressWarnings("unchecked") @Override protected void configure() { super.configure(); @@ -80,6 +81,7 @@ public class PacketComputeServiceContextModule extends }); bind(TemplateOptions.class).to(PacketTemplateOptions.class); bind(CreateNodesInGroupThenAddToSet.class).to(CreateSshKeysThenCreateNodes.class); + bind(NodeAndTemplateOptionsToStatement.class).to(NodeAndTemplateOptionsToStatementWithoutPublicKey.class); } @Provides http://git-wip-us.apache.org/repos/asf/jclouds/blob/d905adeb/providers/packet/src/main/java/org/jclouds/packet/compute/functions/OperatingSystemToImage.java ---------------------------------------------------------------------- diff --git a/providers/packet/src/main/java/org/jclouds/packet/compute/functions/OperatingSystemToImage.java b/providers/packet/src/main/java/org/jclouds/packet/compute/functions/OperatingSystemToImage.java index d28b579..ce28810 100644 --- a/providers/packet/src/main/java/org/jclouds/packet/compute/functions/OperatingSystemToImage.java +++ b/providers/packet/src/main/java/org/jclouds/packet/compute/functions/OperatingSystemToImage.java @@ -16,16 +16,23 @@ */ package org.jclouds.packet.compute.functions; +import static com.google.common.collect.Iterables.tryFind; +import static java.util.Arrays.asList; +import static org.jclouds.compute.domain.OperatingSystem.builder; + +import java.util.Map; + import javax.inject.Singleton; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.ImageBuilder; -import org.jclouds.packet.domain.Distribution; +import org.jclouds.compute.domain.OsFamily; import org.jclouds.packet.domain.OperatingSystem; import com.google.common.base.Function; - -import static org.jclouds.compute.domain.OperatingSystem.builder; +import com.google.common.base.Optional; +import com.google.common.base.Predicate; +import com.google.common.collect.ImmutableMap; /** * Transforms an {@link OperatingSystem} to the jclouds portable model. @@ -33,6 +40,12 @@ import static org.jclouds.compute.domain.OperatingSystem.builder; @Singleton public class OperatingSystemToImage implements Function<OperatingSystem, Image> { + private static final Map<String, OsFamily> OTHER_OS_MAP = ImmutableMap.<String, OsFamily> builder() + .put("nixos", OsFamily.LINUX) + .put("rancher", OsFamily.LINUX) + .put("vmware", OsFamily.ESX) + .build(); + @Override public Image apply(final OperatingSystem input) { ImageBuilder builder = new ImageBuilder(); @@ -40,10 +53,14 @@ public class OperatingSystemToImage implements Function<OperatingSystem, Image> builder.name(input.name()); builder.description(input.name()); builder.status(Image.Status.AVAILABLE); + + OsFamily family = findInStandardFamilies(input.distribution()) + .or(findInOtherOSMap(input.distribution())) + .or(OsFamily.UNRECOGNIZED); builder.operatingSystem(builder() .name(input.name()) - .family(Distribution.fromValue(input.distribution()).osFamily()) + .family(family) .description(input.name()) .version(input.version()) .is64Bit(true) @@ -51,4 +68,27 @@ public class OperatingSystemToImage implements Function<OperatingSystem, Image> return builder.build(); } + + private static Optional<OsFamily> findInStandardFamilies(final String label) { + return tryFind(asList(OsFamily.values()), new Predicate<OsFamily>() { + @Override + public boolean apply(OsFamily input) { + return label.contains(input.value()); + } + }); + } + + private static Optional<OsFamily> findInOtherOSMap(final String label) { + return tryFind(OTHER_OS_MAP.keySet(), new Predicate<String>() { + @Override + public boolean apply(String input) { + return label.contains(input); + } + }).transform(new Function<String, OsFamily>() { + @Override + public OsFamily apply(String input) { + return OTHER_OS_MAP.get(input); + } + }); + } } http://git-wip-us.apache.org/repos/asf/jclouds/blob/d905adeb/providers/packet/src/main/java/org/jclouds/packet/domain/ActionType.java ---------------------------------------------------------------------- diff --git a/providers/packet/src/main/java/org/jclouds/packet/domain/ActionType.java b/providers/packet/src/main/java/org/jclouds/packet/domain/ActionType.java deleted file mode 100644 index 9177ec5..0000000 --- a/providers/packet/src/main/java/org/jclouds/packet/domain/ActionType.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.packet.domain; - -/** - * Performs an action for the given device. Possible actions include: - - power_on - power_off - reboot - rescue: reboot the device into rescue OS. - */ -public enum ActionType { - - POWER_ON ("power_on"), - POWER_OFF ("power_off"), - REBOOT ("reboot"), - RESCUE ("rescue"); - - private final String type; - - ActionType(String type) { - this.type = type; - } -} http://git-wip-us.apache.org/repos/asf/jclouds/blob/d905adeb/providers/packet/src/main/java/org/jclouds/packet/domain/Distribution.java ---------------------------------------------------------------------- diff --git a/providers/packet/src/main/java/org/jclouds/packet/domain/Distribution.java b/providers/packet/src/main/java/org/jclouds/packet/domain/Distribution.java deleted file mode 100644 index 0692d59..0000000 --- a/providers/packet/src/main/java/org/jclouds/packet/domain/Distribution.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.packet.domain; - -import java.util.List; - -import org.jclouds.compute.domain.OsFamily; - -import com.google.common.base.Predicate; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.tryFind; -import static java.util.Arrays.asList; - -public enum Distribution { - - CENTOS(OsFamily.CENTOS, "centos"), - COREOS(OsFamily.COREOS, "coreos"), - DEBIAN(OsFamily.DEBIAN, "debian"), - UBUNTU(OsFamily.UBUNTU, "ubuntu"), - WINDOWS(OsFamily.WINDOWS, "windows"), - UNRECOGNIZED(OsFamily.UNRECOGNIZED, ""); - - private static final List<Distribution> values = asList(Distribution.values()); - - private final OsFamily osFamily; - private final String value; - - private Distribution(OsFamily osFamily, String value) { - this.osFamily = checkNotNull(osFamily, "osFamily cannot be null"); - this.value = checkNotNull(value, "value cannot be null"); - } - - public OsFamily osFamily() { - return this.osFamily; - } - - public String value() { - return this.value; - } - - public static Distribution fromValue(String value) { - return tryFind(values, hasValue(value)).or(UNRECOGNIZED); - } - - private static Predicate<Distribution> hasValue(final String value) { - return new Predicate<Distribution>() { - @Override - public boolean apply(Distribution input) { - return input.value.equalsIgnoreCase(value); - } - }; - } -}
