mirror of https://github.com/apache/jclouds.git
multizone and floating ip support
This commit is contained in:
parent
45b4725fc7
commit
28fd2742fb
|
@ -24,6 +24,7 @@ import static org.jclouds.Constants.PROPERTY_ISO3166_CODES;
|
|||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.openstack.nova.v1_1.NovaPropertiesBuilder;
|
||||
import org.jclouds.openstack.nova.v1_1.reference.NovaConstants;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -36,6 +37,7 @@ public class HPCloudComputePropertiesBuilder extends NovaPropertiesBuilder {
|
|||
Properties properties = super.defaultProperties();
|
||||
properties.setProperty(PROPERTY_ISO3166_CODES, "US-NV");
|
||||
properties.setProperty(PROPERTY_ENDPOINT, "https://region-a.geo-1.identity.hpcloudsvc.com:35357");
|
||||
properties.setProperty(NovaConstants.PROPERTY_NOVA_AUTO_ALLOCATE_FLOATING_IPS, "true");
|
||||
return properties;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.jclouds.compute.BaseTemplateBuilderLiveTest;
|
|||
import org.jclouds.compute.domain.OsFamily;
|
||||
import org.jclouds.compute.domain.OsFamilyVersion64Bit;
|
||||
import org.jclouds.compute.domain.Template;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.options.NovaTemplateOptions;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
|
@ -37,7 +38,7 @@ import com.google.common.collect.ImmutableSet;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live")
|
||||
@Test(groups = "live", singleThreaded = true, testName = "HPCloudComputeTemplateBuilderLiveTest")
|
||||
public class HPCloudComputeTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
|
||||
|
||||
public HPCloudComputeTemplateBuilderLiveTest() {
|
||||
|
@ -73,6 +74,7 @@ public class HPCloudComputeTemplateBuilderLiveTest extends BaseTemplateBuilderLi
|
|||
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "11.10");
|
||||
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
|
||||
assertEquals(defaultTemplate.getLocation().getId(), "az-1.region-a.geo-1");
|
||||
assertEquals(defaultTemplate.getOptions().as(NovaTemplateOptions.class).isAutoAssignFloatingIp(), true);
|
||||
assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
|
||||
}
|
||||
|
||||
|
|
|
@ -21,8 +21,8 @@ package org.jclouds.openstack.nova.v1_1;
|
|||
import java.util.Set;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.location.Region;
|
||||
import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
|
||||
import org.jclouds.location.Zone;
|
||||
import org.jclouds.location.functions.ZoneToEndpoint;
|
||||
import org.jclouds.openstack.nova.v1_1.extensions.FloatingIPAsyncClient;
|
||||
import org.jclouds.openstack.nova.v1_1.extensions.KeyPairAsyncClient;
|
||||
import org.jclouds.openstack.nova.v1_1.extensions.SecurityGroupAsyncClient;
|
||||
|
@ -49,58 +49,58 @@ public interface NovaAsyncClient {
|
|||
|
||||
/**
|
||||
*
|
||||
* @return the region codes configured
|
||||
* @return the Zone codes configured
|
||||
*/
|
||||
@Provides
|
||||
@Region
|
||||
Set<String> getConfiguredRegions();
|
||||
@Zone
|
||||
Set<String> getConfiguredZones();
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Server features.
|
||||
*/
|
||||
@Delegate
|
||||
ServerAsyncClient getServerClientForRegion(
|
||||
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
|
||||
ServerAsyncClient getServerClientForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Flavor features.
|
||||
*/
|
||||
@Delegate
|
||||
FlavorAsyncClient getFlavorClientForRegion(
|
||||
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
|
||||
FlavorAsyncClient getFlavorClientForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Extension features.
|
||||
*/
|
||||
@Delegate
|
||||
ExtensionAsyncClient getExtensionClientForRegion(
|
||||
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
|
||||
ExtensionAsyncClient getExtensionClientForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Image features.
|
||||
*/
|
||||
@Delegate
|
||||
ImageAsyncClient getImageClientForRegion(
|
||||
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
|
||||
ImageAsyncClient getImageClientForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Floating IP features.
|
||||
*/
|
||||
@Delegate
|
||||
Optional<FloatingIPAsyncClient> getFloatingIPExtensionForRegion(
|
||||
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
|
||||
Optional<FloatingIPAsyncClient> getFloatingIPExtensionForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Security Group features.
|
||||
*/
|
||||
@Delegate
|
||||
Optional<SecurityGroupAsyncClient> getSecurityGroupExtensionForRegion(
|
||||
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
|
||||
Optional<SecurityGroupAsyncClient> getSecurityGroupExtensionForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Key Pair features.
|
||||
*/
|
||||
@Delegate
|
||||
Optional<KeyPairAsyncClient> getKeyPairExtensionForRegion(
|
||||
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
|
||||
Optional<KeyPairAsyncClient> getKeyPairExtensionForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
}
|
||||
|
|
|
@ -23,8 +23,8 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.location.Region;
|
||||
import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
|
||||
import org.jclouds.location.Zone;
|
||||
import org.jclouds.location.functions.ZoneToEndpoint;
|
||||
import org.jclouds.openstack.nova.v1_1.extensions.FloatingIPClient;
|
||||
import org.jclouds.openstack.nova.v1_1.extensions.KeyPairClient;
|
||||
import org.jclouds.openstack.nova.v1_1.extensions.SecurityGroupClient;
|
||||
|
@ -51,59 +51,59 @@ import com.google.inject.Provides;
|
|||
public interface NovaClient {
|
||||
/**
|
||||
*
|
||||
* @return the region codes configured
|
||||
* @return the Zone codes configured
|
||||
*/
|
||||
@Provides
|
||||
@Region
|
||||
Set<String> getConfiguredRegions();
|
||||
@Zone
|
||||
Set<String> getConfiguredZones();
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Server features.
|
||||
*/
|
||||
@Delegate
|
||||
ServerClient getServerClientForRegion(
|
||||
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
|
||||
ServerClient getServerClientForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Flavor features.
|
||||
*/
|
||||
@Delegate
|
||||
FlavorClient getFlavorClientForRegion(
|
||||
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
|
||||
FlavorClient getFlavorClientForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Extension features.
|
||||
*/
|
||||
@Delegate
|
||||
ExtensionClient getExtensionClientForRegion(
|
||||
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
|
||||
ExtensionClient getExtensionClientForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Image features.
|
||||
*/
|
||||
@Delegate
|
||||
ImageClient getImageClientForRegion(
|
||||
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
|
||||
ImageClient getImageClientForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Floating IP features.
|
||||
*/
|
||||
@Delegate
|
||||
Optional<FloatingIPClient> getFloatingIPExtensionForRegion(
|
||||
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
|
||||
Optional<FloatingIPClient> getFloatingIPExtensionForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Security Group features.
|
||||
*/
|
||||
@Delegate
|
||||
Optional<SecurityGroupClient> getSecurityGroupExtensionForRegion(
|
||||
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
|
||||
Optional<SecurityGroupClient> getSecurityGroupExtensionForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Key Pair features.
|
||||
*/
|
||||
@Delegate
|
||||
Optional<KeyPairClient> getKeyPairExtensionForRegion(
|
||||
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
|
||||
Optional<KeyPairClient> getKeyPairExtensionForZone(
|
||||
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
|
||||
|
||||
}
|
||||
|
|
|
@ -18,131 +18,156 @@
|
|||
*/
|
||||
package org.jclouds.openstack.nova.v1_1.compute;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.jclouds.compute.ComputeServiceAdapter;
|
||||
import org.jclouds.compute.domain.Template;
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LocationBuilder;
|
||||
import org.jclouds.domain.LoginCredentials;
|
||||
import org.jclouds.location.Zone;
|
||||
import org.jclouds.logging.Logger;
|
||||
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.compute.domain.FlavorInZone;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.domain.ImageInZone;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.domain.ServerInZone;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.domain.ZoneAndId;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.functions.RemoveFloatingIpFromNodeAndDeallocate;
|
||||
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.base.Supplier;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.ImmutableSet.Builder;
|
||||
|
||||
/**
|
||||
* The adapter used by the NovaComputeServiceContextModule to interface the
|
||||
* nova-specific domain model to the computeService generic domain model.
|
||||
*
|
||||
* @author Matt Stephenson
|
||||
* The adapter used by the NovaComputeServiceContextModule to interface the nova-specific domain
|
||||
* model to the computeService generic domain model.
|
||||
*
|
||||
* @author Matt Stephenson, Adrian Cole
|
||||
*/
|
||||
public class NovaComputeServiceAdapter implements ComputeServiceAdapter<Server, Flavor, Image, Location> {
|
||||
public class NovaComputeServiceAdapter implements
|
||||
ComputeServiceAdapter<ServerInZone, FlavorInZone, ImageInZone, Location> {
|
||||
|
||||
private final NovaClient novaClient;
|
||||
private final ServerClient defaultLocationServerClient;
|
||||
private final FlavorClient defaultFlavorClient;
|
||||
private final ImageClient defaultImageClient;
|
||||
private final Set<String> regions;
|
||||
private final String defaultRegion;
|
||||
@Resource
|
||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
protected final NovaClient novaClient;
|
||||
protected final Supplier<Set<String>> zoneIds;
|
||||
protected final RemoveFloatingIpFromNodeAndDeallocate removeFloatingIpFromNodeAndDeallocate;
|
||||
|
||||
@Inject
|
||||
@Named(NovaConstants.PROPERTY_NOVA_AUTO_ALLOCATE_FLOATING_IPS)
|
||||
@VisibleForTesting
|
||||
boolean autoAllocateFloatingIps = false;
|
||||
public NovaComputeServiceAdapter(NovaClient novaClient, @Zone Supplier<Set<String>> zoneIds,
|
||||
RemoveFloatingIpFromNodeAndDeallocate removeFloatingIpFromNodeAndDeallocate) {
|
||||
this.novaClient = checkNotNull(novaClient, "novaClient");
|
||||
this.zoneIds = checkNotNull(zoneIds, "zoneIds");
|
||||
this.removeFloatingIpFromNodeAndDeallocate = checkNotNull(removeFloatingIpFromNodeAndDeallocate,
|
||||
"removeFloatingIpFromNodeAndDeallocate");
|
||||
}
|
||||
|
||||
@Inject
|
||||
public NovaComputeServiceAdapter(NovaClient novaClient) {
|
||||
this.novaClient = novaClient;
|
||||
regions = novaClient.getConfiguredRegions();
|
||||
if (regions.isEmpty()) {
|
||||
throw new IllegalStateException(
|
||||
"No regions exist for this compute service. The Nova compute service requires at least 1 region.");
|
||||
@Override
|
||||
public NodeAndInitialCredentials<ServerInZone> createNodeWithGroupEncodedIntoName(String tag, String name,
|
||||
Template template) {
|
||||
String zoneId = template.getLocation().getId();
|
||||
Server server = novaClient.getServerClientForZone(zoneId).createServer(name, template.getImage().getId(),
|
||||
template.getHardware().getId());
|
||||
|
||||
return new NodeAndInitialCredentials<ServerInZone>(new ServerInZone(server, zoneId), server.getId() + "",
|
||||
LoginCredentials.builder().password(server.getAdminPass()).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<FlavorInZone> listHardwareProfiles() {
|
||||
Builder<FlavorInZone> builder = ImmutableSet.<FlavorInZone> builder();
|
||||
for (final String zoneId : zoneIds.get()) {
|
||||
builder.addAll(Iterables.transform(novaClient.getFlavorClientForZone(zoneId).listFlavorsInDetail(),
|
||||
new Function<Flavor, FlavorInZone>() {
|
||||
|
||||
@Override
|
||||
public FlavorInZone apply(Flavor arg0) {
|
||||
return new FlavorInZone(arg0, zoneId);
|
||||
}
|
||||
|
||||
}));
|
||||
}
|
||||
this.defaultRegion = regions.iterator().next();
|
||||
this.defaultLocationServerClient = novaClient.getServerClientForRegion(defaultRegion);
|
||||
this.defaultFlavorClient = novaClient.getFlavorClientForRegion(defaultRegion);
|
||||
this.defaultImageClient = novaClient.getImageClientForRegion(defaultRegion);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeAndInitialCredentials<Server> createNodeWithGroupEncodedIntoName(String tag, String name,
|
||||
Template template) {
|
||||
String region = template.getLocation() == null ? defaultRegion : template.getLocation().getId();
|
||||
ServerClient serverClient = template.getLocation() != null ? novaClient.getServerClientForRegion(template.getLocation().getId()) : defaultLocationServerClient;
|
||||
// TODO: make NovaTemplateOptions with the following:
|
||||
// security group, key pair, floating ip (attach post server-create?)
|
||||
NovaTemplateOptions templateOptions = NovaTemplateOptions.class.cast(template.getOptions());
|
||||
|
||||
boolean autoAllocateFloatingIps =
|
||||
(this.autoAllocateFloatingIps || templateOptions.isAutoAssignFloatingIp());
|
||||
|
||||
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();
|
||||
public Iterable<ImageInZone> listImages() {
|
||||
Builder<ImageInZone> builder = ImmutableSet.<ImageInZone> builder();
|
||||
for (final String zoneId : zoneIds.get()) {
|
||||
builder.addAll(Iterables.transform(novaClient.getImageClientForZone(zoneId).listImagesInDetail(),
|
||||
new Function<Image, ImageInZone>() {
|
||||
|
||||
@Override
|
||||
public ImageInZone apply(Image arg0) {
|
||||
return new ImageInZone(arg0, zoneId);
|
||||
}
|
||||
|
||||
}));
|
||||
}
|
||||
|
||||
Server server = serverClient.createServer(name, template.getImage().getId(), template.getHardware().getId());
|
||||
|
||||
// Attaching floating ip(s) to server
|
||||
if (floatingIp != null)
|
||||
novaClient.getFloatingIPExtensionForRegion(region).get().addFloatingIP(server.getId(), floatingIp);
|
||||
|
||||
return new NodeAndInitialCredentials<Server>(server, server.getId() + "", LoginCredentials.builder()
|
||||
.password(server.getAdminPass()).build());
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Flavor> listHardwareProfiles() {
|
||||
return defaultFlavorClient.listFlavorsInDetail();
|
||||
}
|
||||
public Iterable<ServerInZone> listNodes() {
|
||||
Builder<ServerInZone> builder = ImmutableSet.<ServerInZone> builder();
|
||||
for (final String zoneId : zoneIds.get()) {
|
||||
builder.addAll(Iterables.transform(novaClient.getServerClientForZone(zoneId).listServersInDetail(),
|
||||
new Function<Server, ServerInZone>() {
|
||||
|
||||
@Override
|
||||
public Iterable<Image> listImages() {
|
||||
return defaultImageClient.listImagesInDetail();
|
||||
@Override
|
||||
public ServerInZone apply(Server arg0) {
|
||||
return new ServerInZone(arg0, zoneId);
|
||||
}
|
||||
|
||||
}));
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Location> listLocations() {
|
||||
return Iterables.transform(novaClient.getConfiguredRegions(), new Function<String, Location>() {
|
||||
|
||||
@Override
|
||||
public Location apply(@Nullable String region) {
|
||||
return new LocationBuilder().id(region).description(region).build();
|
||||
}
|
||||
});
|
||||
// locations provided by keystone
|
||||
return ImmutableSet.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Server getNode(String id) {
|
||||
return defaultLocationServerClient.getServer(id);
|
||||
public ServerInZone getNode(String id) {
|
||||
ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id);
|
||||
Server server = novaClient.getServerClientForZone(zoneAndId.getZone()).getServer(zoneAndId.getId());
|
||||
return server == null ? null : new ServerInZone(server, zoneAndId.getZone());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyNode(String id) {
|
||||
defaultLocationServerClient.deleteServer(id);
|
||||
ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id);
|
||||
if (novaClient.getFloatingIPExtensionForZone(zoneAndId.getZone()).isPresent()) {
|
||||
try {
|
||||
removeFloatingIpFromNodeAndDeallocate.apply(zoneAndId);
|
||||
} catch (RuntimeException e) {
|
||||
logger.warn(e, "<< error removing and deallocating ip from node(%s): %s", id, e.getMessage());
|
||||
}
|
||||
}
|
||||
novaClient.getServerClientForZone(zoneAndId.getZone()).deleteServer(zoneAndId.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rebootNode(String id) {
|
||||
defaultLocationServerClient.rebootServer(id, RebootType.SOFT);
|
||||
ZoneAndId zoneAndId = ZoneAndId.fromSlashEncoded(id);
|
||||
novaClient.getServerClientForZone(zoneAndId.getZone()).rebootServer(zoneAndId.getId(), RebootType.HARD);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -155,14 +180,4 @@ public class NovaComputeServiceAdapter implements ComputeServiceAdapter<Server,
|
|||
throw new UnsupportedOperationException("suspend not supported");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Server> listNodes() {
|
||||
ImmutableSet.Builder<Server> servers = new ImmutableSet.Builder<Server>();
|
||||
|
||||
for (String region : regions) {
|
||||
servers.addAll(novaClient.getServerClientForRegion(region).listServersInDetail());
|
||||
}
|
||||
|
||||
return servers.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,9 +18,13 @@
|
|||
*/
|
||||
package org.jclouds.openstack.nova.v1_1.compute.config;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.compute.ComputeServiceAdapter;
|
||||
import org.jclouds.compute.config.ComputeServiceAdapterContextModule;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
|
@ -28,25 +32,34 @@ import org.jclouds.compute.domain.Image;
|
|||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.OperatingSystem;
|
||||
import org.jclouds.compute.options.TemplateOptions;
|
||||
import org.jclouds.compute.strategy.impl.CreateNodesWithGroupEncodedIntoNameThenAddToSet;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.functions.IdentityFunction;
|
||||
import org.jclouds.openstack.nova.v1_1.NovaAsyncClient;
|
||||
import org.jclouds.openstack.nova.v1_1.NovaClient;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.NovaComputeServiceAdapter;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.domain.RegionAndName;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.functions.FlavorToHardware;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.functions.NovaImageToImage;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.domain.FlavorInZone;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.domain.ImageInZone;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.domain.ServerInZone;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.domain.ZoneAndId;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.functions.FlavorInZoneToHardware;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.functions.ImageInZoneToImage;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.functions.NovaImageToOperatingSystem;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.functions.ServerToNodeMetadata;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.functions.ServerInZoneToNodeMetadata;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.loaders.LoadFloatingIpsForInstance;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.options.NovaTemplateOptions;
|
||||
import org.jclouds.openstack.nova.v1_1.domain.Flavor;
|
||||
import org.jclouds.openstack.nova.v1_1.domain.Server;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.strategy.ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddToSet;
|
||||
import org.jclouds.openstack.nova.v1_1.reference.NovaConstants;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import com.google.inject.name.Names;
|
||||
|
@ -57,8 +70,8 @@ import com.google.inject.name.Names;
|
|||
* @author Matt Stephenson
|
||||
*/
|
||||
public class NovaComputeServiceContextModule
|
||||
extends
|
||||
ComputeServiceAdapterContextModule<NovaClient, NovaAsyncClient, Server, Flavor, org.jclouds.openstack.nova.v1_1.domain.Image, Location> {
|
||||
extends
|
||||
ComputeServiceAdapterContextModule<NovaClient, NovaAsyncClient, ServerInZone, FlavorInZone, ImageInZone, Location> {
|
||||
public NovaComputeServiceContextModule() {
|
||||
super(NovaClient.class, NovaAsyncClient.class);
|
||||
}
|
||||
|
@ -67,20 +80,19 @@ public class NovaComputeServiceContextModule
|
|||
@Override
|
||||
protected void configure() {
|
||||
super.configure();
|
||||
bind(
|
||||
new TypeLiteral<ComputeServiceAdapter<Server, Flavor, org.jclouds.openstack.nova.v1_1.domain.Image, Location>>() {
|
||||
}).to(NovaComputeServiceAdapter.class);
|
||||
bind(new TypeLiteral<ComputeServiceAdapter<ServerInZone, FlavorInZone, ImageInZone, Location>>() {
|
||||
}).to(NovaComputeServiceAdapter.class);
|
||||
|
||||
bind(new TypeLiteral<Function<Server, NodeMetadata>>() {
|
||||
}).to(ServerToNodeMetadata.class);
|
||||
bind(new TypeLiteral<Function<ServerInZone, NodeMetadata>>() {
|
||||
}).to(ServerInZoneToNodeMetadata.class);
|
||||
|
||||
bind(new TypeLiteral<Function<org.jclouds.openstack.nova.v1_1.domain.Image, Image>>() {
|
||||
}).to(NovaImageToImage.class);
|
||||
bind(new TypeLiteral<Function<ImageInZone, Image>>() {
|
||||
}).to(ImageInZoneToImage.class);
|
||||
bind(new TypeLiteral<Function<org.jclouds.openstack.nova.v1_1.domain.Image, OperatingSystem>>() {
|
||||
}).to(NovaImageToOperatingSystem.class);
|
||||
|
||||
bind(new TypeLiteral<Function<Flavor, Hardware>>() {
|
||||
}).to(FlavorToHardware.class);
|
||||
bind(new TypeLiteral<Function<FlavorInZone, Hardware>>() {
|
||||
}).to(FlavorInZoneToHardware.class);
|
||||
|
||||
// we aren't converting location from a provider-specific type
|
||||
bind(new TypeLiteral<Function<Location, Location>>() {
|
||||
|
@ -88,16 +100,50 @@ public class NovaComputeServiceContextModule
|
|||
|
||||
bind(TemplateOptions.class).to(NovaTemplateOptions.class);
|
||||
|
||||
bind(new TypeLiteral<CacheLoader<RegionAndName, Iterable<String>>>() {
|
||||
bind(new TypeLiteral<CacheLoader<ZoneAndId, Iterable<String>>>() {
|
||||
}).annotatedWith(Names.named("FLOATINGIP")).to(LoadFloatingIpsForInstance.class);
|
||||
|
||||
bind(CreateNodesWithGroupEncodedIntoNameThenAddToSet.class).to(
|
||||
ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddToSet.class);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TemplateOptions provideTemplateOptions(Injector injector, TemplateOptions options) {
|
||||
return options.as(NovaTemplateOptions.class).autoAssignFloatingIp(
|
||||
injector.getInstance(Key.get(boolean.class, Names
|
||||
.named(NovaConstants.PROPERTY_NOVA_AUTO_ALLOCATE_FLOATING_IPS))));
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named("FLOATINGIP")
|
||||
protected LoadingCache<RegionAndName, Iterable<String>> instanceToFloatingIps(
|
||||
@Named("FLOATINGIP") CacheLoader<RegionAndName, Iterable<String>> in) {
|
||||
protected LoadingCache<ZoneAndId, Iterable<String>> instanceToFloatingIps(
|
||||
@Named("FLOATINGIP") CacheLoader<ZoneAndId, Iterable<String>> in) {
|
||||
return CacheBuilder.newBuilder().build(in);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Map<String, Location>> createLocationIndexedById(
|
||||
@Memoized Supplier<Set<? extends Location>> locations) {
|
||||
return Suppliers.compose(new Function<Set<? extends Location>, Map<String, Location>>() {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Map<String, Location> apply(Set<? extends Location> arg0) {
|
||||
// TODO: find a nice way to get rid of this cast.
|
||||
Iterable<Location> locations = (Iterable<Location>) arg0;
|
||||
return Maps.uniqueIndex(locations, new Function<Location, String>() {
|
||||
|
||||
@Override
|
||||
public String apply(Location arg0) {
|
||||
return arg0.getId();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}, locations);
|
||||
|
||||
}
|
||||
}
|
|
@ -18,48 +18,31 @@
|
|||
*/
|
||||
package org.jclouds.openstack.nova.v1_1.compute.domain;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import org.jclouds.openstack.nova.v1_1.domain.Flavor;
|
||||
|
||||
/**
|
||||
* @author Adam Lowe
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class RegionAndName {
|
||||
protected final String region;
|
||||
protected final String name;
|
||||
public class FlavorInZone extends ZoneAndId {
|
||||
protected final Flavor image;
|
||||
|
||||
public RegionAndName(String region, String name) {
|
||||
this.region = region;
|
||||
this.name = name;
|
||||
public FlavorInZone(Flavor image, String zoneId) {
|
||||
super(zoneId, checkNotNull(image, "image").getId());
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(region, name);
|
||||
public Flavor getFlavor() {
|
||||
return image;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
RegionAndName other = (RegionAndName) obj;
|
||||
return Objects.equal(region, other.region) && Objects.equal(name, other.name);
|
||||
}
|
||||
|
||||
public String getRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
// superclass hashCode/equals are good enough, and help us use ZoneAndId and FlavorInZone
|
||||
// interchangeably as Map keys
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[region=" + region + ", name=" + name + "]";
|
||||
return "[image=" + image + ", zoneId=" + zoneId + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.openstack.nova.v1_1.compute.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import org.jclouds.openstack.nova.v1_1.domain.Image;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class ImageInZone extends ZoneAndId {
|
||||
protected final Image server;
|
||||
|
||||
public ImageInZone(Image server, String zoneId) {
|
||||
super(zoneId, checkNotNull(server, "server").getId());
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
public Image getImage() {
|
||||
return server;
|
||||
}
|
||||
|
||||
// superclass hashCode/equals are good enough, and help us use ZoneAndId and ImageInZone
|
||||
// interchangeably as Map keys
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[server=" + server + ", zoneId=" + zoneId + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.openstack.nova.v1_1.compute.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import org.jclouds.openstack.nova.v1_1.domain.Server;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class ServerInZone extends ZoneAndId {
|
||||
protected final Server server;
|
||||
|
||||
public ServerInZone(Server server, String zoneId) {
|
||||
super(zoneId, checkNotNull(server, "server").getId());
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
public Server getServer() {
|
||||
return server;
|
||||
}
|
||||
|
||||
// superclass hashCode/equals are good enough, and help us use ZoneAndId and ServerInZone
|
||||
// interchangeably as Map keys
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[server=" + server + ", zoneId=" + zoneId + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.openstack.nova.v1_1.compute.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* @author Adam Lowe
|
||||
*/
|
||||
public class ZoneAndId {
|
||||
public static ZoneAndId fromSlashEncoded(String id) {
|
||||
Iterable<String> parts = Splitter.on('/').split(checkNotNull(id, "id"));
|
||||
checkArgument(Iterables.size(parts) == 2, "id must be in format zoneId/id");
|
||||
return new ZoneAndId(Iterables.get(parts, 0), Iterables.get(parts, 1));
|
||||
}
|
||||
|
||||
public static ZoneAndId fromZoneAndId(String zoneId, String id) {
|
||||
return new ZoneAndId(zoneId, id);
|
||||
}
|
||||
|
||||
private static String slashEncodeZoneAndId(String zoneId, String id) {
|
||||
return checkNotNull(zoneId, "zoneId") + "/" + checkNotNull(id, "id");
|
||||
}
|
||||
|
||||
public String slashEncode() {
|
||||
return slashEncodeZoneAndId(zoneId, id);
|
||||
}
|
||||
|
||||
protected final String zoneId;
|
||||
protected final String id;
|
||||
|
||||
protected ZoneAndId(String zoneId, String id) {
|
||||
this.zoneId = checkNotNull(zoneId, "zoneId");
|
||||
this.id = checkNotNull(id, "id");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(zoneId, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
ZoneAndId other = (ZoneAndId) obj;
|
||||
return Objects.equal(zoneId, other.zoneId) && Objects.equal(id, other.id);
|
||||
}
|
||||
|
||||
public String getZone() {
|
||||
return zoneId;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[zoneId=" + zoneId + ", id=" + id + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,114 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.openstack.nova.v1_1.compute.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.NodeMetadataBuilder;
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.openstack.nova.v1_1.NovaClient;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.domain.ZoneAndId;
|
||||
import org.jclouds.openstack.nova.v1_1.domain.FloatingIP;
|
||||
import org.jclouds.openstack.nova.v1_1.extensions.FloatingIPClient;
|
||||
import org.jclouds.rest.InsufficientResourcesException;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
* A function for adding and allocating an ip to a node
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class AllocateAndAddFloatingIpToNode implements
|
||||
Function<AtomicReference<NodeMetadata>, AtomicReference<NodeMetadata>> {
|
||||
|
||||
@Resource
|
||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
private final Predicate<AtomicReference<NodeMetadata>> nodeRunning;
|
||||
private final NovaClient novaClient;
|
||||
private final LoadingCache<ZoneAndId, Iterable<String>> floatingIpCache;
|
||||
|
||||
@Inject
|
||||
public AllocateAndAddFloatingIpToNode(@Named("NODE_RUNNING") Predicate<AtomicReference<NodeMetadata>> nodeRunning,
|
||||
NovaClient novaClient, @Named("FLOATINGIP") LoadingCache<ZoneAndId, Iterable<String>> floatingIpCache) {
|
||||
this.nodeRunning = checkNotNull(nodeRunning, "nodeRunning");
|
||||
this.novaClient = checkNotNull(novaClient, "novaClient");
|
||||
this.floatingIpCache = checkNotNull(floatingIpCache, "floatingIpCache");
|
||||
}
|
||||
|
||||
@Override
|
||||
public AtomicReference<NodeMetadata> apply(AtomicReference<NodeMetadata> input) {
|
||||
checkState(nodeRunning.apply(input), "node never achieved state running %s", input.get());
|
||||
NodeMetadata node = input.get();
|
||||
// node's location is a host
|
||||
String zoneId = node.getLocation().getParent().getId();
|
||||
FloatingIPClient floatingIpClient = novaClient.getFloatingIPExtensionForZone(zoneId).get();
|
||||
|
||||
FloatingIP ip = null;
|
||||
try {
|
||||
logger.debug(">> allocating or reassigning floating ip for node(%s)", node.getId());
|
||||
ip = floatingIpClient.allocate();
|
||||
} catch (InsufficientResourcesException e) {
|
||||
logger.trace("<< [%s] allocating a new floating ip for node(%s)", e.getMessage(), node.getId());
|
||||
logger.trace(">> searching for existing, unassigned floating ip for node(%s)", node.getId());
|
||||
ArrayList<FloatingIP> unassignedIps = Lists.newArrayList(Iterables.filter(floatingIpClient.listFloatingIPs(),
|
||||
new Predicate<FloatingIP>() {
|
||||
|
||||
@Override
|
||||
public boolean apply(FloatingIP arg0) {
|
||||
return arg0.getFixedIp() == null;
|
||||
}
|
||||
|
||||
}));
|
||||
// try to prevent multiple parallel launches from choosing the same ip.
|
||||
Collections.shuffle(unassignedIps);
|
||||
ip = Iterables.getLast(unassignedIps);
|
||||
}
|
||||
logger.debug(">> adding floatingIp(%s) to node(%s)", ip.getIp(), node.getId());
|
||||
|
||||
floatingIpClient.addFloatingIPToServer(ip.getIp(), node.getProviderId());
|
||||
input.set(NodeMetadataBuilder.fromNodeMetadata(node).publicAddresses(ImmutableSet.of(ip.getIp())).build());
|
||||
floatingIpCache.invalidate(ZoneAndId.fromSlashEncoded(node.getId()));
|
||||
return input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Objects.toStringHelper("AllocateAndAddFloatingIpToNode").toString();
|
||||
}
|
||||
}
|
|
@ -18,6 +18,11 @@
|
|||
*/
|
||||
package org.jclouds.openstack.nova.v1_1.compute.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
|
@ -25,33 +30,33 @@ import org.jclouds.compute.domain.HardwareBuilder;
|
|||
import org.jclouds.compute.domain.Processor;
|
||||
import org.jclouds.compute.domain.internal.VolumeImpl;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.domain.FlavorInZone;
|
||||
import org.jclouds.openstack.nova.v1_1.domain.Flavor;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
|
||||
/**
|
||||
* A function for transforming the nova specific Flavor object to the generic
|
||||
* Hardware object.
|
||||
* A function for transforming the nova specific FlavorInZone object to the generic Hardware object.
|
||||
*
|
||||
* @author Matt Stephenson
|
||||
*/
|
||||
public class FlavorToHardware implements Function<Flavor, Hardware> {
|
||||
public class FlavorInZoneToHardware implements Function<FlavorInZone, Hardware> {
|
||||
|
||||
private final Supplier<Location> defaultLocation;
|
||||
private final Supplier<Map<String, Location>> locationIndex;
|
||||
|
||||
@Inject
|
||||
public FlavorToHardware(Supplier<Location> defaultLocation) {
|
||||
this.defaultLocation = defaultLocation;
|
||||
public FlavorInZoneToHardware(Supplier<Map<String, Location>> locationIndex) {
|
||||
this.locationIndex = checkNotNull(locationIndex, "locationIndex");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Hardware apply(Flavor flavor) {
|
||||
return new HardwareBuilder()
|
||||
// TODO: scope id to region, if there's a chance for conflict
|
||||
.id(flavor.getId()).providerId(flavor.getId()).name(flavor.getName()).ram(flavor.getRam())
|
||||
.processor(new Processor(flavor.getVcpus(), 1.0))
|
||||
.volume(new VolumeImpl(Float.valueOf(flavor.getDisk()), true, true)).location(defaultLocation.get())
|
||||
.build();
|
||||
public Hardware apply(FlavorInZone flavorInZone) {
|
||||
Location location = locationIndex.get().get(flavorInZone.getZone());
|
||||
checkState(location != null, "location %s not in locationIndex: %s", flavorInZone.getZone(), locationIndex.get());
|
||||
Flavor flavor = flavorInZone.getFlavor();
|
||||
return new HardwareBuilder().id(flavorInZone.slashEncode()).providerId(flavor.getId()).name(flavor.getName())
|
||||
.ram(flavor.getRam()).processor(new Processor(flavor.getVcpus(), 1.0)).volume(
|
||||
new VolumeImpl(Float.valueOf(flavor.getDisk()), true, true)).location(location).build();
|
||||
}
|
||||
}
|
|
@ -18,38 +18,45 @@
|
|||
*/
|
||||
package org.jclouds.openstack.nova.v1_1.compute.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.ImageBuilder;
|
||||
import org.jclouds.compute.domain.OperatingSystem;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.domain.ImageInZone;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
|
||||
/**
|
||||
* A function for transforming a nova-specific Image into a generic Image
|
||||
* object.
|
||||
* A function for transforming a nova-specific Image into a generic Image object.
|
||||
*
|
||||
* @author Matt Stephenson
|
||||
*/
|
||||
public class NovaImageToImage implements Function<org.jclouds.openstack.nova.v1_1.domain.Image, Image> {
|
||||
public class ImageInZoneToImage implements Function<ImageInZone, Image> {
|
||||
private final Function<org.jclouds.openstack.nova.v1_1.domain.Image, OperatingSystem> imageToOs;
|
||||
private final Supplier<Location> defaultLocation;
|
||||
private final Supplier<Map<String, Location>> locationIndex;
|
||||
|
||||
@Inject
|
||||
public NovaImageToImage(Function<org.jclouds.openstack.nova.v1_1.domain.Image, OperatingSystem> imageToOs,
|
||||
Supplier<Location> defaultLocation) {
|
||||
this.imageToOs = imageToOs;
|
||||
this.defaultLocation = defaultLocation;
|
||||
public ImageInZoneToImage(Function<org.jclouds.openstack.nova.v1_1.domain.Image, OperatingSystem> imageToOs,
|
||||
Supplier<Map<String, Location>> locationIndex) {
|
||||
this.imageToOs = checkNotNull(imageToOs, "imageToOs");
|
||||
this.locationIndex = checkNotNull(locationIndex, "locationIndex");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image apply(org.jclouds.openstack.nova.v1_1.domain.Image image) {
|
||||
public Image apply(ImageInZone imageInZone) {
|
||||
Location location = locationIndex.get().get(imageInZone.getZone());
|
||||
checkState(location != null, "location %s not in locationIndex: %s", imageInZone.getZone(), locationIndex.get());
|
||||
org.jclouds.openstack.nova.v1_1.domain.Image image = imageInZone.getImage();
|
||||
return new ImageBuilder()
|
||||
// TODO: scope id to region, if there's a chance for conflict
|
||||
.id(image.getId()).providerId(image.getId()).name(image.getName()).operatingSystem(imageToOs.apply(image))
|
||||
.description(image.getName()).location(defaultLocation.get()).build();
|
||||
.id(imageInZone.slashEncode()).providerId(image.getId()).name(image.getName()).operatingSystem(
|
||||
imageToOs.apply(image)).description(image.getName()).location(location).build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.openstack.nova.v1_1.compute.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.openstack.nova.v1_1.NovaClient;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.domain.ZoneAndId;
|
||||
import org.jclouds.openstack.nova.v1_1.extensions.FloatingIPClient;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
|
||||
/**
|
||||
* A function for removing and deallocating an ip address from a node
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class RemoveFloatingIpFromNodeAndDeallocate implements Function<ZoneAndId, ZoneAndId> {
|
||||
|
||||
@Resource
|
||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
private final NovaClient novaClient;
|
||||
private final LoadingCache<ZoneAndId, Iterable<String>> floatingIpCache;
|
||||
|
||||
@Inject
|
||||
public RemoveFloatingIpFromNodeAndDeallocate(NovaClient novaClient,
|
||||
@Named("FLOATINGIP") LoadingCache<ZoneAndId, Iterable<String>> floatingIpCache) {
|
||||
this.novaClient = checkNotNull(novaClient, "novaClient");
|
||||
this.floatingIpCache = checkNotNull(floatingIpCache, "floatingIpCache");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZoneAndId apply(ZoneAndId id) {
|
||||
FloatingIPClient floatingIpClient = novaClient.getFloatingIPExtensionForZone(id.getZone()).get();
|
||||
for (String ip : floatingIpCache.getUnchecked(id)) {
|
||||
logger.debug(">> removing floatingIp(%s) from node(%s)", ip, id);
|
||||
floatingIpClient.removeFloatingIPFromServer(ip, id.getId());
|
||||
logger.debug(">> deallocating floatingIp(%s)", ip);
|
||||
floatingIpClient.deallocate(ip);
|
||||
}
|
||||
floatingIpCache.invalidate(id);
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Objects.toStringHelper("RemoveFloatingIpFromNodeAndDeallocate").toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,146 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.openstack.nova.v1_1.compute.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.parseGroupFromName;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.compute.domain.ComputeMetadata;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.NodeMetadataBuilder;
|
||||
import org.jclouds.compute.domain.OperatingSystem;
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LocationBuilder;
|
||||
import org.jclouds.domain.LocationScope;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.domain.ServerInZone;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.domain.ZoneAndId;
|
||||
import org.jclouds.openstack.nova.v1_1.domain.Address;
|
||||
import org.jclouds.openstack.nova.v1_1.domain.Server;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* A function for transforming a nova-specific Server into a generic NodeMetadata object.
|
||||
*
|
||||
* @author Matt Stephenson, Adam Lowe, Adrian Cole
|
||||
*/
|
||||
public class ServerInZoneToNodeMetadata implements Function<ServerInZone, NodeMetadata> {
|
||||
@Resource
|
||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
protected final Supplier<Map<String, Location>> locationIndex;
|
||||
protected final LoadingCache<ZoneAndId, Iterable<String>> floatingIpCache;
|
||||
protected final Supplier<Set<? extends Image>> images;
|
||||
protected final Supplier<Set<? extends Hardware>> hardwares;
|
||||
|
||||
@Inject
|
||||
public ServerInZoneToNodeMetadata(Supplier<Map<String, Location>> locationIndex,
|
||||
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> hardwares,
|
||||
@Named("FLOATINGIP") LoadingCache<ZoneAndId, Iterable<String>> floatingIpCache) {
|
||||
this.locationIndex = checkNotNull(locationIndex, "locationIndex");
|
||||
this.floatingIpCache = checkNotNull(floatingIpCache, "cache");
|
||||
this.images = checkNotNull(images, "images");
|
||||
this.hardwares = checkNotNull(hardwares, "hardwares");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeMetadata apply(ServerInZone serverInZone) {
|
||||
Location location = locationIndex.get().get(serverInZone.getZone());
|
||||
checkState(location != null, "location %s not in locationIndex: %s", serverInZone.getZone(), locationIndex.get());
|
||||
Server from = serverInZone.getServer();
|
||||
|
||||
NodeMetadataBuilder builder = new NodeMetadataBuilder();
|
||||
builder.id(serverInZone.slashEncode());
|
||||
builder.providerId(from.getId());
|
||||
builder.name(from.getName());
|
||||
builder.hostname(from.getName());
|
||||
builder.location(new LocationBuilder().scope(LocationScope.HOST).id(from.getHostId()).description(
|
||||
from.getHostId()).parent(location).build());
|
||||
builder.userMetadata(from.getMetadata());
|
||||
builder.group(parseGroupFromName(from.getName()));
|
||||
builder.imageId(ZoneAndId.fromZoneAndId(serverInZone.getZone(), from.getImage().getId()).slashEncode());
|
||||
builder.operatingSystem(findOperatingSystemForServerOrNull(serverInZone));
|
||||
builder.hardware(findHardwareForServerOrNull(serverInZone));
|
||||
builder.state(from.getStatus().getNodeState());
|
||||
builder.publicAddresses(getPublicAddresses(serverInZone));
|
||||
builder.privateAddresses(Iterables.transform(from.getPrivateAddresses(),
|
||||
AddressToStringTransformationFunction.INSTANCE));
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
protected Iterable<String> getPublicAddresses(ServerInZone serverInZone) {
|
||||
return Iterables.concat(Iterables.transform(serverInZone.getServer().getPublicAddresses(),
|
||||
AddressToStringTransformationFunction.INSTANCE), floatingIpCache.getUnchecked(serverInZone));
|
||||
}
|
||||
|
||||
private enum AddressToStringTransformationFunction implements Function<Address, String> {
|
||||
INSTANCE;
|
||||
@Override
|
||||
public String apply(Address address) {
|
||||
return address.getAddr();
|
||||
}
|
||||
}
|
||||
|
||||
protected Hardware findHardwareForServerOrNull(ServerInZone serverInZone) {
|
||||
return findObjectOfTypeForServerOrNull(hardwares.get(), "hardware", serverInZone.getServer().getFlavor().getId(),
|
||||
serverInZone);
|
||||
}
|
||||
|
||||
protected OperatingSystem findOperatingSystemForServerOrNull(ServerInZone serverInZone) {
|
||||
Image image = findObjectOfTypeForServerOrNull(images.get(), "image", serverInZone.getServer().getImage().getId(),
|
||||
serverInZone);
|
||||
return (image != null) ? image.getOperatingSystem() : null;
|
||||
}
|
||||
|
||||
public <T extends ComputeMetadata> T findObjectOfTypeForServerOrNull(Set<? extends T> supply, String type,
|
||||
final String objectId, final ZoneAndId serverInZone) {
|
||||
try {
|
||||
return Iterables.find(supply, new Predicate<T>() {
|
||||
@Override
|
||||
public boolean apply(T input) {
|
||||
return input.getId().equals(ZoneAndId.fromZoneAndId(serverInZone.getZone(), objectId).slashEncode());
|
||||
}
|
||||
});
|
||||
} catch (NoSuchElementException e) {
|
||||
logger.debug("could not find %s with id(%s) for server(%s)", type, objectId, serverInZone);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.openstack.nova.v1_1.compute.functions;
|
||||
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.NodeMetadataBuilder;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.domain.RegionAndName;
|
||||
import org.jclouds.openstack.nova.v1_1.domain.Address;
|
||||
import org.jclouds.openstack.nova.v1_1.domain.Server;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* A function for transforming a nova-specific Server into a generic
|
||||
* NodeMetadata object.
|
||||
*
|
||||
* @author Matt Stephenson
|
||||
*/
|
||||
public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
|
||||
private final LoadingCache<RegionAndName, Iterable<String>> floatingIpCache;
|
||||
|
||||
@Inject
|
||||
public ServerToNodeMetadata(@Named("FLOATINGIP") LoadingCache<RegionAndName, Iterable<String>> floatingIpCache) {
|
||||
this.floatingIpCache = checkNotNull(floatingIpCache, "cache");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeMetadata apply(Server server) {
|
||||
return new NodeMetadataBuilder()
|
||||
// TODO: scope id to region, if there's a chance for conflict
|
||||
// TODO: pass correct region into floatingIpCache request
|
||||
.id(server.getId())
|
||||
.providerId(server.getId())
|
||||
.name(server.getName())
|
||||
.publicAddresses(
|
||||
Iterables.concat(Iterables.transform(server.getPublicAddresses(), new AddressToStringTransformationFunction()),
|
||||
floatingIpCache.getUnchecked(new RegionAndName(null, server.getId()))))
|
||||
.privateAddresses(
|
||||
Iterables.transform(server.getPrivateAddresses(), new AddressToStringTransformationFunction()))
|
||||
.state(server.getStatus().getNodeState()).userMetadata(ImmutableMap.copyOf(server.getMetadata())).build();
|
||||
}
|
||||
|
||||
private class AddressToStringTransformationFunction implements Function<Address, String> {
|
||||
@Override
|
||||
public String apply(Address address) {
|
||||
return address.getAddr();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -22,7 +22,7 @@ import javax.inject.Inject;
|
|||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.openstack.nova.v1_1.NovaClient;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.domain.RegionAndName;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.domain.ZoneAndId;
|
||||
import org.jclouds.openstack.nova.v1_1.domain.FloatingIP;
|
||||
import org.jclouds.openstack.nova.v1_1.extensions.FloatingIPClient;
|
||||
|
||||
|
@ -34,38 +34,38 @@ import com.google.common.collect.ImmutableSet;
|
|||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* Each zone may or may not have the floating ip function present. In order to safely proceed, we
|
||||
* must allow the user to determine if a zone has floating ip services before attempting to use
|
||||
* them.
|
||||
*
|
||||
* @author Adam Lowe
|
||||
*/
|
||||
@Singleton
|
||||
public class LoadFloatingIpsForInstance extends CacheLoader<RegionAndName, Iterable<String>> {
|
||||
public class LoadFloatingIpsForInstance extends CacheLoader<ZoneAndId, Iterable<String>> {
|
||||
private final NovaClient client;
|
||||
// TODO this is unlikely to be required once region support is improved
|
||||
private final Iterable<String> regions;
|
||||
|
||||
|
||||
@Inject
|
||||
public LoadFloatingIpsForInstance(NovaClient client) {
|
||||
this.client = client;
|
||||
this.regions = client.getConfiguredRegions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<String> load(final RegionAndName key) throws Exception {
|
||||
String region = key.getRegion() == null ? regions.iterator().next() : key.getRegion();
|
||||
Optional<FloatingIPClient> ipClientOptional = client.getFloatingIPExtensionForRegion(region);
|
||||
public Iterable<String> load(final ZoneAndId key) throws Exception {
|
||||
String zone = key.getZone();
|
||||
Optional<FloatingIPClient> ipClientOptional = client.getFloatingIPExtensionForZone(zone);
|
||||
if (ipClientOptional.isPresent()) {
|
||||
return Iterables.transform(Iterables.filter(ipClientOptional.get().listFloatingIPs(),
|
||||
new Predicate<FloatingIP>() {
|
||||
@Override
|
||||
public boolean apply(FloatingIP input) {
|
||||
return key.getName().equals(input.getInstanceId());
|
||||
}
|
||||
}),
|
||||
new Function<FloatingIP, String>() {
|
||||
@Override
|
||||
public String apply(FloatingIP input) {
|
||||
return input.getIp();
|
||||
}
|
||||
});
|
||||
new Predicate<FloatingIP>() {
|
||||
@Override
|
||||
public boolean apply(FloatingIP input) {
|
||||
return key.getId().equals(input.getInstanceId());
|
||||
}
|
||||
}), new Function<FloatingIP, String>() {
|
||||
@Override
|
||||
public String apply(FloatingIP input) {
|
||||
return input.getIp();
|
||||
}
|
||||
});
|
||||
}
|
||||
return ImmutableSet.of();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,106 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.openstack.nova.v1_1.compute.strategy;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.compute.config.CustomizationResponse;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.Template;
|
||||
import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
|
||||
import org.jclouds.compute.strategy.CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap;
|
||||
import org.jclouds.compute.strategy.ListNodesStrategy;
|
||||
import org.jclouds.compute.strategy.impl.CreateNodesWithGroupEncodedIntoNameThenAddToSet;
|
||||
import org.jclouds.concurrent.Futures;
|
||||
import org.jclouds.openstack.nova.v1_1.NovaClient;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.functions.AllocateAndAddFloatingIpToNode;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.options.NovaTemplateOptions;
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddToSet extends
|
||||
CreateNodesWithGroupEncodedIntoNameThenAddToSet {
|
||||
|
||||
private final AllocateAndAddFloatingIpToNode allocateAndAddFloatingIpToNode;
|
||||
private final NovaClient novaClient;
|
||||
|
||||
@Inject
|
||||
protected ApplyNovaTemplateOptionsCreateNodesWithGroupEncodedIntoNameThenAddToSet(
|
||||
CreateNodeWithGroupEncodedIntoName addNodeWithTagStrategy,
|
||||
ListNodesStrategy listNodesStrategy,
|
||||
@Named("NAMING_CONVENTION") String nodeNamingConvention,
|
||||
CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory,
|
||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor,
|
||||
AllocateAndAddFloatingIpToNode allocateAndAddFloatingIpToNode, NovaClient novaClient) {
|
||||
super(addNodeWithTagStrategy, listNodesStrategy, nodeNamingConvention, executor,
|
||||
customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory);
|
||||
this.allocateAndAddFloatingIpToNode = checkNotNull(allocateAndAddFloatingIpToNode,
|
||||
"allocateAndAddFloatingIpToNode");
|
||||
this.novaClient = checkNotNull(novaClient, "novaClient");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<?, Future<Void>> execute(String group, int count, Template template, Set<NodeMetadata> goodNodes,
|
||||
Map<NodeMetadata, Exception> badNodes, Multimap<NodeMetadata, CustomizationResponse> customizationResponses) {
|
||||
// TODO: make NovaTemplateOptions with the following:
|
||||
// security group, key pair
|
||||
NovaTemplateOptions templateOptions = NovaTemplateOptions.class.cast(template.getOptions());
|
||||
|
||||
String zone = template.getLocation().getId();
|
||||
|
||||
if (templateOptions.isAutoAssignFloatingIp()) {
|
||||
checkArgument(novaClient.getFloatingIPExtensionForZone(zone).isPresent(),
|
||||
"Floating IP settings are required by configuration, but the extension is not available!");
|
||||
}
|
||||
|
||||
return super.execute(group, count, template, goodNodes, badNodes, customizationResponses);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Future<AtomicReference<NodeMetadata>> createNodeInGroupWithNameAndTemplate(String group,
|
||||
final String name, Template template) {
|
||||
|
||||
Future<AtomicReference<NodeMetadata>> future = super.createNodeInGroupWithNameAndTemplate(group, name, template);
|
||||
NovaTemplateOptions templateOptions = NovaTemplateOptions.class.cast(template.getOptions());
|
||||
|
||||
if (templateOptions.isAutoAssignFloatingIp()) {
|
||||
return Futures.compose(future, allocateAndAddFloatingIpToNode, executor);
|
||||
} else {
|
||||
return future;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -30,6 +30,8 @@ import org.jclouds.http.RequiresHttp;
|
|||
import org.jclouds.http.annotation.ClientError;
|
||||
import org.jclouds.http.annotation.Redirection;
|
||||
import org.jclouds.http.annotation.ServerError;
|
||||
import org.jclouds.location.suppliers.ImplicitLocationSupplier;
|
||||
import org.jclouds.location.suppliers.implicit.OnlyLocationOrFirstZone;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule;
|
||||
import org.jclouds.openstack.nova.v1_1.NovaAsyncClient;
|
||||
import org.jclouds.openstack.nova.v1_1.NovaClient;
|
||||
|
@ -59,6 +61,7 @@ import com.google.common.cache.CacheLoader;
|
|||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Scopes;
|
||||
|
||||
/**
|
||||
* Configures the Nova connection.
|
||||
|
@ -96,18 +99,19 @@ public class NovaRestClientModule extends RestClientModule<NovaClient, NovaAsync
|
|||
// property, so it will have to come from somewhere else, maybe we move
|
||||
// this to the the
|
||||
// ContextBuilder
|
||||
install(new KeystoneAuthenticationModule());
|
||||
install(KeystoneAuthenticationModule.forZones());
|
||||
bind(ImplicitLocationSupplier.class).to(OnlyLocationOrFirstZone.class).in(Scopes.SINGLETON);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public LoadingCache<String, Set<Extension>> provideExtensionsByRegion(final Provider<NovaClient> novaClient) {
|
||||
public LoadingCache<String, Set<Extension>> provideExtensionsByZone(final Provider<NovaClient> novaClient) {
|
||||
return CacheBuilder.newBuilder().expireAfterWrite(23, TimeUnit.HOURS)
|
||||
.build(new CacheLoader<String, Set<Extension>>() {
|
||||
|
||||
@Override
|
||||
public Set<Extension> load(String key) throws Exception {
|
||||
return novaClient.get().getExtensionClientForRegion(key).listExtensions();
|
||||
return novaClient.get().getExtensionClientForZone(key).listExtensions();
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -49,7 +49,7 @@ public enum ServerStatus {
|
|||
|
||||
public static ServerStatus fromValue(String v) {
|
||||
try {
|
||||
return valueOf(v);
|
||||
return valueOf(v.replaceAll("\\(.*",""));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
|
|
|
@ -52,14 +52,13 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
* @see FloatingIPClient
|
||||
* @author Jeremy Daggett
|
||||
* @see ExtensionAsyncClient
|
||||
* @see <a href=
|
||||
* "http://docs.openstack.org/api/openstack-compute/2/content/Extensions-d1e1444.html"
|
||||
* @see <a href= "http://docs.openstack.org/api/openstack-compute/2/content/Extensions-d1e1444.html"
|
||||
* />
|
||||
* @see <a href="http://nova.openstack.org/api_ext" />
|
||||
* @see <a href="http://wiki.openstack.org/os_api_floating_ip"/>
|
||||
*/
|
||||
@Extension(of = ServiceType.COMPUTE, namespace = ExtensionNamespaces.FLOATING_IPS)
|
||||
@SkipEncoding({ '/', '=' })
|
||||
@SkipEncoding( { '/', '=' })
|
||||
@RequestFilters(AuthenticateRequest.class)
|
||||
public interface FloatingIPAsyncClient {
|
||||
|
||||
|
@ -105,23 +104,25 @@ public interface FloatingIPAsyncClient {
|
|||
ListenableFuture<Void> deallocate(@PathParam("id") String id);
|
||||
|
||||
/**
|
||||
* @see FloatingIPClient#addFloatingIP
|
||||
* @see FloatingIPClient#addFloatingIPToServer
|
||||
*/
|
||||
@POST
|
||||
@Path("/servers/{server}/action")
|
||||
@Consumes
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Payload("%7B\"addFloatingIp\":%7B\"address\":\"{address}\"%7D%7D")
|
||||
ListenableFuture<Void> addFloatingIP(@PathParam("server") String serverId, @PayloadParam("address") String address);
|
||||
ListenableFuture<Void> addFloatingIPToServer(@PayloadParam("address") String address,
|
||||
@PathParam("server") String serverId);
|
||||
|
||||
/**
|
||||
* @see FloatingIPClient#removeFloatingIP
|
||||
* @see FloatingIPClient#removeFloatingIPFromServer
|
||||
*/
|
||||
@POST
|
||||
@Path("/servers/{server}/action")
|
||||
@Consumes
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Payload("%7B\"removeFloatingIp\":%7B\"address\":\"{address}\"%7D%7D")
|
||||
ListenableFuture<Void> removeFloatingIP(@PathParam("server") String serverId, @PayloadParam("address") String address);
|
||||
ListenableFuture<Void> removeFloatingIPFromServer(@PayloadParam("address") String address,
|
||||
@PathParam("server") String serverId);
|
||||
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ public interface FloatingIPClient {
|
|||
*
|
||||
* NOTE: Possibly move this to ServerClient?
|
||||
*/
|
||||
void addFloatingIP(String serverId, String address);
|
||||
void addFloatingIPToServer(String address, String serverId);
|
||||
|
||||
/**
|
||||
* Remove a Floating IP address from a Server
|
||||
|
@ -88,5 +88,5 @@ public interface FloatingIPClient {
|
|||
*
|
||||
* NOTE: Possibly move this to ServerClient?
|
||||
*/
|
||||
void removeFloatingIP(String serverId, String address);
|
||||
void removeFloatingIPFromServer(String address, String serverId);
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.jclouds.http.HttpErrorHandler;
|
|||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.HttpResponseException;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.InsufficientResourcesException;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
|
||||
/**
|
||||
|
@ -45,22 +46,25 @@ public class NovaErrorHandler implements HttpErrorHandler {
|
|||
String message = data != null ? new String(data) : null;
|
||||
|
||||
Exception exception = message != null ? new HttpResponseException(command, response, message)
|
||||
: new HttpResponseException(command, response);
|
||||
: new HttpResponseException(command, response);
|
||||
message = message != null ? message : String.format("%s -> %s", command.getCurrentRequest().getRequestLine(),
|
||||
response.getStatusLine());
|
||||
response.getStatusLine());
|
||||
switch (response.getStatusCode()) {
|
||||
case 401:
|
||||
case 403:
|
||||
exception = new AuthorizationException(message, exception);
|
||||
break;
|
||||
case 404:
|
||||
if (!command.getCurrentRequest().getMethod().equals("DELETE")) {
|
||||
exception = new ResourceNotFoundException(message, exception);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
exception = new HttpResponseException(command, response, message);
|
||||
break;
|
||||
case 400:
|
||||
if (message.indexOf("quota exceeded") != -1)
|
||||
exception = new InsufficientResourcesException(message, exception);
|
||||
else if (message.indexOf("has no fixed_ips") != -1)
|
||||
exception = new IllegalStateException(message, exception);
|
||||
break;
|
||||
case 401:
|
||||
case 403:
|
||||
exception = new AuthorizationException(message, exception);
|
||||
break;
|
||||
case 404:
|
||||
if (!command.getCurrentRequest().getMethod().equals("DELETE")) {
|
||||
exception = new ResourceNotFoundException(message, exception);
|
||||
}
|
||||
break;
|
||||
}
|
||||
command.setException(exception);
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.jclouds.http.HttpResponse;
|
|||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.openstack.nova.v1_1.handlers.NovaErrorHandler;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.InsufficientResourcesException;
|
||||
import org.jclouds.rest.ResourceNotFoundException;
|
||||
import org.jclouds.util.Strings2;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -49,29 +50,53 @@ public class NovaErrorHandlerTest {
|
|||
@Test
|
||||
public void test401MakesAuthorizationException() {
|
||||
assertCodeMakes("GET", URI.create("https://api.openstack.nova.com/foo"), 401, "", "Unauthorized",
|
||||
AuthorizationException.class);
|
||||
AuthorizationException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test400MakesIllegalStateExceptionOnQuotaExceededOnNoFixedIps() {
|
||||
// should wait until ips are associated w/the server
|
||||
assertCodeMakes(
|
||||
"POST",
|
||||
URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/37936628937291/servers/71554/action"),
|
||||
400,
|
||||
"HTTP/1.1 400 Bad Request",
|
||||
"{\"badRequest\": {\"message\": \"instance |71554| has no fixed_ips. unable to associate floating ip\", \"code\": 400}}",
|
||||
IllegalStateException.class);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void test400MakesInsufficientResourcesExceptionOnQuotaExceeded() {
|
||||
assertCodeMakes(
|
||||
"POST",
|
||||
URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/37936628937291/os-floating-ips"),
|
||||
400,
|
||||
"HTTP/1.1 400 Bad Request",
|
||||
"{\"badRequest\": {\"message\": \"AddressLimitExceeded: Address quota exceeded. You cannot allocate any more addresses\", \"code\": 400}}",
|
||||
InsufficientResourcesException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test404MakesResourceNotFoundException() {
|
||||
assertCodeMakes("GET", URI.create("https://api.openstack.nova.com/foo"), 404, "", "Not Found",
|
||||
ResourceNotFoundException.class);
|
||||
ResourceNotFoundException.class);
|
||||
}
|
||||
|
||||
private void assertCodeMakes(String method, URI uri, int statusCode, String message, String content,
|
||||
Class<? extends Exception> expected) {
|
||||
assertCodeMakes(method, uri, statusCode, message, "text/xml", content, expected);
|
||||
Class<? extends Exception> expected) {
|
||||
assertCodeMakes(method, uri, statusCode, message, "text/json", content, expected);
|
||||
}
|
||||
|
||||
private void assertCodeMakes(String method, URI uri, int statusCode, String message, String contentType,
|
||||
String content, Class<? extends Exception> expected) {
|
||||
String content, Class<? extends Exception> expected) {
|
||||
|
||||
NovaErrorHandler function = Guice.createInjector().getInstance(NovaErrorHandler.class);
|
||||
|
||||
HttpCommand command = createMock(HttpCommand.class);
|
||||
HttpRequest request = new HttpRequest(method, uri);
|
||||
HttpResponse response = new HttpResponse(statusCode, message, Payloads.newInputStreamPayload(Strings2
|
||||
.toInputStream(content)));
|
||||
.toInputStream(content)));
|
||||
response.getPayload().getContentMetadata().setContentType(contentType);
|
||||
|
||||
expect(command.getCurrentRequest()).andReturn(request).atLeastOnce();
|
||||
|
|
|
@ -66,9 +66,9 @@ public class PasswordAuthenticationExpectTest extends BaseNovaClientExpectTest {
|
|||
NovaClient clientWhenServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPassword,
|
||||
responseWithKeystoneAccess, listServers, listServersResponse);
|
||||
|
||||
assertEquals(clientWhenServersExist.getConfiguredRegions(), ImmutableSet.of("North"));
|
||||
assertEquals(clientWhenServersExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1"));
|
||||
|
||||
assertEquals(clientWhenServersExist.getServerClientForRegion("North").listServers().toString(),
|
||||
assertEquals(clientWhenServersExist.getServerClientForZone("az-1.region-a.geo-1").listServers().toString(),
|
||||
new ParseServerListTest().expected().toString());
|
||||
}
|
||||
|
||||
|
|
|
@ -24,9 +24,11 @@ import static org.testng.Assert.assertTrue;
|
|||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.jclouds.compute.ComputeService;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.openstack.nova.v1_1.internal.BaseNovaComputeServiceExpectTest;
|
||||
|
@ -36,76 +38,75 @@ import com.google.common.collect.ImmutableMultimap;
|
|||
|
||||
/**
|
||||
* Tests the compute service abstraction of the nova client.
|
||||
*
|
||||
*
|
||||
* @author Matt Stephenson
|
||||
*/
|
||||
@Test(groups = "unit", testName = "NovaComputeServiceExpectTest")
|
||||
public class NovaComputeServiceExpectTest extends BaseNovaComputeServiceExpectTest {
|
||||
|
||||
public void testListServersWhenResponseIs2xx() throws Exception {
|
||||
HttpRequest getExtensions = HttpRequest
|
||||
.builder()
|
||||
.method("GET")
|
||||
.endpoint(URI.create("https://compute.north.host/v1.1/3456/extensions"))
|
||||
.headers(
|
||||
ImmutableMultimap.<String, String>builder().put("Accept", "application/json")
|
||||
.put("X-Auth-Token", authToken).build()).build();
|
||||
HttpRequest listFloatingIps = HttpRequest
|
||||
.builder()
|
||||
.method("GET")
|
||||
.endpoint(URI.create("https://compute.north.host/v1.1/3456/os-floating-ips"))
|
||||
.headers(
|
||||
ImmutableMultimap.<String, String>builder().put("Accept", "application/json")
|
||||
.put("X-Auth-Token", authToken).build()).build();
|
||||
HttpRequest listServers = HttpRequest
|
||||
.builder()
|
||||
.method("GET")
|
||||
.endpoint(URI.create("https://compute.north.host/v1.1/3456/servers/detail"))
|
||||
.headers(
|
||||
ImmutableMultimap.<String, String>builder().put("Accept", "application/json")
|
||||
.put("X-Auth-Token", authToken).build()).build();
|
||||
HttpRequest listImagesDetail = HttpRequest.builder().method("GET").endpoint(
|
||||
URI.create("https://compute.north.host/v1.1/3456/images/detail")).headers(
|
||||
ImmutableMultimap.<String, String> builder().put("Accept", "application/json").put("X-Auth-Token",
|
||||
authToken).build()).build();
|
||||
|
||||
HttpResponse listImagesDetailResponse = HttpResponse.builder().statusCode(200).payload(
|
||||
payloadFromResource("/image_list_detail.json")).build();
|
||||
|
||||
HttpResponse getExtensionsResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResource("/extension_list_normal.json")).build();
|
||||
|
||||
HttpResponse listFloatingIpsResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResource("/floatingip_list.json")).build();
|
||||
HttpRequest listFlavorsDetail = HttpRequest.builder().method("GET").endpoint(
|
||||
URI.create("https://compute.north.host/v1.1/3456/flavors/detail")).headers(
|
||||
ImmutableMultimap.<String, String> builder().put("Accept", "application/json").put("X-Auth-Token",
|
||||
authToken).build()).build();
|
||||
|
||||
HttpResponse listServersResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResource("/server_list_details.json")).build();
|
||||
HttpResponse listFlavorsDetailResponse = HttpResponse.builder().statusCode(200).payload(
|
||||
payloadFromResource("/flavor_list_detail.json")).build();
|
||||
|
||||
Map<HttpRequest, HttpResponse> requestResponseMap = ImmutableMap.of(
|
||||
keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess,
|
||||
listFloatingIps, listFloatingIpsResponse,
|
||||
getExtensions, getExtensionsResponse,
|
||||
listServers, listServersResponse);
|
||||
HttpRequest listFloatingIps = HttpRequest.builder().method("GET").endpoint(
|
||||
URI.create("https://compute.north.host/v1.1/3456/os-floating-ips")).headers(
|
||||
ImmutableMultimap.<String, String> builder().put("Accept", "application/json").put("X-Auth-Token",
|
||||
authToken).build()).build();
|
||||
|
||||
HttpResponse listFloatingIpsResponse = HttpResponse.builder().statusCode(200).payload(
|
||||
payloadFromResource("/floatingip_list.json")).build();
|
||||
|
||||
HttpRequest listServers = HttpRequest.builder().method("GET").endpoint(
|
||||
URI.create("https://compute.north.host/v1.1/3456/servers/detail")).headers(
|
||||
ImmutableMultimap.<String, String> builder().put("Accept", "application/json").put("X-Auth-Token",
|
||||
authToken).build()).build();
|
||||
|
||||
HttpResponse listServersResponse = HttpResponse.builder().statusCode(200).payload(
|
||||
payloadFromResource("/server_list_details.json")).build();
|
||||
|
||||
Map<HttpRequest, HttpResponse> requestResponseMap = ImmutableMap.<HttpRequest, HttpResponse> builder().put(
|
||||
keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess).put(extensionsOfNovaRequest,
|
||||
extensionsOfNovaResponse).put(listFloatingIps, listFloatingIpsResponse).put(listServers,
|
||||
listServersResponse).put(listImagesDetail, listImagesDetailResponse).put(listFlavorsDetail,
|
||||
listFlavorsDetailResponse).build();
|
||||
|
||||
ComputeService clientWhenServersExist = requestsSendResponses(requestResponseMap);
|
||||
|
||||
assertNotNull(clientWhenServersExist.listAssignableLocations());
|
||||
assertEquals(clientWhenServersExist.listAssignableLocations().size(), 1);
|
||||
assertEquals(clientWhenServersExist.listAssignableLocations().iterator().next().getId(), "North");
|
||||
Set<? extends Location> locations = clientWhenServersExist.listAssignableLocations();
|
||||
assertNotNull(locations);
|
||||
assertEquals(locations.size(), 1);
|
||||
assertEquals(locations.iterator().next().getId(), "az-1.region-a.geo-1");
|
||||
|
||||
assertNotNull(clientWhenServersExist.listNodes());
|
||||
assertEquals(clientWhenServersExist.listNodes().size(), 1);
|
||||
assertEquals(clientWhenServersExist.listNodes().iterator().next().getId(), "52415800-8b69-11e0-9b19-734f000004d2");
|
||||
assertEquals(clientWhenServersExist.listNodes().iterator().next().getId(),
|
||||
"az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f000004d2");
|
||||
assertEquals(clientWhenServersExist.listNodes().iterator().next().getName(), "sample-server");
|
||||
}
|
||||
|
||||
public void testListServersWhenReponseIs404IsEmpty() throws Exception {
|
||||
HttpRequest listServers = HttpRequest
|
||||
.builder()
|
||||
.method("GET")
|
||||
.endpoint(URI.create("https://compute.north.host/v1.1/3456/servers/detail"))
|
||||
.headers(
|
||||
ImmutableMultimap.<String, String>builder().put("Accept", "application/json")
|
||||
.put("X-Auth-Token", authToken).build()).build();
|
||||
HttpRequest listServers = HttpRequest.builder().method("GET").endpoint(
|
||||
URI.create("https://compute.north.host/v1.1/3456/servers/detail")).headers(
|
||||
ImmutableMultimap.<String, String> builder().put("Accept", "application/json").put("X-Auth-Token",
|
||||
authToken).build()).build();
|
||||
|
||||
HttpResponse listServersResponse = HttpResponse.builder().statusCode(404).build();
|
||||
|
||||
ComputeService clientWhenNoServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
|
||||
responseWithKeystoneAccess, listServers, listServersResponse);
|
||||
responseWithKeystoneAccess, listServers, listServersResponse);
|
||||
|
||||
assertTrue(clientWhenNoServersExist.listNodes().isEmpty());
|
||||
}
|
||||
|
|
|
@ -0,0 +1,132 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.openstack.nova.v1_1.compute.functions;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.NodeMetadataBuilder;
|
||||
import org.jclouds.compute.domain.NodeState;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LocationBuilder;
|
||||
import org.jclouds.domain.LocationScope;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.openstack.nova.v1_1.internal.BaseNovaComputeServiceExpectTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* Tests the compute service abstraction of the nova client.
|
||||
*
|
||||
* @author Matt Stephenson
|
||||
*/
|
||||
@Test(groups = "unit", testName = "AllocateAndAddFloatingIpToNodeTest")
|
||||
public class AllocateAndAddFloatingIpToNodeTest extends BaseNovaComputeServiceExpectTest {
|
||||
final Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id("openstack-nova").description(
|
||||
"openstack-nova").build();
|
||||
final Location zone = new LocationBuilder().id("az-1.region-a.geo-1").description("az-1.region-a.geo-1").scope(
|
||||
LocationScope.ZONE).parent(provider).build();
|
||||
final Location host = new LocationBuilder().scope(LocationScope.HOST).id("hostId").description("hostId")
|
||||
.parent(zone).build();
|
||||
final NodeMetadata node = new NodeMetadataBuilder().id("az-1.region-a.geo-1/71592").providerId("71592").location(
|
||||
host).name("Server 71592").state(NodeState.RUNNING).privateAddresses(ImmutableSet.of("10.4.27.237"))
|
||||
.build();
|
||||
|
||||
HttpRequest allocateFloatingIP = HttpRequest.builder().method("POST").endpoint(
|
||||
URI.create("https://compute.north.host/v1.1/3456/os-floating-ips")).headers(
|
||||
ImmutableMultimap.<String, String> builder().put("Accept", "application/json").put("X-Auth-Token",
|
||||
authToken).build()).payload(payloadFromStringWithContentType("{}", "application/json")).build();
|
||||
|
||||
HttpResponse addFloatingIPResponse = HttpResponse.builder().statusCode(200).build();
|
||||
|
||||
public void testAllocateWhenAllocationReturnsIpIsAddedToServerAndUpdatesNodeMetadata() throws Exception {
|
||||
HttpResponse allocateFloatingIPResponse = HttpResponse.builder().statusCode(200).payload(
|
||||
payloadFromResource("/floatingip_details.json")).build();
|
||||
|
||||
HttpRequest addFloatingIPRequest = addFloatingIPForAddress("10.0.0.3");
|
||||
|
||||
AllocateAndAddFloatingIpToNode fn = requestsSendResponses(
|
||||
ImmutableMap.<HttpRequest, HttpResponse> builder().put(keystoneAuthWithAccessKeyAndSecretKey,
|
||||
responseWithKeystoneAccess).put(extensionsOfNovaRequest, extensionsOfNovaResponse).put(
|
||||
allocateFloatingIP, allocateFloatingIPResponse)
|
||||
.put(addFloatingIPRequest, addFloatingIPResponse).build()).getContext().utils().injector()
|
||||
.getInstance(AllocateAndAddFloatingIpToNode.class);
|
||||
|
||||
AtomicReference<NodeMetadata> nodeRef = new AtomicReference<NodeMetadata>(node);
|
||||
fn.apply(nodeRef);
|
||||
NodeMetadata node1 = nodeRef.get();
|
||||
assertNotNull(node1);
|
||||
assertEquals(node1.getPublicAddresses(), ImmutableSet.of("10.0.0.3"));
|
||||
|
||||
}
|
||||
|
||||
private HttpRequest addFloatingIPForAddress(String address) {
|
||||
HttpRequest addFloatingIPRequest = HttpRequest.builder().method("POST").endpoint(
|
||||
URI.create("https://compute.north.host/v1.1/3456/servers/71592/action"))
|
||||
.headers(
|
||||
ImmutableMultimap.<String, String> builder().put("Accept", "*/*")
|
||||
.put("X-Auth-Token", authToken).build()).payload(
|
||||
payloadFromStringWithContentType("{\"addFloatingIp\":{\"address\":\"" + address + "\"}}",
|
||||
"application/json")).build();
|
||||
return addFloatingIPRequest;
|
||||
}
|
||||
|
||||
public void testAllocateWhenAllocationFailsLookupUnusedIpAddToServerAndUpdatesNodeMetadata() throws Exception {
|
||||
HttpResponse allocateFloatingIPResponse = HttpResponse
|
||||
.builder()
|
||||
.statusCode(400)
|
||||
.payload(
|
||||
payloadFromStringWithContentType(
|
||||
"{\"badRequest\": {\"message\": \"AddressLimitExceeded: Address quota exceeded. You cannot allocate any more addresses\", \"code\": 400}}",
|
||||
"application/json")).build();
|
||||
|
||||
HttpRequest listFloatingIPs = HttpRequest.builder().method("GET").endpoint(
|
||||
URI.create("https://compute.north.host/v1.1/3456/os-floating-ips")).headers(
|
||||
ImmutableMultimap.<String, String> builder().put("Accept", "application/json").put("X-Auth-Token",
|
||||
authToken).build()).build();
|
||||
|
||||
HttpResponse listFloatingIPsResponseForUnassigned = HttpResponse.builder().statusCode(200).payload(
|
||||
payloadFromResource("/floatingip_list.json")).build();
|
||||
|
||||
HttpRequest addFloatingIPRequest = addFloatingIPForAddress("10.0.0.5");
|
||||
|
||||
AllocateAndAddFloatingIpToNode fn = requestsSendResponses(
|
||||
ImmutableMap.<HttpRequest, HttpResponse> builder().put(keystoneAuthWithAccessKeyAndSecretKey,
|
||||
responseWithKeystoneAccess).put(extensionsOfNovaRequest, extensionsOfNovaResponse).put(
|
||||
allocateFloatingIP, allocateFloatingIPResponse)
|
||||
.put(addFloatingIPRequest, addFloatingIPResponse).put(listFloatingIPs,
|
||||
listFloatingIPsResponseForUnassigned).build()).getContext().utils().injector()
|
||||
.getInstance(AllocateAndAddFloatingIpToNode.class);
|
||||
|
||||
AtomicReference<NodeMetadata> nodeRef = new AtomicReference<NodeMetadata>(node);
|
||||
fn.apply(nodeRef);
|
||||
NodeMetadata node1 = nodeRef.get();
|
||||
assertNotNull(node1);
|
||||
assertEquals(node1.getPublicAddresses(), ImmutableSet.of("10.0.0.5"));
|
||||
|
||||
}
|
||||
}
|
|
@ -22,32 +22,51 @@ import static org.testng.Assert.assertEquals;
|
|||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LocationBuilder;
|
||||
import org.jclouds.domain.LocationScope;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.domain.FlavorInZone;
|
||||
import org.jclouds.openstack.nova.v1_1.domain.Flavor;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
/**
|
||||
* Tests the function used to transform Flavor objects into Hardware objects
|
||||
*
|
||||
* @author Matt Stephenson
|
||||
* @author Matt Stephenson, Adrian Cole
|
||||
*/
|
||||
public class FlavorToHardwareTest {
|
||||
@Test(testName = "FlavorInZoneToHardwareTest")
|
||||
public class FlavorInZoneToHardwareTest {
|
||||
Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id("openstack-nova").description(
|
||||
"openstack-nova").build();
|
||||
Location zone = new LocationBuilder().id("az-1.region-a.geo-1").description("az-1.region-a.geo-1").scope(
|
||||
LocationScope.ZONE).parent(provider).build();
|
||||
Supplier<Map<String, Location>> locationIndex = Suppliers.<Map<String, Location>> ofInstance(ImmutableMap
|
||||
.<String, Location> of("az-1.region-a.geo-1", zone));
|
||||
|
||||
@Test
|
||||
public void testConversion() {
|
||||
public void testConversionWhereLocationFound() {
|
||||
|
||||
UUID id = UUID.randomUUID();
|
||||
Flavor flavorToConvert = Flavor.builder().id(id.toString()).name("Test Flavor " + id).ram(262144).disk(10000)
|
||||
.vcpus(16).build();
|
||||
|
||||
Hardware converted = new FlavorToHardware(Suppliers.<Location> ofInstance(null)).apply(flavorToConvert);
|
||||
FlavorInZone flavorInZoneToConvert = new FlavorInZone(Flavor.builder().id(id.toString())
|
||||
.name("Test Flavor " + id).ram(262144).disk(10000).vcpus(16).build(), "az-1.region-a.geo-1");
|
||||
|
||||
Hardware converted = new FlavorInZoneToHardware(locationIndex).apply(flavorInZoneToConvert);
|
||||
|
||||
Flavor flavorToConvert = flavorInZoneToConvert.getFlavor();
|
||||
assertEquals(converted.getName(), flavorToConvert.getName());
|
||||
assertEquals(converted.getId(), flavorToConvert.getId());
|
||||
assertEquals(converted.getId(), flavorInZoneToConvert.slashEncode());
|
||||
assertEquals(converted.getProviderId(), flavorToConvert.getId());
|
||||
assertEquals(converted.getLocation(), locationIndex.get().get("az-1.region-a.geo-1"));
|
||||
|
||||
assertEquals(converted.getRam(), flavorToConvert.getRam());
|
||||
|
||||
assertNotNull(converted.getProcessors());
|
||||
|
@ -59,4 +78,15 @@ public class FlavorToHardwareTest {
|
|||
assertEquals(converted.getVolumes().iterator().next().getSize(), Float.valueOf(flavorToConvert.getDisk()));
|
||||
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalStateException.class)
|
||||
public void testConversionWhereLocationNotFound() {
|
||||
|
||||
UUID id = UUID.randomUUID();
|
||||
|
||||
FlavorInZone flavorInZoneToConvert = new FlavorInZone(Flavor.builder().id(id.toString())
|
||||
.name("Test Flavor " + id).ram(262144).disk(10000).vcpus(16).build(), "South");
|
||||
new FlavorInZoneToHardware(locationIndex).apply(flavorInZoneToConvert);
|
||||
}
|
||||
|
||||
}
|
|
@ -20,6 +20,7 @@ package org.jclouds.openstack.nova.v1_1.compute.functions;
|
|||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -27,35 +28,65 @@ import javax.annotation.Nullable;
|
|||
import org.jclouds.compute.domain.OperatingSystem;
|
||||
import org.jclouds.compute.domain.OsFamily;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LocationBuilder;
|
||||
import org.jclouds.domain.LocationScope;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.domain.ImageInZone;
|
||||
import org.jclouds.openstack.nova.v1_1.domain.Image;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
/**
|
||||
* Tests the function that transforms nova-specific images to generic images.
|
||||
*
|
||||
* @author Matt Stephenson
|
||||
* @author Matt Stephenson, Adrian Cole
|
||||
*/
|
||||
public class NovaImageToImageTest {
|
||||
@Test(testName = "ImageInZoneToHardwareTest")
|
||||
public class ImageInZoneToImageTest {
|
||||
|
||||
Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id("openstack-nova").description(
|
||||
"openstack-nova").build();
|
||||
Location zone = new LocationBuilder().id("az-1.region-a.geo-1").description("az-1.region-a.geo-1").scope(
|
||||
LocationScope.ZONE).parent(provider).build();
|
||||
Supplier<Map<String, Location>> locationIndex = Suppliers.<Map<String, Location>> ofInstance(ImmutableMap
|
||||
.<String, Location> of("az-1.region-a.geo-1", zone));
|
||||
|
||||
@Test
|
||||
public void testConversion() {
|
||||
public void testConversionWhereLocationFound() {
|
||||
UUID id = UUID.randomUUID();
|
||||
Image novaImageToConvert = Image.builder().id(id.toString()).name("Test Image " + id).build();
|
||||
OperatingSystem operatingSystem = new OperatingSystem(OsFamily.UBUNTU, "My Test OS", "My Test Version", "x86",
|
||||
"My Test OS", true);
|
||||
NovaImageToImage converter = new NovaImageToImage(new MockImageToOsConverter(operatingSystem),
|
||||
Suppliers.<Location> ofInstance(null));
|
||||
org.jclouds.compute.domain.Image convertedImage = converter.apply(novaImageToConvert);
|
||||
"My Test OS", true);
|
||||
ImageInZoneToImage converter = new ImageInZoneToImage(new MockImageToOsConverter(operatingSystem), locationIndex);
|
||||
|
||||
assertEquals(convertedImage.getId(), novaImageToConvert.getId());
|
||||
ImageInZone novaImageInZoneToConvert = new ImageInZone(novaImageToConvert, "az-1.region-a.geo-1");
|
||||
|
||||
org.jclouds.compute.domain.Image convertedImage = converter.apply(novaImageInZoneToConvert);
|
||||
|
||||
assertEquals(convertedImage.getId(), novaImageInZoneToConvert.slashEncode());
|
||||
assertEquals(convertedImage.getProviderId(), novaImageToConvert.getId());
|
||||
assertEquals(convertedImage.getLocation(), locationIndex.get().get("az-1.region-a.geo-1"));
|
||||
|
||||
assertEquals(convertedImage.getName(), novaImageToConvert.getName());
|
||||
assertEquals(convertedImage.getOperatingSystem(), operatingSystem);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = IllegalStateException.class)
|
||||
public void testConversionWhereLocationNotFound() {
|
||||
UUID id = UUID.randomUUID();
|
||||
Image novaImageToConvert = Image.builder().id(id.toString()).name("Test Image " + id).build();
|
||||
OperatingSystem operatingSystem = new OperatingSystem(OsFamily.UBUNTU, "My Test OS", "My Test Version", "x86",
|
||||
"My Test OS", true);
|
||||
ImageInZoneToImage converter = new ImageInZoneToImage(new MockImageToOsConverter(operatingSystem), locationIndex);
|
||||
|
||||
ImageInZone novaImageInZoneToConvert = new ImageInZone(novaImageToConvert, "South");
|
||||
|
||||
converter.apply(novaImageInZoneToConvert);
|
||||
}
|
||||
|
||||
private class MockImageToOsConverter implements Function<Image, OperatingSystem> {
|
||||
|
||||
private final OperatingSystem operatingSystem;
|
|
@ -0,0 +1,145 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.openstack.nova.v1_1.compute.functions;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.easymock.classextension.EasyMock;
|
||||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.domain.HardwareBuilder;
|
||||
import org.jclouds.compute.domain.Image;
|
||||
import org.jclouds.compute.domain.ImageBuilder;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.OperatingSystem;
|
||||
import org.jclouds.compute.domain.OsFamily;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.domain.LocationBuilder;
|
||||
import org.jclouds.domain.LocationScope;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.domain.ServerInZone;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.domain.ZoneAndId;
|
||||
import org.jclouds.openstack.nova.v1_1.domain.Server;
|
||||
import org.jclouds.openstack.nova.v1_1.parse.ParseServerTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* Tests for the function for transforming a nova specific Server into a generic NodeMetadata
|
||||
* object.
|
||||
*
|
||||
* @author Matt Stephenson, Adam Lowe, Adrian Cole
|
||||
*/
|
||||
@Test(testName = "ServerInZoneToNodeMetadataTest")
|
||||
public class ServerInZoneToNodeMetadataTest {
|
||||
|
||||
Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id("openstack-nova").description(
|
||||
"openstack-nova").build();
|
||||
Location zone = new LocationBuilder().id("az-1.region-a.geo-1").description("az-1.region-a.geo-1").scope(
|
||||
LocationScope.ZONE).parent(provider).build();
|
||||
Supplier<Map<String, Location>> locationIndex = Suppliers.<Map<String, Location>> ofInstance(ImmutableMap
|
||||
.<String, Location> of("az-1.region-a.geo-1", zone));
|
||||
|
||||
@Test
|
||||
public void testWhenNoHardwareOrImageMatchServerScopedIdsImageIdIsStillSet() {
|
||||
|
||||
Hardware existingHardware = new HardwareBuilder().id("az-1.region-a.geo-1/FOOOOOOOO").providerId("FOOOOOOOO")
|
||||
.location(zone).build();
|
||||
Image existingImage = new ImageBuilder().id("az-1.region-a.geo-1/FOOOOOOOO").operatingSystem(
|
||||
OperatingSystem.builder().family(OsFamily.LINUX).description("foobuntu").build())
|
||||
.providerId("FOOOOOOOO").description("foobuntu").location(zone).build();
|
||||
|
||||
checkHardwareAndImageStatus(null, existingHardware, "az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f6f006e54",
|
||||
null, existingImage);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhenNoHardwareAndImageMatchServerScopedIdsHardwareOperatingSystemAndImageIdAreSet() {
|
||||
|
||||
Hardware existingHardware = new HardwareBuilder().id("az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f216543fd")
|
||||
.providerId("52415800-8b69-11e0-9b19-734f216543fd").location(zone).build();
|
||||
Image existingImage = new ImageBuilder().id("az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f6f006e54")
|
||||
.operatingSystem(OperatingSystem.builder().family(OsFamily.LINUX).description("foobuntu").build())
|
||||
.providerId("52415800-8b69-11e0-9b19-734f6f006e54").description("foobuntu").location(zone).build();
|
||||
|
||||
checkHardwareAndImageStatus(existingHardware, existingHardware, existingImage.getId(), existingImage
|
||||
.getOperatingSystem(), existingImage);
|
||||
}
|
||||
|
||||
// TODO: clean up this syntax
|
||||
@SuppressWarnings("unchecked")
|
||||
private void checkHardwareAndImageStatus(Hardware expectedHardware, Hardware existingHardware,
|
||||
String expectedImageId, OperatingSystem expectedOs, Image existingImage) {
|
||||
|
||||
Set<Image> images = existingImage == null ? ImmutableSet.<Image> of() : ImmutableSet.of(existingImage);
|
||||
Set<Hardware> hardwares = existingHardware == null ? ImmutableSet.<Hardware> of() : ImmutableSet
|
||||
.of(existingHardware);
|
||||
Server serverToConvert = new ParseServerTest().expected();
|
||||
|
||||
ServerInZone serverInZoneToConvert = new ServerInZone(serverToConvert, "az-1.region-a.geo-1");
|
||||
|
||||
LoadingCache<ZoneAndId, Iterable<String>> mockLoadingCache = EasyMock.createMock(LoadingCache.class);
|
||||
EasyMock.expect(mockLoadingCache.getUnchecked(serverInZoneToConvert)).andReturn(ImmutableSet.<String> of());
|
||||
EasyMock.replay(mockLoadingCache);
|
||||
|
||||
ServerInZoneToNodeMetadata converter = new ServerInZoneToNodeMetadata(locationIndex, Suppliers
|
||||
.<Set<? extends Image>> ofInstance(images), Suppliers.<Set<? extends Hardware>> ofInstance(hardwares),
|
||||
mockLoadingCache);
|
||||
|
||||
NodeMetadata convertedNodeMetadata = converter.apply(serverInZoneToConvert);
|
||||
|
||||
assertEquals(serverInZoneToConvert.slashEncode(), convertedNodeMetadata.getId());
|
||||
assertEquals(serverToConvert.getId(), convertedNodeMetadata.getProviderId());
|
||||
|
||||
assertEquals(convertedNodeMetadata.getLocation().getScope(), LocationScope.HOST);
|
||||
assertEquals(convertedNodeMetadata.getLocation().getId(), "e4d909c290d0fb1ca068ffaddf22cbd0");
|
||||
|
||||
assertEquals(convertedNodeMetadata.getLocation().getParent(), locationIndex.get().get("az-1.region-a.geo-1"));
|
||||
|
||||
assertEquals(serverToConvert.getName(), convertedNodeMetadata.getName());
|
||||
assertEquals(convertedNodeMetadata.getGroup(), "sample");
|
||||
|
||||
assertEquals(convertedNodeMetadata.getImageId(), expectedImageId);
|
||||
assertEquals(convertedNodeMetadata.getOperatingSystem(), expectedOs);
|
||||
|
||||
assertEquals(convertedNodeMetadata.getHardware(), expectedHardware);
|
||||
|
||||
assertEquals(serverToConvert.getStatus().getNodeState(), convertedNodeMetadata.getState());
|
||||
|
||||
assertNotNull(convertedNodeMetadata.getPrivateAddresses());
|
||||
assertEquals(convertedNodeMetadata.getPrivateAddresses(), ImmutableSet.of("10.176.42.16"));
|
||||
|
||||
assertNotNull(convertedNodeMetadata.getPublicAddresses());
|
||||
assertEquals(convertedNodeMetadata.getPublicAddresses(), ImmutableSet.of("67.23.10.132", "::babe:67.23.10.132",
|
||||
"67.23.10.131", "::babe:4317:0A83", "::babe:10.176.42.16"));
|
||||
|
||||
assertNotNull(convertedNodeMetadata.getUserMetadata());
|
||||
assertEquals(convertedNodeMetadata.getUserMetadata(), ImmutableMap.<String, String> of("Server Label",
|
||||
"Web Head 1", "Image Version", "2.1"));
|
||||
|
||||
EasyMock.verify(mockLoadingCache);
|
||||
}
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.openstack.nova.v1_1.compute.functions;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.easymock.EasyMock;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.domain.RegionAndName;
|
||||
import org.jclouds.openstack.nova.v1_1.domain.Address;
|
||||
import org.jclouds.openstack.nova.v1_1.domain.Server;
|
||||
import org.jclouds.openstack.nova.v1_1.domain.ServerStatus;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
/**
|
||||
* Tests for the function for transforming a nova specific Server into a generic
|
||||
* NodeMetadata object.
|
||||
*
|
||||
* @author Matt Stephenson
|
||||
*/
|
||||
public class ServerToNodeMetadataTest {
|
||||
@Test
|
||||
public void testConversion() {
|
||||
UUID id = UUID.randomUUID();
|
||||
Server serverToConvert = Server.builder().id(id.toString()).name("Test Server " + id)
|
||||
.privateAddresses(Address.createV4("10.0.0.1")).publicAddresses(Address.createV4("1.0.1.1"))
|
||||
.status(ServerStatus.ACTIVE).metadata(ImmutableMap.of("test", "testing")).build();
|
||||
|
||||
LoadingCache<RegionAndName, Iterable<String>> mockLoadingCache = EasyMock.createMock(LoadingCache.class);
|
||||
EasyMock.expect(mockLoadingCache.getUnchecked(new RegionAndName(null, id.toString()))).andReturn(ImmutableSet.<String>of());
|
||||
EasyMock.replay(mockLoadingCache);
|
||||
|
||||
ServerToNodeMetadata converter = new ServerToNodeMetadata(mockLoadingCache);
|
||||
NodeMetadata convertedNodeMetadata = converter.apply(serverToConvert);
|
||||
|
||||
assertEquals(serverToConvert.getId(), convertedNodeMetadata.getId());
|
||||
assertEquals(serverToConvert.getId(), convertedNodeMetadata.getProviderId());
|
||||
assertEquals(serverToConvert.getName(), convertedNodeMetadata.getName());
|
||||
assertEquals(serverToConvert.getStatus().getNodeState(), convertedNodeMetadata.getState());
|
||||
|
||||
assertNotNull(convertedNodeMetadata.getPrivateAddresses());
|
||||
assertEquals(convertedNodeMetadata.getPrivateAddresses().size(), 1);
|
||||
assertEquals(convertedNodeMetadata.getPrivateAddresses().iterator().next(), "10.0.0.1");
|
||||
|
||||
assertNotNull(convertedNodeMetadata.getPublicAddresses());
|
||||
assertEquals(convertedNodeMetadata.getPublicAddresses().size(), 1);
|
||||
assertEquals(convertedNodeMetadata.getPublicAddresses().iterator().next(), "1.0.1.1");
|
||||
|
||||
assertNotNull(convertedNodeMetadata.getUserMetadata());
|
||||
assertEquals(convertedNodeMetadata.getUserMetadata().size(), 1);
|
||||
assertEquals(convertedNodeMetadata.getUserMetadata().get("test"), "testing");
|
||||
|
||||
EasyMock.verify(mockLoadingCache);
|
||||
}
|
||||
}
|
|
@ -26,7 +26,7 @@ import static org.testng.Assert.assertEquals;
|
|||
import static org.testng.AssertJUnit.assertFalse;
|
||||
|
||||
import org.jclouds.openstack.nova.v1_1.NovaClient;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.domain.RegionAndName;
|
||||
import org.jclouds.openstack.nova.v1_1.compute.domain.ZoneAndId;
|
||||
import org.jclouds.openstack.nova.v1_1.domain.FloatingIP;
|
||||
import org.jclouds.openstack.nova.v1_1.extensions.FloatingIPClient;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -45,8 +45,7 @@ public class LoadFloatingIpsForInstanceTest {
|
|||
NovaClient client = createMock(NovaClient.class);
|
||||
FloatingIPClient ipClient = createMock(FloatingIPClient.class);
|
||||
|
||||
expect(client.getConfiguredRegions()).andReturn(ImmutableSet.of("region")).atLeastOnce();
|
||||
expect(client.getFloatingIPExtensionForRegion("region")).andReturn(Optional.of(ipClient)).atLeastOnce();
|
||||
expect(client.getFloatingIPExtensionForZone("Zone")).andReturn(Optional.of(ipClient)).atLeastOnce();
|
||||
expect(ipClient.listFloatingIPs()).andReturn(
|
||||
ImmutableSet.<FloatingIP>of(FloatingIP.builder().id("1").ip("1.1.1.1").fixedIp("10.1.1.1").instanceId("i-blah").build()))
|
||||
.atLeastOnce();
|
||||
|
@ -56,7 +55,7 @@ public class LoadFloatingIpsForInstanceTest {
|
|||
|
||||
LoadFloatingIpsForInstance parser = new LoadFloatingIpsForInstance(client);
|
||||
|
||||
assertEquals(ImmutableSet.copyOf(parser.load(new RegionAndName("region", "i-blah"))), ImmutableSet.of("1.1.1.1"));
|
||||
assertEquals(ImmutableSet.copyOf(parser.load(ZoneAndId.fromZoneAndId("Zone", "i-blah"))), ImmutableSet.of("1.1.1.1"));
|
||||
|
||||
verify(client);
|
||||
verify(ipClient);
|
||||
|
@ -67,8 +66,7 @@ public class LoadFloatingIpsForInstanceTest {
|
|||
NovaClient client = createMock(NovaClient.class);
|
||||
FloatingIPClient ipClient = createMock(FloatingIPClient.class);
|
||||
|
||||
expect(client.getConfiguredRegions()).andReturn(ImmutableSet.of("region")).atLeastOnce();
|
||||
expect(client.getFloatingIPExtensionForRegion("region")).andReturn(Optional.of(ipClient)).atLeastOnce();
|
||||
expect(client.getFloatingIPExtensionForZone("Zone")).andReturn(Optional.of(ipClient)).atLeastOnce();
|
||||
|
||||
expect(ipClient.listFloatingIPs()).andReturn(ImmutableSet.<FloatingIP>of()).atLeastOnce();
|
||||
|
||||
|
@ -77,7 +75,7 @@ public class LoadFloatingIpsForInstanceTest {
|
|||
|
||||
LoadFloatingIpsForInstance parser = new LoadFloatingIpsForInstance(client);
|
||||
|
||||
assertFalse(parser.load(new RegionAndName("region", "i-blah")).iterator().hasNext());
|
||||
assertFalse(parser.load(ZoneAndId.fromZoneAndId("Zone", "i-blah")).iterator().hasNext());
|
||||
|
||||
verify(client);
|
||||
verify(ipClient);
|
||||
|
@ -89,8 +87,7 @@ public class LoadFloatingIpsForInstanceTest {
|
|||
NovaClient client = createMock(NovaClient.class);
|
||||
FloatingIPClient ipClient = createMock(FloatingIPClient.class);
|
||||
|
||||
expect(client.getConfiguredRegions()).andReturn(ImmutableSet.of("region")).atLeastOnce();
|
||||
expect(client.getFloatingIPExtensionForRegion("region")).andReturn(Optional.of(ipClient)).atLeastOnce();
|
||||
expect(client.getFloatingIPExtensionForZone("Zone")).andReturn(Optional.of(ipClient)).atLeastOnce();
|
||||
|
||||
expect(ipClient.listFloatingIPs()).andReturn(
|
||||
ImmutableSet.<FloatingIP>of(FloatingIP.builder().id("1").ip("1.1.1.1").build()))
|
||||
|
@ -101,7 +98,7 @@ public class LoadFloatingIpsForInstanceTest {
|
|||
|
||||
LoadFloatingIpsForInstance parser = new LoadFloatingIpsForInstance(client);
|
||||
|
||||
assertFalse(parser.load(new RegionAndName("region", "i-blah")).iterator().hasNext());
|
||||
assertFalse(parser.load(ZoneAndId.fromZoneAndId("Zone", "i-blah")).iterator().hasNext());
|
||||
|
||||
verify(client);
|
||||
verify(ipClient);
|
||||
|
|
|
@ -49,9 +49,9 @@ public class FloatingIPAsyncClientExpectTest extends BaseNovaAsyncClientExpectTe
|
|||
NovaAsyncClient clientWhenExtensionNotInList = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse);
|
||||
|
||||
assertEquals(clientWhenExtensionNotInList.getConfiguredRegions(), ImmutableSet.of("North"));
|
||||
assertEquals(clientWhenExtensionNotInList.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1"));
|
||||
|
||||
assertTrue(clientWhenExtensionNotInList.getFloatingIPExtensionForRegion("North").isPresent());
|
||||
assertTrue(clientWhenExtensionNotInList.getFloatingIPExtensionForZone("az-1.region-a.geo-1").isPresent());
|
||||
|
||||
}
|
||||
|
||||
|
@ -60,9 +60,9 @@ public class FloatingIPAsyncClientExpectTest extends BaseNovaAsyncClientExpectTe
|
|||
NovaAsyncClient clientWhenExtensionNotInList = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, unmatchedExtensionsOfNovaResponse);
|
||||
|
||||
assertEquals(clientWhenExtensionNotInList.getConfiguredRegions(), ImmutableSet.of("North"));
|
||||
assertEquals(clientWhenExtensionNotInList.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1"));
|
||||
|
||||
assertFalse(clientWhenExtensionNotInList.getFloatingIPExtensionForRegion("North").isPresent());
|
||||
assertFalse(clientWhenExtensionNotInList.getFloatingIPExtensionForZone("az-1.region-a.geo-1").isPresent());
|
||||
|
||||
}
|
||||
|
||||
|
@ -81,9 +81,9 @@ public class FloatingIPAsyncClientExpectTest extends BaseNovaAsyncClientExpectTe
|
|||
NovaAsyncClient clientWhenFloatingIPsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, listFloatingIPs, listFloatingIPsResponse);
|
||||
|
||||
assertEquals(clientWhenFloatingIPsExist.getConfiguredRegions(), ImmutableSet.of("North"));
|
||||
assertEquals(clientWhenFloatingIPsExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1"));
|
||||
|
||||
assertEquals(clientWhenFloatingIPsExist.getFloatingIPExtensionForRegion("North").get().listFloatingIPs().get()
|
||||
assertEquals(clientWhenFloatingIPsExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().listFloatingIPs().get()
|
||||
.toString(), new ParseFloatingIPListTest().expected().toString());
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,7 @@ public class FloatingIPAsyncClientExpectTest extends BaseNovaAsyncClientExpectTe
|
|||
NovaAsyncClient clientWhenNoServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, listFloatingIPs, listFloatingIPsResponse);
|
||||
|
||||
assertTrue(clientWhenNoServersExist.getFloatingIPExtensionForRegion("North").get().listFloatingIPs().get()
|
||||
assertTrue(clientWhenNoServersExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().listFloatingIPs().get()
|
||||
.isEmpty());
|
||||
}
|
||||
|
||||
|
@ -120,7 +120,7 @@ public class FloatingIPAsyncClientExpectTest extends BaseNovaAsyncClientExpectTe
|
|||
NovaAsyncClient clientWhenFloatingIPsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, getFloatingIP, getFloatingIPResponse);
|
||||
|
||||
assertEquals(clientWhenFloatingIPsExist.getFloatingIPExtensionForRegion("North").get().getFloatingIP("1").get()
|
||||
assertEquals(clientWhenFloatingIPsExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().getFloatingIP("1").get()
|
||||
.toString(), new ParseFloatingIPTest().expected().toString());
|
||||
}
|
||||
|
||||
|
@ -138,7 +138,7 @@ public class FloatingIPAsyncClientExpectTest extends BaseNovaAsyncClientExpectTe
|
|||
NovaAsyncClient clientWhenNoServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, getFloatingIP, getFloatingIPResponse);
|
||||
|
||||
assertNull(clientWhenNoServersExist.getFloatingIPExtensionForRegion("North").get().getFloatingIP("1").get());
|
||||
assertNull(clientWhenNoServersExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().getFloatingIP("1").get());
|
||||
}
|
||||
|
||||
public void testAllocateWhenResponseIs2xx() throws Exception {
|
||||
|
@ -158,7 +158,7 @@ public class FloatingIPAsyncClientExpectTest extends BaseNovaAsyncClientExpectTe
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, allocateFloatingIP,
|
||||
allocateFloatingIPResponse);
|
||||
|
||||
assertEquals(clientWhenFloatingIPsExist.getFloatingIPExtensionForRegion("North").get().allocate().get()
|
||||
assertEquals(clientWhenFloatingIPsExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().allocate().get()
|
||||
.toString(), new ParseFloatingIPTest().expected().toString());
|
||||
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ public class FloatingIPAsyncClientExpectTest extends BaseNovaAsyncClientExpectTe
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, allocateFloatingIP,
|
||||
allocateFloatingIPResponse);
|
||||
|
||||
assertNull(clientWhenNoServersExist.getFloatingIPExtensionForRegion("North").get().allocate().get());
|
||||
assertNull(clientWhenNoServersExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().allocate().get());
|
||||
}
|
||||
|
||||
}
|
|
@ -48,9 +48,9 @@ public class FloatingIPClientExpectTest extends BaseNovaClientExpectTest {
|
|||
NovaClient clientWhenExtensionNotInList = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse);
|
||||
|
||||
assertEquals(clientWhenExtensionNotInList.getConfiguredRegions(), ImmutableSet.of("North"));
|
||||
assertEquals(clientWhenExtensionNotInList.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1"));
|
||||
|
||||
assertTrue(clientWhenExtensionNotInList.getFloatingIPExtensionForRegion("North").isPresent());
|
||||
assertTrue(clientWhenExtensionNotInList.getFloatingIPExtensionForZone("az-1.region-a.geo-1").isPresent());
|
||||
|
||||
}
|
||||
|
||||
|
@ -59,9 +59,9 @@ public class FloatingIPClientExpectTest extends BaseNovaClientExpectTest {
|
|||
NovaClient clientWhenExtensionNotInList = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, unmatchedExtensionsOfNovaResponse);
|
||||
|
||||
assertEquals(clientWhenExtensionNotInList.getConfiguredRegions(), ImmutableSet.of("North"));
|
||||
assertEquals(clientWhenExtensionNotInList.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1"));
|
||||
|
||||
assertFalse(clientWhenExtensionNotInList.getFloatingIPExtensionForRegion("North").isPresent());
|
||||
assertFalse(clientWhenExtensionNotInList.getFloatingIPExtensionForZone("az-1.region-a.geo-1").isPresent());
|
||||
|
||||
}
|
||||
|
||||
|
@ -80,9 +80,9 @@ public class FloatingIPClientExpectTest extends BaseNovaClientExpectTest {
|
|||
NovaClient clientWhenFloatingIPsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, listFloatingIPs, listFloatingIPsResponse);
|
||||
|
||||
assertEquals(clientWhenFloatingIPsExist.getConfiguredRegions(), ImmutableSet.of("North"));
|
||||
assertEquals(clientWhenFloatingIPsExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1"));
|
||||
|
||||
assertEquals(clientWhenFloatingIPsExist.getFloatingIPExtensionForRegion("North").get().listFloatingIPs()
|
||||
assertEquals(clientWhenFloatingIPsExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().listFloatingIPs()
|
||||
.toString(), new ParseFloatingIPListTest().expected().toString());
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,7 @@ public class FloatingIPClientExpectTest extends BaseNovaClientExpectTest {
|
|||
NovaClient clientWhenNoServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, listFloatingIPs, listFloatingIPsResponse);
|
||||
|
||||
assertTrue(clientWhenNoServersExist.getFloatingIPExtensionForRegion("North").get().listFloatingIPs().isEmpty());
|
||||
assertTrue(clientWhenNoServersExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().listFloatingIPs().isEmpty());
|
||||
}
|
||||
|
||||
public void testGetFloatingIPWhenResponseIs2xx() throws Exception {
|
||||
|
@ -118,7 +118,7 @@ public class FloatingIPClientExpectTest extends BaseNovaClientExpectTest {
|
|||
NovaClient clientWhenFloatingIPsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, getFloatingIP, getFloatingIPResponse);
|
||||
|
||||
assertEquals(clientWhenFloatingIPsExist.getFloatingIPExtensionForRegion("North").get().getFloatingIP("1")
|
||||
assertEquals(clientWhenFloatingIPsExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().getFloatingIP("1")
|
||||
.toString(), new ParseFloatingIPTest().expected().toString());
|
||||
}
|
||||
|
||||
|
@ -136,7 +136,7 @@ public class FloatingIPClientExpectTest extends BaseNovaClientExpectTest {
|
|||
NovaClient clientWhenNoServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, getFloatingIP, getFloatingIPResponse);
|
||||
|
||||
assertNull(clientWhenNoServersExist.getFloatingIPExtensionForRegion("North").get().getFloatingIP("1"));
|
||||
assertNull(clientWhenNoServersExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().getFloatingIP("1"));
|
||||
}
|
||||
|
||||
public void testAllocateWhenResponseIs2xx() throws Exception {
|
||||
|
@ -156,7 +156,7 @@ public class FloatingIPClientExpectTest extends BaseNovaClientExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, allocateFloatingIP,
|
||||
allocateFloatingIPResponse);
|
||||
|
||||
assertEquals(clientWhenFloatingIPsExist.getFloatingIPExtensionForRegion("North").get().allocate().toString(),
|
||||
assertEquals(clientWhenFloatingIPsExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().allocate().toString(),
|
||||
new ParseFloatingIPTest().expected().toString());
|
||||
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ public class FloatingIPClientExpectTest extends BaseNovaClientExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, allocateFloatingIP,
|
||||
allocateFloatingIPResponse);
|
||||
|
||||
assertNull(clientWhenNoServersExist.getFloatingIPExtensionForRegion("North").get().allocate());
|
||||
assertNull(clientWhenNoServersExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().allocate());
|
||||
}
|
||||
|
||||
}
|
|
@ -51,8 +51,8 @@ public class FloatingIPClientLiveTest extends BaseNovaClientLiveTest {
|
|||
|
||||
@Test
|
||||
public void testListFloatingIPs() throws Exception {
|
||||
for (String regionId : context.getApi().getConfiguredRegions()) {
|
||||
Optional<FloatingIPClient> clientOption = context.getApi().getFloatingIPExtensionForRegion(regionId);
|
||||
for (String zoneId : context.getApi().getConfiguredZones()) {
|
||||
Optional<FloatingIPClient> clientOption = context.getApi().getFloatingIPExtensionForZone(zoneId);
|
||||
if (!clientOption.isPresent())
|
||||
continue;
|
||||
FloatingIPClient client = clientOption.get();
|
||||
|
@ -73,8 +73,8 @@ public class FloatingIPClientLiveTest extends BaseNovaClientLiveTest {
|
|||
|
||||
@Test
|
||||
public void testAllocateAndDeallocateFloatingIPs() throws Exception {
|
||||
for (String regionId : context.getApi().getConfiguredRegions()) {
|
||||
Optional<FloatingIPClient> clientOption = context.getApi().getFloatingIPExtensionForRegion(regionId);
|
||||
for (String zoneId : context.getApi().getConfiguredZones()) {
|
||||
Optional<FloatingIPClient> clientOption = context.getApi().getFloatingIPExtensionForZone(zoneId);
|
||||
if (!clientOption.isPresent())
|
||||
continue;
|
||||
FloatingIPClient client = clientOption.get();
|
||||
|
@ -104,33 +104,33 @@ public class FloatingIPClientLiveTest extends BaseNovaClientLiveTest {
|
|||
|
||||
@Test
|
||||
public void testAddAndRemoveFloatingIp() throws Exception {
|
||||
for (String regionId : context.getApi().getConfiguredRegions()) {
|
||||
Optional<FloatingIPClient> clientOption = context.getApi().getFloatingIPExtensionForRegion(regionId);
|
||||
for (String zoneId : context.getApi().getConfiguredZones()) {
|
||||
Optional<FloatingIPClient> clientOption = context.getApi().getFloatingIPExtensionForZone(zoneId);
|
||||
if (!clientOption.isPresent())
|
||||
continue;
|
||||
FloatingIPClient client = clientOption.get();
|
||||
ServerClient serverClient = context.getApi().getServerClientForRegion(regionId);
|
||||
Server server = serverClient.createServer("test", imageIdForRegion(regionId), flavorRefForRegion(regionId));
|
||||
ServerClient serverClient = context.getApi().getServerClientForZone(zoneId);
|
||||
Server server = serverClient.createServer("test", imageIdForZone(zoneId), flavorRefForZone(zoneId));
|
||||
blockUntilServerActive(server.getId(), serverClient);
|
||||
FloatingIP floatingIP = client.allocate();
|
||||
assertNotNull(floatingIP);
|
||||
try {
|
||||
client.addFloatingIP(server.getId(), floatingIP.getIp());
|
||||
client.addFloatingIPToServer(floatingIP.getIp(), server.getId());
|
||||
assertEventually(new ServerHasFloatingIP(serverClient, server.getId(), floatingIP.getIp()));
|
||||
} finally {
|
||||
client.removeFloatingIP(server.getId(), floatingIP.getIp());
|
||||
client.removeFloatingIPFromServer(floatingIP.getIp(), server.getId());
|
||||
serverClient.deleteServer(server.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String imageIdForRegion(String regionId) {
|
||||
ImageClient imageClient = context.getApi().getImageClientForRegion(regionId);
|
||||
private String imageIdForZone(String zoneId) {
|
||||
ImageClient imageClient = context.getApi().getImageClientForZone(zoneId);
|
||||
return Iterables.getLast(imageClient.listImages()).getId();
|
||||
}
|
||||
|
||||
private String flavorRefForRegion(String regionId) {
|
||||
FlavorClient flavorClient = context.getApi().getFlavorClientForRegion(regionId);
|
||||
private String flavorRefForZone(String zoneId) {
|
||||
FlavorClient flavorClient = context.getApi().getFlavorClientForZone(zoneId);
|
||||
return Iterables.getLast(flavorClient.listFlavors()).getId();
|
||||
}
|
||||
|
||||
|
|
|
@ -57,9 +57,9 @@ public class KeyPairClientExpectTest extends BaseNovaClientExpectTest {
|
|||
NovaClient clientWhenServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, listKeyPairs, listKeyPairsResponse);
|
||||
|
||||
assertEquals(clientWhenServersExist.getConfiguredRegions(), ImmutableSet.of("North"));
|
||||
assertEquals(clientWhenServersExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1"));
|
||||
|
||||
assertEquals(clientWhenServersExist.getKeyPairExtensionForRegion("North").get().listKeyPairs().toString(),
|
||||
assertEquals(clientWhenServersExist.getKeyPairExtensionForZone("az-1.region-a.geo-1").get().listKeyPairs().toString(),
|
||||
new ParseKeyPairListTest().expected().toString());
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ public class KeyPairClientExpectTest extends BaseNovaClientExpectTest {
|
|||
NovaClient clientWhenNoServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, listKeyPairs, listKeyPairsResponse);
|
||||
|
||||
assertTrue(clientWhenNoServersExist.getKeyPairExtensionForRegion("North").get().listKeyPairs().isEmpty());
|
||||
assertTrue(clientWhenNoServersExist.getKeyPairExtensionForZone("az-1.region-a.geo-1").get().listKeyPairs().isEmpty());
|
||||
|
||||
}
|
||||
|
||||
|
@ -98,7 +98,7 @@ public class KeyPairClientExpectTest extends BaseNovaClientExpectTest {
|
|||
NovaClient clientWhenServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, createKeyPair, createKeyPairResponse);
|
||||
|
||||
assertEquals(clientWhenServersExist.getKeyPairExtensionForRegion("North").get().createKeyPair("testkeypair")
|
||||
assertEquals(clientWhenServersExist.getKeyPairExtensionForZone("az-1.region-a.geo-1").get().createKeyPair("testkeypair")
|
||||
.toString(), new ParseKeyPairTest().expected().toString());
|
||||
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ public class KeyPairClientExpectTest extends BaseNovaClientExpectTest {
|
|||
|
||||
assertEquals(
|
||||
clientWhenServersExist
|
||||
.getKeyPairExtensionForRegion("North")
|
||||
.getKeyPairExtensionForZone("az-1.region-a.geo-1")
|
||||
.get()
|
||||
.createKeyPairWithPublicKey(
|
||||
"testkeypair",
|
||||
|
@ -146,6 +146,6 @@ public class KeyPairClientExpectTest extends BaseNovaClientExpectTest {
|
|||
NovaClient clientWhenServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
|
||||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, deleteKeyPair, deleteKeyPairResponse);
|
||||
|
||||
assertTrue(clientWhenServersExist.getKeyPairExtensionForRegion("North").get().deleteKeyPair("testkeypair"));
|
||||
assertTrue(clientWhenServersExist.getKeyPairExtensionForZone("az-1.region-a.geo-1").get().deleteKeyPair("testkeypair"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,8 +36,8 @@ import org.testng.annotations.Test;
|
|||
public class KeyPairClientLiveTest extends BaseNovaClientLiveTest {
|
||||
|
||||
public void testListKeyPairs() throws Exception {
|
||||
for (String regionId : context.getApi().getConfiguredRegions()) {
|
||||
KeyPairClient client = context.getApi().getKeyPairExtensionForRegion(regionId).get();
|
||||
for (String zoneId : context.getApi().getConfiguredZones()) {
|
||||
KeyPairClient client = context.getApi().getKeyPairExtensionForZone(zoneId).get();
|
||||
Set<Map<String, KeyPair>> keyPairsList = client.listKeyPairs();
|
||||
assertNotNull(keyPairsList);
|
||||
}
|
||||
|
@ -45,8 +45,8 @@ public class KeyPairClientLiveTest extends BaseNovaClientLiveTest {
|
|||
|
||||
public void testCreateAndDeleteKeyPair() throws Exception {
|
||||
final String KEYPAIR_NAME = "testkp";
|
||||
for (String regionId : context.getApi().getConfiguredRegions()) {
|
||||
KeyPairClient client = context.getApi().getKeyPairExtensionForRegion(regionId).get();
|
||||
for (String zoneId : context.getApi().getConfiguredZones()) {
|
||||
KeyPairClient client = context.getApi().getKeyPairExtensionForZone(zoneId).get();
|
||||
KeyPair keyPair = null;
|
||||
try {
|
||||
keyPair = client.createKeyPair(KEYPAIR_NAME);
|
||||
|
@ -63,8 +63,8 @@ public class KeyPairClientLiveTest extends BaseNovaClientLiveTest {
|
|||
final String KEYPAIR_NAME = "testkp";
|
||||
final String PUBLIC_KEY = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCrrBREFxz3002l1HuXz0+UOdJQ/mOYD5DiJwwB/TOybwIKQJPOxJWA9gBoo4k9dthTKBTaEYbzrll7iZcp59E80S6mNiAr3mUgi+x5Y8uyXeJ2Ws+h6peVyFVUu9epkwpcTd1GVfdcVWsTajwDz9+lxCDhl0RZKDFoT0scTxbj/w== nova@nv-aw2az2-api0002";
|
||||
|
||||
for (String regionId : context.getApi().getConfiguredRegions()) {
|
||||
KeyPairClient client = context.getApi().getKeyPairExtensionForRegion(regionId).get();
|
||||
for (String zoneId : context.getApi().getConfiguredZones()) {
|
||||
KeyPairClient client = context.getApi().getKeyPairExtensionForZone(zoneId).get();
|
||||
KeyPair keyPair = null;
|
||||
try {
|
||||
keyPair = client.createKeyPairWithPublicKey(KEYPAIR_NAME, PUBLIC_KEY);
|
||||
|
|
|
@ -61,9 +61,9 @@ public class SecurityGroupClientExpectTest extends BaseNovaClientExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, listSecurityGroups,
|
||||
listSecurityGroupsResponse);
|
||||
|
||||
assertEquals(clientWhenSecurityGroupsExist.getConfiguredRegions(), ImmutableSet.of("North"));
|
||||
assertEquals(clientWhenSecurityGroupsExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1"));
|
||||
|
||||
assertEquals(clientWhenSecurityGroupsExist.getSecurityGroupExtensionForRegion("North").get().listSecurityGroups()
|
||||
assertEquals(clientWhenSecurityGroupsExist.getSecurityGroupExtensionForZone("az-1.region-a.geo-1").get().listSecurityGroups()
|
||||
.toString(), new ParseSecurityGroupListTest().expected().toString());
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,7 @@ public class SecurityGroupClientExpectTest extends BaseNovaClientExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, listListSecurityGroups,
|
||||
listListSecurityGroupsResponse);
|
||||
|
||||
assertTrue(clientWhenNoSecurityGroupsExist.getSecurityGroupExtensionForRegion("North").get().listSecurityGroups()
|
||||
assertTrue(clientWhenNoSecurityGroupsExist.getSecurityGroupExtensionForZone("az-1.region-a.geo-1").get().listSecurityGroups()
|
||||
.isEmpty());
|
||||
}
|
||||
|
||||
|
@ -103,7 +103,7 @@ public class SecurityGroupClientExpectTest extends BaseNovaClientExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, getSecurityGroup,
|
||||
getSecurityGroupResponse);
|
||||
|
||||
assertEquals(clientWhenSecurityGroupsExist.getSecurityGroupExtensionForRegion("North").get()
|
||||
assertEquals(clientWhenSecurityGroupsExist.getSecurityGroupExtensionForZone("az-1.region-a.geo-1").get()
|
||||
.getSecurityGroup("0").toString(), new ParseSecurityGroupTest().expected().toString());
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ public class SecurityGroupClientExpectTest extends BaseNovaClientExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, getSecurityGroup,
|
||||
getSecurityGroupResponse);
|
||||
|
||||
assertNull(clientWhenNoSecurityGroupsExist.getSecurityGroupExtensionForRegion("North").get()
|
||||
assertNull(clientWhenNoSecurityGroupsExist.getSecurityGroupExtensionForZone("az-1.region-a.geo-1").get()
|
||||
.getSecurityGroup("0"));
|
||||
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ public class SecurityGroupClientExpectTest extends BaseNovaClientExpectTest {
|
|||
createSecurityGroupResponse);
|
||||
|
||||
assertEquals(
|
||||
clientWhenSecurityGroupsExist.getSecurityGroupExtensionForRegion("North").get()
|
||||
clientWhenSecurityGroupsExist.getSecurityGroupExtensionForZone("az-1.region-a.geo-1").get()
|
||||
.createSecurityGroup("name", "description").toString(), createSecurityGroupExpected().toString());
|
||||
}
|
||||
|
||||
|
@ -167,7 +167,7 @@ public class SecurityGroupClientExpectTest extends BaseNovaClientExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, deleteSecurityGroup,
|
||||
deleteSecurityGroupResponse);
|
||||
|
||||
assertTrue(clientWhenServersExist.getSecurityGroupExtensionForRegion("North").get().deleteSecurityGroup("160"));
|
||||
assertTrue(clientWhenServersExist.getSecurityGroupExtensionForZone("az-1.region-a.geo-1").get().deleteSecurityGroup("160"));
|
||||
|
||||
}
|
||||
|
||||
|
@ -191,7 +191,7 @@ public class SecurityGroupClientExpectTest extends BaseNovaClientExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, createSecurityGroupRule,
|
||||
createSecurityGroupRuleResponse);
|
||||
|
||||
assertEquals(clientWhenSecurityGroupsExist.getSecurityGroupExtensionForRegion("North").get()
|
||||
assertEquals(clientWhenSecurityGroupsExist.getSecurityGroupExtensionForZone("az-1.region-a.geo-1").get()
|
||||
.createSecurityGroupRule("tcp", "80", "8080", "0.0.0.0/0", "", "161").toString(),
|
||||
createSecurityGroupRuleExpected().toString());
|
||||
}
|
||||
|
@ -211,7 +211,7 @@ public class SecurityGroupClientExpectTest extends BaseNovaClientExpectTest {
|
|||
responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, deleteSecurityGroupRule,
|
||||
deleteSecurityGroupRuleResponse);
|
||||
|
||||
assertTrue(clientWhenSecurityGroupsExist.getSecurityGroupExtensionForRegion("North").get()
|
||||
assertTrue(clientWhenSecurityGroupsExist.getSecurityGroupExtensionForZone("az-1.region-a.geo-1").get()
|
||||
.deleteSecurityGroupRule("161"));
|
||||
|
||||
}
|
||||
|
|
|
@ -38,16 +38,16 @@ public class SecurityGroupClientLiveTest extends BaseNovaClientLiveTest {
|
|||
public static final String SECURITY_GROUP_NAME = "testsg";
|
||||
|
||||
public void listSecurityGroups() throws Exception {
|
||||
for (String regionId : context.getApi().getConfiguredRegions()) {
|
||||
SecurityGroupClient client = context.getApi().getSecurityGroupExtensionForRegion(regionId).get();
|
||||
for (String zoneId : context.getApi().getConfiguredZones()) {
|
||||
SecurityGroupClient client = context.getApi().getSecurityGroupExtensionForZone(zoneId).get();
|
||||
Set<SecurityGroup> securityGroupsList = client.listSecurityGroups();
|
||||
assertNotNull(securityGroupsList);
|
||||
}
|
||||
}
|
||||
|
||||
public void createGetAndDeleteSecurityGroup() throws Exception {
|
||||
for (String regionId : context.getApi().getConfiguredRegions()) {
|
||||
SecurityGroupClient client = context.getApi().getSecurityGroupExtensionForRegion(regionId).get();
|
||||
for (String zoneId : context.getApi().getConfiguredZones()) {
|
||||
SecurityGroupClient client = context.getApi().getSecurityGroupExtensionForZone(zoneId).get();
|
||||
SecurityGroup securityGroup = null;
|
||||
String id;
|
||||
try {
|
||||
|
@ -65,8 +65,8 @@ public class SecurityGroupClientLiveTest extends BaseNovaClientLiveTest {
|
|||
}
|
||||
|
||||
public void createAndDeleteSecurityGroupRule() throws Exception {
|
||||
for (String regionId : context.getApi().getConfiguredRegions()) {
|
||||
SecurityGroupClient client = context.getApi().getSecurityGroupExtensionForRegion(regionId).get();
|
||||
for (String zoneId : context.getApi().getConfiguredZones()) {
|
||||
SecurityGroupClient client = context.getApi().getSecurityGroupExtensionForZone(zoneId).get();
|
||||
SecurityGroup securityGroup = null;
|
||||
|
||||
try {
|
||||
|
|
|
@ -58,9 +58,9 @@ public class ExtensionClientExpectTest extends BaseNovaClientExpectTest {
|
|||
NovaClient clientWhenExtensionsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
|
||||
responseWithKeystoneAccess, listExtensions, listExtensionsResponse);
|
||||
|
||||
assertEquals(clientWhenExtensionsExist.getConfiguredRegions(), ImmutableSet.of("North"));
|
||||
assertEquals(clientWhenExtensionsExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1"));
|
||||
|
||||
assertEquals(clientWhenExtensionsExist.getExtensionClientForRegion("North").listExtensions().toString(),
|
||||
assertEquals(clientWhenExtensionsExist.getExtensionClientForZone("az-1.region-a.geo-1").listExtensions().toString(),
|
||||
new ParseExtensionListTest().expected().toString());
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ public class ExtensionClientExpectTest extends BaseNovaClientExpectTest {
|
|||
NovaClient clientWhenNoServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
|
||||
responseWithKeystoneAccess, listExtensions, listExtensionsResponse);
|
||||
|
||||
assertTrue(clientWhenNoServersExist.getExtensionClientForRegion("North").listExtensions().isEmpty());
|
||||
assertTrue(clientWhenNoServersExist.getExtensionClientForZone("az-1.region-a.geo-1").listExtensions().isEmpty());
|
||||
}
|
||||
|
||||
// TODO: gson deserializer for Multimap
|
||||
|
@ -98,7 +98,7 @@ public class ExtensionClientExpectTest extends BaseNovaClientExpectTest {
|
|||
NovaClient clientWhenExtensionsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
|
||||
responseWithKeystoneAccess, getExtension, getExtensionResponse);
|
||||
|
||||
assertEquals(clientWhenExtensionsExist.getExtensionClientForRegion("North").getExtensionByAlias("RS-PIE")
|
||||
assertEquals(clientWhenExtensionsExist.getExtensionClientForZone("az-1.region-a.geo-1").getExtensionByAlias("RS-PIE")
|
||||
.toString(), new ParseExtensionTest().expected().toString());
|
||||
}
|
||||
|
||||
|
@ -117,7 +117,7 @@ public class ExtensionClientExpectTest extends BaseNovaClientExpectTest {
|
|||
NovaClient clientWhenNoExtensionsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
|
||||
responseWithKeystoneAccess, getExtension, getExtensionResponse);
|
||||
|
||||
assertNull(clientWhenNoExtensionsExist.getExtensionClientForRegion("North").getExtensionByAlias("RS-PIE"));
|
||||
assertNull(clientWhenNoExtensionsExist.getExtensionClientForZone("az-1.region-a.geo-1").getExtensionByAlias("RS-PIE"));
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -42,8 +42,8 @@ public class ExtensionClientLiveTest extends BaseNovaClientLiveTest {
|
|||
*/
|
||||
@Test
|
||||
public void testListExtensions() throws Exception {
|
||||
for (String regionId : context.getApi().getConfiguredRegions()) {
|
||||
ExtensionClient client = context.getApi().getExtensionClientForRegion(regionId);
|
||||
for (String zoneId : context.getApi().getConfiguredZones()) {
|
||||
ExtensionClient client = context.getApi().getExtensionClientForZone(zoneId);
|
||||
Set<Extension> response = client.listExtensions();
|
||||
assert null != response;
|
||||
assertTrue(response.size() >= 0);
|
||||
|
|
|
@ -58,9 +58,9 @@ public class FlavorClientExpectTest extends BaseNovaClientExpectTest {
|
|||
NovaClient clientWhenFlavorsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
|
||||
responseWithKeystoneAccess, listFlavors, listFlavorsResponse);
|
||||
|
||||
assertEquals(clientWhenFlavorsExist.getConfiguredRegions(), ImmutableSet.of("North"));
|
||||
assertEquals(clientWhenFlavorsExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1"));
|
||||
|
||||
assertEquals(clientWhenFlavorsExist.getFlavorClientForRegion("North").listFlavors().toString(),
|
||||
assertEquals(clientWhenFlavorsExist.getFlavorClientForZone("az-1.region-a.geo-1").listFlavors().toString(),
|
||||
new ParseFlavorListTest().expected().toString());
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ public class FlavorClientExpectTest extends BaseNovaClientExpectTest {
|
|||
NovaClient clientWhenNoServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
|
||||
responseWithKeystoneAccess, listFlavors, listFlavorsResponse);
|
||||
|
||||
assertTrue(clientWhenNoServersExist.getFlavorClientForRegion("North").listFlavors().isEmpty());
|
||||
assertTrue(clientWhenNoServersExist.getFlavorClientForZone("az-1.region-a.geo-1").listFlavors().isEmpty());
|
||||
}
|
||||
|
||||
// TODO: gson deserializer for Multimap
|
||||
|
@ -99,7 +99,7 @@ public class FlavorClientExpectTest extends BaseNovaClientExpectTest {
|
|||
responseWithKeystoneAccess, getFlavor, getFlavorResponse);
|
||||
|
||||
assertEquals(
|
||||
clientWhenFlavorsExist.getFlavorClientForRegion("North").getFlavor("52415800-8b69-11e0-9b19-734f1195ff37")
|
||||
clientWhenFlavorsExist.getFlavorClientForZone("az-1.region-a.geo-1").getFlavor("52415800-8b69-11e0-9b19-734f1195ff37")
|
||||
.toString(), new ParseFlavorTest().expected().toString());
|
||||
}
|
||||
|
||||
|
@ -118,7 +118,7 @@ public class FlavorClientExpectTest extends BaseNovaClientExpectTest {
|
|||
NovaClient clientWhenNoFlavorsExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
|
||||
responseWithKeystoneAccess, getFlavor, getFlavorResponse);
|
||||
|
||||
assertNull(clientWhenNoFlavorsExist.getFlavorClientForRegion("North").getFlavor("123"));
|
||||
assertNull(clientWhenNoFlavorsExist.getFlavorClientForZone("az-1.region-a.geo-1").getFlavor("123"));
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -43,8 +43,8 @@ public class FlavorClientLiveTest extends BaseNovaClientLiveTest {
|
|||
*/
|
||||
@Test
|
||||
public void testListFlavors() throws Exception {
|
||||
for (String regionId : context.getApi().getConfiguredRegions()) {
|
||||
FlavorClient client = context.getApi().getFlavorClientForRegion(regionId);
|
||||
for (String zoneId : context.getApi().getConfiguredZones()) {
|
||||
FlavorClient client = context.getApi().getFlavorClientForZone(zoneId);
|
||||
Set<Resource> response = client.listFlavors();
|
||||
assert null != response;
|
||||
assertTrue(response.size() >= 0);
|
||||
|
@ -64,8 +64,8 @@ public class FlavorClientLiveTest extends BaseNovaClientLiveTest {
|
|||
*/
|
||||
@Test
|
||||
public void testListFlavorsInDetail() throws Exception {
|
||||
for (String regionId : context.getApi().getConfiguredRegions()) {
|
||||
FlavorClient client = context.getApi().getFlavorClientForRegion(regionId);
|
||||
for (String zoneId : context.getApi().getConfiguredZones()) {
|
||||
FlavorClient client = context.getApi().getFlavorClientForZone(zoneId);
|
||||
Set<Flavor> response = client.listFlavorsInDetail();
|
||||
assert null != response;
|
||||
assertTrue(response.size() >= 0);
|
||||
|
|
|
@ -57,9 +57,9 @@ public class ImageClientExpectTest extends BaseNovaClientExpectTest {
|
|||
NovaClient clientWhenImagesExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
|
||||
responseWithKeystoneAccess, listImages, listImagesResponse);
|
||||
|
||||
assertEquals(clientWhenImagesExist.getConfiguredRegions(), ImmutableSet.of("North"));
|
||||
assertEquals(clientWhenImagesExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1"));
|
||||
|
||||
assertEquals(clientWhenImagesExist.getImageClientForRegion("North").listImages().toString(),
|
||||
assertEquals(clientWhenImagesExist.getImageClientForZone("az-1.region-a.geo-1").listImages().toString(),
|
||||
new ParseImageListTest().expected().toString());
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ public class ImageClientExpectTest extends BaseNovaClientExpectTest {
|
|||
NovaClient clientWhenNoServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
|
||||
responseWithKeystoneAccess, listImages, listImagesResponse);
|
||||
|
||||
assertTrue(clientWhenNoServersExist.getImageClientForRegion("North").listImages().isEmpty());
|
||||
assertTrue(clientWhenNoServersExist.getImageClientForZone("az-1.region-a.geo-1").listImages().isEmpty());
|
||||
}
|
||||
|
||||
public void testGetImageWhenResponseIs2xx() throws Exception {
|
||||
|
@ -97,7 +97,7 @@ public class ImageClientExpectTest extends BaseNovaClientExpectTest {
|
|||
responseWithKeystoneAccess, getImage, getImageResponse);
|
||||
|
||||
assertEquals(
|
||||
clientWhenImagesExist.getImageClientForRegion("North").getImage("52415800-8b69-11e0-9b19-734f5736d2a2")
|
||||
clientWhenImagesExist.getImageClientForZone("az-1.region-a.geo-1").getImage("52415800-8b69-11e0-9b19-734f5736d2a2")
|
||||
.toString(), new ParseImageTest().expected().toString());
|
||||
}
|
||||
|
||||
|
@ -115,7 +115,7 @@ public class ImageClientExpectTest extends BaseNovaClientExpectTest {
|
|||
NovaClient clientWhenNoImagesExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
|
||||
responseWithKeystoneAccess, getImage, getImageResponse);
|
||||
|
||||
assertNull(clientWhenNoImagesExist.getImageClientForRegion("North").getImage(
|
||||
assertNull(clientWhenNoImagesExist.getImageClientForZone("az-1.region-a.geo-1").getImage(
|
||||
"52415800-8b69-11e0-9b19-734f5736d2a2"));
|
||||
|
||||
}
|
||||
|
|
|
@ -39,8 +39,8 @@ public class ImageClientLiveTest extends BaseNovaClientLiveTest {
|
|||
|
||||
@Test
|
||||
public void testListImages() throws Exception {
|
||||
for (String regionId : context.getApi().getConfiguredRegions()) {
|
||||
ImageClient client = context.getApi().getImageClientForRegion(regionId);
|
||||
for (String zoneId : context.getApi().getConfiguredZones()) {
|
||||
ImageClient client = context.getApi().getImageClientForZone(zoneId);
|
||||
Set<Resource> response = client.listImages();
|
||||
assertNotNull(response);
|
||||
assertTrue(response.size() >= 0);
|
||||
|
@ -56,8 +56,8 @@ public class ImageClientLiveTest extends BaseNovaClientLiveTest {
|
|||
|
||||
@Test
|
||||
public void testListImagesInDetail() throws Exception {
|
||||
for (String regionId : context.getApi().getConfiguredRegions()) {
|
||||
ImageClient client = context.getApi().getImageClientForRegion(regionId);
|
||||
for (String zoneId : context.getApi().getConfiguredZones()) {
|
||||
ImageClient client = context.getApi().getImageClientForZone(zoneId);
|
||||
Set<Image> response = client.listImagesInDetail();
|
||||
assertNotNull(response);
|
||||
assertTrue(response.size() >= 0);
|
||||
|
|
|
@ -56,9 +56,9 @@ public class ServerClientExpectTest extends BaseNovaClientExpectTest {
|
|||
NovaClient clientWhenServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
|
||||
responseWithKeystoneAccess, listServers, listServersResponse);
|
||||
|
||||
assertEquals(clientWhenServersExist.getConfiguredRegions(), ImmutableSet.of("North"));
|
||||
assertEquals(clientWhenServersExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1"));
|
||||
|
||||
assertEquals(clientWhenServersExist.getServerClientForRegion("North").listServers().toString(),
|
||||
assertEquals(clientWhenServersExist.getServerClientForZone("az-1.region-a.geo-1").listServers().toString(),
|
||||
new ParseServerListTest().expected().toString());
|
||||
}
|
||||
|
||||
|
@ -76,6 +76,6 @@ public class ServerClientExpectTest extends BaseNovaClientExpectTest {
|
|||
NovaClient clientWhenNoServersExist = requestsSendResponses(keystoneAuthWithAccessKeyAndSecretKey,
|
||||
responseWithKeystoneAccess, listServers, listServersResponse);
|
||||
|
||||
assertTrue(clientWhenNoServersExist.getServerClientForRegion("North").listServers().isEmpty());
|
||||
assertTrue(clientWhenNoServersExist.getServerClientForZone("az-1.region-a.geo-1").listServers().isEmpty());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,8 +38,8 @@ public class ServerClientLiveTest extends BaseNovaClientLiveTest {
|
|||
|
||||
@Test
|
||||
public void testListServersInDetail() throws Exception {
|
||||
for (String regionId : context.getApi().getConfiguredRegions()) {
|
||||
ServerClient client = context.getApi().getServerClientForRegion(regionId);
|
||||
for (String zoneId : context.getApi().getConfiguredZones()) {
|
||||
ServerClient client = context.getApi().getServerClientForZone(zoneId);
|
||||
Set<Resource> response = client.listServers();
|
||||
assert null != response;
|
||||
assertTrue(response.size() >= 0);
|
||||
|
|
|
@ -60,7 +60,7 @@ public class ParseServerTest extends BaseItemParserTest<Server> {
|
|||
.id("52415800-8b69-11e0-9b19-734f000004d2")
|
||||
.tenantId("1234")
|
||||
.userId("5678")
|
||||
.name("sample-server")
|
||||
.name("sample-f352")
|
||||
.updated(new SimpleDateFormatDateService().iso8601SecondsDateParse("2010-10-10T12:00:00Z"))
|
||||
.created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2010-08-10T12:00:00Z"))
|
||||
.hostId("e4d909c290d0fb1ca068ffaddf22cbd0")
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{"flavors": [{"rxtx_quota": 0, "name": "standard.xsmall", "links": [{"href": "https://az-2.region-a.geo-1.compute.hpcloudsvc.com/v1.1/37936628937291/flavors/100", "rel": "self"}, {"href": "https://az-2.region-a.geo-1.compute.hpcloudsvc.com/37936628937291/flavors/100", "rel": "bookmark"}], "ram": 1024, "vcpus": 1, "rxtx_cap": 0, "swap": 0, "disk": 30, "id": 100}, {"rxtx_quota": 0, "name": "standard.small", "links": [{"href": "https://az-2.region-a.geo-1.compute.hpcloudsvc.com/v1.1/37936628937291/flavors/101", "rel": "self"}, {"href": "https://az-2.region-a.geo-1.compute.hpcloudsvc.com/37936628937291/flavors/101", "rel": "bookmark"}], "ram": 2048, "vcpus": 2, "rxtx_cap": 0, "swap": 0, "disk": 60, "id": 101}, {"rxtx_quota": 0, "name": "standard.2xlarge", "links": [{"href": "https://az-2.region-a.geo-1.compute.hpcloudsvc.com/v1.1/37936628937291/flavors/105", "rel": "self"}, {"href": "https://az-2.region-a.geo-1.compute.hpcloudsvc.com/37936628937291/flavors/105", "rel": "bookmark"}], "ram": 32768, "vcpus": 8, "rxtx_cap": 0, "swap": 0, "disk": 960, "id": 105}, {"rxtx_quota": 0, "name": "standard.large", "links": [{"href": "https://az-2.region-a.geo-1.compute.hpcloudsvc.com/v1.1/37936628937291/flavors/103", "rel": "self"}, {"href": "https://az-2.region-a.geo-1.compute.hpcloudsvc.com/37936628937291/flavors/103", "rel": "bookmark"}], "ram": 8192, "vcpus": 4, "rxtx_cap": 0, "swap": 0, "disk": 240, "id": 103}, {"rxtx_quota": 0, "name": "standard.medium", "links": [{"href": "https://az-2.region-a.geo-1.compute.hpcloudsvc.com/v1.1/37936628937291/flavors/102", "rel": "self"}, {"href": "https://az-2.region-a.geo-1.compute.hpcloudsvc.com/37936628937291/flavors/102", "rel": "bookmark"}], "ram": 4096, "vcpus": 2, "rxtx_cap": 0, "swap": 0, "disk": 120, "id": 102}, {"rxtx_quota": 0, "name": "standard.xlarge", "links": [{"href": "https://az-2.region-a.geo-1.compute.hpcloudsvc.com/v1.1/37936628937291/flavors/104", "rel": "self"}, {"href": "https://az-2.region-a.geo-1.compute.hpcloudsvc.com/37936628937291/flavors/104", "rel": "bookmark"}], "ram": 16384, "vcpus": 4, "rxtx_cap": 0, "swap": 0, "disk": 480, "id": 104}]}
|
File diff suppressed because one or more lines are too long
|
@ -3,13 +3,13 @@
|
|||
"id": "52415800-8b69-11e0-9b19-734f000004d2",
|
||||
"tenant_id": "1234",
|
||||
"user_id": "5678",
|
||||
"name": "sample-server",
|
||||
"name": "sample-f352",
|
||||
"updated": "2010-10-10T12:00:00Z",
|
||||
"created": "2010-08-10T12:00:00Z",
|
||||
"hostId": "e4d909c290d0fb1ca068ffaddf22cbd0",
|
||||
"accessIPv4" : "67.23.10.132",
|
||||
"accessIPv6" : "::babe:67.23.10.132",
|
||||
"status": "BUILD",
|
||||
"status": "BUILD(scheduling)",
|
||||
"progress": 60,
|
||||
"image" : {
|
||||
"id": "52415800-8b69-11e0-9b19-734f6f006e54",
|
||||
|
|
Loading…
Reference in New Issue