diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIMachineIfNotAlreadyExists.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIMachineIfNotAlreadyExists.java index 3fe29248bd..dd63a310c0 100644 --- a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIMachineIfNotAlreadyExists.java +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIMachineIfNotAlreadyExists.java @@ -67,7 +67,7 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExists implements Fu VirtualBoxManager manager, ComputeServiceContext context, String settingsFile, String osTypeId, String vmId, boolean forceOverwrite, String cloneName, String hostId, - String snashotName, String snapshotDesc, String controllerIDE) { + String snapshotName, String snapshotDesc, String controllerIDE) { this.manager = manager; this.context = context; this.settingsFile = settingsFile; @@ -76,7 +76,7 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExists implements Fu this.forceOverwrite = forceOverwrite; this.cloneName = cloneName; this.hostId = hostId; - this.snapshotName = snashotName; + this.snapshotName = snapshotName; this.snapshotDesc = snapshotDesc; this.controllerIDE = controllerIDE; } @@ -123,20 +123,24 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExists implements Fu // TODO this behavior can be improved String bridgedInterface = activeBridgedInterfaces.get(0); - ensureBridgedNetworkingIsAppliedToMachine(cloneName, macAddress, bridgedInterface); + long adapterSlot = 0l; + ensureBridgedNetworkingIsAppliedToMachine(adapterSlot, cloneName, macAddress, bridgedInterface); // detach iso - ensureMachineHasDistroMediumDetached(cloneName, controllerIDE); + // TODO: also hard-coded values here + int controllerPort = 0; + int device = 0; + ensureMachineHasDistroMediumDetached(cloneName, controllerIDE, controllerPort, device); return clonedMachine; } - private void ensureBridgedNetworkingIsAppliedToMachine(String vmName, String macAddress, String hostInterface) { - lockMachineAndApply(manager, Write, vmName, new AttachBridgedAdapterToMachine(0l, macAddress, hostInterface)); + private void ensureBridgedNetworkingIsAppliedToMachine(long adapterSlot, String vmName, String macAddress, String hostInterface) { + lockMachineAndApply(manager, Write, vmName, new AttachBridgedAdapterToMachine(adapterSlot, macAddress, hostInterface)); } - private void ensureMachineHasDistroMediumDetached(String vmName, String controllerIDE) { - lockMachineAndApply(manager, Write, vmName, new DetachDistroMediumToMachine(checkNotNull(controllerIDE, "controllerIDE"))); + private void ensureMachineHasDistroMediumDetached(String vmName, String controllerIDE, int controllerPort, int device) { + lockMachineAndApply(manager, Write, vmName, new DetachDistroMediumFromMachine(checkNotNull(controllerIDE, "controllerIDE"), controllerPort, device)); } } diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/DetachDistroMediumToMachine.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/DetachDistroMediumFromMachine.java similarity index 79% rename from sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/DetachDistroMediumToMachine.java rename to sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/DetachDistroMediumFromMachine.java index 0d141c6106..827dff0b52 100644 --- a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/DetachDistroMediumToMachine.java +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/DetachDistroMediumFromMachine.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -29,19 +29,21 @@ import com.google.common.base.Function; /** * @author Andrea Turli */ -public class DetachDistroMediumToMachine implements Function { +public class DetachDistroMediumFromMachine implements Function { private final String controller; + private int controllerPort; + private int device; - public DetachDistroMediumToMachine(String controller) { + public DetachDistroMediumFromMachine(String controller, int controllerPort, int device) { this.controller = controller; + this.controllerPort = controllerPort; + this.device = device; } @Override public Void apply(@Nullable IMachine machine) { try { - int controllerPort = 0; - int device = 0; machine.detachDevice(controller, controllerPort, device); machine.saveSettings(); } catch (VBoxException e) { @@ -52,7 +54,7 @@ public class DetachDistroMediumToMachine implements Function { } private boolean alreadyDetached(VBoxException e) { - return e.getMessage().indexOf("is already detached from port") != -1; + return e.getMessage().contains("is already detached from port"); } } \ No newline at end of file diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/DetachDistroMediumToMachineTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/DetachDistroMediumFromMachineTest.java similarity index 75% rename from sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/DetachDistroMediumToMachineTest.java rename to sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/DetachDistroMediumFromMachineTest.java index 8bf0658981..c56e666d9c 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/DetachDistroMediumToMachineTest.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/DetachDistroMediumFromMachineTest.java @@ -31,8 +31,8 @@ import org.virtualbox_4_1.VBoxException; /** * @author Andrea Turli */ -@Test(groups = "unit", testName = "DetachDistroMediumToMachineTest") -public class DetachDistroMediumToMachineTest { +@Test(groups = "unit", testName = "DetachDistroMediumFromMachineTest") +public class DetachDistroMediumFromMachineTest { @Test public void testDetachDistroMedium() throws Exception { @@ -40,12 +40,15 @@ public class DetachDistroMediumToMachineTest { String controller = "IDE Controller"; IMachine machine = createMock(IMachine.class); + int controllerPort = 0; + int device = 1; + machine.saveSettings(); - machine.detachDevice(controller, 0, 0); + machine.detachDevice(controller, controllerPort, device); replay(machine); - new DetachDistroMediumToMachine(controller).apply(machine); + new DetachDistroMediumFromMachine(controller, controllerPort, device).apply(machine); verify(machine); @@ -65,14 +68,16 @@ public class DetachDistroMediumToMachineTest { errorBuilder.append("of this virtual machine (0x80BB000C)"); String isoAlreadyAttachedException = errorBuilder.toString(); - VBoxException isoAttachedException = new VBoxException(createNiceMock(Throwable.class), - isoAlreadyAttachedException); - machine.detachDevice(controller, 0, 0); + int controllerPort = 0; + int device = 1; + + VBoxException isoAttachedException = new VBoxException(createNiceMock(Throwable.class), isoAlreadyAttachedException); + machine.detachDevice(controller, controllerPort, device); expectLastCall().andThrow(isoAttachedException); replay(machine); - new DetachDistroMediumToMachine(controller).apply(machine); + new DetachDistroMediumFromMachine(controller, controllerPort, device).apply(machine); verify(machine); @@ -81,7 +86,7 @@ public class DetachDistroMediumToMachineTest { @Test(expectedExceptions = VBoxException.class) public void testFailOnOtherVBoxErrors() throws Exception { - String controller = "IDE Controller"; + String controllerName = "IDE Controller"; IMachine machine = createNiceMock(IMachine.class); @@ -90,14 +95,16 @@ public class DetachDistroMediumToMachineTest { errorBuilder.append("Some other VBox error"); String isoAlreadyAttachedException = errorBuilder.toString(); - VBoxException isoAttachedException = new VBoxException(createNiceMock(Throwable.class), - isoAlreadyAttachedException); - machine.detachDevice(controller, 0, 0); + int controllerPort = 0; + int device = 1; + + VBoxException isoAttachedException = new VBoxException(createNiceMock(Throwable.class), isoAlreadyAttachedException); + machine.detachDevice(controllerName, controllerPort, device); expectLastCall().andThrow(isoAttachedException); replay(machine); - new DetachDistroMediumToMachine(controller).apply(machine); + new DetachDistroMediumFromMachine(controllerName, controllerPort, device).apply(machine); }