diff --git a/labs/virtualbox/README.md b/labs/virtualbox/README.md index 28f45e58d2..bbad852a73 100644 --- a/labs/virtualbox/README.md +++ b/labs/virtualbox/README.md @@ -17,8 +17,8 @@ That's it! Enjoy local cluster goodness by running: For java guidance look into src/test/java/org/jclouds/virtualbox/compute/VirtualBoxExperimentLiveTest.java. For now nat+host-only is the only available network configuration, nodes should be accessible from the host by: -> ssh -i ~/.ssh/id_rsa -o "UserKnownHostsFile /dev/null" -o StrictHostKeyChecking=no dralves@127.0.0.1 -p 300X -where X is the node index with regard to creation order (0,1,2,etc...) +> ssh -i ~/.ssh/id_rsa -o "UserKnownHostsFile /dev/null" -o StrictHostKeyChecking=no me@192.168.86.X +where X is the node index with regard to creation order starting at 2 (2,3,4, etc...) It *should* behave as anyother provider, if not please report. @@ -26,4 +26,5 @@ It *should* behave as anyother provider, if not please report. - jclouds-vbox is still at alpha stage please report any issues you find. - jclouds-vbox has been mostly tested on Mac OSX, it might work on Linux, but it won't work on windows for the moment. -- cached isos, vm's and most configs are kept at ~/.jclouds-vbox/ by default. \ No newline at end of file +- cached isos, vm's and most configs are kept at ~/.jclouds-vbox/ by default. +- jclouds-vbox assumes vbox has the default host-only network vboxnet0, that the network is in 192.168.86.0/255.255.255.0 and that the host as address 1 in this network. \ No newline at end of file diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxComputeServiceContextModule.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxComputeServiceContextModule.java index e00cc5ace4..7ca72d7108 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxComputeServiceContextModule.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxComputeServiceContextModule.java @@ -248,7 +248,8 @@ public class VirtualBoxComputeServiceContextModule extends @VisibleForTesting public static final Map machineToNodeState = ImmutableMap - . builder().put(MachineState.Running, NodeState.RUNNING) + . builder() + .put(MachineState.Running, NodeState.RUNNING) .put(MachineState.PoweredOff, NodeState.SUSPENDED) .put(MachineState.DeletingSnapshot, NodeState.PENDING) .put(MachineState.DeletingSnapshotOnline, NodeState.PENDING) @@ -260,12 +261,15 @@ public class VirtualBoxComputeServiceContextModule extends .put(MachineState.Stopping, NodeState.PENDING) .put(MachineState.Restoring, NodeState.PENDING) // TODO What to map these states to? - .put(MachineState.FirstOnline, NodeState.PENDING).put(MachineState.FirstTransient, NodeState.PENDING) - .put(MachineState.LastOnline, NodeState.PENDING).put(MachineState.LastTransient, NodeState.PENDING) - .put(MachineState.Teleported, NodeState.PENDING).put(MachineState.TeleportingIn, NodeState.PENDING) - .put(MachineState.TeleportingPausedVM, NodeState.PENDING).put(MachineState.Aborted, NodeState.ERROR) + .put(MachineState.FirstOnline, NodeState.PENDING) + .put(MachineState.FirstTransient, NodeState.PENDING) + .put(MachineState.LastOnline, NodeState.PENDING) + .put(MachineState.LastTransient, NodeState.PENDING) + .put(MachineState.Teleported, NodeState.PENDING) + .put(MachineState.TeleportingIn, NodeState.PENDING) + .put(MachineState.TeleportingPausedVM, NodeState.PENDING) + .put(MachineState.Aborted, NodeState.ERROR) .put(MachineState.Stuck, NodeState.ERROR) - .put(MachineState.Null, NodeState.UNRECOGNIZED).build(); } diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToNodeMetadata.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToNodeMetadata.java index c65c41872a..e95d405543 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToNodeMetadata.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToNodeMetadata.java @@ -88,17 +88,17 @@ public class IMachineToNodeMetadata implements Function for (String nameProtocolnumberAddressInboudportGuestTargetport : natAdapter.getNatDriver().getRedirects()) { Iterable stuff = Splitter.on(',').split(nameProtocolnumberAddressInboudportGuestTargetport); String protocolNumber = Iterables.get(stuff, 1); - String hostAddress = Iterables.get(stuff, 2); String inboundPort = Iterables.get(stuff, 3); String targetPort = Iterables.get(stuff, 5); if ("1".equals(protocolNumber) && "22".equals(targetPort)) { int inPort = Integer.parseInt(inboundPort); - ipTermination = inPort % NodeCreator.NODE_PORT_INIT; - nodeMetadataBuilder.publicAddresses(ImmutableSet.of(hostAddress)).loginPort(inPort); + ipTermination = inPort % NodeCreator.NODE_PORT_INIT + 2; +// nodeMetadataBuilder.publicAddresses(ImmutableSet.of(hostAddress)).loginPort(inPort); } } nodeMetadataBuilder.privateAddresses(ImmutableSet.of((NodeCreator.VMS_NETWORK + ipTermination) + "")); + nodeMetadataBuilder.publicAddresses(ImmutableSet.of((NodeCreator.VMS_NETWORK + ipTermination) + "")); LoginCredentials loginCredentials = new LoginCredentials("toor", "password", null, true); nodeMetadataBuilder.credentials(loginCredentials); diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/NodeCreator.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/NodeCreator.java index 9372e9bbca..6414f9e07d 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/NodeCreator.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/NodeCreator.java @@ -23,7 +23,6 @@ import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX; import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_NODE_PREFIX; -import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import javax.inject.Inject; @@ -32,9 +31,10 @@ import javax.inject.Singleton; import org.jclouds.compute.ComputeServiceAdapter.NodeAndInitialCredentials; import org.jclouds.compute.callables.RunScriptOnNode; import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.NodeMetadataBuilder; import org.jclouds.compute.options.RunScriptOptions; import org.jclouds.domain.LoginCredentials; -import org.jclouds.virtualbox.domain.BridgedIf; +import org.jclouds.virtualbox.config.VirtualBoxComputeServiceContextModule; import org.jclouds.virtualbox.domain.CloneSpec; import org.jclouds.virtualbox.domain.ExecutionType; import org.jclouds.virtualbox.domain.Master; @@ -48,13 +48,17 @@ import org.jclouds.virtualbox.statements.SetIpAddress; import org.jclouds.virtualbox.util.MachineUtils; import org.virtualbox_4_1.CleanupMode; import org.virtualbox_4_1.IMachine; +import org.virtualbox_4_1.INetworkAdapter; import org.virtualbox_4_1.IProgress; 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.Splitter; import com.google.common.base.Supplier; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; /** * Creates nodes, by cloning a master vm and based on the provided {@link NodeSpec}. Must be @@ -70,7 +74,7 @@ public class NodeCreator implements Function hostSupplier) { this.manager = manager; this.cloner = cloner; - this.nodePorts = new AtomicInteger(NODE_PORT_INIT + 1); - this.nodeIps = new AtomicInteger(1); + this.nodePorts = new AtomicInteger(NODE_PORT_INIT); + this.nodeIps = new AtomicInteger(2); this.machineUtils = machineUtils; this.imachineToNodeMetadata = imachineToNodeMetadata; this.scriptRunnerFactory = scriptRunnerFactory; @@ -145,10 +149,6 @@ public class NodeCreator implements Function stuff = Splitter.on(',').split(nameProtocolnumberAddressInboudportGuestTargetport); + String protocolNumber = Iterables.get(stuff, 1); + String inboundPort = Iterables.get(stuff, 3); + String targetPort = Iterables.get(stuff, 5); + if ("1".equals(protocolNumber) && "22".equals(targetPort)) { + int inPort = Integer.parseInt(inboundPort); + nodeMetadataBuilder.loginPort(inPort); + } + } + + LoginCredentials loginCredentials = new LoginCredentials("toor", "password", null, true); + nodeMetadataBuilder.credentials(loginCredentials); + + return nodeMetadataBuilder.build(); + } private NetworkSpec createNetworkSpecForHostOnlyNATNICs(NetworkInterfaceCard natIfaceCard, NetworkInterfaceCard hostOnlyIfaceCard) { return NetworkSpec.builder().addNIC(natIfaceCard).addNIC(hostOnlyIfaceCard).build(); } - private NetworkSpec createNetworkSpecForBridgedNIC() { - List activeBridgedInterfaces = new RetrieveActiveBridgedInterfaces(scriptRunnerFactory) - .apply(hostSupplier.get()); - BridgedIf bridgedActiveInterface = checkNotNull(activeBridgedInterfaces.get(0), "activeBridgedIf"); - - NetworkAdapter bridgedAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.Bridged) - .build(); - NetworkInterfaceCard bridgedNIC = NetworkInterfaceCard.builder().addNetworkAdapter(bridgedAdapter) - .addHostInterfaceName(bridgedActiveInterface.getName()).slot(0L).build(); - - NetworkSpec networkSpec = NetworkSpec.builder().addNIC(bridgedNIC).build(); - return networkSpec; - } } diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/BaseVirtualBoxClientLiveTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/BaseVirtualBoxClientLiveTest.java index ab3ece2872..33c55a390d 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/BaseVirtualBoxClientLiveTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/BaseVirtualBoxClientLiveTest.java @@ -119,10 +119,8 @@ public class BaseVirtualBoxClientLiveTest extends BaseVersionedServiceLiveTest { } protected void ensureIdentityPropertyIsSpecifiedOrTakeFromDefaults() { - Properties defaultVBoxProperties = new VirtualBoxPropertiesBuilder().build(); if (!System.getProperties().containsKey("test." + provider + ".identity")) - System.setProperty("test." + provider + ".identity", - defaultVBoxProperties.getProperty(Constants.PROPERTY_IDENTITY)); + System.setProperty("test." + provider + ".identity", "administrator"); } @BeforeClass(groups = "live") diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IMachineToNodeMetadataTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IMachineToNodeMetadataTest.java index 177a108f70..390a43e373 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IMachineToNodeMetadataTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IMachineToNodeMetadataTest.java @@ -44,7 +44,7 @@ public class IMachineToNodeMetadataTest { IMachine vm = createNiceMock(IMachine.class); expect(vm.getName()).andReturn("mocked-vm").anyTimes(); - expect(vm.getState()).andReturn(MachineState.PoweredOff).once(); + expect(vm.getState()).andReturn(MachineState.PoweredOff).anyTimes(); INetworkAdapter nat = createNiceMock(INetworkAdapter.class); INATEngine natEng = createNiceMock(INATEngine.class); @@ -53,7 +53,7 @@ public class IMachineToNodeMetadataTest { expect(nat.getAttachmentType()).andReturn(NetworkAttachmentType.NAT).once(); expect(nat.getNatDriver()).andReturn(natEng).anyTimes(); expect(natEng.getHostIP()).andReturn("127.0.0.1").once(); - expect(natEng.getRedirects()).andReturn(ImmutableList.of("0,1,127.0.0.1,3001,,22")); + expect(natEng.getRedirects()).andReturn(ImmutableList.of("0,1,127.0.0.1,3000,,22")); INetworkAdapter hostOnly = createNiceMock(INetworkAdapter.class); @@ -63,9 +63,9 @@ public class IMachineToNodeMetadataTest { assertEquals("mocked-vm", node.getName()); assertEquals(1, node.getPrivateAddresses().size()); - assertEquals((NodeCreator.VMS_NETWORK + 1), Iterables.get(node.getPrivateAddresses(), 0)); + assertEquals((NodeCreator.VMS_NETWORK + 2), Iterables.get(node.getPrivateAddresses(), 0)); assertEquals(1, node.getPublicAddresses().size()); - assertEquals("127.0.0.1", Iterables.get(node.getPublicAddresses(), 0)); - assertEquals(3001, node.getLoginPort()); + assertEquals((NodeCreator.VMS_NETWORK + 2), Iterables.get(node.getPublicAddresses(), 0)); + assertEquals(22, node.getLoginPort()); } }