mirror of https://github.com/apache/jclouds.git
added multi-vdc images to vcloud
This commit is contained in:
parent
ea8bb3f454
commit
99cc8000e8
|
@ -29,9 +29,15 @@ import org.jclouds.compute.domain.Image;
|
||||||
import org.jclouds.compute.domain.Template;
|
import org.jclouds.compute.domain.Template;
|
||||||
import org.jclouds.compute.domain.TemplateBuilder;
|
import org.jclouds.compute.domain.TemplateBuilder;
|
||||||
import org.jclouds.ssh.jsch.config.JschSshClientModule;
|
import org.jclouds.ssh.jsch.config.JschSshClientModule;
|
||||||
|
import org.jclouds.vcloud.VCloudClient;
|
||||||
|
import org.jclouds.vcloud.VCloudMediaType;
|
||||||
|
import org.jclouds.vcloud.domain.NamedResource;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
@ -80,4 +86,28 @@ public class BlueLockVCloudComputeServiceLiveTest extends BaseComputeServiceLive
|
||||||
public void testReboot() throws Exception {
|
public void testReboot() throws Exception {
|
||||||
super.testReboot();
|
super.testReboot();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testExample() throws Exception {
|
||||||
|
|
||||||
|
// get a synchronous object to use for manipulating vcloud objects in BlueLock
|
||||||
|
VCloudClient bluelockClient = VCloudClient.class.cast(context.getProviderSpecificContext()
|
||||||
|
.getApi());
|
||||||
|
|
||||||
|
// look at only vApp templates in my default vDC
|
||||||
|
Map<String, NamedResource> vAppTemplatesByName = Maps.filterValues(bluelockClient
|
||||||
|
.getDefaultVDC().getResourceEntities(), new Predicate<NamedResource>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(NamedResource input) {
|
||||||
|
return input.getType().equals(VCloudMediaType.VAPPTEMPLATE_XML);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
// get details on a specific template I know by name
|
||||||
|
bluelockClient.getVAppTemplate(vAppTemplatesByName
|
||||||
|
.get("Ubuntu904Serverx64 1CPUx1GBx20GB a01").getId());
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -293,44 +293,44 @@ public class VCloudComputeServiceContextModule extends VCloudContextModule {
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
protected Map<String, ? extends Image> provideImages(final VCloudClient client,
|
protected Map<String, ? extends Image> provideImages(final VCloudClient client,
|
||||||
final Location vDC, LogHolder holder,
|
LogHolder holder, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor,
|
||||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor,
|
|
||||||
Function<ComputeMetadata, String> indexer) throws InterruptedException,
|
Function<ComputeMetadata, String> indexer) throws InterruptedException,
|
||||||
ExecutionException, TimeoutException {
|
ExecutionException, TimeoutException {
|
||||||
// TODO multi-VDC
|
|
||||||
final Set<Image> images = Sets.newHashSet();
|
final Set<Image> images = Sets.newHashSet();
|
||||||
holder.logger.debug(">> providing images");
|
holder.logger.debug(">> providing vAppTemplates");
|
||||||
Map<String, NamedResource> resources = client.getDefaultVDC().getResourceEntities();
|
for (final NamedResource vDC : client.getDefaultOrganization().getVDCs().values()) {
|
||||||
Map<String, ListenableFuture<Void>> responses = Maps.newHashMap();
|
Map<String, NamedResource> resources = client.getVDC(vDC.getId()).getResourceEntities();
|
||||||
|
Map<String, ListenableFuture<Void>> responses = Maps.newHashMap();
|
||||||
|
|
||||||
for (final NamedResource resource : resources.values()) {
|
for (final NamedResource resource : resources.values()) {
|
||||||
if (resource.getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) {
|
if (resource.getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) {
|
||||||
responses.put(resource.getName(), ConcurrentUtils.makeListenable(executor
|
responses.put(resource.getName(), ConcurrentUtils.makeListenable(executor
|
||||||
.submit(new Callable<Void>() {
|
.submit(new Callable<Void>() {
|
||||||
@Override
|
@Override
|
||||||
public Void call() throws Exception {
|
public Void call() throws Exception {
|
||||||
OsFamily myOs = null;
|
OsFamily myOs = null;
|
||||||
for (OsFamily os : OsFamily.values()) {
|
for (OsFamily os : OsFamily.values()) {
|
||||||
if (resource.getName().toLowerCase().replaceAll("\\s", "").indexOf(
|
if (resource.getName().toLowerCase().replaceAll("\\s", "")
|
||||||
os.toString()) != -1) {
|
.indexOf(os.toString()) != -1) {
|
||||||
myOs = os;
|
myOs = os;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Architecture arch = resource.getName().indexOf("64") == -1 ? Architecture.X86_32
|
||||||
|
: Architecture.X86_64;
|
||||||
|
VAppTemplate template = client.getVAppTemplate(resource.getId());
|
||||||
|
images.add(new ImageImpl(resource.getId(), template.getName(), vDC
|
||||||
|
.getId(), template.getLocation(), ImmutableMap
|
||||||
|
.<String, String> of(), template.getDescription(), "", myOs,
|
||||||
|
template.getName(), arch));
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
Architecture arch = resource.getName().indexOf("64") == -1 ? Architecture.X86_32
|
}), executor));
|
||||||
: Architecture.X86_64;
|
|
||||||
VAppTemplate template = client.getVAppTemplate(resource.getId());
|
|
||||||
images.add(new ImageImpl(resource.getId(), template.getName(), vDC
|
|
||||||
.getId(), template.getLocation(), ImmutableMap
|
|
||||||
.<String, String> of(), template.getDescription(), "", myOs,
|
|
||||||
template.getName(), arch));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}), executor));
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
ConcurrentUtils.awaitCompletion(responses, executor, null, holder.logger,
|
||||||
|
"vAppTemplates in " + vDC);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConcurrentUtils.awaitCompletion(responses, executor, null, holder.logger, "images");
|
|
||||||
return Maps.uniqueIndex(images, indexer);
|
return Maps.uniqueIndex(images, indexer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -136,7 +136,7 @@ public class VCloudComputeClientLiveTest {
|
||||||
if (id != null)
|
if (id != null)
|
||||||
computeClient.stop(id);
|
computeClient.stop(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeGroups(groups = { "live" })
|
@BeforeGroups(groups = { "live" })
|
||||||
public void setupClient() {
|
public void setupClient() {
|
||||||
String account = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
|
String account = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
|
||||||
|
|
|
@ -49,5 +49,24 @@ public class HostingDotComVCloudComputeServiceLiveTest extends BaseComputeServic
|
||||||
protected JschSshClientModule getSshModule() {
|
protected JschSshClientModule getSshModule() {
|
||||||
return new JschSshClientModule();
|
return new JschSshClientModule();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// //Takes too long
|
||||||
|
// @Override
|
||||||
|
// @Test(enabled = false)
|
||||||
|
// public void testCreate() throws Exception {
|
||||||
|
// super.testCreate();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// @Test(enabled = false)
|
||||||
|
// public void testGet() throws Exception {
|
||||||
|
// super.testGet();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// @Test(enabled = false)
|
||||||
|
// public void testReboot() throws Exception {
|
||||||
|
// super.testReboot();
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
|
@ -19,7 +19,9 @@
|
||||||
package org.jclouds.vcloud.terremark.compute.config;
|
package org.jclouds.vcloud.terremark.compute.config;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
@ -30,11 +32,20 @@ import org.jclouds.Constants;
|
||||||
import org.jclouds.compute.domain.Architecture;
|
import org.jclouds.compute.domain.Architecture;
|
||||||
import org.jclouds.compute.domain.ComputeMetadata;
|
import org.jclouds.compute.domain.ComputeMetadata;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
|
import org.jclouds.compute.domain.OsFamily;
|
||||||
import org.jclouds.compute.domain.Size;
|
import org.jclouds.compute.domain.Size;
|
||||||
|
import org.jclouds.compute.domain.internal.ImageImpl;
|
||||||
import org.jclouds.compute.domain.internal.SizeImpl;
|
import org.jclouds.compute.domain.internal.SizeImpl;
|
||||||
|
import org.jclouds.concurrent.ConcurrentUtils;
|
||||||
import org.jclouds.vcloud.VCloudClient;
|
import org.jclouds.vcloud.VCloudClient;
|
||||||
|
import org.jclouds.vcloud.VCloudMediaType;
|
||||||
import org.jclouds.vcloud.compute.VCloudComputeClient;
|
import org.jclouds.vcloud.compute.VCloudComputeClient;
|
||||||
import org.jclouds.vcloud.compute.config.VCloudComputeServiceContextModule;
|
import org.jclouds.vcloud.compute.config.VCloudComputeServiceContextModule;
|
||||||
|
import org.jclouds.vcloud.domain.Catalog;
|
||||||
|
import org.jclouds.vcloud.domain.CatalogItem;
|
||||||
|
import org.jclouds.vcloud.domain.NamedResource;
|
||||||
|
import org.jclouds.vcloud.domain.VAppTemplate;
|
||||||
|
import org.jclouds.vcloud.domain.VDC;
|
||||||
import org.jclouds.vcloud.terremark.TerremarkVCloudClient;
|
import org.jclouds.vcloud.terremark.TerremarkVCloudClient;
|
||||||
import org.jclouds.vcloud.terremark.compute.TerremarkVCloudComputeClient;
|
import org.jclouds.vcloud.terremark.compute.TerremarkVCloudComputeClient;
|
||||||
import org.jclouds.vcloud.terremark.domain.ComputeOptions;
|
import org.jclouds.vcloud.terremark.domain.ComputeOptions;
|
||||||
|
@ -45,6 +56,7 @@ import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures the {@link TerremarkVCloudComputeServiceContext}; requires
|
* Configures the {@link TerremarkVCloudComputeServiceContext}; requires
|
||||||
|
@ -71,6 +83,56 @@ public class TerremarkVCloudComputeServiceContextModule extends VCloudComputeSer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Terremark does not provide vApp templates in the vDC resourceEntity list. Rather, you must
|
||||||
|
* query the catalog.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected Map<String, ? extends Image> provideImages(final VCloudClient client,
|
||||||
|
LogHolder holder, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor,
|
||||||
|
Function<ComputeMetadata, String> indexer) throws InterruptedException,
|
||||||
|
ExecutionException, TimeoutException {
|
||||||
|
final Set<Image> images = Sets.newHashSet();
|
||||||
|
holder.logger.debug(">> providing vAppTemplates");
|
||||||
|
final VDC vDC = client.getDefaultVDC();
|
||||||
|
|
||||||
|
Catalog response = client.getDefaultCatalog();
|
||||||
|
Map<String, ListenableFuture<Void>> responses = Maps.newHashMap();
|
||||||
|
|
||||||
|
for (final NamedResource resource : response.values()) {
|
||||||
|
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
|
||||||
|
final CatalogItem item = client.getCatalogItem(resource.getId());
|
||||||
|
if (item.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) {
|
||||||
|
responses.put(item.getName(), ConcurrentUtils.makeListenable(executor
|
||||||
|
.submit(new Callable<Void>() {
|
||||||
|
@Override
|
||||||
|
public Void call() throws Exception {
|
||||||
|
OsFamily myOs = null;
|
||||||
|
for (OsFamily os : OsFamily.values()) {
|
||||||
|
if (resource.getName().toLowerCase().replaceAll("\\s", "")
|
||||||
|
.indexOf(os.toString()) != -1) {
|
||||||
|
myOs = os;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Architecture arch = resource.getName().indexOf("64") == -1 ? Architecture.X86_32
|
||||||
|
: Architecture.X86_64;
|
||||||
|
VAppTemplate template = client.getVAppTemplate(item.getEntity()
|
||||||
|
.getId());
|
||||||
|
images.add(new ImageImpl(resource.getId(), template.getName(), vDC
|
||||||
|
.getId(), template.getLocation(), ImmutableMap
|
||||||
|
.<String, String> of(), template.getDescription(), "", myOs,
|
||||||
|
template.getName(), arch));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}), executor));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ConcurrentUtils.awaitCompletion(responses, executor, null, holder.logger, "vAppTemplates in "
|
||||||
|
+ vDC);
|
||||||
|
return Maps.uniqueIndex(images, indexer);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Map<String, ? extends Size> provideSizes(Function<ComputeMetadata, String> indexer,
|
protected Map<String, ? extends Size> provideSizes(Function<ComputeMetadata, String> indexer,
|
||||||
VCloudClient client, Map<String, ? extends Image> images, LogHolder holder,
|
VCloudClient client, Map<String, ? extends Image> images, LogHolder holder,
|
||||||
|
|
Loading…
Reference in New Issue