From 863bd2aa7b45c2dd84b03f39050e005ca4cee384 Mon Sep 17 00:00:00 2001 From: Andrea Turli Date: Fri, 23 Sep 2011 16:33:08 +0100 Subject: [PATCH] issue 384: cache loader in testutils - to be finished --- .../virtualbox/experiment/TestUtils.java | 62 ++++++++++++++++--- 1 file changed, 55 insertions(+), 7 deletions(-) diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/experiment/TestUtils.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/experiment/TestUtils.java index b8513f5f56..3aed31e8cf 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/experiment/TestUtils.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/experiment/TestUtils.java @@ -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 cacheLoader = new CacheLoader() { + /* + * (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.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");