mirror of https://github.com/apache/jclouds.git
removed the floating ip option, as it needs more thought
This commit is contained in:
parent
31575a812f
commit
811abdb43c
|
@ -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,31 +90,20 @@ public class NovaComputeServiceAdapter implements ComputeServiceAdapter<Server,
|
|||
// security group, key pair, floating ip (attach post server-create?)
|
||||
NovaTemplateOptions templateOptions = NovaTemplateOptions.class.cast(template.getOptions());
|
||||
|
||||
boolean autoAllocateFloatingIps = templateOptions.getFloatingIps().isEmpty() &&
|
||||
boolean autoAllocateFloatingIps =
|
||||
(this.autoAllocateFloatingIps || templateOptions.isAutoAssignFloatingIp());
|
||||
Set<String> floatingIps = templateOptions.getFloatingIps();
|
||||
FloatingIPClient floatingIPClient = null;
|
||||
|
||||
if (autoAllocateFloatingIps || !templateOptions.getFloatingIps().isEmpty()) {
|
||||
Optional<FloatingIPClient> 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, server.getId() + "", LoginCredentials.builder()
|
||||
.password(server.getAdminPass()).build());
|
||||
|
|
|
@ -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<String> 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<String> 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<String> 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<String> 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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue