improved hardware matching (hardware's id is now the same as the image id *without* prefix)

This commit is contained in:
David Ribeiro Alves 2012-03-12 15:03:56 +00:00
parent 3370dd819d
commit 8f92009699
1 changed files with 5 additions and 4 deletions

View File

@ -25,6 +25,7 @@ import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.HardwareBuilder; import org.jclouds.compute.domain.HardwareBuilder;
import org.jclouds.compute.predicates.ImagePredicates; import org.jclouds.compute.predicates.ImagePredicates;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import org.jclouds.virtualbox.config.VirtualBoxConstants;
import org.virtualbox_4_1.IGuestOSType; import org.virtualbox_4_1.IGuestOSType;
import org.virtualbox_4_1.IMachine; import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.VirtualBoxManager; import org.virtualbox_4_1.VirtualBoxManager;
@ -44,14 +45,14 @@ public class IMachineToHardware implements Function<IMachine, Hardware> {
@Override @Override
public Hardware apply(@Nullable IMachine vm) { public Hardware apply(@Nullable IMachine vm) {
String osTypeId = vm.getOSTypeId(); String osTypeId = vm.getOSTypeId();
String vmNameWithoutPrefix = vm.getName().replace(VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX, "");
IGuestOSType guestOSType = virtualBoxManager.get().getVBox().getGuestOSType(osTypeId); IGuestOSType guestOSType = virtualBoxManager.get().getVBox().getGuestOSType(osTypeId);
Boolean is64Bit = guestOSType.getIs64Bit(); Boolean is64Bit = guestOSType.getIs64Bit();
HardwareBuilder hardwareBuilder = new HardwareBuilder(); HardwareBuilder hardwareBuilder = new HardwareBuilder();
hardwareBuilder.ids(vm.getName()); hardwareBuilder.ids(vmNameWithoutPrefix);
hardwareBuilder.supportsImage(ImagePredicates.idEquals(vm.getName()));
hardwareBuilder.is64Bit(is64Bit); hardwareBuilder.is64Bit(is64Bit);
hardwareBuilder.supportsImage(ImagePredicates.idEquals(vm.getName())); hardwareBuilder.supportsImage(ImagePredicates.idEquals(vmNameWithoutPrefix));
hardwareBuilder.hypervisor("VirtualBox"); hardwareBuilder.hypervisor("VirtualBox");
return hardwareBuilder.build(); return hardwareBuilder.build();
} }