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/06/12 06:38:36 UTC
jclouds-labs git commit: Improve OS detection and SSH configuration
in Packet
Repository: jclouds-labs
Updated Branches:
refs/heads/2.0.x f294ab108 -> 1fbb79721
Improve OS detection and SSH configuration in Packet
Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs/commit/1fbb7972
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs/tree/1fbb7972
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs/diff/1fbb7972
Branch: refs/heads/2.0.x
Commit: 1fbb7972188cab146fecb431b74c6e097a841dd3
Parents: f294ab1
Author: El del tallat <ib...@abiquo.com>
Authored: Mon Jun 12 08:31:51 2017 +0200
Committer: El del tallat <ib...@abiquo.com>
Committed: Mon Jun 12 08:31:51 2017 +0200
----------------------------------------------------------------------
.../PacketComputeServiceContextModule.java | 16 ++--
.../functions/OperatingSystemToImage.java | 77 ++++++++++++++------
.../strategy/CreateSshKeysThenCreateNodes.java | 1 +
.../org/jclouds/packet/domain/ActionType.java | 39 ----------
.../org/jclouds/packet/domain/Distribution.java | 68 -----------------
5 files changed, 66 insertions(+), 135 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1fbb7972/packet/src/main/java/org/jclouds/packet/compute/config/PacketComputeServiceContextModule.java
----------------------------------------------------------------------
diff --git a/packet/src/main/java/org/jclouds/packet/compute/config/PacketComputeServiceContextModule.java b/packet/src/main/java/org/jclouds/packet/compute/config/PacketComputeServiceContextModule.java
index 0a64f43..576f2ba 100644
--- a/packet/src/main/java/org/jclouds/packet/compute/config/PacketComputeServiceContextModule.java
+++ b/packet/src/main/java/org/jclouds/packet/compute/config/PacketComputeServiceContextModule.java
@@ -16,11 +16,19 @@
*/
package org.jclouds.packet.compute.config;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_RUNNING;
+import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_SUSPENDED;
+import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_TERMINATED;
+import static org.jclouds.util.Predicates2.retry;
+
import org.jclouds.compute.ComputeServiceAdapter;
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;
@@ -49,16 +57,9 @@ import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
import com.google.inject.name.Named;
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_RUNNING;
-import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_SUSPENDED;
-import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_TERMINATED;
-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-labs/blob/1fbb7972/packet/src/main/java/org/jclouds/packet/compute/functions/OperatingSystemToImage.java
----------------------------------------------------------------------
diff --git a/packet/src/main/java/org/jclouds/packet/compute/functions/OperatingSystemToImage.java b/packet/src/main/java/org/jclouds/packet/compute/functions/OperatingSystemToImage.java
index d28b579..656ed88 100644
--- a/packet/src/main/java/org/jclouds/packet/compute/functions/OperatingSystemToImage.java
+++ b/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,22 +40,50 @@ import static org.jclouds.compute.domain.OperatingSystem.builder;
@Singleton
public class OperatingSystemToImage implements Function<OperatingSystem, Image> {
- @Override
- public Image apply(final OperatingSystem input) {
- ImageBuilder builder = new ImageBuilder();
- builder.ids(input.slug());
- builder.name(input.name());
- builder.description(input.name());
- builder.status(Image.Status.AVAILABLE);
-
- builder.operatingSystem(builder()
- .name(input.name())
- .family(Distribution.fromValue(input.distribution()).osFamily())
- .description(input.name())
- .version(input.version())
- .is64Bit(true)
- .build());
-
- return builder.build();
- }
+ 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();
+ builder.ids(input.slug());
+ 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(family).description(input.name())
+ .version(input.version()).is64Bit(true).build());
+
+ 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-labs/blob/1fbb7972/packet/src/main/java/org/jclouds/packet/compute/strategy/CreateSshKeysThenCreateNodes.java
----------------------------------------------------------------------
diff --git a/packet/src/main/java/org/jclouds/packet/compute/strategy/CreateSshKeysThenCreateNodes.java b/packet/src/main/java/org/jclouds/packet/compute/strategy/CreateSshKeysThenCreateNodes.java
index 3a5a02a..148079f 100644
--- a/packet/src/main/java/org/jclouds/packet/compute/strategy/CreateSshKeysThenCreateNodes.java
+++ b/packet/src/main/java/org/jclouds/packet/compute/strategy/CreateSshKeysThenCreateNodes.java
@@ -150,6 +150,7 @@ public class CreateSshKeysThenCreateNodes extends CreateNodesWithGroupEncodedInt
logger.debug(">> key pair not found. creating a new key pair %s ...", label);
SshKey newKey = api.sshKeyApi().create(label, options.getPublicKey());
logger.debug(">> key pair created! %s", newKey);
+ generatedSshKeyIds.add(newKey.id());
} else {
logger.debug(">> key pair found! %s", key);
generatedSshKeyIds.add(key.id());
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1fbb7972/packet/src/main/java/org/jclouds/packet/domain/ActionType.java
----------------------------------------------------------------------
diff --git a/packet/src/main/java/org/jclouds/packet/domain/ActionType.java b/packet/src/main/java/org/jclouds/packet/domain/ActionType.java
deleted file mode 100644
index 9177ec5..0000000
--- a/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-labs/blob/1fbb7972/packet/src/main/java/org/jclouds/packet/domain/Distribution.java
----------------------------------------------------------------------
diff --git a/packet/src/main/java/org/jclouds/packet/domain/Distribution.java b/packet/src/main/java/org/jclouds/packet/domain/Distribution.java
deleted file mode 100644
index 0692d59..0000000
--- a/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);
- }
- };
- }
-}