From 811abdb43c39d7584df88a8421ee16033e735a42 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 18 Mar 2012 11:54:21 -0700 Subject: [PATCH] removed the floating ip option, as it needs more thought --- .../compute/NovaComputeServiceAdapter.java | 44 +++++++------------ .../compute/options/NovaTemplateOptions.java | 38 ++-------------- 2 files changed, 21 insertions(+), 61 deletions(-) diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/NovaComputeServiceAdapter.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/NovaComputeServiceAdapter.java index 9323e17440..23148c4802 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/NovaComputeServiceAdapter.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/NovaComputeServiceAdapter.java @@ -18,14 +18,14 @@ */ package org.jclouds.openstack.nova.v1_1.compute; +import static com.google.common.base.Preconditions.checkArgument; + import java.util.Set; import javax.annotation.Nullable; import javax.inject.Inject; import javax.inject.Named; -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Optional; import org.jclouds.compute.ComputeServiceAdapter; import org.jclouds.compute.domain.Template; import org.jclouds.domain.Location; @@ -33,18 +33,19 @@ import org.jclouds.domain.LocationBuilder; import org.jclouds.domain.LoginCredentials; import org.jclouds.openstack.nova.v1_1.NovaClient; import org.jclouds.openstack.nova.v1_1.compute.options.NovaTemplateOptions; -import org.jclouds.openstack.nova.v1_1.domain.*; -import org.jclouds.openstack.nova.v1_1.extensions.FloatingIPClient; +import org.jclouds.openstack.nova.v1_1.domain.Flavor; +import org.jclouds.openstack.nova.v1_1.domain.Image; +import org.jclouds.openstack.nova.v1_1.domain.RebootType; +import org.jclouds.openstack.nova.v1_1.domain.Server; import org.jclouds.openstack.nova.v1_1.features.FlavorClient; import org.jclouds.openstack.nova.v1_1.features.ImageClient; import org.jclouds.openstack.nova.v1_1.features.ServerClient; +import org.jclouds.openstack.nova.v1_1.reference.NovaConstants; +import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; -import org.jclouds.openstack.nova.v1_1.reference.NovaConstants; - -import static com.google.common.base.Preconditions.checkArgument; /** * The adapter used by the NovaComputeServiceContextModule to interface the @@ -89,32 +90,21 @@ public class NovaComputeServiceAdapter implements ComputeServiceAdapter floatingIps = templateOptions.getFloatingIps(); - FloatingIPClient floatingIPClient = null; - - if (autoAllocateFloatingIps || !templateOptions.getFloatingIps().isEmpty()) { - Optional floatingIPClientWrapper = novaClient.getFloatingIPExtensionForRegion(region); - checkArgument(floatingIPClientWrapper.isPresent(), "Floating IP settings are required by configuration, but the extension is not available!"); - floatingIPClient = floatingIPClientWrapper.get(); - } - - // Allocate floating ip(s) - if (floatingIPClient != null && autoAllocateFloatingIps) { - floatingIps.add(floatingIPClient.allocate().getId()); + + String floatingIp = null; + if (autoAllocateFloatingIps) { + checkArgument(novaClient.getFloatingIPExtensionForRegion(region).isPresent(), "Floating IP settings are required by configuration, but the extension is not available!"); + floatingIp = novaClient.getFloatingIPExtensionForRegion(region).get().allocate().getId(); } Server server = serverClient.createServer(name, template.getImage().getId(), template.getHardware().getId()); // Attaching floating ip(s) to server - // TODO what if we're creating n nodes in group? the user would likely expect a single floatingIp per server! - if (floatingIPClient != null) { - for (String floatingIp : floatingIps) { - floatingIPClient.addFloatingIP(server.getId(), floatingIp); - } - } - + if (floatingIp != null) + novaClient.getFloatingIPExtensionForRegion(region).get().addFloatingIP(server.getId(), floatingIp); + return new NodeAndInitialCredentials(server, server.getId() + "", LoginCredentials.builder() .password(server.getAdminPass()).build()); } diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/options/NovaTemplateOptions.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/options/NovaTemplateOptions.java index ae6edbefb5..37a430aa1d 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/options/NovaTemplateOptions.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/compute/options/NovaTemplateOptions.java @@ -18,19 +18,15 @@ */ package org.jclouds.openstack.nova.v1_1.compute.options; -import com.google.common.base.Objects; -import com.google.common.collect.ImmutableSet; +import java.util.Map; + import org.jclouds.compute.options.TemplateOptions; import org.jclouds.domain.Credentials; import org.jclouds.domain.LoginCredentials; import org.jclouds.io.Payload; import org.jclouds.scriptbuilder.domain.Statement; -import java.util.Map; -import java.util.Set; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; +import com.google.common.base.Objects; /** * Contains options supported in the {@code ComputeService#runNode} operation on @@ -63,12 +59,10 @@ public class NovaTemplateOptions extends TemplateOptions implements Cloneable { if (to instanceof NovaTemplateOptions) { NovaTemplateOptions eTo = NovaTemplateOptions.class.cast(to); eTo.autoAssignFloatingIp(isAutoAssignFloatingIp()); - eTo.floatingIps(getFloatingIps()); } } private boolean autoAssignFloatingIp = false; - private Set floatingIps = ImmutableSet.of(); public static final NovaTemplateOptions NONE = new NovaTemplateOptions(); @@ -76,7 +70,6 @@ public class NovaTemplateOptions extends TemplateOptions implements Cloneable { * @see #isAutoAssignFloatingIp() */ public NovaTemplateOptions autoAssignFloatingIp(boolean enable) { - checkState(floatingIps.isEmpty(), "Cannot auto assign when a floating ip is configured"); this.autoAssignFloatingIp = enable; return this; } @@ -88,22 +81,6 @@ public class NovaTemplateOptions extends TemplateOptions implements Cloneable { return autoAssignFloatingIp; } - /** - * @see #getFloatingIps() - */ - public NovaTemplateOptions floatingIps(Set floatingIps) { - checkState(!autoAssignFloatingIp, "Cannot assign a floating ip when auto assign floating up is enabled"); - this.floatingIps = ImmutableSet.copyOf(checkNotNull(floatingIps, "floatingIps")); - return this; - } - - /** - * @return the ids of the configured floating ips - */ - public Set getFloatingIps() { - return floatingIps; - } - public static class Builder { /** @@ -113,13 +90,6 @@ public class NovaTemplateOptions extends TemplateOptions implements Cloneable { return new NovaTemplateOptions().autoAssignFloatingIp(enable); } - /** - * @see NovaTemplateOptions# - */ - public static NovaTemplateOptions floatingIp(Set floatingIps) { - return new NovaTemplateOptions().floatingIps(floatingIps); - } - // methods that only facilitate returning the correct object type /** @@ -389,6 +359,6 @@ public class NovaTemplateOptions extends TemplateOptions implements Cloneable { @Override public String toString() { - return String.format("[autoAssignFloatingIp=%s, floatingIps=%s]", autoAssignFloatingIp, floatingIps); + return String.format("[autoAssignFloatingIp=%s]", autoAssignFloatingIp); } }