Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Mike Arnold 2012-03-12 16:23:28 -05:00
commit 60528df8c6
19 changed files with 101 additions and 80 deletions

View File

@ -18,7 +18,7 @@
*/ */
package org.jclouds.hpcloud.compute.features; package org.jclouds.hpcloud.compute.features;
import org.jclouds.openstack.nova.v1_1.features.FloatingIPClientLiveTest; import org.jclouds.openstack.nova.v1_1.extensions.FloatingIPClientLiveTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
/** /**

View File

@ -23,11 +23,11 @@ import java.util.Set;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import org.jclouds.location.Region; import org.jclouds.location.Region;
import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull; import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
import org.jclouds.openstack.nova.v1_1.extensions.FloatingIPAsyncClient;
import org.jclouds.openstack.nova.v1_1.extensions.KeyPairAsyncClient;
import org.jclouds.openstack.nova.v1_1.extensions.SecurityGroupAsyncClient;
import org.jclouds.openstack.nova.v1_1.features.FlavorAsyncClient; import org.jclouds.openstack.nova.v1_1.features.FlavorAsyncClient;
import org.jclouds.openstack.nova.v1_1.features.FloatingIPAsyncClient;
import org.jclouds.openstack.nova.v1_1.features.ImageAsyncClient; import org.jclouds.openstack.nova.v1_1.features.ImageAsyncClient;
import org.jclouds.openstack.nova.v1_1.features.KeyPairAsyncClient;
import org.jclouds.openstack.nova.v1_1.features.SecurityGroupAsyncClient;
import org.jclouds.openstack.nova.v1_1.features.ServerAsyncClient; import org.jclouds.openstack.nova.v1_1.features.ServerAsyncClient;
import org.jclouds.rest.annotations.Delegate; import org.jclouds.rest.annotations.Delegate;
import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.EndpointParam;

View File

@ -25,11 +25,11 @@ import org.jclouds.concurrent.Timeout;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import org.jclouds.location.Region; import org.jclouds.location.Region;
import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull; import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
import org.jclouds.openstack.nova.v1_1.extensions.FloatingIPClient;
import org.jclouds.openstack.nova.v1_1.extensions.KeyPairClient;
import org.jclouds.openstack.nova.v1_1.extensions.SecurityGroupClient;
import org.jclouds.openstack.nova.v1_1.features.FlavorClient; import org.jclouds.openstack.nova.v1_1.features.FlavorClient;
import org.jclouds.openstack.nova.v1_1.features.FloatingIPClient;
import org.jclouds.openstack.nova.v1_1.features.ImageClient; import org.jclouds.openstack.nova.v1_1.features.ImageClient;
import org.jclouds.openstack.nova.v1_1.features.KeyPairClient;
import org.jclouds.openstack.nova.v1_1.features.SecurityGroupClient;
import org.jclouds.openstack.nova.v1_1.features.ServerClient; import org.jclouds.openstack.nova.v1_1.features.ServerClient;
import org.jclouds.rest.annotations.Delegate; import org.jclouds.rest.annotations.Delegate;
import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.EndpointParam;

View File

@ -28,16 +28,16 @@ import org.jclouds.http.annotation.ServerError;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule; import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule;
import org.jclouds.openstack.nova.v1_1.NovaAsyncClient; import org.jclouds.openstack.nova.v1_1.NovaAsyncClient;
import org.jclouds.openstack.nova.v1_1.NovaClient; import org.jclouds.openstack.nova.v1_1.NovaClient;
import org.jclouds.openstack.nova.v1_1.extensions.FloatingIPAsyncClient;
import org.jclouds.openstack.nova.v1_1.extensions.FloatingIPClient;
import org.jclouds.openstack.nova.v1_1.extensions.KeyPairAsyncClient;
import org.jclouds.openstack.nova.v1_1.extensions.KeyPairClient;
import org.jclouds.openstack.nova.v1_1.extensions.SecurityGroupAsyncClient;
import org.jclouds.openstack.nova.v1_1.extensions.SecurityGroupClient;
import org.jclouds.openstack.nova.v1_1.features.FlavorAsyncClient; import org.jclouds.openstack.nova.v1_1.features.FlavorAsyncClient;
import org.jclouds.openstack.nova.v1_1.features.FlavorClient; import org.jclouds.openstack.nova.v1_1.features.FlavorClient;
import org.jclouds.openstack.nova.v1_1.features.FloatingIPAsyncClient;
import org.jclouds.openstack.nova.v1_1.features.FloatingIPClient;
import org.jclouds.openstack.nova.v1_1.features.ImageAsyncClient; import org.jclouds.openstack.nova.v1_1.features.ImageAsyncClient;
import org.jclouds.openstack.nova.v1_1.features.ImageClient; import org.jclouds.openstack.nova.v1_1.features.ImageClient;
import org.jclouds.openstack.nova.v1_1.features.KeyPairAsyncClient;
import org.jclouds.openstack.nova.v1_1.features.KeyPairClient;
import org.jclouds.openstack.nova.v1_1.features.SecurityGroupAsyncClient;
import org.jclouds.openstack.nova.v1_1.features.SecurityGroupClient;
import org.jclouds.openstack.nova.v1_1.features.ServerAsyncClient; import org.jclouds.openstack.nova.v1_1.features.ServerAsyncClient;
import org.jclouds.openstack.nova.v1_1.features.ServerClient; import org.jclouds.openstack.nova.v1_1.features.ServerClient;
import org.jclouds.openstack.nova.v1_1.handlers.NovaErrorHandler; import org.jclouds.openstack.nova.v1_1.handlers.NovaErrorHandler;

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.jclouds.openstack.nova.v1_1.features; package org.jclouds.openstack.nova.v1_1.extensions;
import java.util.Set; import java.util.Set;
@ -48,6 +48,7 @@ import com.google.common.util.concurrent.ListenableFuture;
* *
* @see FloatingIPClient * @see FloatingIPClient
* @author Jeremy Daggett * @author Jeremy Daggett
* @see <a href="http://wiki.openstack.org/os_api_floating_ip"/>
*/ */
@SkipEncoding({ '/', '=' }) @SkipEncoding({ '/', '=' })
@RequestFilters(AuthenticateRequest.class) @RequestFilters(AuthenticateRequest.class)

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.jclouds.openstack.nova.v1_1.features; package org.jclouds.openstack.nova.v1_1.extensions;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.jclouds.openstack.nova.v1_1.features; package org.jclouds.openstack.nova.v1_1.extensions;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -49,6 +49,7 @@ import com.google.common.util.concurrent.ListenableFuture;
* *
* @see KeyPairClient * @see KeyPairClient
* @author Jeremy Daggett * @author Jeremy Daggett
* @see <a href="http://nova.openstack.org/api_ext/ext_keypairs.html" />
*/ */
@SkipEncoding({ '/', '=' }) @SkipEncoding({ '/', '=' })
@RequestFilters(AuthenticateRequest.class) @RequestFilters(AuthenticateRequest.class)

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.jclouds.openstack.nova.v1_1.features; package org.jclouds.openstack.nova.v1_1.extensions;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.jclouds.openstack.nova.v1_1.features; package org.jclouds.openstack.nova.v1_1.extensions;
import java.util.Set; import java.util.Set;
@ -50,6 +50,7 @@ import com.google.common.util.concurrent.ListenableFuture;
* *
* @see SecurityGroupClient * @see SecurityGroupClient
* @author Jeremy Daggett * @author Jeremy Daggett
* @see <a href="http://wiki.openstack.org/os-security-groups" />
*/ */
@SkipEncoding({ '/', '=' }) @SkipEncoding({ '/', '=' })
@RequestFilters(AuthenticateRequest.class) @RequestFilters(AuthenticateRequest.class)

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.jclouds.openstack.nova.v1_1.features; package org.jclouds.openstack.nova.v1_1.extensions;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;

View File

@ -35,7 +35,7 @@ import org.jclouds.openstack.nova.v1_1.domain.Flavor;
* /> * />
* @author Jeremy Daggett * @author Jeremy Daggett
*/ */
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
public interface FlavorClient { public interface FlavorClient {
/** /**

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.jclouds.openstack.nova.v1_1.features; package org.jclouds.openstack.nova.v1_1.extensions;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull; import static org.testng.Assert.assertNull;

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.jclouds.openstack.nova.v1_1.features; package org.jclouds.openstack.nova.v1_1.extensions;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertFalse;
@ -30,6 +30,10 @@ import org.jclouds.openstack.nova.v1_1.domain.Address;
import org.jclouds.openstack.nova.v1_1.domain.FloatingIP; import org.jclouds.openstack.nova.v1_1.domain.FloatingIP;
import org.jclouds.openstack.nova.v1_1.domain.Server; import org.jclouds.openstack.nova.v1_1.domain.Server;
import org.jclouds.openstack.nova.v1_1.domain.ServerStatus; import org.jclouds.openstack.nova.v1_1.domain.ServerStatus;
import org.jclouds.openstack.nova.v1_1.extensions.FloatingIPClient;
import org.jclouds.openstack.nova.v1_1.features.FlavorClient;
import org.jclouds.openstack.nova.v1_1.features.ImageClient;
import org.jclouds.openstack.nova.v1_1.features.ServerClient;
import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientLiveTest; import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientLiveTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.jclouds.openstack.nova.v1_1.features; package org.jclouds.openstack.nova.v1_1.extensions;
import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;

View File

@ -16,9 +16,10 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.jclouds.openstack.nova.v1_1.features; package org.jclouds.openstack.nova.v1_1.extensions;
import org.jclouds.openstack.nova.v1_1.domain.KeyPair; import org.jclouds.openstack.nova.v1_1.domain.KeyPair;
import org.jclouds.openstack.nova.v1_1.extensions.KeyPairClient;
import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientLiveTest; import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientLiveTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;

View File

@ -4,7 +4,7 @@
<file>target/test-data/jclouds.log</file> <file>target/test-data/jclouds.log</file>
<layout class="ch.qos.logback.classic.PatternLayout"> <layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%d %-5p [%c] (%t) %m%n</Pattern> <Pattern>%d %-5p [%c] [%thread] %m%n</Pattern>
</layout> </layout>
</appender> </appender>
@ -12,7 +12,7 @@
<file>target/test-data/jclouds-wire.log</file> <file>target/test-data/jclouds-wire.log</file>
<layout class="ch.qos.logback.classic.PatternLayout"> <layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%d %-5p [%c] (%t) %m%n</Pattern> <Pattern>%d %-5p [%c] [%thread] %m%n</Pattern>
</layout> </layout>
</appender> </appender>
@ -20,7 +20,7 @@
<file>target/test-data/jclouds-compute.log</file> <file>target/test-data/jclouds-compute.log</file>
<layout class="ch.qos.logback.classic.PatternLayout"> <layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%d %-5p [%c] (%t) %m%n</Pattern> <Pattern>%d %-5p [%c] [%thread] %m%n</Pattern>
</layout> </layout>
</appender> </appender>
@ -28,7 +28,7 @@
<file>target/test-data/jclouds-ssh.log</file> <file>target/test-data/jclouds-ssh.log</file>
<layout class="ch.qos.logback.classic.PatternLayout"> <layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%d %-5p [%c] (%t) %m%n</Pattern> <Pattern>%d %-5p [%c] [%thread] %m%n</Pattern>
</layout> </layout>
</appender> </appender>

View File

@ -19,6 +19,8 @@
package org.jclouds.virtualbox.functions; package org.jclouds.virtualbox.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static org.jclouds.virtualbox.config.VirtualBoxComputeServiceContextModule.machineToNodeState; import static org.jclouds.virtualbox.config.VirtualBoxComputeServiceContextModule.machineToNodeState;
import java.util.HashSet; import java.util.HashSet;
@ -41,6 +43,7 @@ import org.jclouds.logging.Logger;
import org.virtualbox_4_1.IMachine; import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.INetworkAdapter; import org.virtualbox_4_1.INetworkAdapter;
import org.virtualbox_4_1.MachineState; import org.virtualbox_4_1.MachineState;
import org.virtualbox_4_1.NetworkAttachmentType;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
@ -66,23 +69,8 @@ public class IMachineToNodeMetadata implements Function<IMachine, NodeMetadata>
locationBuilder.scope(LocationScope.HOST); locationBuilder.scope(LocationScope.HOST);
nodeMetadataBuilder.location(locationBuilder.build()); nodeMetadataBuilder.location(locationBuilder.build());
HardwareBuilder hardwareBuilder = new HardwareBuilder();
hardwareBuilder.ram(vm.getMemorySize().intValue());
// TODO: Get more processor information
Set<Processor> processors = new HashSet<Processor>();
for (int i = 0; i < vm.getCPUCount(); i++) {
Processor processor = new Processor(1, 0);
processors.add(processor);
}
hardwareBuilder.processors(processors);
// TODO: How to get this?
hardwareBuilder.is64Bit(false);
nodeMetadataBuilder.hostname(vm.getName()); nodeMetadataBuilder.hostname(vm.getName());
MachineState vmState = vm.getState(); MachineState vmState = vm.getState();
NodeState nodeState = machineToNodeState.get(vmState); NodeState nodeState = machineToNodeState.get(vmState);
if (nodeState == null) if (nodeState == null)
@ -91,20 +79,32 @@ public class IMachineToNodeMetadata implements Function<IMachine, NodeMetadata>
logger.debug("Setting virtualbox node to: " + nodeState + " from machine state: " + vmState); logger.debug("Setting virtualbox node to: " + nodeState + " from machine state: " + vmState);
INetworkAdapter networkAdapter = vm.getNetworkAdapter(0l); // hardcoded set-up that works only for nat+host-only
if (networkAdapter != null) {
nodeMetadataBuilder.privateAddresses(ImmutableSet.of(networkAdapter.getNatDriver().getHostIP())); // nat adapter
for (String nameProtocolnumberAddressInboudportGuestTargetport : networkAdapter.getNatDriver().getRedirects()){ INetworkAdapter natAdapter = vm.getNetworkAdapter(0l);
Iterable<String> stuff = Splitter.on(',').split(nameProtocolnumberAddressInboudportGuestTargetport); checkNotNull(natAdapter, "slot 0 networkadapter");
String protocolNumber = Iterables.get(stuff, 1); checkState(natAdapter.getAttachmentType() == NetworkAttachmentType.NAT,
String hostAddress= Iterables.get(stuff, 2); "expecting slot 0 to be a NAT attachment type (was: " + natAdapter.getAttachmentType() + ")");
String inboundPort= Iterables.get(stuff, 3);
String targetPort= Iterables.get(stuff, 5); int ipTermination = 0;
if ("1".equals(protocolNumber) && "22".equals(targetPort))
nodeMetadataBuilder.privateAddresses(ImmutableSet.of(hostAddress)).loginPort(Integer.parseInt(inboundPort)); nodeMetadataBuilder.publicAddresses(ImmutableSet.of(natAdapter.getNatDriver().getHostIP()));
for (String nameProtocolnumberAddressInboudportGuestTargetport : natAdapter.getNatDriver().getRedirects()) {
Iterable<String> 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);
} }
} }
nodeMetadataBuilder.privateAddresses(ImmutableSet.of((NodeCreator.VMS_NETWORK + ipTermination) + ""));
LoginCredentials loginCredentials = new LoginCredentials("toor", "password", null, true); LoginCredentials loginCredentials = new LoginCredentials("toor", "password", null, true);
nodeMetadataBuilder.credentials(loginCredentials); nodeMetadataBuilder.credentials(loginCredentials);

View File

@ -68,8 +68,7 @@ public class NodeCreator implements Function<NodeSpec, NodeAndInitialCredentials
private final Supplier<VirtualBoxManager> manager; private final Supplier<VirtualBoxManager> manager;
private final Function<CloneSpec, IMachine> cloner; private final Function<CloneSpec, IMachine> cloner;
private final AtomicInteger nodePorts; private final AtomicInteger nodes;
private final AtomicInteger nodeIps;
private MachineUtils machineUtils; private MachineUtils machineUtils;
private Function<IMachine, NodeMetadata> imachineToNodeMetadata; private Function<IMachine, NodeMetadata> imachineToNodeMetadata;
@ -78,8 +77,7 @@ public class NodeCreator implements Function<NodeSpec, NodeAndInitialCredentials
MachineUtils machineUtils, Function<IMachine, NodeMetadata> imachineToNodeMetadata) { MachineUtils machineUtils, Function<IMachine, NodeMetadata> imachineToNodeMetadata) {
this.manager = manager; this.manager = manager;
this.cloner = cloner; this.cloner = cloner;
this.nodePorts = new AtomicInteger(NODE_PORT_INIT); this.nodes = new AtomicInteger(0);
this.nodeIps = new AtomicInteger(1);
this.machineUtils = machineUtils; this.machineUtils = machineUtils;
this.imachineToNodeMetadata = imachineToNodeMetadata; this.imachineToNodeMetadata = imachineToNodeMetadata;
} }
@ -117,12 +115,12 @@ public class NodeCreator implements Function<NodeSpec, NodeAndInitialCredentials
.forceOverwrite(true).build(); .forceOverwrite(true).build();
NetworkAdapter natAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.NAT) NetworkAdapter natAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.NAT)
.tcpRedirectRule("127.0.0.1", this.nodePorts.getAndIncrement(), "", 22).build(); .tcpRedirectRule("127.0.0.1", NODE_PORT_INIT + this.nodes.getAndIncrement(), "", 22).build();
NetworkInterfaceCard natIfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(natAdapter).slot(0L).build(); NetworkInterfaceCard natIfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(natAdapter).slot(0L).build();
NetworkAdapter hostOnlyAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.HostOnly) NetworkAdapter hostOnlyAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.HostOnly)
.staticIp(VMS_NETWORK + this.nodeIps.getAndIncrement()).build(); .staticIp(VMS_NETWORK + this.nodes.getAndIncrement()).build();
NetworkInterfaceCard hostOnlyIfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(hostOnlyAdapter) NetworkInterfaceCard hostOnlyIfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(hostOnlyAdapter)
.addHostInterfaceName(HOST_ONLY_IFACE_NAME).slot(1L).build(); .addHostInterfaceName(HOST_ONLY_IFACE_NAME).slot(1L).build();

View File

@ -19,38 +19,53 @@
package org.jclouds.virtualbox.functions; package org.jclouds.virtualbox.functions;
import java.util.Map; import static junit.framework.Assert.assertEquals;
import java.util.Set; import static org.easymock.EasyMock.createNiceMock;
import static org.easymock.EasyMock.eq;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.domain.Credentials;
import org.jclouds.virtualbox.VirtualBox;
import org.jclouds.virtualbox.config.VirtualBoxComputeServiceContextModule;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.INATEngine;
import org.virtualbox_4_1.INetworkAdapter;
import org.virtualbox_4_1.MachineState; import org.virtualbox_4_1.MachineState;
import org.virtualbox_4_1.VirtualBoxManager; import org.virtualbox_4_1.NetworkAttachmentType;
import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables;
public class IMachineToNodeMetadataTest { public class IMachineToNodeMetadataTest {
@Test @Test
public void testCreate() throws Exception { public void testCreate() throws Exception {
Credentials creds = new Credentials("admin", "123456"); IMachine vm = createNiceMock(IMachine.class);
VirtualBoxManager manager = VirtualBoxManager.createInstance("");
Map<MachineState, NodeState> machineToNodeState = VirtualBoxComputeServiceContextModule.machineToNodeState; expect(vm.getName()).andReturn("mocked-vm").anyTimes();
Set<Image> images = ImmutableSet.of(); expect(vm.getState()).andReturn(MachineState.PoweredOff).once();
Set<org.jclouds.compute.domain.Hardware> hardwares = ImmutableSet.of();
VirtualBox virtualBox = new VirtualBox(); INetworkAdapter nat = createNiceMock(INetworkAdapter.class);
IMachineToNodeMetadata parser = new IMachineToNodeMetadata(); INATEngine natEng = createNiceMock(INATEngine.class);
IMachineToHardware hwParser = new IMachineToHardware(Suppliers.ofInstance(manager));
// hwParser.apply() expect(vm.getNetworkAdapter(eq(0l))).andReturn(nat).once();
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"));
INetworkAdapter hostOnly = createNiceMock(INetworkAdapter.class);
replay(vm, nat, natEng, hostOnly);
NodeMetadata node = new IMachineToNodeMetadata().apply(vm);
assertEquals("mocked-vm", node.getName());
assertEquals(1, node.getPrivateAddresses().size());
assertEquals((NodeCreator.VMS_NETWORK + 1), Iterables.get(node.getPrivateAddresses(), 0));
assertEquals(1, node.getPublicAddresses().size());
assertEquals("127.0.0.1", Iterables.get(node.getPublicAddresses(), 0));
assertEquals(3001, node.getLoginPort());
} }
} }