issue 384: refactor UnregisterMachine to take advantage of autoDelete

This commit is contained in:
andreaturli 2011-12-21 00:06:09 +00:00
parent 762f8d29bb
commit a877784107
12 changed files with 166 additions and 76 deletions

View File

@ -19,10 +19,12 @@
package org.jclouds.virtualbox.domain;
import com.google.common.base.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
import org.virtualbox_4_1.DeviceType;
import com.google.common.base.Objects;
/**
* A representation of a hard disk in a VirtualBox VM.
* <p/>
@ -36,20 +38,22 @@ public class HardDisk {
public static final String DEFAULT_DISK_FORMAT = "vdi";
// NB the name is not independent; the IMedium name is chosen based on the last part of diskPath
private final String name;
private final String diskFormat;
private final String diskPath;
private final DeviceDetails deviceDetails;
private final boolean autoDelete;
public HardDisk(DeviceDetails deviceDetails, String diskPath, String diskFormat, String name) {
public HardDisk(DeviceDetails deviceDetails, String diskPath, String diskFormat, boolean autoDelete) {
checkNotNull(deviceDetails, "deviceDetails");
checkNotNull(diskPath, "diskPath");
checkNotNull(diskFormat, "diskFormat");
checkNotNull(name, "name");
this.diskPath = diskPath;
this.diskFormat = diskFormat;
this.deviceDetails = deviceDetails;
this.name = name;
this.name = diskPath.substring(diskPath.lastIndexOf("/") + 1);
this.autoDelete = autoDelete;
}
public String getDiskPath() {
@ -68,7 +72,11 @@ public class HardDisk {
return name;
}
@Override
public boolean isAutoDelete() {
return autoDelete;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o instanceof HardDisk) {
@ -95,4 +103,50 @@ public class HardDisk {
", name=" + name +
'}';
}
public static Builder builder() {
return new Builder();
}
public static class Builder {
private String diskFormat = "vdi";
private String diskPath;
private int controllerPort;
private int deviceSlot;
private DeviceType deviceType = DeviceType.HardDisk;
private boolean autoDelete = false;
public Builder diskFormat(String diskFormat) {
this.diskFormat = diskFormat;
return this;
}
public Builder diskpath(String diskPath) {
this.diskPath = diskPath;
return this;
}
public Builder controllerPort(int controllerPort) {
this.controllerPort = controllerPort;
return this;
}
public Builder deviceSlot(int deviceSlot) {
this.deviceSlot = deviceSlot;
return this;
}
public Builder autoDelete(boolean autoDelete) {
this.autoDelete = autoDelete;
return this;
}
public HardDisk build() {
checkNotNull(diskPath);
checkNotNull(controllerPort);
checkNotNull(deviceSlot);
return new HardDisk(new DeviceDetails(controllerPort, deviceSlot, deviceType), diskPath, diskFormat, autoDelete);
}
}
}

View File

@ -78,7 +78,7 @@ public class StorageController {
public HardDisk getHardDisk(String diskName) {
final Iterable<HardDisk> hardDisks = filter(getHardDisks(), new HardDiskPredicate(diskName));
return Iterables.getOnlyElement(hardDisks);
return Iterables.getFirst(hardDisks, HardDisk.builder().diskpath("notfound").controllerPort(0).deviceSlot(0).build());
}
public Set<HardDisk> getHardDisks() {
@ -143,13 +143,8 @@ public class StorageController {
return this;
}
public Builder attachHardDisk(int controllerPort, int deviceSlot, String diskPath, String name) {
hardDisks.add(new HardDisk(new DeviceDetails(controllerPort, deviceSlot, DeviceType.HardDisk), diskPath, DEFAULT_DISK_FORMAT, name));
return this;
}
public Builder attachHardDisk(int controllerPort, int deviceSlot, String diskPath, String diskFormat, String name) {
hardDisks.add(new HardDisk(new DeviceDetails(controllerPort, deviceSlot, DeviceType.HardDisk), diskPath, diskFormat, name));
public Builder attachHardDisk(HardDisk hardDisk) {
hardDisks.add(hardDisk);
return this;
}
@ -160,7 +155,7 @@ public class StorageController {
}
}
public class HardDiskPredicate implements Predicate<HardDisk> {
private class HardDiskPredicate implements Predicate<HardDisk> {
private String diskName;

View File

@ -19,6 +19,8 @@ U * Licensed to jclouds, Inc. (jclouds) under one or more
package org.jclouds.virtualbox.functions.admin;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Collections;
import java.util.List;
@ -28,9 +30,8 @@ import javax.inject.Named;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger;
import org.jclouds.virtualbox.domain.ErrorCode;
import org.jclouds.virtualbox.domain.StorageController;
import org.jclouds.virtualbox.domain.VmSpec;
import org.virtualbox_4_1.CleanupMode;
import org.virtualbox_4_1.DeviceType;
import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.IMedium;
import org.virtualbox_4_1.IProgress;
@ -38,10 +39,13 @@ import org.virtualbox_4_1.VBoxException;
import org.virtualbox_4_1.VirtualBoxManager;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Throwables;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
public class UnregisterMachineIfExistsAndDeleteItsMedia implements Function<VmSpec, Void> {
public class UnregisterMachineIfExistsAndDeleteItsMedia implements
Function<VmSpec, Void> {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
@ -72,21 +76,41 @@ public class UnregisterMachineIfExistsAndDeleteItsMedia implements Function<VmSp
}
}
if(!mediaToBeDeleted.isEmpty()) {
List<IMedium> filteredMediaToBeDeleted = Lists.newArrayList(Iterables
.filter(mediaToBeDeleted, new AutoDeleteHardDiskPredicate(vmSpec)));
checkNotNull(filteredMediaToBeDeleted);
if (!filteredMediaToBeDeleted.isEmpty()) {
try {
for (IMedium iMedium : mediaToBeDeleted) {
if(iMedium.getDeviceType().equals(DeviceType.HardDisk)) {
IProgress deletion = machine.delete(Lists.newArrayList(iMedium));
deletion.waitForCompletion(-1);
}
}
IProgress deletion = machine.delete(filteredMediaToBeDeleted);
deletion.waitForCompletion(-1);
} catch (Exception e) {
logger.error(e, "Problem in deleting the media attached to %s", machine.getName());
logger.error(e, "Problem in deleting the media attached to %s",
machine.getName());
Throwables.propagate(e);
}
}
return null;
}
private class AutoDeleteHardDiskPredicate implements Predicate<IMedium> {
private VmSpec vmSpec;
public AutoDeleteHardDiskPredicate(VmSpec vmSpec) {
this.vmSpec = vmSpec;
}
@Override
public boolean apply(IMedium medium) {
for (StorageController controller : vmSpec.getControllers()) {
if (controller.getHardDisk(medium.getName()).isAutoDelete())
return true;
}
return false;
}
};
}

View File

@ -19,13 +19,13 @@
package org.jclouds.virtualbox.domain;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import org.testng.annotations.Test;
import org.virtualbox_4_1.CleanupMode;
import org.virtualbox_4_1.StorageBus;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
public class VmSpecTest {
@Test
@ -77,6 +77,8 @@ public class VmSpecTest {
.controller(
StorageController.builder().name("Controller")
.bus(StorageBus.IDE)
.attachHardDisk(0, 0, "/tmp/tempdisk.vdi", "tempdisk").build());
.attachHardDisk(HardDisk.builder().diskpath("/tmp/tempdisk.vdi")
.controllerPort(0).deviceSlot(0).build())
.build());
}
}

View File

@ -27,11 +27,12 @@ import static org.easymock.classextension.EasyMock.createMock;
import static org.easymock.classextension.EasyMock.createNiceMock;
import static org.easymock.classextension.EasyMock.replay;
import static org.easymock.classextension.EasyMock.verify;
import static org.virtualbox_4_1.DeviceType.HardDisk;
import org.jclouds.virtualbox.domain.DeviceDetails;
import org.jclouds.virtualbox.domain.HardDisk;
import org.jclouds.virtualbox.domain.StorageController;
import org.testng.annotations.Test;
import org.virtualbox_4_1.DeviceType;
import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.IMedium;
import org.virtualbox_4_1.IProgress;
@ -54,7 +55,7 @@ public class AttachMediumToMachineIfNotAlreadyAttachedTest {
String diskName = "admin";
String diskFormat = "vdi";
int controllerPort = 0;
int device = 1;
int deviceSlot = 1;
VirtualBoxManager manager = createNiceMock(VirtualBoxManager.class);
IMachine machine = createMock(IMachine.class);
@ -66,14 +67,15 @@ public class AttachMediumToMachineIfNotAlreadyAttachedTest {
expect(vBox.createHardDisk(diskFormat, diskPath)).andReturn(hardDisk);
expect(hardDisk.createBaseStorage(anyLong(), anyLong())).andReturn(progress);
machine.attachDevice(controllerName, controllerPort, device, HardDisk, hardDisk);
machine.attachDevice(controllerName, controllerPort, deviceSlot, DeviceType.HardDisk, hardDisk);
machine.saveSettings();
replay(manager, machine, vBox, hardDisk);
StorageController controller = StorageController.builder()
.name(controllerName)
.bus(StorageBus.IDE)
.attachHardDisk(controllerPort, device, diskPath, diskName)
.attachHardDisk(HardDisk.builder().diskpath(diskPath)
.controllerPort(controllerPort).deviceSlot(deviceSlot).build())
.build();
@ -105,7 +107,7 @@ public class AttachMediumToMachineIfNotAlreadyAttachedTest {
VBoxException isoAttachedException = new VBoxException(createNiceMock(Throwable.class),
isoAlreadyAttachedException);
machine.attachDevice(controllerName, controllerPort, deviceSlot, HardDisk, hardDisk);
machine.attachDevice(controllerName, controllerPort, deviceSlot, DeviceType.HardDisk, hardDisk);
expectLastCall().andThrow(isoAttachedException);
replay(manager, machine, vBox, hardDisk);
@ -113,7 +115,8 @@ public class AttachMediumToMachineIfNotAlreadyAttachedTest {
StorageController controller = StorageController.builder()
.name(controllerName)
.bus(StorageBus.IDE)
.attachHardDisk(controllerPort, deviceSlot, "/Users/mattias/jclouds-virtualbox-test/testadmin.vdi", "testadmin")
.attachHardDisk(HardDisk.builder().diskpath("/Users/mattias/jclouds-virtualbox-test/testadmin.vdi")
.controllerPort(controllerPort).deviceSlot(deviceSlot).build())
.build();
DeviceDetails deviceDetails = getOnlyElement(controller.getHardDisks()).getDeviceDetails();
@ -142,7 +145,7 @@ public class AttachMediumToMachineIfNotAlreadyAttachedTest {
VBoxException isoAttachedException = new VBoxException(createNiceMock(Throwable.class),
isoAlreadyAttachedException);
machine.attachDevice(controllerName, controllerPort, deviceSlot, HardDisk, hardDisk);
machine.attachDevice(controllerName, controllerPort, deviceSlot, DeviceType.HardDisk, hardDisk);
expectLastCall().andThrow(isoAttachedException);
replay(manager, machine, vBox, hardDisk);
@ -151,7 +154,8 @@ public class AttachMediumToMachineIfNotAlreadyAttachedTest {
StorageController controller = StorageController.builder()
.name(controllerName)
.bus(StorageBus.IDE)
.attachHardDisk(controllerPort, deviceSlot, "/Users/mattias/jclouds-virtualbox-test/testadmin.vdi", "testadmin")
.attachHardDisk(HardDisk.builder().diskpath("/Users/mattias/jclouds-virtualbox-test/testadmin.vdi")
.controllerPort(controllerPort).deviceSlot(deviceSlot).build())
.build();
DeviceDetails deviceDetails = getOnlyElement(controller.getHardDisks()).getDeviceDetails();

View File

@ -32,6 +32,7 @@ import org.jclouds.net.IPSocket;
import org.jclouds.predicates.InetSocketAddressConnect;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
import org.jclouds.virtualbox.domain.HardDisk;
import org.jclouds.virtualbox.domain.StorageController;
import org.jclouds.virtualbox.domain.VmSpec;
import org.jclouds.virtualbox.util.PropertyUtils;
@ -90,7 +91,8 @@ public class CloneAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends Ba
String workingDir = PropertyUtils.getWorkingDirFromProperty();
StorageController ideController = StorageController.builder().name(controllerIDE).bus(StorageBus.IDE)
.attachISO(0, 0, workingDir + "/ubuntu-11.04-server-i386.iso")
.attachHardDisk(0, 1, workingDir + "/testadmin.vdi", "testadmin")
.attachHardDisk(HardDisk.builder().diskpath(workingDir + "/testadmin.vdi")
.controllerPort(0).deviceSlot(1).build())
.attachISO(1, 1, workingDir + "/VBoxGuestAdditions_4.1.2.iso").build();
VmSpec vmSpecification = VmSpec.builder().id(vmId).name(vmName).osTypeId(osTypeId)
.memoryMB(512)

View File

@ -44,6 +44,7 @@ import org.jclouds.net.IPSocket;
import org.jclouds.predicates.InetSocketAddressConnect;
import org.jclouds.predicates.RetryablePredicate;
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;
@ -85,14 +86,16 @@ public class CreateAndInstallVmLiveTest extends BaseVirtualBoxClientLiveTest {
credential = "password";
String workingDir = PropertyUtils.getWorkingDirFromProperty();
HardDisk hardDisk = HardDisk.builder().diskpath(workingDir + "/testadmin.vdi").autoDelete(true)
.controllerPort(0).deviceSlot(1).build();
ideController = StorageController.builder().name(ideControllerName).bus(StorageBus.IDE)
.attachISO(0, 0, workingDir + "/ubuntu-11.04-server-i386.iso")
.attachHardDisk(0, 1, workingDir + "/testadmin.vdi", "testadmin")
.attachHardDisk(hardDisk)
.attachISO(1, 1, workingDir + "/VBoxGuestAdditions_4.1.2.iso").build();
vmSpecification = VmSpec.builder().id(vmId).name(vmName).memoryMB(512).osTypeId(osTypeId)
.controller(ideController)
.forceOverwrite(true)
.cleanUpMode(CleanupMode.DetachAllReturnHardDisksOnly)
.cleanUpMode(CleanupMode.Full)
.natNetworkAdapter(0, NatAdapter.builder().tcpRedirectRule("127.0.0.1", 2222, "", 22).build()).build();
new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(vmSpecification);

View File

@ -24,6 +24,7 @@ import static org.testng.Assert.fail;
import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
import org.jclouds.virtualbox.domain.ErrorCode;
import org.jclouds.virtualbox.domain.HardDisk;
import org.jclouds.virtualbox.domain.StorageController;
import org.jclouds.virtualbox.domain.VmSpec;
import org.jclouds.virtualbox.functions.admin.UnregisterMachineIfExistsAndDeleteItsMedia;
@ -51,7 +52,8 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends B
String workingDir = PropertyUtils.getWorkingDirFromProperty();
ideController = StorageController.builder().name(ideControllerName).bus(StorageBus.IDE)
.attachISO(0, 0, workingDir + "/ubuntu-11.04-server-i386.iso")
.attachHardDisk(0, 1, workingDir + "/testadmin.vdi", "testadmin")
.attachHardDisk(HardDisk.builder().diskpath(workingDir + "/testadmin.vdi")
.controllerPort(0).deviceSlot(1).build())
.attachISO(1, 1, workingDir + "/VBoxGuestAdditions_4.1.2.iso").build();
}

View File

@ -19,20 +19,19 @@
package org.jclouds.virtualbox.functions;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import java.io.File;
import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
import org.jclouds.virtualbox.domain.DeviceDetails;
import org.jclouds.virtualbox.domain.ErrorCode;
import org.jclouds.virtualbox.domain.HardDisk;
import org.testng.annotations.Test;
import org.virtualbox_4_1.DeviceType;
import org.virtualbox_4_1.VBoxException;
import java.io.File;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
/**
* @author Mattias Holmqvist
*/
@ -41,7 +40,7 @@ public class CreateMediumIfNotAlreadyExistsLiveTest extends BaseVirtualBoxClient
@Test
public void testCreateMedium() throws Exception {
String path = System.getProperty("user.home") + "/jclouds-virtualbox-test/test-medium-1.vdi";
HardDisk hardDisk = new HardDisk(new DeviceDetails(0, 0, DeviceType.HardDisk), path, "vdi", "vdi");
HardDisk hardDisk = HardDisk.builder().diskpath(path).controllerPort(0).deviceSlot(0).build();
new CreateMediumIfNotAlreadyExists(manager, true).apply(hardDisk);
manager.getVBox().findMedium(path, DeviceType.HardDisk);
assertFileCanBeDeleted(path);
@ -50,7 +49,7 @@ public class CreateMediumIfNotAlreadyExistsLiveTest extends BaseVirtualBoxClient
@Test
public void testCreateMediumFailWhenUsingNonFullyQualifiedPath() throws Exception {
String path = "test-medium-2.vdi";
HardDisk hardDisk = new HardDisk(new DeviceDetails(0, 0, DeviceType.HardDisk), path, "vdi", "vdi");
HardDisk hardDisk = HardDisk.builder().diskpath(path).controllerPort(0).deviceSlot(0).build();
try {
new CreateMediumIfNotAlreadyExists(manager, true).apply(hardDisk);
fail();
@ -63,7 +62,7 @@ public class CreateMediumIfNotAlreadyExistsLiveTest extends BaseVirtualBoxClient
@Test
public void testCreateSameMediumTwiceWhenUsingOverwrite() throws Exception {
String path = System.getProperty("user.home") + "/jclouds-virtualbox-test/test-medium-3.vdi";
HardDisk hardDisk = new HardDisk(new DeviceDetails(0, 0, DeviceType.HardDisk), path, "vdi", "vdi");
HardDisk hardDisk = HardDisk.builder().diskpath(path).controllerPort(0).deviceSlot(0).build();
new CreateMediumIfNotAlreadyExists(manager, true).apply(hardDisk);
new CreateMediumIfNotAlreadyExists(manager, true).apply(hardDisk);
manager.getVBox().findMedium(path, DeviceType.HardDisk);

View File

@ -28,7 +28,6 @@ import static org.easymock.classextension.EasyMock.replay;
import static org.easymock.classextension.EasyMock.verify;
import static org.testng.Assert.assertNotSame;
import org.jclouds.virtualbox.domain.DeviceDetails;
import org.jclouds.virtualbox.domain.HardDisk;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@ -160,7 +159,7 @@ public class CreateMediumIfNotAlreadyExistsTest {
}
private HardDisk createTestHardDisk() {
return new HardDisk(new DeviceDetails(0, 0, DeviceType.HardDisk), adminDiskPath, diskFormat, diskName);
return HardDisk.builder().diskpath(adminDiskPath).controllerPort(0).deviceSlot(0).build();
}
}

View File

@ -29,6 +29,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.jclouds.virtualbox.domain.HardDisk;
import org.jclouds.virtualbox.domain.NatAdapter;
import org.jclouds.virtualbox.domain.StorageController;
import org.jclouds.virtualbox.domain.VmSpec;
@ -63,7 +64,7 @@ public class UnregisterMachineIfExistsAndDeleteItsMediaTest {
String workingDir = PropertyUtils.getWorkingDirFromProperty();
StorageController ideController = StorageController.builder().name(ideControllerName).bus(StorageBus.IDE)
.attachISO(0, 0, workingDir + "/ubuntu-11.04-server-i386.iso")
.attachHardDisk(0, 1, workingDir + "/testadmin.vdi", "testadmin")
.attachHardDisk(HardDisk.builder().diskpath(workingDir + "/testadmin.vdi").controllerPort(0).deviceSlot(1).build())
.attachISO(1, 1, workingDir + "/VBoxGuestAdditions_4.1.2.iso").build();
VmSpec vmSpecification = VmSpec.builder().id(vmId).name(vmName).memoryMB(512).osTypeId(osTypeId)
.controller(ideController)

View File

@ -1,24 +1,5 @@
package org.jclouds.virtualbox.predicates;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import org.jclouds.compute.ComputeServiceContext;
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.domain.ExecutionType;
import org.jclouds.virtualbox.domain.StorageController;
import org.jclouds.virtualbox.domain.VmSpec;
import org.jclouds.virtualbox.functions.CreateAndInstallVm;
import org.jclouds.virtualbox.functions.LaunchMachineIfNotAlreadyRunning;
import org.jclouds.virtualbox.util.PropertyUtils;
import org.testng.annotations.Test;
import org.virtualbox_4_1.*;
import java.util.concurrent.TimeUnit;
import static org.jclouds.virtualbox.domain.ExecutionType.HEADLESS;
import static org.jclouds.virtualbox.experiment.TestUtils.computeServiceForLocalhostAndGuest;
import static org.jclouds.virtualbox.util.MachineUtils.applyForMachine;
@ -26,6 +7,31 @@ import static org.jclouds.virtualbox.util.MachineUtils.lockSessionOnMachineAndAp
import static org.testng.Assert.assertTrue;
import static org.virtualbox_4_1.LockType.Shared;
import java.util.concurrent.TimeUnit;
import org.jclouds.compute.ComputeServiceContext;
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.domain.ExecutionType;
import org.jclouds.virtualbox.domain.HardDisk;
import org.jclouds.virtualbox.domain.StorageController;
import org.jclouds.virtualbox.domain.VmSpec;
import org.jclouds.virtualbox.functions.CreateAndInstallVm;
import org.jclouds.virtualbox.functions.LaunchMachineIfNotAlreadyRunning;
import org.jclouds.virtualbox.util.PropertyUtils;
import org.testng.annotations.Test;
import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.IProgress;
import org.virtualbox_4_1.ISession;
import org.virtualbox_4_1.StorageBus;
import org.virtualbox_4_1.VirtualBoxManager;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
@Test(groups = "live", singleThreaded = true, testName = "SshAvailableLiveTest")
public class SshAvailableLiveTest extends BaseVirtualBoxClientLiveTest {
@ -64,12 +70,11 @@ public class SshAvailableLiveTest extends BaseVirtualBoxClientLiveTest {
Predicate<IPSocket> socketTester = new RetryablePredicate<IPSocket>(
new InetSocketAddressConnect(), 10, 1, TimeUnit.SECONDS);
String vmId = "jclouds-image-iso-2";
String isoName = "ubuntu-11.04-server-i386.iso";
String workingDir = PropertyUtils.getWorkingDirFromProperty();
StorageController ideController = StorageController.builder().name("IDE Controller").bus(StorageBus.IDE)
.attachISO(0, 0, workingDir + "/ubuntu-11.04-server-i386.iso")
.attachHardDisk(0, 1, workingDir + "/testadmin.vdi", "testadmin").build();
.attachHardDisk(HardDisk.builder().diskpath(workingDir + "/testadmin.vdi").controllerPort(0).deviceSlot(1).build()).build();
VmSpec vmSpecification = VmSpec.builder().id(vmId).name(vmName).osTypeId("")
.memoryMB(512)
.controller(ideController)