issue 384: cache loader in testutils - to be finished

This commit is contained in:
Andrea Turli 2011-09-23 16:33:08 +01:00
parent b524f7c9f2
commit 863bd2aa7b
1 changed files with 55 additions and 7 deletions

View File

@ -18,9 +18,11 @@
*/
package org.jclouds.virtualbox.experiment;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map;
import org.jclouds.byon.Node;
import org.jclouds.byon.config.CacheNodeStoreModule;
import org.jclouds.compute.ComputeServiceContext;
@ -30,10 +32,11 @@ import org.jclouds.encryption.bouncycastle.config.BouncyCastleCryptoModule;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.jclouds.sshj.config.SshjSshClientModule;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheLoader;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;
public class TestUtils {
public static ComputeServiceContext computeServiceForLocalhost() throws IOException {
@ -66,6 +69,51 @@ public class TestUtils {
new SshjSshClientModule(), new SLF4JLoggingModule(), new BouncyCastleCryptoModule(), new CacheNodeStoreModule(nodeMap)));
}
public static ComputeServiceContext computeServiceForVBox() throws IOException {
Node host = Node.builder().id("host")
.name("host installing virtualbox")
.hostname("localhost")
.osFamily(OsFamily.LINUX.toString())
.osDescription(System.getProperty("os.name"))
.osVersion(System.getProperty("os.version"))
.group("ssh")
.username(System.getProperty("user.name"))
.credentialUrl(privateKeyFile())
.build();
Node guest = Node.builder().id("guest")
.name("new guest")
.hostname("localhost")
.loginPort(2222)
.osFamily(OsFamily.UBUNTU.toString())
.osDescription("ubuntu/11.04")
.osVersion(System.getProperty("11.04"))
.group("guest")
.username("toor")
.sudoPassword("password")
.credential("password")
.build();
final CacheLoader<String, Node> cacheLoader = new CacheLoader<String, Node>() {
/*
* (non-Javadoc)
* @see com.google.common.cache.CacheLoader#load(java.lang.Object)
* this will take the machine from vbox and convert to a node by id
* so you would use vbox/arp commands whatever and then return Node.builder().....
* inside the load method
*/
@Override
public Node load(String instanceName) throws Exception {
// TODO Auto-generated method stub
return null;
}
};
return new ComputeServiceContextFactory().createContext("byon", "foo", "bar", ImmutableSet.<Module>of(
new SshjSshClientModule(), new SLF4JLoggingModule(), new BouncyCastleCryptoModule(), new CacheNodeStoreModule(cacheLoader)));
}
private static URI privateKeyFile() {
try {
return new URI("file://" + System.getProperty("user.home") + "/.ssh/id_rsa");