mirror of https://github.com/apache/jclouds.git
issue 384: cosmetic fixes
This commit is contained in:
parent
caec80d560
commit
85fae1687b
|
@ -19,10 +19,6 @@
|
|||
|
||||
package org.jclouds.virtualbox.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.virtualbox.util.MachineUtils.lockMachineAndApply;
|
||||
import static org.virtualbox_4_1.LockType.Write;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -60,8 +56,6 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExists implements Fu
|
|||
private VirtualBoxManager manager;
|
||||
private VmSpec vmSpec;
|
||||
private CloneOptions cloneOptions;
|
||||
// private String snapshotName;
|
||||
// private String snapshotDesc;
|
||||
|
||||
@Inject
|
||||
public CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(
|
||||
|
@ -75,8 +69,6 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExists implements Fu
|
|||
this.manager = manager;
|
||||
this.vmSpec = vmSpec;
|
||||
this.cloneOptions = cloneOptions;
|
||||
// this.snapshotName = snapshotName;
|
||||
// this.snapshotDesc = snapshotDesc;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -115,32 +107,7 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExists implements Fu
|
|||
|
||||
// registering
|
||||
manager.getVBox().registerMachine(clonedMachine);
|
||||
/*
|
||||
// Bridged Network
|
||||
List<String> activeBridgedInterfaces = new RetrieveActiveBridgedInterfaces(context).apply(hostId);
|
||||
checkNotNull(activeBridgedInterfaces);
|
||||
String macAddress = manager.getVBox().getHost().generateMACAddress();
|
||||
|
||||
// TODO this behavior can be improved
|
||||
String bridgedInterface = activeBridgedInterfaces.get(0);
|
||||
long adapterSlot = 0l;
|
||||
ensureBridgedNetworkingIsAppliedToMachine(adapterSlot, cloneName, macAddress, bridgedInterface);
|
||||
|
||||
// detach iso
|
||||
// TODO: also hard-coded values here
|
||||
int controllerPort = 0;
|
||||
int device = 0;
|
||||
ensureMachineHasDistroMediumDetached(cloneName, controllerIDE, controllerPort, device);
|
||||
*/
|
||||
return clonedMachine;
|
||||
}
|
||||
|
||||
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, int controllerPort, int device) {
|
||||
lockMachineAndApply(manager, Write, vmName, new DetachDistroMediumFromMachine(checkNotNull(controllerIDE, "controllerIDE"), controllerPort, device));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -64,9 +64,11 @@ public class IsLinkedClone implements Predicate<IMachine> {
|
|||
// more than one machine is attached to this hd
|
||||
for (IMedium child : iMedium.getParent().getChildren()) {
|
||||
for (String machineId : child.getMachineIds()) {
|
||||
IMachine iMachine = manager.getVBox().findMachine(machineId);
|
||||
IMachine iMachine = manager.getVBox().findMachine(
|
||||
machineId);
|
||||
if (!iMachine.getName().equals(machine.getName())) {
|
||||
logger.debug("Machine %s is a linked clone", machine.getName());
|
||||
logger.debug("Machine %s is a linked clone",
|
||||
machine.getName());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,12 +19,11 @@
|
|||
|
||||
package org.jclouds.virtualbox.predicates;
|
||||
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
|
||||
import org.jclouds.virtualbox.domain.HardDisk;
|
||||
import org.jclouds.virtualbox.domain.NatAdapter;
|
||||
import org.jclouds.virtualbox.domain.StorageController;
|
||||
import org.jclouds.virtualbox.domain.VmSpec;
|
||||
import org.jclouds.virtualbox.functions.CloneAndRegisterMachineFromIMachineIfNotAlreadyExists;
|
||||
|
@ -57,55 +56,62 @@ public class IsLinkedClonesLiveTest extends BaseVirtualBoxClientLiveTest {
|
|||
private VmSpec masterSpec;
|
||||
private VmSpec cloneSpec;
|
||||
|
||||
@BeforeGroups(groups = {"live"})
|
||||
@BeforeGroups(groups = { "live" })
|
||||
public void setUp() throws Exception {
|
||||
identity = "toor";
|
||||
credential = "password";
|
||||
|
||||
String workingDir = PropertyUtils.getWorkingDirFromProperty();
|
||||
HardDisk hardDisk = HardDisk.builder().diskpath(workingDir + "/testadmin.vdi").autoDelete(true)
|
||||
HardDisk hardDisk = HardDisk.builder()
|
||||
.diskpath(workingDir + "/testadmin.vdi").autoDelete(true)
|
||||
.controllerPort(0).deviceSlot(1).build();
|
||||
masterStorageController = StorageController.builder().name(ideControllerName).bus(StorageBus.IDE)
|
||||
masterStorageController = StorageController.builder()
|
||||
.name(ideControllerName).bus(StorageBus.IDE)
|
||||
.attachISO(0, 0, workingDir + "/ubuntu-11.04-server-i386.iso")
|
||||
.attachHardDisk(hardDisk)
|
||||
.attachISO(1, 1, workingDir + "/VBoxGuestAdditions_4.1.2.iso").build();
|
||||
masterSpec = VmSpec.builder().id(vmId).name(vmName).memoryMB(512).osTypeId(osTypeId)
|
||||
.controller(masterStorageController)
|
||||
.forceOverwrite(true)
|
||||
.cleanUpMode(CleanupMode.Full)
|
||||
.attachISO(1, 1, workingDir + "/VBoxGuestAdditions_4.1.2.iso")
|
||||
.build();
|
||||
masterSpec = VmSpec.builder().id(vmId).name(vmName).memoryMB(512)
|
||||
.osTypeId(osTypeId).controller(masterStorageController)
|
||||
.forceOverwrite(true).cleanUpMode(CleanupMode.Full).build();
|
||||
|
||||
cloneSpec = VmSpec.builder().id(cloneId).name(cloneName).memoryMB(512).osTypeId(osTypeId)
|
||||
.forceOverwrite(true)
|
||||
.cleanUpMode(CleanupMode.Full)
|
||||
.build();
|
||||
cloneSpec = VmSpec.builder().id(cloneId).name(cloneName).memoryMB(512)
|
||||
.osTypeId(osTypeId).forceOverwrite(true)
|
||||
.cleanUpMode(CleanupMode.Full).build();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testLinkedClone() {
|
||||
|
||||
VirtualBoxManager manager = (VirtualBoxManager) context.getProviderSpecificContext().getApi();
|
||||
VirtualBoxManager manager = (VirtualBoxManager) context
|
||||
.getProviderSpecificContext().getApi();
|
||||
new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(masterSpec);
|
||||
|
||||
IMachine master = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager).apply(masterSpec);
|
||||
IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(manager, cloneSpec, CloneOptions.Link).apply(master);
|
||||
IMachine master = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(
|
||||
manager).apply(masterSpec);
|
||||
IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(
|
||||
manager, cloneSpec, CloneOptions.Link).apply(master);
|
||||
|
||||
assertTrue(new IsLinkedClone(manager).apply(clone));
|
||||
new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(new IMachineToVmSpec().apply(clone));
|
||||
new UnregisterMachineIfExistsAndDeleteItsMedia(manager)
|
||||
.apply(new IMachineToVmSpec().apply(clone));
|
||||
new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(masterSpec);
|
||||
}
|
||||
|
||||
public void testFullClone() {
|
||||
|
||||
VirtualBoxManager manager = (VirtualBoxManager) context.getProviderSpecificContext().getApi();
|
||||
VirtualBoxManager manager = (VirtualBoxManager) context
|
||||
.getProviderSpecificContext().getApi();
|
||||
new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(masterSpec);
|
||||
|
||||
IMachine master = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager).apply(masterSpec);
|
||||
IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(manager, cloneSpec).apply(master);
|
||||
IMachine master = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(
|
||||
manager).apply(masterSpec);
|
||||
IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(
|
||||
manager, cloneSpec).apply(master);
|
||||
|
||||
assertFalse(new IsLinkedClone(manager).apply(clone));
|
||||
new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(new IMachineToVmSpec().apply(clone));
|
||||
new UnregisterMachineIfExistsAndDeleteItsMedia(manager)
|
||||
.apply(new IMachineToVmSpec().apply(clone));
|
||||
new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(masterSpec);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue