mirror of https://github.com/apache/jclouds.git
issue 384: modified CloneAndRegister constructor
This commit is contained in:
parent
85fae1687b
commit
7e68bba81c
|
@ -55,20 +55,14 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExists implements Fu
|
||||||
|
|
||||||
private VirtualBoxManager manager;
|
private VirtualBoxManager manager;
|
||||||
private VmSpec vmSpec;
|
private VmSpec vmSpec;
|
||||||
private CloneOptions cloneOptions;
|
boolean isLinkedClone;
|
||||||
|
|
||||||
@Inject
|
|
||||||
public CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(
|
|
||||||
VirtualBoxManager manager, VmSpec vmSpec) {
|
|
||||||
this(manager, vmSpec, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(
|
public CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(
|
||||||
VirtualBoxManager manager, VmSpec vmSpec, CloneOptions cloneOptions) {
|
VirtualBoxManager manager, VmSpec vmSpec, boolean isLinkedClone) {
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
this.vmSpec = vmSpec;
|
this.vmSpec = vmSpec;
|
||||||
this.cloneOptions = cloneOptions;
|
this.isLinkedClone = isLinkedClone;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -93,8 +87,8 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExists implements Fu
|
||||||
String settingsFile = manager.getVBox().composeMachineFilename(vmSpec.getVmName(), workingDir);
|
String settingsFile = manager.getVBox().composeMachineFilename(vmSpec.getVmName(), workingDir);
|
||||||
IMachine clonedMachine = manager.getVBox().createMachine(settingsFile, vmSpec.getVmName(), vmSpec.getOsTypeId(), vmSpec.getVmId(), vmSpec.isForceOverwrite());
|
IMachine clonedMachine = manager.getVBox().createMachine(settingsFile, vmSpec.getVmName(), vmSpec.getOsTypeId(), vmSpec.getVmId(), vmSpec.isForceOverwrite());
|
||||||
List<CloneOptions> options = new ArrayList<CloneOptions>();
|
List<CloneOptions> options = new ArrayList<CloneOptions>();
|
||||||
if(cloneOptions != null)
|
if(isLinkedClone)
|
||||||
options.add(cloneOptions);
|
options.add(CloneOptions.Link);
|
||||||
|
|
||||||
// TODO snapshot name
|
// TODO snapshot name
|
||||||
ISnapshot currentSnapshot = new TakeSnapshotIfNotAlreadyAttached(manager, "snapshotName", "snapshotDesc").apply(master);
|
ISnapshot currentSnapshot = new TakeSnapshotIfNotAlreadyAttached(manager, "snapshotName", "snapshotDesc").apply(master);
|
||||||
|
|
|
@ -22,13 +22,8 @@ package org.jclouds.virtualbox.functions;
|
||||||
import static org.jclouds.virtualbox.experiment.TestUtils.computeServiceForLocalhostAndGuest;
|
import static org.jclouds.virtualbox.experiment.TestUtils.computeServiceForLocalhostAndGuest;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import org.jclouds.compute.ComputeServiceContext;
|
import org.jclouds.compute.ComputeServiceContext;
|
||||||
import org.jclouds.domain.Credentials;
|
import org.jclouds.domain.Credentials;
|
||||||
import org.jclouds.net.IPSocket;
|
|
||||||
import org.jclouds.predicates.InetSocketAddressConnect;
|
|
||||||
import org.jclouds.predicates.RetryablePredicate;
|
|
||||||
import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
|
import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
|
||||||
import org.jclouds.virtualbox.domain.HardDisk;
|
import org.jclouds.virtualbox.domain.HardDisk;
|
||||||
import org.jclouds.virtualbox.domain.StorageController;
|
import org.jclouds.virtualbox.domain.StorageController;
|
||||||
|
@ -42,8 +37,6 @@ import org.virtualbox_4_1.ISession;
|
||||||
import org.virtualbox_4_1.StorageBus;
|
import org.virtualbox_4_1.StorageBus;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_1.VirtualBoxManager;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Andrea Turli
|
* @author Andrea Turli
|
||||||
*/
|
*/
|
||||||
|
@ -51,14 +44,11 @@ import com.google.common.base.Predicate;
|
||||||
public class CloneAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends
|
public class CloneAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends
|
||||||
BaseVirtualBoxClientLiveTest {
|
BaseVirtualBoxClientLiveTest {
|
||||||
|
|
||||||
private String settingsFile = null;
|
private static final boolean IS_LINKED_CLONE = true;
|
||||||
private boolean forceOverwrite = true;
|
|
||||||
private String vmId = "jclouds-image-iso-1";
|
private String vmId = "jclouds-image-iso-1";
|
||||||
private String osTypeId = "";
|
private String osTypeId = "DEBIAN";
|
||||||
private String guestId = "guest";
|
private String guestId = "guest";
|
||||||
private String hostId = "host";
|
private String hostId = "host";
|
||||||
private String snapshotName = "snap";
|
|
||||||
private String snapshotDesc = "snapDesc";
|
|
||||||
|
|
||||||
private String vmName = "jclouds-image-virtualbox-iso-to-machine-test";
|
private String vmName = "jclouds-image-virtualbox-iso-to-machine-test";
|
||||||
private String cloneName = vmName + "_clone";
|
private String cloneName = vmName + "_clone";
|
||||||
|
@ -66,8 +56,6 @@ public class CloneAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends
|
||||||
|
|
||||||
private String ideControllerName = "IDE Controller";
|
private String ideControllerName = "IDE Controller";
|
||||||
private CleanupMode mode = CleanupMode.Full;
|
private CleanupMode mode = CleanupMode.Full;
|
||||||
private StorageController ideController;
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCloneMachineFromAnotherMachine() throws Exception {
|
public void testCloneMachineFromAnotherMachine() throws Exception {
|
||||||
|
@ -90,7 +78,7 @@ public class CloneAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends
|
||||||
.cleanUpMode(mode)
|
.cleanUpMode(mode)
|
||||||
.forceOverwrite(true).build();
|
.forceOverwrite(true).build();
|
||||||
IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(
|
IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(
|
||||||
manager, clonedVmSpec).apply(master);
|
manager, clonedVmSpec, IS_LINKED_CLONE).apply(master);
|
||||||
assertEquals(clone.getName(), clonedVmSpec.getVmName());
|
assertEquals(clone.getName(), clonedVmSpec.getVmName());
|
||||||
new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(clonedVmSpec);
|
new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(clonedVmSpec);
|
||||||
new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(new IMachineToVmSpec().apply(master));
|
new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(new IMachineToVmSpec().apply(master));
|
||||||
|
@ -99,8 +87,6 @@ public class CloneAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends
|
||||||
private IMachine getMasterNode(VirtualBoxManager manager,
|
private IMachine getMasterNode(VirtualBoxManager manager,
|
||||||
ComputeServiceContext localHostContext) {
|
ComputeServiceContext localHostContext) {
|
||||||
try {
|
try {
|
||||||
Predicate<IPSocket> socketTester = new RetryablePredicate<IPSocket>(
|
|
||||||
new InetSocketAddressConnect(), 10, 1, TimeUnit.SECONDS);
|
|
||||||
String workingDir = PropertyUtils.getWorkingDirFromProperty();
|
String workingDir = PropertyUtils.getWorkingDirFromProperty();
|
||||||
StorageController ideController = StorageController
|
StorageController ideController = StorageController
|
||||||
.builder()
|
.builder()
|
||||||
|
|
|
@ -34,7 +34,6 @@ import org.jclouds.virtualbox.util.PropertyUtils;
|
||||||
import org.testng.annotations.BeforeGroups;
|
import org.testng.annotations.BeforeGroups;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.CleanupMode;
|
import org.virtualbox_4_1.CleanupMode;
|
||||||
import org.virtualbox_4_1.CloneOptions;
|
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_1.IMachine;
|
||||||
import org.virtualbox_4_1.StorageBus;
|
import org.virtualbox_4_1.StorageBus;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_1.VirtualBoxManager;
|
||||||
|
@ -46,8 +45,9 @@ import org.virtualbox_4_1.VirtualBoxManager;
|
||||||
@Test(groups = "live", singleThreaded = true, testName = "IsLinkedClonesLiveTest")
|
@Test(groups = "live", singleThreaded = true, testName = "IsLinkedClonesLiveTest")
|
||||||
public class IsLinkedClonesLiveTest extends BaseVirtualBoxClientLiveTest {
|
public class IsLinkedClonesLiveTest extends BaseVirtualBoxClientLiveTest {
|
||||||
|
|
||||||
private String vmId = "jclouds-image-iso-1";
|
private static final boolean IS_LINKED_CLONE = true;
|
||||||
private String osTypeId = "";
|
private String vmId = "jclouds-image-iso-1";
|
||||||
|
private String osTypeId = "DEBIAN";
|
||||||
private String ideControllerName = "IDE Controller";
|
private String ideControllerName = "IDE Controller";
|
||||||
private String cloneId = "jclouds-is-linked-clone-clone";
|
private String cloneId = "jclouds-is-linked-clone-clone";
|
||||||
private String cloneName = "jclouds-is-linked-clone-clone";
|
private String cloneName = "jclouds-is-linked-clone-clone";
|
||||||
|
@ -90,7 +90,7 @@ public class IsLinkedClonesLiveTest extends BaseVirtualBoxClientLiveTest {
|
||||||
IMachine master = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(
|
IMachine master = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(
|
||||||
manager).apply(masterSpec);
|
manager).apply(masterSpec);
|
||||||
IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(
|
IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(
|
||||||
manager, cloneSpec, CloneOptions.Link).apply(master);
|
manager, cloneSpec, IS_LINKED_CLONE).apply(master);
|
||||||
|
|
||||||
assertTrue(new IsLinkedClone(manager).apply(clone));
|
assertTrue(new IsLinkedClone(manager).apply(clone));
|
||||||
new UnregisterMachineIfExistsAndDeleteItsMedia(manager)
|
new UnregisterMachineIfExistsAndDeleteItsMedia(manager)
|
||||||
|
@ -107,7 +107,7 @@ public class IsLinkedClonesLiveTest extends BaseVirtualBoxClientLiveTest {
|
||||||
IMachine master = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(
|
IMachine master = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(
|
||||||
manager).apply(masterSpec);
|
manager).apply(masterSpec);
|
||||||
IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(
|
IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(
|
||||||
manager, cloneSpec).apply(master);
|
manager, cloneSpec, !IS_LINKED_CLONE).apply(master);
|
||||||
|
|
||||||
assertFalse(new IsLinkedClone(manager).apply(clone));
|
assertFalse(new IsLinkedClone(manager).apply(clone));
|
||||||
new UnregisterMachineIfExistsAndDeleteItsMedia(manager)
|
new UnregisterMachineIfExistsAndDeleteItsMedia(manager)
|
||||||
|
|
Loading…
Reference in New Issue