linked image to hardware in virtualbox

This commit is contained in:
Adrian Cole 2011-09-27 15:11:39 -07:00
parent 65f3bd17a3
commit 2baf711a32
2 changed files with 19 additions and 12 deletions

View File

@ -21,15 +21,17 @@
package org.jclouds.virtualbox.functions;
import com.google.common.base.Function;
import javax.inject.Inject;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.HardwareBuilder;
import org.jclouds.compute.predicates.ImagePredicates;
import org.jclouds.javax.annotation.Nullable;
import org.virtualbox_4_1.IGuestOSType;
import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.VirtualBoxManager;
import javax.inject.Inject;
import com.google.common.base.Function;
public class IMachineToHardware implements Function<IMachine, Hardware> {
@ -50,6 +52,7 @@ public class IMachineToHardware implements Function<IMachine, Hardware> {
HardwareBuilder hardwareBuilder = new HardwareBuilder();
hardwareBuilder.ids(vm.getId());
hardwareBuilder.is64Bit(is64Bit);
hardwareBuilder.supportsImage(ImagePredicates.idEquals(vm.getId()));
return hardwareBuilder.build();
}
}

View File

@ -21,19 +21,20 @@
package org.jclouds.virtualbox.functions;
import org.jclouds.compute.domain.Hardware;
import org.testng.annotations.Test;
import org.virtualbox_4_1.IGuestOSType;
import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.IVirtualBox;
import org.virtualbox_4_1.VirtualBoxManager;
import static org.easymock.EasyMock.eq;
import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createNiceMock;
import static org.easymock.classextension.EasyMock.replay;
import static org.testng.Assert.assertEquals;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.predicates.ImagePredicates;
import org.testng.annotations.Test;
import org.virtualbox_4_1.IGuestOSType;
import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.IVirtualBox;
import org.virtualbox_4_1.VirtualBoxManager;
@Test(groups = "unit")
public class IMachineToHardwareTest {
@ -53,7 +54,7 @@ public class IMachineToHardwareTest {
expect(vBox.getGuestOSType(eq("os-type"))).andReturn(guestOsType);
expect(vbm.getVBox()).andReturn(vBox);
expect(guestOsType.getIs64Bit()).andReturn(true);
expect(vm.getId()).andReturn(machineId);
expect(vm.getId()).andReturn(machineId).atLeastOnce();
replay(vbm, vBox, vm, guestOsType);
@ -61,7 +62,10 @@ public class IMachineToHardwareTest {
assertEquals(hardware.getId(), machineId);
assertEquals(hardware.getProviderId(), machineId);
// for starters assume 1-to-1 relationship hardware to image (which
// correlate to a single source IMachine)
assertEquals(hardware.supportsImage().toString(), ImagePredicates.idEquals(machineId).toString());
}
}