Issue 112: normalized os type

git-svn-id: http://jclouds.googlecode.com/svn/trunk@2299 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-11-17 21:17:03 +00:00
parent f2410e5889
commit 4b43b70a53
4 changed files with 26 additions and 45 deletions

View File

@ -6,7 +6,6 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -16,6 +15,7 @@ import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.TaskStatus; import org.jclouds.vcloud.domain.TaskStatus;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.inject.Inject;
/** /**
* *

View File

@ -2,8 +2,6 @@ package org.jclouds.vcloud.terremark.domain;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.vcloud.VCloudAsyncClient;
/** /**
* *
* VirtualResource such as disks or CPU * VirtualResource such as disks or CPU

View File

@ -86,18 +86,10 @@ public class TerremarkVCloudComputeClientLiveTest {
private Map<Image, Expectation> expectationMap = ImmutableMap.<Image, Expectation> builder() private Map<Image, Expectation> expectationMap = ImmutableMap.<Image, Expectation> builder()
.put(Image.CENTOS_53, .put(Image.CENTOS_53,
new Expectation(4194304 / 4 * 10, "Red Hat Enterprise Linux 5 (32-bit)")).put( new Expectation(4194304 / 4 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).put(
Image.RHEL_53, Image.RHEL_53,
new Expectation(4194304 / 4 * 10, "Red Hat Enterprise Linux 5 (32-bit)")).put(
Image.UMBUNTU_SERVER_90, new Expectation(4194304, "Ubuntu Linux (32-bit)"))
.put(Image.UMBUNTU_JEOS_90, new Expectation(4194304, "Ubuntu Linux (32-bit)")).put(
Image.CENTOS_53_64,
new Expectation(4194304 / 4 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).put( new Expectation(4194304 / 4 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).put(
Image.RHEL_53_64, Image.UMBUNTU_90, new Expectation(4194304, "Ubuntu Linux (64-bit)")).build();
new Expectation(4194304 / 4 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).put(
Image.UMBUNTU_SERVER_90_64, new Expectation(4194304, "Ubuntu Linux (64-bit)"))
.put(Image.UMBUNTU_JEOS_90_64, new Expectation(4194304, "Ubuntu Linux (64-bit)"))
.build();
private InternetService is; private InternetService is;
private Node node; private Node node;
@ -107,7 +99,7 @@ public class TerremarkVCloudComputeClientLiveTest {
@Test @Test
public void testPowerOn() throws InterruptedException, ExecutionException, TimeoutException, public void testPowerOn() throws InterruptedException, ExecutionException, TimeoutException,
IOException { IOException {
Image toTest = Image.CENTOS_53; Image toTest = Image.UMBUNTU_90;
String serverName = getCompatibleServerName(toTest); String serverName = getCompatibleServerName(toTest);
int processorCount = 1; int processorCount = 1;
@ -139,8 +131,8 @@ public class TerremarkVCloudComputeClientLiveTest {
is = tmClient.addInternetService("SSH", "TCP", 22); is = tmClient.addInternetService("SSH", "TCP", 22);
node = tmClient.addNode(is.getId(), privateAddress, id + "-SSH", 22); node = tmClient.addNode(is.getId(), privateAddress, id + "-SSH", 22);
publicIp = is.getPublicIpAddress().getAddress(); publicIp = is.getPublicIpAddress().getAddress();
assert addressTester.apply(publicIp); // assert addressTester.apply(publicIp);
client.testSsh(publicIp); client.exec(publicIp, "uname -a");
} }
private void verifyConfigurationOfVApp(VApp vApp, String serverName, String expectedOs, private void verifyConfigurationOfVApp(VApp vApp, String serverName, String expectedOs,
@ -192,8 +184,8 @@ public class TerremarkVCloudComputeClientLiveTest {
@SuppressWarnings("unused") @SuppressWarnings("unused")
@Provides @Provides
private Predicate<InetAddress> addressTester(AddressReachable open) { private Predicate<InetAddress> addressTester(AddressReachable reachable) {
return open; return new RetryablePredicate<InetAddress>(reachable, 60, 5, TimeUnit.SECONDS);
} }
@SuppressWarnings("unused") @SuppressWarnings("unused")

View File

@ -34,6 +34,7 @@ import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.ssh.ExecResponse;
import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshClient;
import org.jclouds.ssh.SshClient.Factory; import org.jclouds.ssh.SshClient.Factory;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
@ -41,11 +42,9 @@ import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.terremark.domain.VApp; import org.jclouds.vcloud.terremark.domain.VApp;
import org.jclouds.vcloud.terremark.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.terremark.options.InstantiateVAppTemplateOptions;
import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.MapMaker;
/** /**
* *
@ -71,31 +70,18 @@ public class VCloudComputeClient {
private final Factory sshFactory; private final Factory sshFactory;
public enum Image { public enum Image {
CENTOS_53, CENTOS_53_64, RHEL_53, RHEL_53_64, UMBUNTU_JEOS_90, UMBUNTU_JEOS_90_64, UMBUNTU_SERVER_90, UMBUNTU_SERVER_90_64 CENTOS_53, RHEL_53, UMBUNTU_90
} }
private Map<Image, String> imageCatalogNameMap = ImmutableMap.<Image, String> builder().put( private Map<Image, String> imageCatalogIdMap = ImmutableMap.<Image, String> builder().put(
Image.CENTOS_53, "CentOS 5.3 (32-bit)").put(Image.RHEL_53, "RHEL 5.3 (32-bit)").put( Image.CENTOS_53, "6").put(Image.RHEL_53, "8").put(Image.UMBUNTU_90, "10").build();
Image.UMBUNTU_JEOS_90, "Ubuntu JeOS 9.04 (32-bit)").put(Image.UMBUNTU_SERVER_90,
"Ubuntu Server 9.04 (64-bit)").put(Image.CENTOS_53_64, "CentOS 5.3 (64-bit)").put(
Image.RHEL_53_64, "RHEL 5.3 (64-bit)").put(Image.UMBUNTU_JEOS_90_64,
"Ubuntu JeOS 9.04 (64-bit)").put(Image.UMBUNTU_SERVER_90_64,
"Ubuntu Server 9.04 (64-bit)").build();
private Map<String, String> catalogNameTemplateIdMap = new MapMaker()
.makeComputingMap(new Function<String, String>() {
@Override
public String apply(String from) {
return tmClient.getCatalog().get(from).getId();
}
});
public String start(String name, int minCores, int minMegs, Image image) { public String start(String name, int minCores, int minMegs, Image image) {
checkArgument(imageCatalogNameMap.containsKey(image), "image not configured: " + image); checkArgument(imageCatalogIdMap.containsKey(image), "image not configured: " + image);
String templateId = catalogNameTemplateIdMap.get(imageCatalogNameMap.get(image)); String templateId = imageCatalogIdMap.get(image);
logger.debug(">> instantiating vApp name(%s) minCores(%d) minMegs(%d) image(%s)", name, logger.debug(">> instantiating vApp name(%s) minCores(%d) minMegs(%d) template(%s)", name,
minCores, minMegs, image); minCores, minMegs, templateId);
VApp vApp = tmClient.instantiateVAppTemplate(name, templateId, VApp vApp = tmClient.instantiateVAppTemplate(name, templateId,
InstantiateVAppTemplateOptions.Builder.cpuCount(minCores).megabytes(minMegs)); InstantiateVAppTemplateOptions.Builder.cpuCount(minCores).megabytes(minMegs));
logger.debug("<< instantiated VApp(%s)", vApp.getId()); logger.debug("<< instantiated VApp(%s)", vApp.getId());
@ -123,11 +109,14 @@ public class VCloudComputeClient {
return Iterables.getLast(vApp.getNetworkToAddresses().values()); return Iterables.getLast(vApp.getNetworkToAddresses().values());
} }
public void testSsh(InetAddress address) { public ExecResponse exec(InetAddress address, String command) {
InetSocketAddress sshSocket = new InetSocketAddress(address, 22); InetSocketAddress sshSocket = new InetSocketAddress(address, 22);
logger.debug(">> sshConnect socket(%s)", sshSocket); String username = "vcloud";
checkSsh(sshSocket, "vcloud", "p4ssw0rd"); String password = "p4ssw0rd";
logger.debug("<< sshOk socket(%s)", sshSocket); logger.debug(">> exec ssh://%s@%s/%s", username, sshSocket, command);
ExecResponse exec = exec(sshSocket, username, password, command);
logger.debug("<< output(%s) error(%s)", exec.getOutput(), exec.getError());
return exec;
} }
public void reboot(String id) { public void reboot(String id) {
@ -151,13 +140,15 @@ public class VCloudComputeClient {
logger.debug("<< deleted vApp(%s)", vApp.getId()); logger.debug("<< deleted vApp(%s)", vApp.getId());
} }
private void checkSsh(InetSocketAddress socket, String username, String password) { private ExecResponse exec(InetSocketAddress socket, String username, String password,
String command) {
if (!socketTester.apply(socket)) { if (!socketTester.apply(socket)) {
throw new SocketNotOpenException(socket); throw new SocketNotOpenException(socket);
} }
SshClient connection = sshFactory.create(socket, username, password); SshClient connection = sshFactory.create(socket, username, password);
try { try {
connection.connect(); connection.connect();
return connection.exec(command);
} finally { } finally {
if (connection != null) if (connection != null)
connection.disconnect(); connection.disconnect();