From 17fce876618c231b780896446d8722fc44489593 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Mon, 2 Jul 2012 15:23:52 -0700 Subject: [PATCH] switched keystone-backed providers and apis to strictly return a single scope of location --- .../compute/NovaComputeServiceAdapter.java | 23 +++++++++- .../NovaComputeServiceContextModule.java | 2 +- .../v2_0/config/NovaRestClientModule.java | 7 ++- .../v1_0/config/GlanceRestClientModule.java | 14 +++++- .../v1_0/config/QuantumRestClientModule.java | 14 +++++- .../v1/config/SwiftRestClientModule.java | 12 +++++ .../us/CloudServersUSProviderMetadata.java | 9 ++-- ...dServersUSComputeServiceContextModule.java | 45 +++++++++++++++++++ ...CloudServersUSTemplateBuilderLiveTest.java | 14 +++--- .../HPCloudObjectStorageRestClientModule.java | 13 +++++- 10 files changed, 133 insertions(+), 20 deletions(-) create mode 100644 labs/rackspace-cloudservers-us/src/main/java/org/jclouds/rackspace/cloudservers/us/config/CloudServersUSComputeServiceContextModule.java diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapter.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapter.java index f24965e9f0..eb0830c726 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapter.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapter.java @@ -55,6 +55,7 @@ import org.jclouds.openstack.nova.v2_0.options.CreateServerOptions; import org.jclouds.openstack.nova.v2_0.predicates.ImagePredicates; import com.google.common.base.Function; +import com.google.common.base.Objects; import com.google.common.base.Optional; import com.google.common.base.Supplier; import com.google.common.cache.LoadingCache; @@ -155,8 +156,26 @@ public class NovaComputeServiceAdapter implements public Iterable listImages() { Builder builder = ImmutableSet.builder(); for (final String zoneId : zoneIds.get()) { - builder.addAll(transform(filter(novaClient.getImageClientForZone(zoneId).listImagesInDetail(), ImagePredicates - .statusEquals(Image.Status.ACTIVE)), new Function() { + Set images = novaClient.getImageClientForZone(zoneId).listImagesInDetail(); + if (images.size() == 0) { + logger.debug("no images found in zone %s", zoneId); + continue; + } + Iterable active = filter(images, ImagePredicates.statusEquals(Image.Status.ACTIVE)); + if (images.size() == 0) { + logger.debug("no images with status active in zone %s; non-active: %s", zoneId, + transform(active, new Function() { + + @Override + public String apply(Image input) { + return Objects.toStringHelper("").add("id", input.getId()).add("status", input.getStatus()) + .toString(); + } + + })); + continue; + } + builder.addAll(transform(active, new Function() { @Override public ImageInZone apply(Image arg0) { diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/config/NovaComputeServiceContextModule.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/config/NovaComputeServiceContextModule.java index c3c27647d5..6e191420b8 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/config/NovaComputeServiceContextModule.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/config/NovaComputeServiceContextModule.java @@ -124,7 +124,7 @@ public class NovaComputeServiceContextModule extends // we aren't converting location from a provider-specific type bind(new TypeLiteral>() { - }).to((Class) IdentityFunction.class); + }).to(Class.class.cast(IdentityFunction.class)); bind(TemplateOptions.class).to(NovaTemplateOptions.class); diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/config/NovaRestClientModule.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/config/NovaRestClientModule.java index 5fd507692d..35c965838c 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/config/NovaRestClientModule.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/config/NovaRestClientModule.java @@ -30,7 +30,9 @@ 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.location.suppliers.LocationsSupplier; +import org.jclouds.location.suppliers.all.ZoneToProvider; +import org.jclouds.location.suppliers.implicit.FirstZone; import org.jclouds.openstack.nova.v2_0.NovaAsyncClient; import org.jclouds.openstack.nova.v2_0.NovaClient; import org.jclouds.openstack.nova.v2_0.domain.Extension; @@ -125,7 +127,8 @@ public class NovaRestClientModule extends RestClientModule>of(CloudIdentityAuthenticationModuleForZones.class, NovaRestClientModule.class, NovaComputeServiceContextModule.class)) + .defaultModules(ImmutableSet.>of(CloudIdentityAuthenticationModuleForZones.class, NovaRestClientModule.class, CloudServersUSComputeServiceContextModule.class)) .build()) .homepage(URI.create("http://www.rackspace.com/cloud/nextgen")) .console(URI.create("https://mycloud.rackspace.com")) diff --git a/labs/rackspace-cloudservers-us/src/main/java/org/jclouds/rackspace/cloudservers/us/config/CloudServersUSComputeServiceContextModule.java b/labs/rackspace-cloudservers-us/src/main/java/org/jclouds/rackspace/cloudservers/us/config/CloudServersUSComputeServiceContextModule.java new file mode 100644 index 0000000000..c2843374d8 --- /dev/null +++ b/labs/rackspace-cloudservers-us/src/main/java/org/jclouds/rackspace/cloudservers/us/config/CloudServersUSComputeServiceContextModule.java @@ -0,0 +1,45 @@ +/** + * 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.rackspace.cloudservers.us.config; + +import java.util.Map; + +import org.jclouds.compute.domain.OsFamily; +import org.jclouds.domain.LoginCredentials; +import org.jclouds.openstack.nova.v2_0.compute.config.NovaComputeServiceContextModule; + +import com.google.common.collect.ImmutableMap; +import com.google.inject.Injector; + +/** + * + * @author Adrian Cole + */ +public class CloudServersUSComputeServiceContextModule extends NovaComputeServiceContextModule { + + /** + * CloudServers images are accessible via the root user, not ubuntu + */ + @Override + protected Map osFamilyToCredentials(Injector injector) { + return ImmutableMap.of(OsFamily.WINDOWS, LoginCredentials.builder().user("Administrator").build(), + OsFamily.UBUNTU, LoginCredentials.builder().user("root").build()); + } + +} \ No newline at end of file diff --git a/labs/rackspace-cloudservers-us/src/test/java/org/jclouds/rackspace/cloudservers/us/compute/CloudServersUSTemplateBuilderLiveTest.java b/labs/rackspace-cloudservers-us/src/test/java/org/jclouds/rackspace/cloudservers/us/compute/CloudServersUSTemplateBuilderLiveTest.java index f60ce66323..a200418d7a 100644 --- a/labs/rackspace-cloudservers-us/src/test/java/org/jclouds/rackspace/cloudservers/us/compute/CloudServersUSTemplateBuilderLiveTest.java +++ b/labs/rackspace-cloudservers-us/src/test/java/org/jclouds/rackspace/cloudservers/us/compute/CloudServersUSTemplateBuilderLiveTest.java @@ -53,14 +53,16 @@ public class CloudServersUSTemplateBuilderLiveTest extends BaseTemplateBuilderLi public boolean apply(OsFamilyVersion64Bit input) { switch (input.family) { case UBUNTU: - return (input.version.equals("") || (input.version.matches("^1[01].*") && !input.version + return (input.version.equals("") || (input.version.matches("^1[012].*") && !input.version .equals("10.10"))) && input.is64Bit; case DEBIAN: return input.is64Bit && !input.version.equals("5.0"); case CENTOS: - return (input.version.equals("") || input.version.equals("5.6") || input.version.equals("6.0")) + return (input.version.equals("") || input.version.equals("5.0")|| input.version.equals("5.6") || input.version.equals("6.0")) && input.is64Bit; + case WINDOWS: + return input.is64Bit && input.version.equals(""); default: return false; } @@ -73,15 +75,15 @@ public class CloudServersUSTemplateBuilderLiveTest extends BaseTemplateBuilderLi public void testTemplateBuilder() { Template defaultTemplate = this.view.getComputeService().templateBuilder().build(); assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); - assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "11.10"); + assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "12.04"); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); - assertEquals(defaultTemplate.getImage().getName(), "Ubuntu 11.10"); + assertEquals(defaultTemplate.getImage().getName(), "Ubuntu 12.04 LTS"); assertEquals(defaultTemplate.getImage().getDefaultCredentials().getUser(), "root"); assertEquals(defaultTemplate.getLocation().getId(), "DFW"); assertEquals(defaultTemplate.getImage().getLocation().getId(), "DFW"); assertEquals(defaultTemplate.getHardware().getLocation().getId(), "DFW"); - assertEquals(defaultTemplate.getOptions().as(NovaTemplateOptions.class).shouldAutoAssignFloatingIp(), true); - assertEquals(getCores(defaultTemplate.getHardware()), 4.0d); + assertEquals(defaultTemplate.getOptions().as(NovaTemplateOptions.class).shouldAutoAssignFloatingIp(), false); + assertEquals(getCores(defaultTemplate.getHardware()), 1.0d); } @Override diff --git a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/config/HPCloudObjectStorageRestClientModule.java b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/config/HPCloudObjectStorageRestClientModule.java index cf64278291..7452087c0d 100644 --- a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/config/HPCloudObjectStorageRestClientModule.java +++ b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/config/HPCloudObjectStorageRestClientModule.java @@ -31,7 +31,11 @@ import org.jclouds.hpcloud.objectstorage.extensions.HPCloudCDNAsyncClient; import org.jclouds.hpcloud.objectstorage.extensions.HPCloudCDNClient; import org.jclouds.hpcloud.services.HPExtensionCDN; import org.jclouds.hpcloud.services.HPExtensionServiceType; +import org.jclouds.location.suppliers.ImplicitLocationSupplier; +import org.jclouds.location.suppliers.LocationsSupplier; import org.jclouds.location.suppliers.RegionIdToURISupplier; +import org.jclouds.location.suppliers.all.RegionToProvider; +import org.jclouds.location.suppliers.implicit.FirstRegion; import org.jclouds.openstack.swift.CommonSwiftAsyncClient; import org.jclouds.openstack.swift.CommonSwiftClient; import org.jclouds.openstack.swift.config.SwiftRestClientModule; @@ -63,7 +67,14 @@ public class HPCloudObjectStorageRestClientModule extends bind(CommonSwiftClient.class).to(HPCloudObjectStorageClient.class).in(Scopes.SINGLETON); bind(CommonSwiftAsyncClient.class).to(HPCloudObjectStorageAsyncClient.class).in(Scopes.SINGLETON); } - + + @Override + protected void installLocations() { + super.installLocations(); + bind(ImplicitLocationSupplier.class).to(FirstRegion.class).in(Scopes.SINGLETON); + bind(LocationsSupplier.class).to(RegionToProvider.class).in(Scopes.SINGLETON); + } + @Provides @Singleton @HPExtensionCDN