mirror of https://github.com/apache/jclouds.git
stuck on adapter problems
This commit is contained in:
parent
d0b4d81f9f
commit
3a4cd0b4bc
|
@ -62,6 +62,7 @@ import org.jclouds.virtualbox.domain.ExecutionType;
|
|||
import org.jclouds.virtualbox.domain.IsoSpec;
|
||||
import org.jclouds.virtualbox.domain.Master;
|
||||
import org.jclouds.virtualbox.domain.MasterSpec;
|
||||
import org.jclouds.virtualbox.domain.NodeSpec;
|
||||
import org.jclouds.virtualbox.domain.YamlImage;
|
||||
import org.jclouds.virtualbox.functions.CloneAndRegisterMachineFromIMachineIfNotAlreadyExists;
|
||||
import org.jclouds.virtualbox.functions.CreateAndInstallVm;
|
||||
|
@ -140,7 +141,7 @@ public class VirtualBoxComputeServiceContextModule extends
|
|||
bind(new TypeLiteral<Function<MasterSpec, IMachine>>() {
|
||||
}).to((Class) CreateAndInstallVm.class);
|
||||
// the machine cloning function
|
||||
bind(new TypeLiteral<Function<IMachine, NodeAndInitialCredentials<IMachine>>>() {
|
||||
bind(new TypeLiteral<Function<NodeSpec, NodeAndInitialCredentials<IMachine>>>() {
|
||||
}).to((Class) NodeCreator.class);
|
||||
bind(new TypeLiteral<Function<CloneSpec, IMachine>>() {
|
||||
}).to((Class) CloneAndRegisterMachineFromIMachineIfNotAlreadyExists.class);
|
||||
|
|
|
@ -64,7 +64,7 @@ public class VmSpec {
|
|||
private String name;
|
||||
private String id;
|
||||
private String osTypeId = "";
|
||||
private boolean forceOverwrite;
|
||||
private boolean forceOverwrite = true;
|
||||
private long memory;
|
||||
private CleanupMode cleanUpMode;
|
||||
|
||||
|
|
|
@ -118,7 +118,7 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExists implements
|
|||
IProgress progress = currentSnapshot.getMachine().cloneTo(
|
||||
clonedMachine, CloneMode.MachineState, options);
|
||||
|
||||
if (progress.getCompleted())
|
||||
progress.waitForCompletion(-1);
|
||||
logger.debug("clone done");
|
||||
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
package org.jclouds.virtualbox.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Named;
|
||||
|
@ -32,9 +31,6 @@ import org.jclouds.net.IPSocket;
|
|||
import org.jclouds.ssh.SshClient;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.INetworkAdapter;
|
||||
import org.virtualbox_4_1.ISystemProperties;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
import org.virtualbox_4_1.jaxws.ISystemPropertiesGetMaxNetworkAdapters;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Splitter;
|
||||
|
@ -69,7 +65,6 @@ public class IMachineToSshClient implements Function<IMachine, SshClient> {
|
|||
String targetPort = Iterables.get(stuff, 5);
|
||||
// TODO: we need a way to align the default login credentials from the iso with the
|
||||
// vmspec
|
||||
logger.warn("PROTOCOLNUMBER: "+nameProtocolnumberAddressInboudportGuestTargetport);
|
||||
if ("1".equals(protocolNumber) && "22".equals(targetPort)) {
|
||||
client = sshClientFactory.create(new IPSocket(hostAddress, Integer.parseInt(inboundPort)),
|
||||
LoginCredentials.builder().user("toor").password("password").authenticateSudo(true).build());
|
||||
|
|
|
@ -151,13 +151,16 @@ public class MastersCache extends AbstractLoadingCache<Image, Master> {
|
|||
|
||||
// try and find a master machine in vbox
|
||||
try {
|
||||
masterMachine = manager.get().getVBox().findMachine(masterSpec.getVmSpec().getVmId());
|
||||
masterMachine = manager.get().getVBox().findMachine(vmName);
|
||||
} catch (VBoxException e) {
|
||||
if (machineNotFoundException(e))
|
||||
if (machineNotFoundException(e)) {
|
||||
// create the master machine if it can't be found
|
||||
masterMachine = masterCreatorAndInstaller.apply(masterSpec);
|
||||
else
|
||||
}
|
||||
else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
Master master = Master.builder().machine(masterMachine).spec(masterSpec).build();
|
||||
|
||||
|
|
|
@ -19,19 +19,32 @@
|
|||
|
||||
package org.jclouds.virtualbox.functions;
|
||||
|
||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX;
|
||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_NODE_PREFIX;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.ComputeServiceAdapter.NodeAndInitialCredentials;
|
||||
import org.jclouds.domain.LoginCredentials;
|
||||
import org.jclouds.virtualbox.domain.CloneSpec;
|
||||
import org.jclouds.virtualbox.domain.ExecutionType;
|
||||
import org.jclouds.virtualbox.domain.Master;
|
||||
import org.jclouds.virtualbox.domain.NetworkAdapter;
|
||||
import org.jclouds.virtualbox.domain.NetworkInterfaceCard;
|
||||
import org.jclouds.virtualbox.domain.NetworkSpec;
|
||||
import org.jclouds.virtualbox.domain.NodeSpec;
|
||||
import org.jclouds.virtualbox.domain.VmSpec;
|
||||
import org.virtualbox_4_1.CleanupMode;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.ISession;
|
||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
|
||||
@Singleton
|
||||
public class NodeCreator implements Function<NodeSpec, NodeAndInitialCredentials<IMachine>> {
|
||||
|
||||
private final Supplier<VirtualBoxManager> manager;
|
||||
|
@ -49,12 +62,42 @@ public class NodeCreator implements Function<NodeSpec, NodeAndInitialCredentials
|
|||
Master master = nodeSpec.getMaster();
|
||||
|
||||
if (master.getMachine().getCurrentSnapshot() != null) {
|
||||
ISession session = manager.get().openMachineSession(master.getMachine());
|
||||
ISession session;
|
||||
try {
|
||||
session = manager.get().openMachineSession(master.getMachine());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("error opening vbox machine session: " + e.getMessage(), e);
|
||||
}
|
||||
session.getConsole().deleteSnapshot(master.getMachine().getCurrentSnapshot().getId());
|
||||
session.unlockMachine();
|
||||
}
|
||||
String masterNameWithoutPrefix = master.getSpec().getVmSpec().getVmName().replace(VIRTUALBOX_IMAGE_PREFIX, "");
|
||||
|
||||
String cloneName = VIRTUALBOX_NODE_PREFIX + masterNameWithoutPrefix + "-" + nodeSpec.getTag() + "-"
|
||||
+ nodeSpec.getName();
|
||||
|
||||
VmSpec cloneVmSpec = VmSpec.builder().id(cloneName).name(cloneName).memoryMB(512).cleanUpMode(CleanupMode.Full)
|
||||
.forceOverwrite(true).build();
|
||||
|
||||
NetworkAdapter networkAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.Bridged)
|
||||
.build();
|
||||
|
||||
NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(networkAdapter)
|
||||
.build();
|
||||
|
||||
NetworkSpec cloneNetworkSpec = NetworkSpec.builder().addNIC(0L, networkInterfaceCard).build();
|
||||
|
||||
CloneSpec cloneSpec = CloneSpec.builder().linked(true).master(master.getMachine())
|
||||
.network(cloneNetworkSpec).vm(cloneVmSpec).build();
|
||||
|
||||
IMachine cloned = cloner.apply(cloneSpec);
|
||||
|
||||
new LaunchMachineIfNotAlreadyRunning(manager.get(), ExecutionType.GUI, "").apply(cloned);
|
||||
|
||||
// TODO get credentials from somewhere else (they are also HC in IMachineToSshClient)
|
||||
NodeAndInitialCredentials<IMachine> nodeAndInitialCredentials = new NodeAndInitialCredentials<IMachine>(cloned,
|
||||
cloneName, LoginCredentials.builder().user("toor").password("password").authenticateSudo(true).build());
|
||||
|
||||
return nodeAndInitialCredentials;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,9 @@ import org.jclouds.compute.ComputeServiceContext;
|
|||
import org.jclouds.compute.ComputeServiceContextFactory;
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.OsFamily;
|
||||
import org.jclouds.compute.functions.DefaultCredentialsFromImageOrOverridingCredentials;
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.compute.strategy.PrioritizeCredentialsFromTemplate;
|
||||
import org.jclouds.config.ValueOfConfigurationKeyOrNull;
|
||||
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
|
||||
import org.jclouds.sshj.config.SshjSshClientModule;
|
||||
|
@ -82,6 +84,8 @@ public class BaseVirtualBoxClientLiveTest extends BaseVersionedServiceLiveTest {
|
|||
protected String workingDir;
|
||||
protected String isosDir;
|
||||
protected Supplier<NodeMetadata> host;
|
||||
protected static final PrioritizeCredentialsFromTemplate prioritizeCredentialsFromTemplate = new PrioritizeCredentialsFromTemplate(
|
||||
new DefaultCredentialsFromImageOrOverridingCredentials());
|
||||
|
||||
@Override
|
||||
protected void setupCredentials() {
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.jclouds.virtualbox.compute;
|
||||
|
||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_NODE_PREFIX;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import org.jclouds.compute.ComputeServiceAdapter.NodeAndInitialCredentials;
|
||||
|
@ -31,12 +32,9 @@ import org.jclouds.domain.LoginCredentials;
|
|||
import org.jclouds.net.IPSocket;
|
||||
import org.jclouds.ssh.SshClient;
|
||||
import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
|
||||
import org.jclouds.virtualbox.domain.VmSpec;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
@Test(groups = "live", singleThreaded = true, testName = "VirtualBoxComputeServiceAdapterLiveTest")
|
||||
|
@ -51,20 +49,17 @@ public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClien
|
|||
adapter = context.utils().injector().getInstance(VirtualBoxComputeServiceAdapter.class);
|
||||
}
|
||||
|
||||
private static final PrioritizeCredentialsFromTemplate prioritizeCredentialsFromTemplate = new PrioritizeCredentialsFromTemplate(
|
||||
new DefaultCredentialsFromImageOrOverridingCredentials());
|
||||
|
||||
@Test
|
||||
public void testCreateNodeWithGroupEncodedIntoNameThenStoreCredentials() {
|
||||
String group = "foo";
|
||||
String name = "foo-ef4";
|
||||
String machineName = VIRTUALBOX_NODE_PREFIX + "myTestId-" + group + "-" + name;
|
||||
// get the image from
|
||||
Image image = Iterables.get(adapter.listImages(),0);
|
||||
Image image = Iterables.get(adapter.listImages(), 0);
|
||||
System.out.println(context.getComputeService().templateBuilder());
|
||||
Template template = context.getComputeService().templateBuilder().fromImage(image).build();
|
||||
machine = adapter.createNodeWithGroupEncodedIntoName(group, name, template);
|
||||
assertEquals(machine.getNode().getName(), name);
|
||||
assertEquals(machine.getNodeId(), machine.getNode().getId());
|
||||
assertEquals(machine.getNode().getName(), machineName);
|
||||
// is there a place for group?
|
||||
// check other things, like cpu correct, mem correct, image/os is correct
|
||||
// (as possible)
|
||||
|
@ -73,7 +68,6 @@ public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClien
|
|||
// InetAddresses.isInetAddress(machine.getPrimaryBackendIpAddress()) :
|
||||
// machine;
|
||||
doConnectViaSsh(machine.getNode(), prioritizeCredentialsFromTemplate.apply(template, machine.getCredentials()));
|
||||
|
||||
}
|
||||
|
||||
protected void doConnectViaSsh(IMachine machine, LoginCredentials creds) {
|
||||
|
@ -94,7 +88,7 @@ public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClien
|
|||
@Test
|
||||
public void testListHardwareProfiles() {
|
||||
Iterable<IMachine> profiles = adapter.listHardwareProfiles();
|
||||
assertEquals(1,Iterables.size(profiles));
|
||||
assertEquals(1, Iterables.size(profiles));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -109,7 +103,7 @@ public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClien
|
|||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
if (machine != null)
|
||||
adapter.destroyNode(machine.getNodeId() + "");
|
||||
// adapter.destroyNode(machine.getNodeId() + "");
|
||||
super.tearDown();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import static org.testng.Assert.assertEquals;
|
|||
import org.jclouds.config.ValueOfConfigurationKeyOrNull;
|
||||
import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
|
||||
import org.jclouds.virtualbox.domain.CloneSpec;
|
||||
import org.jclouds.virtualbox.domain.ExecutionType;
|
||||
import org.jclouds.virtualbox.domain.HardDisk;
|
||||
import org.jclouds.virtualbox.domain.IsoSpec;
|
||||
import org.jclouds.virtualbox.domain.MasterSpec;
|
||||
|
@ -139,6 +140,11 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExistsLiveTest exten
|
|||
IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(
|
||||
manager, workingDir,machineUtils).apply(cloneSpec);
|
||||
assertEquals(clone.getName(), cloneSpec.getVmSpec().getVmName());
|
||||
|
||||
new LaunchMachineIfNotAlreadyRunning(manager.get(), ExecutionType.GUI, "").apply(clone);
|
||||
|
||||
// TODO ssh into the node
|
||||
|
||||
} finally {
|
||||
for (VmSpec spec : ImmutableSet.of(cloneSpec.getVmSpec(),
|
||||
sourceMachineSpec.getVmSpec()))
|
||||
|
|
|
@ -61,63 +61,50 @@ public class IMachinePredicatesLiveTest extends BaseVirtualBoxClientLiveTest {
|
|||
private String vmName;
|
||||
private StorageController masterStorageController;
|
||||
private MasterSpec masterMachineSpec;
|
||||
private NetworkSpec networkSpec;
|
||||
private CloneSpec cloneSpec;
|
||||
|
||||
@Override
|
||||
@BeforeClass(groups = "live")
|
||||
public void setupClient() {
|
||||
super.setupClient();
|
||||
vmName = VIRTUALBOX_IMAGE_PREFIX
|
||||
+ CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, getClass()
|
||||
.getSimpleName());
|
||||
vmName = VIRTUALBOX_IMAGE_PREFIX + CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, getClass().getSimpleName());
|
||||
|
||||
cloneName = VIRTUALBOX_IMAGE_PREFIX
|
||||
+ "Clone#"
|
||||
+ CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, getClass()
|
||||
.getSimpleName());
|
||||
cloneName = VIRTUALBOX_IMAGE_PREFIX + "Clone#"
|
||||
+ CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, getClass().getSimpleName());
|
||||
|
||||
HardDisk hardDisk = HardDisk.builder().diskpath(adminDisk)
|
||||
.autoDelete(true).controllerPort(0).deviceSlot(1).build();
|
||||
masterStorageController = StorageController.builder()
|
||||
.name(ideControllerName).bus(StorageBus.IDE)
|
||||
.attachISO(0, 0, operatingSystemIso).attachHardDisk(hardDisk)
|
||||
.attachISO(1, 1, guestAdditionsIso).build();
|
||||
VmSpec masterSpec = VmSpec.builder().id(vmName).name(vmName)
|
||||
.memoryMB(512).osTypeId(osTypeId)
|
||||
.controller(masterStorageController).forceOverwrite(true)
|
||||
.cleanUpMode(CleanupMode.Full).build();
|
||||
masterMachineSpec = MasterSpec
|
||||
.builder()
|
||||
.iso(IsoSpec.builder().sourcePath(operatingSystemIso)
|
||||
.installationScript("").build()).vm(masterSpec)
|
||||
HardDisk hardDisk = HardDisk.builder().diskpath(adminDisk).autoDelete(true).controllerPort(0).deviceSlot(1).build();
|
||||
masterStorageController = StorageController.builder().name(ideControllerName).bus(StorageBus.IDE)
|
||||
.attachISO(0, 0, operatingSystemIso).attachHardDisk(hardDisk).attachISO(1, 1, guestAdditionsIso).build();
|
||||
VmSpec masterSpec = VmSpec.builder().id(vmName).name(vmName).memoryMB(512).osTypeId(osTypeId)
|
||||
.controller(masterStorageController).forceOverwrite(true).cleanUpMode(CleanupMode.Full).build();
|
||||
masterMachineSpec = MasterSpec.builder()
|
||||
.iso(IsoSpec.builder().sourcePath(operatingSystemIso).installationScript("").build()).vm(masterSpec)
|
||||
.network(NetworkSpec.builder().build()).build();
|
||||
|
||||
NetworkAdapter networkAdapter = NetworkAdapter.builder()
|
||||
.networkAttachmentType(NetworkAttachmentType.Bridged).build();
|
||||
NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard
|
||||
.builder().addNetworkAdapter(networkAdapter).build();
|
||||
|
||||
NetworkSpec networkSpec = NetworkSpec.builder()
|
||||
.addNIC(0L, networkInterfaceCard).build();
|
||||
|
||||
VmSpec clonedVmSpec = VmSpec.builder().id(cloneName).name(cloneName)
|
||||
.memoryMB(512).cleanUpMode(CleanupMode.Full)
|
||||
.forceOverwrite(true).build();
|
||||
|
||||
cloneSpec = CloneSpec.builder().vm(clonedVmSpec).network(networkSpec)
|
||||
NetworkAdapter networkAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.Bridged)
|
||||
.build();
|
||||
NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(networkAdapter)
|
||||
.build();
|
||||
|
||||
this.networkSpec = NetworkSpec.builder().addNIC(0L, networkInterfaceCard).build();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLinkedClone() {
|
||||
|
||||
Injector injector = context.utils().injector();
|
||||
IMachine master = injector.getInstance(
|
||||
CreateAndRegisterMachineFromIsoIfNotAlreadyExists.class).apply(
|
||||
IMachine master = injector.getInstance(CreateAndRegisterMachineFromIsoIfNotAlreadyExists.class).apply(
|
||||
masterMachineSpec);
|
||||
IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(
|
||||
manager, workingDir, cloneSpec, true, machineUtils)
|
||||
.apply(master);
|
||||
|
||||
VmSpec clonedVmSpec = VmSpec.builder().id(cloneName).name(cloneName).memoryMB(512).cleanUpMode(CleanupMode.Full)
|
||||
.forceOverwrite(true).build();
|
||||
|
||||
this.cloneSpec = CloneSpec.builder().vm(clonedVmSpec).network(networkSpec).master(master).linked(true).build();
|
||||
|
||||
IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(manager, workingDir, machineUtils)
|
||||
.apply(cloneSpec);
|
||||
|
||||
assertTrue(isLinkedClone().apply(clone));
|
||||
}
|
||||
|
@ -125,8 +112,7 @@ public class IMachinePredicatesLiveTest extends BaseVirtualBoxClientLiveTest {
|
|||
@BeforeMethod
|
||||
@AfterMethod
|
||||
void cleanUpVms() {
|
||||
for (VmSpec spec : ImmutableSet.of(cloneSpec.getVmSpec(),
|
||||
masterMachineSpec.getVmSpec()))
|
||||
for (VmSpec spec : ImmutableSet.of(cloneSpec.getVmSpec(), masterMachineSpec.getVmSpec()))
|
||||
this.undoVm(spec);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue