diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapter.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapter.java index 37d684f107..dcf9f3f4d0 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapter.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapter.java @@ -20,6 +20,7 @@ package org.jclouds.virtualbox.compute; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; import static com.google.common.collect.Iterables.filter; import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX; import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_NODE_PREFIX; @@ -90,7 +91,7 @@ public class VirtualBoxComputeServiceAdapter implements ComputeServiceAdapter { + // TODO parameterize public static final int MASTER_PORT = 2222; @Resource 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 b32137ce2c..a4ec912af4 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 @@ -1,5 +1,5 @@ /** -mh * Licensed to jclouds, Inc. (jclouds) under one or more + * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. jclouds licenses this file @@ -54,9 +54,17 @@ import com.google.common.base.Supplier; @Singleton public class NodeCreator implements Function> { + // TODO parameterize public static final int NODE_PORT_INIT = 3000; + + // TODO parameterize public static final String VMS_NETWORK = "33.33.33."; + + // TODO parameterize public static final String HOST_ONLY_IFACE_NAME = "vboxnet0"; + + // TODO parameterize + public static final boolean USE_LINKED = true; private final Supplier manager; private final Function cloner; @@ -70,7 +78,7 @@ public class NodeCreator implements Function imachineToNodeMetadata) { this.manager = manager; this.cloner = cloner; - this.nodePorts = new AtomicInteger(3000); + this.nodePorts = new AtomicInteger(NODE_PORT_INIT); this.nodeIps = new AtomicInteger(1); this.machineUtils = machineUtils; this.imachineToNodeMetadata = imachineToNodeMetadata; @@ -115,7 +123,7 @@ public class NodeCreator implements Function mastersCache; - private final ExecutorService singleThreadExec = Executors.newSingleThreadExecutor(); + private final ExecutorService singleThreadExec = MoreExecutors.sameThreadExecutor(); @Override protected void setupCredentials() { diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/statements/SetIpAddressTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/statements/SetIpAddressTest.java new file mode 100644 index 0000000000..f72ea3d1fe --- /dev/null +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/statements/SetIpAddressTest.java @@ -0,0 +1,67 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.virtualbox.statements; + +import static junit.framework.Assert.assertEquals; + +import org.jclouds.scriptbuilder.domain.OsFamily; +import org.jclouds.virtualbox.domain.NetworkAdapter; +import org.jclouds.virtualbox.domain.NetworkInterfaceCard; +import org.testng.annotations.Test; +import org.virtualbox_4_1.NetworkAttachmentType; + +public class SetIpAddressTest { + + @Test + public void testSetIpeth0() { + NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard + .builder() + .slot(0L) + .addNetworkAdapter( + NetworkAdapter.builder().staticIp("127.0.0.1").networkAttachmentType(NetworkAttachmentType.NAT) + .build()).build(); + SetIpAddress setIpAddressStmtm = new SetIpAddress(networkInterfaceCard); + assertEquals("ifconfig eth0 127.0.0.1;", setIpAddressStmtm.render(OsFamily.UNIX)); + } + + @Test + public void testSetIpeth3() { + NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard + .builder() + .slot(3L) + .addNetworkAdapter( + NetworkAdapter.builder().staticIp("localhost").networkAttachmentType(NetworkAttachmentType.NAT) + .build()).build(); + SetIpAddress setIpAddressStmtm = new SetIpAddress(networkInterfaceCard); + assertEquals("ifconfig eth3 localhost;", setIpAddressStmtm.render(OsFamily.UNIX)); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testThrowsIllegalArgumentExceptionOnWrongSlot() { + NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard + .builder() + .slot(4L) + .addNetworkAdapter( + NetworkAdapter.builder().staticIp("localhost").networkAttachmentType(NetworkAttachmentType.NAT) + .build()).build(); + SetIpAddress setIpAddressStmtm = new SetIpAddress(networkInterfaceCard); + } + +}