formatting in virtualbox

This commit is contained in:
Adrian Cole 2011-10-29 11:00:02 +02:00
parent 71ac2b89e1
commit d300681bcc
45 changed files with 853 additions and 820 deletions

View File

@ -30,11 +30,11 @@ import com.google.inject.Module;
/**
* Creates compute service context for VirtualBox
*
*
* @author Mattias Holmqvist, Andrea Turli
*/
public class VirtualBoxContextBuilder extends StandaloneComputeServiceContextBuilder<VirtualBoxManager> {
public VirtualBoxContextBuilder(Properties properties) {
super(VirtualBoxManager.class, properties);
}
@ -43,5 +43,5 @@ public class VirtualBoxContextBuilder extends StandaloneComputeServiceContextBui
protected void addContextModule(List<Module> modules) {
modules.add(new VirtualBoxComputeServiceContextModule());
}
}

View File

@ -19,17 +19,19 @@
package org.jclouds.virtualbox;
import org.jclouds.PropertiesBuilder;
import org.jclouds.virtualbox.config.VirtualBoxConstants;
import static org.jclouds.Constants.PROPERTY_CREDENTIAL;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.Constants.PROPERTY_IDENTITY;
import java.io.File;
import java.util.Properties;
import static org.jclouds.Constants.*;
import org.jclouds.PropertiesBuilder;
import org.jclouds.virtualbox.config.VirtualBoxConstants;
/**
* Builds properties for VirtualBox integration.
*
*
* @author Mattias Holmqvist
*/
public class VirtualBoxPropertiesBuilder extends PropertiesBuilder {
@ -51,24 +53,24 @@ public class VirtualBoxPropertiesBuilder extends PropertiesBuilder {
properties.put(VirtualBoxConstants.VIRTUALBOX_PRESEED_URL, "http://dl.dropbox.com/u/693111/preseed.cfg");
properties.put(VirtualBoxConstants.VIRTUALBOX_SNAPSHOT_DESCRIPTION, "jclouds-virtualbox-snaphot");
properties.put(VirtualBoxConstants.VIRTUALBOX_HOSTNAME, "jclouds-virtualbox-kickstart-admin");
properties.put(VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE, "<Esc><Esc><Enter> "
+ "/install/vmlinuz noapic preseed/url=http://10.0.2.2:8080/src/test/resources/preseed.cfg "
+ "debian-installer=en_US auto locale=en_US kbd-chooser/method=us "
+ "hostname="
+ properties.get(VirtualBoxConstants.VIRTUALBOX_HOSTNAME)
+ " "
+ "fb=false debconf/frontend=noninteractive "
+ "keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false "
+ "initrd=/install/initrd.gz -- <Enter>");
properties
.put(VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE,
"<Esc><Esc><Enter> "
+ "/install/vmlinuz noapic preseed/url=http://10.0.2.2:8080/src/test/resources/preseed.cfg "
+ "debian-installer=en_US auto locale=en_US kbd-chooser/method=us "
+ "hostname="
+ properties.get(VirtualBoxConstants.VIRTUALBOX_HOSTNAME)
+ " "
+ "fb=false debconf/frontend=noninteractive "
+ "keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false "
+ "initrd=/install/initrd.gz -- <Enter>");
properties.put(VirtualBoxConstants.VIRTUALBOX_WORKINGDIR, System.getProperty("user.home") + File.separator
+ System.getProperty("test.virtualbox.workingDir", "jclouds-virtualbox-test"));
properties.put(VirtualBoxConstants.VIRTUALBOX_WORKINGDIR, System.getProperty("user.home")
+ File.separator
+ System.getProperty("test.virtualbox.workingDir",
"jclouds-virtualbox-test"));
// TODO: Add more properties and use the wired properties from test code.
properties.put(VirtualBoxConstants.VIRTUALBOX_DISTRO_ISO_NAME, "ubuntu-11.04-server-i386.iso");
properties.put(VirtualBoxConstants.VIRTUALBOX_JETTY_PORT, "8080");
return properties;

View File

@ -19,23 +19,28 @@
package org.jclouds.virtualbox.compute;
import com.google.common.base.Function;
import com.google.common.cache.CacheLoader;
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_MACHINE_CREDENTIAL;
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_MACHINE_GROUP;
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_MACHINE_LOCATION;
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_MACHINE_USERNAME;
import java.net.URI;
import java.net.URISyntaxException;
import javax.inject.Inject;
import org.jclouds.byon.Node;
import org.jclouds.compute.domain.OsFamily;
import org.virtualbox_4_1.IGuestOSType;
import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.VirtualBoxManager;
import javax.inject.Inject;
import java.net.URI;
import java.net.URISyntaxException;
import static org.jclouds.virtualbox.config.VirtualBoxConstants.*;
import com.google.common.base.Function;
import com.google.common.cache.CacheLoader;
/**
* Loads a node from a VirtualBox IMachine
*
*
* @author Mattias Holmqvist
*/
public class LoadMachineFromVirtualBox extends CacheLoader<String, Node> {
@ -53,16 +58,10 @@ public class LoadMachineFromVirtualBox extends CacheLoader<String, Node> {
public Node load(final String id) throws Exception {
if (id.equals("host")) {
final Node hostNode = Node.builder().id("host")
.name("host installing virtualbox")
.hostname("localhost")
.osFamily(OsFamily.LINUX.toString())
.osDescription(System.getProperty("os.name"))
.osVersion(System.getProperty("os.version"))
.group("ssh")
.username(System.getProperty("user.name"))
.credentialUrl(privateKeyFile())
.build();
final Node hostNode = Node.builder().id("host").name("host installing virtualbox").hostname("localhost")
.osFamily(OsFamily.LINUX.toString()).osDescription(System.getProperty("os.name"))
.osVersion(System.getProperty("os.version")).group("ssh").username(System.getProperty("user.name"))
.credentialUrl(privateKeyFile()).build();
return hostNode;
}
@ -71,23 +70,14 @@ public class LoadMachineFromVirtualBox extends CacheLoader<String, Node> {
final String osTypeId = machine.getOSTypeId();
final IGuestOSType guestOSType = manager.getVBox().getGuestOSType(osTypeId);
final Node node = Node.builder()
.id(machine.getId())
.name(machine.getName())
.description(machine.getDescription())
.loginPort(22)
.group(System.getProperty(VIRTUALBOX_MACHINE_GROUP))
.username(System.getProperty(VIRTUALBOX_MACHINE_USERNAME))
.credential(System.getProperty(VIRTUALBOX_MACHINE_CREDENTIAL))
.sudoPassword(System.getProperty(VIRTUALBOX_MACHINE_CREDENTIAL))
.locationId(System.getProperty(VIRTUALBOX_MACHINE_LOCATION))
.os64Bit(guestOSType.getIs64Bit())
.osArch(guestOSType.getDescription())
.osFamily(guestOSType.getFamilyDescription())
.osVersion(guestOSType.getId())
.osDescription(guestOSType.getDescription())
.hostname(ipAddress)
.build();
final Node node = Node.builder().id(machine.getId()).name(machine.getName())
.description(machine.getDescription()).loginPort(22).group(System.getProperty(VIRTUALBOX_MACHINE_GROUP))
.username(System.getProperty(VIRTUALBOX_MACHINE_USERNAME))
.credential(System.getProperty(VIRTUALBOX_MACHINE_CREDENTIAL))
.sudoPassword(System.getProperty(VIRTUALBOX_MACHINE_CREDENTIAL))
.locationId(System.getProperty(VIRTUALBOX_MACHINE_LOCATION)).os64Bit(guestOSType.getIs64Bit())
.osArch(guestOSType.getDescription()).osFamily(guestOSType.getFamilyDescription())
.osVersion(guestOSType.getId()).osDescription(guestOSType.getDescription()).hostname(ipAddress).build();
return node;

View File

@ -19,10 +19,16 @@
package org.jclouds.virtualbox.compute;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Throwables;
import com.google.inject.Singleton;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.transform;
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX;
import java.util.Collections;
import java.util.Map;
import javax.inject.Inject;
import org.jclouds.compute.ComputeServiceAdapter;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.Template;
@ -30,15 +36,17 @@ import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.location.suppliers.JustProvider;
import org.virtualbox_4_1.*;
import org.virtualbox_4_1.CleanupMode;
import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.IProgress;
import org.virtualbox_4_1.ISession;
import org.virtualbox_4_1.SessionState;
import org.virtualbox_4_1.VirtualBoxManager;
import javax.inject.Inject;
import java.util.*;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.transform;
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Throwables;
import com.google.inject.Singleton;
/**
* Defines the connection between the
@ -55,7 +63,8 @@ public class VirtualBoxComputeServiceAdapter implements ComputeServiceAdapter<IM
private Function<IMachine, Image> iMachineToImage;
@Inject
public VirtualBoxComputeServiceAdapter(VirtualBoxManager manager, JustProvider justProvider, Function<IMachine, Image> iMachineToImage) {
public VirtualBoxComputeServiceAdapter(VirtualBoxManager manager, JustProvider justProvider,
Function<IMachine, Image> iMachineToImage) {
this.iMachineToImage = iMachineToImage;
this.manager = checkNotNull(manager, "manager");
this.justProvider = checkNotNull(justProvider, "justProvider");
@ -77,8 +86,8 @@ public class VirtualBoxComputeServiceAdapter implements ComputeServiceAdapter<IM
return manager.getVBox().getMachines();
}
@Override
public Iterable<Image> listImages() {
@Override
public Iterable<Image> listImages() {
final Predicate<? super IMachine> imagePredicate = new Predicate<IMachine>() {
@Override
public boolean apply(@Nullable IMachine iMachine) {
@ -87,7 +96,7 @@ public class VirtualBoxComputeServiceAdapter implements ComputeServiceAdapter<IM
};
final Iterable<IMachine> imageMachines = filter(manager.getVBox().getMachines(), imagePredicate);
return transform(imageMachines, iMachineToImage);
}
}
@SuppressWarnings("unchecked")
@Override

View File

@ -57,20 +57,21 @@ import com.google.inject.TypeLiteral;
/**
* @author Mattias Holmqvist, Andrea Turli
*/
public class VirtualBoxComputeServiceContextModule extends ComputeServiceAdapterContextModule<VirtualBoxManager, VirtualBoxManager, IMachine, IMachine, Image, Location> {
public class VirtualBoxComputeServiceContextModule extends
ComputeServiceAdapterContextModule<VirtualBoxManager, VirtualBoxManager, IMachine, IMachine, Image, Location> {
public VirtualBoxComputeServiceContextModule() {
super(VirtualBoxManager.class, VirtualBoxManager.class);
}
@Provides
@Singleton
protected VirtualBoxManager createInstance(@Provider URI endpoint, @Named(Constants.PROPERTY_IDENTITY) String identity,
@Named(Constants.PROPERTY_CREDENTIAL) String credential) {
VirtualBoxManager manager = VirtualBoxManager.createInstance("");
manager.connect(endpoint.toASCIIString(), identity, credential);
return manager;
protected VirtualBoxManager createInstance(@Provider URI endpoint,
@Named(Constants.PROPERTY_IDENTITY) String identity, @Named(Constants.PROPERTY_CREDENTIAL) String credential) {
VirtualBoxManager manager = VirtualBoxManager.createInstance("");
manager.connect(endpoint.toASCIIString(), identity, credential);
return manager;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@ -100,31 +101,24 @@ public class VirtualBoxComputeServiceContextModule extends ComputeServiceAdapter
@VisibleForTesting
public static final Map<MachineState, NodeState> machineToNodeState = ImmutableMap
.<MachineState, NodeState>builder()
.put(MachineState.Running, NodeState.RUNNING)
.put(MachineState.PoweredOff, NodeState.SUSPENDED)
.put(MachineState.DeletingSnapshot, NodeState.PENDING)
.put(MachineState.DeletingSnapshotOnline, NodeState.PENDING)
.put(MachineState.DeletingSnapshotPaused, NodeState.PENDING)
.put(MachineState.FaultTolerantSyncing, NodeState.PENDING)
.put(MachineState.LiveSnapshotting, NodeState.PENDING)
.put(MachineState.SettingUp, NodeState.PENDING)
.put(MachineState.Starting, NodeState.PENDING)
.put(MachineState.Stopping, NodeState.PENDING)
.put(MachineState.Restoring, NodeState.PENDING)
// TODO What to map these states to?
.put(MachineState.FirstOnline, NodeState.PENDING)
.put(MachineState.FirstTransient, NodeState.PENDING)
.put(MachineState.LastOnline, NodeState.PENDING)
.put(MachineState.LastTransient, NodeState.PENDING)
.put(MachineState.Teleported, NodeState.PENDING)
.put(MachineState.TeleportingIn, NodeState.PENDING)
.put(MachineState.TeleportingPausedVM, NodeState.PENDING)
.<MachineState, NodeState> builder().put(MachineState.Running, NodeState.RUNNING)
.put(MachineState.PoweredOff, NodeState.SUSPENDED).put(MachineState.DeletingSnapshot, NodeState.PENDING)
.put(MachineState.DeletingSnapshotOnline, NodeState.PENDING)
.put(MachineState.DeletingSnapshotPaused, NodeState.PENDING)
.put(MachineState.FaultTolerantSyncing, NodeState.PENDING)
.put(MachineState.LiveSnapshotting, NodeState.PENDING)
.put(MachineState.SettingUp, NodeState.PENDING)
.put(MachineState.Starting, NodeState.PENDING)
.put(MachineState.Stopping, NodeState.PENDING)
.put(MachineState.Restoring, NodeState.PENDING)
// TODO What to map these states to?
.put(MachineState.FirstOnline, NodeState.PENDING).put(MachineState.FirstTransient, NodeState.PENDING)
.put(MachineState.LastOnline, NodeState.PENDING).put(MachineState.LastTransient, NodeState.PENDING)
.put(MachineState.Teleported, NodeState.PENDING).put(MachineState.TeleportingIn, NodeState.PENDING)
.put(MachineState.TeleportingPausedVM, NodeState.PENDING)
.put(MachineState.Aborted, NodeState.ERROR).put(MachineState.Stuck, NodeState.ERROR)
.put(MachineState.Aborted, NodeState.ERROR)
.put(MachineState.Stuck, NodeState.ERROR)
.put(MachineState.Null, NodeState.UNRECOGNIZED).build();
.put(MachineState.Null, NodeState.UNRECOGNIZED).build();
}

View File

@ -21,7 +21,7 @@ package org.jclouds.virtualbox.config;
/**
* Configuration properties used for interacting with VirtualBox instances.
*
*
* @author Mattias Holmqvist, Andrea Turli
*
*/
@ -34,11 +34,11 @@ public interface VirtualBoxConstants {
public static final String VIRTUALBOX_SNAPSHOT_DESCRIPTION = "jclouds.virtualbox.snapshotDescription";
public static final String VIRTUALBOX_INSTALLATION_KEY_SEQUENCE = "jclouds.virtualbox.installationkeysequence";
public static final String VIRTUALBOX_HOSTNAME = "jclouds.virtualbox.hostname";
public static final String VIRTUALBOX_WORKINGDIR = "jclouds.virtualbox.workingdir";
public static final String VIRTUALBOX_ISOFILE = "jclouds.virtualbox.isofile";
public static final String VIRTUALBOX_MACHINE_GROUP = "jclouds.virtualbox.machinegroup";

View File

@ -1,4 +1,4 @@
/*
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -19,17 +19,18 @@
package org.jclouds.virtualbox.domain;
import org.virtualbox_4_1.VBoxException;
import org.virtualbox_4_1.jaxws.RuntimeFaultMsg;
import java.util.HashMap;
import java.util.Map;
import org.virtualbox_4_1.VBoxException;
import org.virtualbox_4_1.jaxws.RuntimeFaultMsg;
/**
* Maps the error codes in the Virtual Box Java API into enum values.
* <p/>
* <p/>
* To get the error code from a VBoxException, use:
*
* <pre>
* try {
* ...
@ -41,32 +42,17 @@ import java.util.Map;
* ErrorCode errorCode = ErrorCode.valueOf(faultCode);
* }
* </pre>
*
*
* @author Mattias Holmqvist
*/
public enum ErrorCode {
VBOX_E_OBJECT_NOT_FOUND(2159738881L),
VBOX_E_INVALID_VM_STATE(2159738882L),
VBOX_E_VM_ERROR(2159738883L),
VBOX_E_FILE_ERROR(2159738884L),
VBOX_E_IPRT_ERROR(2159738885L),
VBOX_E_PDM_ERROR(2159738886L),
VBOX_E_INVALID_OBJECT_STATE(2159738887L),
VBOX_E_HOST_ERROR(2159738888L),
VBOX_E_NOT_SUPPORTED(2159738889L),
VBOX_E_XML_ERROR(2159738890L),
VBOX_E_INVALID_SESSION_STATE(2159738891L),
VBOX_E_OBJECT_IN_USE(2159738892L),
VBOX_E_ACCESSDENIED(2147942405L),
VBOX_E_POINTER(2147500035L),
VBOX_E_FAIL(2147500037L),
VBOX_E_NOTIMPL(2147500033L),
VBOX_E_OUTOFMEMORY(2147942414L),
VBOX_E_INVALIDARG(2147942487L),
VBOX_E_UNEXPECTED(2147549183L),
VBOX_E_UNKNOWN_ERROR_CODE(-1L),
VBOX_E_ERROR_CODE_UNAVAILABLE(-2L);
VBOX_E_OBJECT_NOT_FOUND(2159738881L), VBOX_E_INVALID_VM_STATE(2159738882L), VBOX_E_VM_ERROR(2159738883L), VBOX_E_FILE_ERROR(
2159738884L), VBOX_E_IPRT_ERROR(2159738885L), VBOX_E_PDM_ERROR(2159738886L), VBOX_E_INVALID_OBJECT_STATE(
2159738887L), VBOX_E_HOST_ERROR(2159738888L), VBOX_E_NOT_SUPPORTED(2159738889L), VBOX_E_XML_ERROR(2159738890L), VBOX_E_INVALID_SESSION_STATE(
2159738891L), VBOX_E_OBJECT_IN_USE(2159738892L), VBOX_E_ACCESSDENIED(2147942405L), VBOX_E_POINTER(2147500035L), VBOX_E_FAIL(
2147500037L), VBOX_E_NOTIMPL(2147500033L), VBOX_E_OUTOFMEMORY(2147942414L), VBOX_E_INVALIDARG(2147942487L), VBOX_E_UNEXPECTED(
2147549183L), VBOX_E_UNKNOWN_ERROR_CODE(-1L), VBOX_E_ERROR_CODE_UNAVAILABLE(-2L);
private long code;
@ -84,8 +70,9 @@ public enum ErrorCode {
/**
* Returns an ErrorCode from the fault code given by the VirtualBox API.
*
* @param vboxException the exception to get the error code from.
*
* @param vboxException
* the exception to get the error code from.
* @return an ErrorCode representing the given fault code.
*/
public static ErrorCode valueOf(VBoxException vboxException) {

View File

@ -1,4 +1,4 @@
/*
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -21,10 +21,7 @@ package org.jclouds.virtualbox.domain;
public enum ExecutionType {
GUI("gui"),
HEADLESS("headless"),
SDL("sdl"),
EMERGENCYSTOP("emergencystop");
GUI("gui"), HEADLESS("headless"), SDL("sdl"), EMERGENCYSTOP("emergencystop");
private final String type;

View File

@ -41,73 +41,73 @@ import com.google.common.collect.Maps;
* Serializes to the following
*
* <pre>
id: myTestId
name: ubuntu-11.04-server-i386
description: ubuntu 11.04 server (i386)
os_arch: x86
os_family: linux
os_description: ubuntu
os_version: 11.04
iso: http://releases.ubuntu.com/11.04/ubuntu-11.04-server-i386.iso
keystroke_sequence: |
<Esc><Esc><Enter>
/install/vmlinuz noapic preseed/url=http://10.0.2.2:8080/src/test/resources/preseed.cfg
debian-installer=en_US auto locale=en_US kbd-chooser/method=us
hostname=vmName
fb=false debconf/frontend=noninteractive
keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false
initrd=/install/initrd.gz -- <Enter>
preseed_cfg: |
## Options to set on the command line
d-i debian-installer/locale string en_US.utf8
d-i console-setup/ask_detect boolean false
d-i console-setup/layout string USA
d-i netcfg/get_hostname string unassigned-hostname
d-i netcfg/get_domain string unassigned-domain
# Continue without a default route
# Not working , specify a dummy in the DHCP
d-i time/zone string UTC
d-i clock-setup/utc-auto boolean true
d-i clock-setup/utc boolean true
d-i kbd-chooser/method select American English
d-i netcfg/wireless_wep string
d-i base-installer/kernel/override-image string linux-server
# Choices: Dialog, Readline, Gnome, Kde, Editor, Noninteractive
d-i debconf debconf/frontend select Noninteractive
d-i pkgsel/install-language-support boolean false
tasksel tasksel/first multiselect standard, ubuntu-server
d-i partman-auto/method string lvm
d-i partman-lvm/confirm boolean true
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-auto/choose_recipe select atomic
d-i partman/confirm_write_new_label boolean true
d-i partman/confirm_nooverwrite boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
# Write the changes to disks and configure LVM?
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman-auto-lvm/guided_size string max
## Default user, we can get away with a recipe to change this
d-i passwd/user-fullname string toor
d-i passwd/username string toor
d-i passwd/user-password password password
d-i passwd/user-password-again password password
d-i user-setup/encrypt-home boolean false
d-i user-setup/allow-password-weak boolean true
# Individual additional packages to install
d-i pkgsel/include string openssh-server ntp
# Whether to upgrade packages after debootstrap.
# Allowed values: none, safe-upgrade, full-upgrade
d-i pkgsel/upgrade select full-upgrade
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true
d-i finish-install/reboot_in_progress note
#For the update
d-i pkgsel/update-policy select none
# debconf-get-selections --install
#Use mirror
choose-mirror-bin mirror/http/proxy string
* id: myTestId
* name: ubuntu-11.04-server-i386
* description: ubuntu 11.04 server (i386)
* os_arch: x86
* os_family: linux
* os_description: ubuntu
* os_version: 11.04
* iso: http://releases.ubuntu.com/11.04/ubuntu-11.04-server-i386.iso
* keystroke_sequence: |
* <Esc><Esc><Enter>
* /install/vmlinuz noapic preseed/url=http://10.0.2.2:8080/src/test/resources/preseed.cfg
* debian-installer=en_US auto locale=en_US kbd-chooser/method=us
* hostname=vmName
* fb=false debconf/frontend=noninteractive
* keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false
* initrd=/install/initrd.gz -- <Enter>
* preseed_cfg: |
* ## Options to set on the command line
* d-i debian-installer/locale string en_US.utf8
* d-i console-setup/ask_detect boolean false
* d-i console-setup/layout string USA
* d-i netcfg/get_hostname string unassigned-hostname
* d-i netcfg/get_domain string unassigned-domain
* # Continue without a default route
* # Not working , specify a dummy in the DHCP
* d-i time/zone string UTC
* d-i clock-setup/utc-auto boolean true
* d-i clock-setup/utc boolean true
* d-i kbd-chooser/method select American English
* d-i netcfg/wireless_wep string
* d-i base-installer/kernel/override-image string linux-server
* # Choices: Dialog, Readline, Gnome, Kde, Editor, Noninteractive
* d-i debconf debconf/frontend select Noninteractive
* d-i pkgsel/install-language-support boolean false
* tasksel tasksel/first multiselect standard, ubuntu-server
* d-i partman-auto/method string lvm
* d-i partman-lvm/confirm boolean true
* d-i partman-lvm/device_remove_lvm boolean true
* d-i partman-auto/choose_recipe select atomic
* d-i partman/confirm_write_new_label boolean true
* d-i partman/confirm_nooverwrite boolean true
* d-i partman/choose_partition select finish
* d-i partman/confirm boolean true
* # Write the changes to disks and configure LVM?
* d-i partman-lvm/confirm boolean true
* d-i partman-lvm/confirm_nooverwrite boolean true
* d-i partman-auto-lvm/guided_size string max
* ## Default user, we can get away with a recipe to change this
* d-i passwd/user-fullname string toor
* d-i passwd/username string toor
* d-i passwd/user-password password password
* d-i passwd/user-password-again password password
* d-i user-setup/encrypt-home boolean false
* d-i user-setup/allow-password-weak boolean true
* # Individual additional packages to install
* d-i pkgsel/include string openssh-server ntp
* # Whether to upgrade packages after debootstrap.
* # Allowed values: none, safe-upgrade, full-upgrade
* d-i pkgsel/upgrade select full-upgrade
* d-i grub-installer/only_debian boolean true
* d-i grub-installer/with_other_os boolean true
* d-i finish-install/reboot_in_progress note
* #For the update
* d-i pkgsel/update-policy select none
* # debconf-get-selections --install
* #Use mirror
* choose-mirror-bin mirror/http/proxy string
* </pre>
*
* @author Kelvin Kakugawa
@ -143,14 +143,11 @@ public class YamlImage {
return null;
OsFamily family = parseOsFamilyOrUnrecognized(arg0.os_family);
OperatingSystem operatingSystem = OperatingSystem.builder()
.description(arg0.os_description)
.family(family)
.version(arg0.os_version)
.is64Bit(arg0.os_64bit)
.build();
OperatingSystem operatingSystem = OperatingSystem.builder().description(arg0.os_description).family(family)
.version(arg0.os_version).is64Bit(arg0.os_64bit).build();
return new ImageBuilder().id(arg0.id).name(arg0.name).description(arg0.description).operatingSystem(operatingSystem).build();
return new ImageBuilder().id(arg0.id).name(arg0.name).description(arg0.description)
.operatingSystem(operatingSystem).build();
}
};

View File

@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.virtualbox.functions;
import static com.google.common.base.Preconditions.checkNotNull;

View File

@ -1,4 +1,4 @@
/*
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -19,10 +19,11 @@
package org.jclouds.virtualbox.functions;
import com.google.common.base.Function;
import javax.annotation.Nullable;
import org.virtualbox_4_1.IMachine;
import javax.annotation.Nullable;
import com.google.common.base.Function;
/**
* @author Mattias Holmqvist

View File

@ -19,13 +19,14 @@
package org.jclouds.virtualbox.functions;
import com.google.common.base.Function;
import javax.annotation.Nullable;
import org.virtualbox_4_1.DeviceType;
import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.IMedium;
import org.virtualbox_4_1.VBoxException;
import javax.annotation.Nullable;
import com.google.common.base.Function;
/**
* @author Mattias Holmqvist

View File

@ -19,12 +19,14 @@
package org.jclouds.virtualbox.functions;
import com.google.common.base.Function;
import org.virtualbox_4_1.*;
import javax.annotation.Nullable;
import static org.virtualbox_4_1.DeviceType.HardDisk;
import org.virtualbox_4_1.DeviceType;
import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.IMedium;
import org.virtualbox_4_1.VBoxException;
import com.google.common.base.Function;
/**
* @author Mattias Holmqvist
@ -37,7 +39,8 @@ public class AttachMediumToMachineIfNotAlreadyAttached implements Function<IMach
private int device;
private DeviceType deviceType;
public AttachMediumToMachineIfNotAlreadyAttached(String controllerIDE, IMedium hardDisk, int controllerPort, int device, DeviceType deviceType) {
public AttachMediumToMachineIfNotAlreadyAttached(String controllerIDE, IMedium hardDisk, int controllerPort,
int device, DeviceType deviceType) {
this.controllerIDE = controllerIDE;
this.hardDisk = hardDisk;
this.controllerPort = controllerPort;

View File

@ -1,4 +1,4 @@
/*
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -19,14 +19,15 @@
package org.jclouds.virtualbox.functions;
import com.google.common.base.Function;
import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.INetworkAdapter;
import static org.virtualbox_4_1.NATProtocol.TCP;
import static org.virtualbox_4_1.NetworkAttachmentType.NAT;
import javax.annotation.Nullable;
import static org.virtualbox_4_1.NATProtocol.TCP;
import static org.virtualbox_4_1.NetworkAttachmentType.NAT;
import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.INetworkAdapter;
import com.google.common.base.Function;
/**
* @author Mattias Holmqvist

View File

@ -19,14 +19,14 @@
package org.jclouds.virtualbox.functions;
import javax.annotation.Nullable;
import com.google.common.base.Function;
import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.IVirtualBox;
import org.virtualbox_4_1.VBoxException;
import org.virtualbox_4_1.VirtualBoxManager;
import javax.annotation.Nullable;
import com.google.common.base.Function;
/**
* @author Mattias Holmqvist
@ -40,7 +40,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExists implements Functi
private VirtualBoxManager manager;
public CreateAndRegisterMachineFromIsoIfNotAlreadyExists(String settingsFile, String osTypeId, String vmId,
boolean forceOverwrite, VirtualBoxManager manager) {
boolean forceOverwrite, VirtualBoxManager manager) {
this.settingsFile = settingsFile;
this.osTypeId = osTypeId;
this.vmId = vmId;

View File

@ -19,11 +19,17 @@
package org.jclouds.virtualbox.functions;
import com.google.common.base.Function;
import org.virtualbox_4_1.*;
import javax.annotation.Nullable;
import org.virtualbox_4_1.DeviceType;
import org.virtualbox_4_1.IMedium;
import org.virtualbox_4_1.IProgress;
import org.virtualbox_4_1.IVirtualBox;
import org.virtualbox_4_1.VBoxException;
import org.virtualbox_4_1.VirtualBoxManager;
import com.google.common.base.Function;
/**
* @author Mattias Holmqvist
*/
@ -71,15 +77,18 @@ public class CreateMediumIfNotAlreadyExists implements Function<String, IMedium>
private void createBaseStorage(IMedium hardDisk) {
try {
long size = 4L * 1024L * 1024L * 1024L - 4L;
IProgress storageCreation = hardDisk.createBaseStorage(size, (long) org.virtualbox_4_1.jaxws.MediumVariant.STANDARD.ordinal());
IProgress storageCreation = hardDisk.createBaseStorage(size,
(long) org.virtualbox_4_1.jaxws.MediumVariant.STANDARD.ordinal());
storageCreation.waitForCompletion(-1);
} catch (VBoxException e) {
if (fileNotFoundException(e)) {
// File for medium could not be found. Something wrong with creation.
// File for medium could not be found. Something wrong with
// creation.
hardDisk.deleteStorage();
}
if (!storageAlreadyExists(e)) {
// Hard disk file was created but the storage had been created before that.
// Hard disk file was created but the storage had been created
// before that.
throw e;
}
}
@ -90,8 +99,8 @@ public class CreateMediumIfNotAlreadyExists implements Function<String, IMedium>
}
private boolean storageAlreadyExists(VBoxException e) {
return e.getMessage().indexOf("VirtualBox error: Storage for the medium ") != -1 &&
e.getMessage().indexOf("is already created") != -1;
return e.getMessage().indexOf("VirtualBox error: Storage for the medium ") != -1
&& e.getMessage().indexOf("is already created") != -1;
}
}

View File

@ -44,7 +44,6 @@ public class IMachineToHardware implements Function<IMachine, Hardware> {
public Hardware apply(@Nullable IMachine vm) {
String osTypeId = vm.getOSTypeId();
IGuestOSType guestOSType = virtualBoxManager.getVBox().getGuestOSType(osTypeId);
Boolean is64Bit = guestOSType.getIs64Bit();
HardwareBuilder hardwareBuilder = new HardwareBuilder();

View File

@ -58,8 +58,7 @@ public class IMachineToImage implements Function<IMachine, Image> {
IGuestOSType guestOSType = virtualboxManager.getVBox().getGuestOSType(from.getOSTypeId());
OsFamily family = parseOsFamilyOrUnrecognized(guestOSType.getDescription());
String version = parseVersionOrReturnEmptyString(family, guestOSType.getDescription(),
osVersionMap);
String version = parseVersionOrReturnEmptyString(family, guestOSType.getDescription(), osVersionMap);
OperatingSystem os = OperatingSystem.builder().description(guestOSType.getDescription()).family(family)
.version(version).is64Bit(guestOSType.getIs64Bit()).build();

View File

@ -19,7 +19,10 @@
package org.jclouds.virtualbox.functions;
import com.google.common.base.Function;
import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot;
import javax.annotation.Nullable;
import org.jclouds.compute.ComputeService;
import org.jclouds.compute.domain.ExecResponse;
import org.jclouds.compute.options.RunScriptOptions;
@ -28,13 +31,11 @@ import org.virtualbox_4_1.IGuestOSType;
import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.VirtualBoxManager;
import javax.annotation.Nullable;
import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot;
import com.google.common.base.Function;
/**
* Get an IP address from an IMachine using arp of the host machine.
*
*
* @author Mattias Holmqvist, Andrea Turli
*/
public class IMachineToIpAddress implements Function<IMachine, String> {
@ -63,18 +64,25 @@ public class IMachineToIpAddress implements Function<IMachine, String> {
IMachine hostMachine = manager.getVBox().findMachine(hostId);
if (isOSX(hostMachine)) {
if (simplifiedMacAddressOfClonedVM.contains("00"))
simplifiedMacAddressOfClonedVM = new StringBuffer(simplifiedMacAddressOfClonedVM).delete(simplifiedMacAddressOfClonedVM.indexOf("00"), simplifiedMacAddressOfClonedVM.indexOf("00") + 1).toString();
simplifiedMacAddressOfClonedVM = new StringBuffer(simplifiedMacAddressOfClonedVM).delete(
simplifiedMacAddressOfClonedVM.indexOf("00"), simplifiedMacAddressOfClonedVM.indexOf("00") + 1)
.toString();
if (simplifiedMacAddressOfClonedVM.contains("0"))
if (simplifiedMacAddressOfClonedVM.indexOf("0") + 1 != ':' && simplifiedMacAddressOfClonedVM.indexOf("0") - 1 != ':')
simplifiedMacAddressOfClonedVM = new StringBuffer(simplifiedMacAddressOfClonedVM).delete(simplifiedMacAddressOfClonedVM.indexOf("0"), simplifiedMacAddressOfClonedVM.indexOf("0") + 1).toString();
if (simplifiedMacAddressOfClonedVM.indexOf("0") + 1 != ':'
&& simplifiedMacAddressOfClonedVM.indexOf("0") - 1 != ':')
simplifiedMacAddressOfClonedVM = new StringBuffer(simplifiedMacAddressOfClonedVM).delete(
simplifiedMacAddressOfClonedVM.indexOf("0"), simplifiedMacAddressOfClonedVM.indexOf("0") + 1)
.toString();
}
// TODO: This is both shell-dependent and hard-coded. Needs to be fixed.
ExecResponse execResponse = runScriptOnNode(hostId, "for i in {1..254} ; do ping -c 1 -t 1 192.168.2.$i & done", runAsRoot(false).wrapInInitScript(false));
ExecResponse execResponse = runScriptOnNode(hostId, "for i in {1..254} ; do ping -c 1 -t 1 192.168.2.$i & done",
runAsRoot(false).wrapInInitScript(false));
System.out.println(execResponse);
String arpLine = runScriptOnNode(hostId, "arp -an | grep " + simplifiedMacAddressOfClonedVM, runAsRoot(false).wrapInInitScript(false)).getOutput();
String arpLine = runScriptOnNode(hostId, "arp -an | grep " + simplifiedMacAddressOfClonedVM,
runAsRoot(false).wrapInInitScript(false)).getOutput();
String ipAddress = arpLine.substring(arpLine.indexOf("(") + 1, arpLine.indexOf(")"));
System.out.println("IP address " + ipAddress);
return ipAddress;

View File

@ -19,8 +19,19 @@
package org.jclouds.virtualbox.functions;
import com.google.common.base.Function;
import org.jclouds.compute.domain.*;
import static org.jclouds.virtualbox.config.VirtualBoxComputeServiceContextModule.machineToNodeState;
import java.util.HashSet;
import java.util.Set;
import javax.annotation.Resource;
import javax.inject.Named;
import org.jclouds.compute.domain.HardwareBuilder;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeMetadataBuilder;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Credentials;
import org.jclouds.domain.LocationBuilder;
@ -31,12 +42,7 @@ import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.INetworkAdapter;
import org.virtualbox_4_1.MachineState;
import javax.annotation.Resource;
import javax.inject.Named;
import java.util.HashSet;
import java.util.Set;
import static org.jclouds.virtualbox.config.VirtualBoxComputeServiceContextModule.machineToNodeState;
import com.google.common.base.Function;
public class IMachineToNodeMetadata implements Function<IMachine, NodeMetadata> {
@ -57,7 +63,7 @@ public class IMachineToNodeMetadata implements Function<IMachine, NodeMetadata>
locationBuilder.id("");
locationBuilder.scope(LocationScope.HOST);
nodeMetadataBuilder.location(locationBuilder.build());
HardwareBuilder hardwareBuilder = new HardwareBuilder();
hardwareBuilder.ram(vm.getMemorySize().intValue());
@ -75,7 +81,6 @@ public class IMachineToNodeMetadata implements Function<IMachine, NodeMetadata>
nodeMetadataBuilder.hostname(vm.getName());
nodeMetadataBuilder.loginPort(18083);
MachineState vmState = vm.getState();
NodeState nodeState = machineToNodeState.get(vmState);
if (nodeState == null)
@ -90,8 +95,8 @@ public class IMachineToNodeMetadata implements Function<IMachine, NodeMetadata>
System.out.println("Interface: " + bridgedInterface);
}
// nodeMetadataBuilder.imageId("");
// nodeMetadataBuilder.group("");
// nodeMetadataBuilder.imageId("");
// nodeMetadataBuilder.group("");
String provider = "virtualbox";
String identity = System.getProperty("test." + provider + ".identity", "administrator");
@ -101,5 +106,5 @@ public class IMachineToNodeMetadata implements Function<IMachine, NodeMetadata>
nodeMetadataBuilder.id(vm.getId());
return nodeMetadataBuilder.build();
}
}

View File

@ -19,8 +19,22 @@
package org.jclouds.virtualbox.functions;
import com.google.common.base.Function;
import com.google.inject.Inject;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot;
import static org.jclouds.compute.options.RunScriptOptions.Builder.wrapInInitScript;
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE;
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_WORKINGDIR;
import static org.virtualbox_4_1.AccessMode.ReadOnly;
import static org.virtualbox_4_1.DeviceType.DVD;
import static org.virtualbox_4_1.DeviceType.HardDisk;
import static org.virtualbox_4_1.LockType.Shared;
import static org.virtualbox_4_1.LockType.Write;
import java.io.File;
import javax.annotation.Resource;
import javax.inject.Named;
import org.eclipse.jetty.server.Server;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.domain.ExecResponse;
@ -34,22 +48,18 @@ import org.jclouds.virtualbox.config.VirtualBoxConstants;
import org.jclouds.virtualbox.domain.ExecutionType;
import org.jclouds.virtualbox.functions.admin.StartJettyIfNotAlreadyRunning;
import org.jclouds.virtualbox.settings.KeyboardScancodes;
import org.virtualbox_4_1.*;
import org.virtualbox_4_1.AccessMode;
import org.virtualbox_4_1.DeviceType;
import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.IMedium;
import org.virtualbox_4_1.IProgress;
import org.virtualbox_4_1.ISession;
import org.virtualbox_4_1.LockType;
import org.virtualbox_4_1.VBoxException;
import org.virtualbox_4_1.VirtualBoxManager;
import javax.annotation.Resource;
import javax.inject.Named;
import java.io.File;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot;
import static org.jclouds.compute.options.RunScriptOptions.Builder.wrapInInitScript;
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE;
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_WORKINGDIR;
import static org.virtualbox_4_1.AccessMode.ReadOnly;
import static org.virtualbox_4_1.DeviceType.DVD;
import static org.virtualbox_4_1.DeviceType.HardDisk;
import static org.virtualbox_4_1.LockType.Shared;
import static org.virtualbox_4_1.LockType.Write;
import com.google.common.base.Function;
import com.google.inject.Inject;
public class IsoToIMachine implements Function<String, IMachine> {
@ -73,8 +83,8 @@ public class IsoToIMachine implements Function<String, IMachine> {
@Inject
public IsoToIMachine(VirtualBoxManager manager, String adminDisk, String diskFormat, String settingsFile,
String vmName, String osTypeId, String vmId, boolean forceOverwrite, String controllerIDE,
ComputeServiceContext context, String hostId, String guestId, Credentials credentials) {
String vmName, String osTypeId, String vmId, boolean forceOverwrite, String controllerIDE,
ComputeServiceContext context, String hostId, String guestId, Credentials credentials) {
super();
this.manager = manager;
this.adminDisk = adminDisk;
@ -98,7 +108,8 @@ public class IsoToIMachine implements Function<String, IMachine> {
String baseResource = ".";
Server server = new StartJettyIfNotAlreadyRunning(port).apply(baseResource);
IMachine vm = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(settingsFile, osTypeId, vmId, forceOverwrite, manager).apply(vmName);
IMachine vm = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(settingsFile, osTypeId, vmId, forceOverwrite,
manager).apply(vmName);
String defaultWorkingDir = System.getProperty("user.home") + "/jclouds-virtualbox-test";
String workingDir = System.getProperty(VIRTUALBOX_WORKINGDIR, defaultWorkingDir);
@ -129,7 +140,7 @@ public class IsoToIMachine implements Function<String, IMachine> {
String guestAdditionsDvd = workingDir + "/VBoxGuestAdditions_4.1.2.iso";
final IMedium guestAdditionsDvdMedium = manager.getVBox().openMedium(guestAdditionsDvd, DeviceType.DVD,
AccessMode.ReadOnly, forceOverwrite);
AccessMode.ReadOnly, forceOverwrite);
// Guest additions
ensureGuestAdditionsMediumIsAttached(vmName, guestAdditionsDvdMedium);
@ -178,13 +189,13 @@ public class IsoToIMachine implements Function<String, IMachine> {
}
private void ensureGuestAdditionsMediumIsAttached(String vmName, final IMedium guestAdditionsDvdMedium) {
lockMachineAndApply(manager, Write, vmName,
new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE, guestAdditionsDvdMedium, 1, 1, DeviceType.DVD));
lockMachineAndApply(manager, Write, vmName, new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE,
guestAdditionsDvdMedium, 1, 1, DeviceType.DVD));
}
private void ensureMachineHasHardDiskAttached(String vmName, IMedium hardDisk) {
lockMachineAndApply(manager, Write, vmName,
new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE, hardDisk, 0, 1, HardDisk));
lockMachineAndApply(manager, Write, vmName, new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE,
hardDisk, 0, 1, HardDisk));
}
private void ensureMachineHasMemory(String vmName, final long memorySize) {
@ -198,10 +209,12 @@ public class IsoToIMachine implements Function<String, IMachine> {
private void ensureMachineHasAttachedDistroMedium(String isoName, String workingDir, String controllerIDE) {
final String pathToIsoFile = checkFileExists(workingDir + "/" + isoName);
final IMedium distroMedium = manager.getVBox().openMedium(pathToIsoFile, DVD, ReadOnly, forceOverwrite);
lockMachineAndApply(manager, Write, vmName,
new AttachDistroMediumToMachine(
checkNotNull(controllerIDE, "controllerIDE"),
checkNotNull(distroMedium, "distroMedium")));
lockMachineAndApply(
manager,
Write,
vmName,
new AttachDistroMediumToMachine(checkNotNull(controllerIDE, "controllerIDE"), checkNotNull(distroMedium,
"distroMedium")));
}
public static String checkFileExists(String filePath) {
@ -213,7 +226,7 @@ public class IsoToIMachine implements Function<String, IMachine> {
public void ensureMachineHasIDEControllerNamed(String vmName, String controllerIDE) {
lockMachineAndApply(manager, Write, checkNotNull(vmName, "vmName"),
new AddIDEControllerIfNotExists(checkNotNull(controllerIDE, "controllerIDE")));
new AddIDEControllerIfNotExists(checkNotNull(controllerIDE, "controllerIDE")));
}
private <T> T applyForMachine(VirtualBoxManager manager, final String machineId, final Function<IMachine, T> function) {
@ -232,7 +245,7 @@ public class IsoToIMachine implements Function<String, IMachine> {
}
public static <T> T lockMachineAndApply(VirtualBoxManager manager, final LockType type, final String machineId,
final Function<IMachine, T> function) {
final Function<IMachine, T> function) {
return lockSessionOnMachineAndApply(manager, type, machineId, new Function<ISession, T>() {
@Override
@ -250,7 +263,7 @@ public class IsoToIMachine implements Function<String, IMachine> {
}
public static <T> T lockSessionOnMachineAndApply(VirtualBoxManager manager, LockType type, String machineId,
Function<ISession, T> function) {
Function<ISession, T> function) {
try {
ISession session = manager.getSessionObject();
IMachine immutableMachine = manager.getVBox().findMachine(machineId);
@ -262,17 +275,17 @@ public class IsoToIMachine implements Function<String, IMachine> {
}
} catch (VBoxException e) {
throw new RuntimeException(String.format("error applying %s to %s with %s lock: %s", function, machineId,
type, e.getMessage()), e);
type, e.getMessage()), e);
}
}
private String defaultInstallSequence() {
return "<Esc><Esc><Enter> "
+ "/install/vmlinuz noapic preseed/url=http://10.0.2.2:8080/src/test/resources/preseed.cfg "
+ "debian-installer=en_US auto locale=en_US kbd-chooser/method=us " + "hostname=" + vmName + " "
+ "fb=false debconf/frontend=noninteractive "
+ "keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false "
+ "initrd=/install/initrd.gz -- <Enter>";
+ "/install/vmlinuz noapic preseed/url=http://10.0.2.2:8080/src/test/resources/preseed.cfg "
+ "debian-installer=en_US auto locale=en_US kbd-chooser/method=us " + "hostname=" + vmName + " "
+ "fb=false debconf/frontend=noninteractive "
+ "keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false "
+ "initrd=/install/initrd.gz -- <Enter>";
}
private void sendKeyboardSequence(String keyboardSequence) {

View File

@ -19,34 +19,36 @@
package org.jclouds.virtualbox.functions;
import com.google.common.base.Function;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger;
import org.jclouds.virtualbox.domain.ErrorCode;
import org.jclouds.virtualbox.domain.ExecutionType;
import org.virtualbox_4_1.*;
import org.virtualbox_4_1.jaxws.RuntimeFaultMsg;
import static com.google.common.base.Throwables.propagate;
import javax.annotation.Nullable;
import javax.annotation.Resource;
import javax.inject.Named;
import javax.lang.model.type.ExecutableType;
import static com.google.common.base.Throwables.propagate;
import static javax.xml.bind.DatatypeConverter.parseUnsignedInt;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger;
import org.jclouds.virtualbox.domain.ErrorCode;
import org.jclouds.virtualbox.domain.ExecutionType;
import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.IProgress;
import org.virtualbox_4_1.VBoxException;
import org.virtualbox_4_1.VirtualBoxManager;
import com.google.common.base.Function;
/**
* Starts a machine using launchMachine() with the provided type and environment.
* Starts a machine using launchMachine() with the provided type and
* environment.
* <p/>
* Note that launchMachine() may throw VBoxException with the following error codes:
* Note that launchMachine() may throw VBoxException with the following error
* codes:
* <p/>
* VBOX_E_UNEXPECTED: Virtual machine not registered.
* VBOX_E_INVALIDARG: Invalid session type type.
* VBOX_E_OBJECT_NOT_FOUND: No machine matching machineId found.
* VBOX_E_INVALID_OBJECT_STATE: Session already open or being opened.
* VBOX_E_IPRT_ERROR: Launching process for machine failed.
* VBOX_E_VM_ERROR: Failed to assign machine to session.
*
* VBOX_E_UNEXPECTED: Virtual machine not registered. VBOX_E_INVALIDARG: Invalid
* session type type. VBOX_E_OBJECT_NOT_FOUND: No machine matching machineId
* found. VBOX_E_INVALID_OBJECT_STATE: Session already open or being opened.
* VBOX_E_IPRT_ERROR: Launching process for machine failed. VBOX_E_VM_ERROR:
* Failed to assign machine to session.
*
* @author Mattias Holmqvist
*
* @see ErrorCode
@ -70,7 +72,8 @@ public class LaunchMachineIfNotAlreadyRunning implements Function<IMachine, Void
@Override
public Void apply(@Nullable IMachine machine) {
try {
final IProgress progress = machine.launchVMProcess(manager.getSessionObject(), type.stringValue(), environment);
final IProgress progress = machine
.launchVMProcess(manager.getSessionObject(), type.stringValue(), environment);
progress.waitForCompletion(-1);
Thread.sleep(5000);
} catch (InterruptedException e) {
@ -78,12 +81,12 @@ public class LaunchMachineIfNotAlreadyRunning implements Function<IMachine, Void
} catch (VBoxException e) {
ErrorCode errorCode = ErrorCode.valueOf(e);
switch (errorCode) {
case VBOX_E_INVALID_OBJECT_STATE:
logger.warn(e, "Could not start machine. Got error code %s from launchMachine(). " +
"The machine might already be running.", errorCode);
break;
default:
propagate(e);
case VBOX_E_INVALID_OBJECT_STATE:
logger.warn(e, "Could not start machine. Got error code %s from launchMachine(). "
+ "The machine might already be running.", errorCode);
break;
default:
propagate(e);
}
}
return null;

View File

@ -58,8 +58,8 @@ public class FileDownloadFromURI implements Function<URI, File> {
@Inject
public FileDownloadFromURI(final ComputeServiceContext context,
@Named(VIRTUALBOX_WORKINGDIR) final String workingDir,
@Named(VirtualBoxConstants.VIRTUALBOX_ISOFILE) final String isoFile) {
@Named(VIRTUALBOX_WORKINGDIR) final String workingDir,
@Named(VirtualBoxConstants.VIRTUALBOX_ISOFILE) final String isoFile) {
this.context = context;
this.workingDir = workingDir;
this.isoFile = isoFile;

View File

@ -1,28 +1,4 @@
package org.jclouds.virtualbox.functions.admin;
import com.google.common.base.Function;
import com.google.common.base.Functions;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import org.jclouds.compute.domain.Image;
import org.jclouds.virtualbox.domain.YamlImage;
import org.yaml.snakeyaml.Loader;
import org.yaml.snakeyaml.TypeDescription;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;
import javax.inject.Singleton;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import static com.google.common.base.Preconditions.checkState;
/**
*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -39,7 +15,34 @@ import static com.google.common.base.Preconditions.checkState;
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.jclouds.virtualbox.functions.admin;
import static com.google.common.base.Preconditions.checkState;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import javax.inject.Singleton;
import org.jclouds.compute.domain.Image;
import org.jclouds.virtualbox.domain.YamlImage;
import org.yaml.snakeyaml.Loader;
import org.yaml.snakeyaml.TypeDescription;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;
import com.google.common.base.Function;
import com.google.common.base.Functions;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
/**
*
* @author Andrea Turli
*/
@ -53,12 +56,12 @@ public class ImageFromYamlStream implements Function<InputStream, Cache<String,
public static class Config {
public List<YamlImage> images;
}
private Object construct(String data) {
Yaml yaml = new Yaml();
return yaml.load(data);
Yaml yaml = new Yaml();
return yaml.load(data);
}
@Override
public Cache<String, Image> apply(InputStream source) {
@ -74,15 +77,15 @@ public class ImageFromYamlStream implements Function<InputStream, Cache<String,
checkState(config.images != null, "missing images: collection");
Map<String, Image> backingMap = Maps.uniqueIndex(Iterables.transform(config.images, YamlImage.toImage),
new Function<Image, String>() {
public String apply(Image image) {
return image.getId();
}
});
Cache<String, Image> cache = CacheBuilder.newBuilder().build(CacheLoader.from(Functions.forMap(backingMap)));
for (String node : backingMap.keySet())
cache.getUnchecked(node);
return cache;
new Function<Image, String>() {
public String apply(Image image) {
return image.getId();
}
});
Cache<String, Image> cache = CacheBuilder.newBuilder().build(CacheLoader.from(Functions.forMap(backingMap)));
for (String node : backingMap.keySet())
cache.getUnchecked(node);
return cache;
}
}

View File

@ -43,65 +43,65 @@ import com.google.inject.Singleton;
*/
public class StartJettyIfNotAlreadyRunning implements Function<String, Server> {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
private final int port;
private final int port;
@Inject
public StartJettyIfNotAlreadyRunning(
@Named(VirtualBoxConstants.VIRTUALBOX_JETTY_PORT) final String port) {
this.port = Integer.parseInt(port);
}
@Inject
public StartJettyIfNotAlreadyRunning(@Named(VirtualBoxConstants.VIRTUALBOX_JETTY_PORT) final String port) {
this.port = Integer.parseInt(port);
}
@Override
public Server apply(@Nullable String baseResource) {
final Server server = ServerJetty.getInstance().getServer();
@Override
public Server apply(@Nullable String baseResource) {
final Server server = ServerJetty.getInstance().getServer();
if (!server.getState().equals(Server.STARTED) && !new InetSocketAddressConnect().apply(new IPSocket("localhost", port))) {
ResourceHandler resource_handler = new ResourceHandler();
resource_handler.setDirectoriesListed(true);
resource_handler.setWelcomeFiles(new String[] { "index.html" });
if (!server.getState().equals(Server.STARTED)
&& !new InetSocketAddressConnect().apply(new IPSocket("localhost", port))) {
ResourceHandler resource_handler = new ResourceHandler();
resource_handler.setDirectoriesListed(true);
resource_handler.setWelcomeFiles(new String[] { "index.html" });
resource_handler.setResourceBase(baseResource);
logger.info("serving " + resource_handler.getBaseResource());
resource_handler.setResourceBase(baseResource);
logger.info("serving " + resource_handler.getBaseResource());
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() });
server.setHandler(handlers);
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() });
server.setHandler(handlers);
try {
server.start();
} catch (Exception e) {
logger.error(e, "Server jetty could not be started at this %s", baseResource);
}
return server;
} else {
logger.debug("Server jetty serving %s already running. Skipping start", baseResource);
return server;
}
try {
server.start();
} catch (Exception e) {
logger.error(e, "Server jetty could not be started at this %s", baseResource);
}
return server;
} else {
logger.debug("Server jetty serving %s already running. Skipping start", baseResource);
return server;
}
}
@Singleton
private static class ServerJetty {
private static ServerJetty instance;
private Server server;
private String port = System.getProperty(VirtualBoxConstants.VIRTUALBOX_JETTY_PORT, "8080");
}
private ServerJetty() {
this.server = new Server(Integer.parseInt(port));
}
@Singleton
private static class ServerJetty {
private static ServerJetty instance;
private Server server;
private String port = System.getProperty(VirtualBoxConstants.VIRTUALBOX_JETTY_PORT, "8080");
public static ServerJetty getInstance() {
if (instance == null)
instance = new ServerJetty();
return instance;
}
private ServerJetty() {
this.server = new Server(Integer.parseInt(port));
}
public Server getServer() {
return server;
}
}
public static ServerJetty getInstance() {
if (instance == null)
instance = new ServerJetty();
return instance;
}
public Server getServer() {
return server;
}
}
}

View File

@ -20,8 +20,14 @@
package org.jclouds.virtualbox.functions.admin;
import com.google.common.base.Function;
import com.google.common.cache.Cache;
import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot;
import java.net.URI;
import javax.annotation.Nullable;
import javax.annotation.Resource;
import javax.inject.Named;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Credentials;
@ -30,14 +36,7 @@ import org.jclouds.net.IPSocket;
import org.jclouds.predicates.InetSocketAddressConnect;
import org.virtualbox_4_1.VirtualBoxManager;
import javax.annotation.Nullable;
import javax.annotation.Resource;
import javax.inject.Named;
import java.net.URI;
import java.util.concurrent.ExecutionException;
import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot;
import com.google.common.base.Function;
public class StartVBoxIfNotAlreadyRunning implements Function<URI, VirtualBoxManager> {

View File

@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.virtualbox.settings;
import java.util.Collections;
@ -24,138 +25,139 @@ import java.util.Map;
public class KeyboardScancodes {
// http://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html
public static final Map<String, String> NORMAL_KEYBOARD_BUTTON_MAP = createMap();
public static final Map<String, String> SPECIAL_KEYBOARD_BUTTON_MAP = createSpecialMap();
// http://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html
private static Map<String, String> createMap() {
Map<String, String> alphaToHex = new HashMap<String, String>();
alphaToHex.put("1", "02 82");
alphaToHex.put("2", "03 83");
alphaToHex.put("3", "04 84");
alphaToHex.put("4", "05 85");
alphaToHex.put("5", "06 86");
alphaToHex.put("6", "07 87");
alphaToHex.put("7", "08 88");
alphaToHex.put("8", "09 89");
alphaToHex.put("9", "0a 8a");
alphaToHex.put("0", "0b 8b");
alphaToHex.put("-", "0c 8c");
alphaToHex.put("=", "0d 8d");
alphaToHex.put("Tab", "0f 8f");
alphaToHex.put("q", "10 90");
alphaToHex.put("w", "11 91");
alphaToHex.put("e", "12 92");
alphaToHex.put("r", "13 93");
alphaToHex.put("t", "14 94");
alphaToHex.put("y", "15 95");
alphaToHex.put("u", "16 96");
alphaToHex.put("i", "17 97");
alphaToHex.put("o", "18 98");
alphaToHex.put("p", "19 99");
public static final Map<String, String> NORMAL_KEYBOARD_BUTTON_MAP = createMap();
public static final Map<String, String> SPECIAL_KEYBOARD_BUTTON_MAP = createSpecialMap();
alphaToHex.put("Q", "2a 10 aa");
alphaToHex.put("W", "2a 11 aa");
alphaToHex.put("E", "2a 12 aa");
alphaToHex.put("R", "2a 13 aa");
alphaToHex.put("T", "2a 14 aa");
alphaToHex.put("Y", "2a 15 aa");
alphaToHex.put("U", "2a 16 aa");
alphaToHex.put("I", "2a 17 aa");
alphaToHex.put("O", "2a 18 aa");
alphaToHex.put("P", "2a 19 aa");
private static Map<String, String> createMap() {
Map<String, String> alphaToHex = new HashMap<String, String>();
alphaToHex.put("1", "02 82");
alphaToHex.put("2", "03 83");
alphaToHex.put("3", "04 84");
alphaToHex.put("4", "05 85");
alphaToHex.put("5", "06 86");
alphaToHex.put("6", "07 87");
alphaToHex.put("7", "08 88");
alphaToHex.put("8", "09 89");
alphaToHex.put("9", "0a 8a");
alphaToHex.put("0", "0b 8b");
alphaToHex.put("-", "0c 8c");
alphaToHex.put("=", "0d 8d");
alphaToHex.put("Tab", "0f 8f");
alphaToHex.put("q", "10 90");
alphaToHex.put("w", "11 91");
alphaToHex.put("e", "12 92");
alphaToHex.put("r", "13 93");
alphaToHex.put("t", "14 94");
alphaToHex.put("y", "15 95");
alphaToHex.put("u", "16 96");
alphaToHex.put("i", "17 97");
alphaToHex.put("o", "18 98");
alphaToHex.put("p", "19 99");
alphaToHex.put("a", "1e 9e");
alphaToHex.put("s", "1f 9f");
alphaToHex.put("d", "20 a0");
alphaToHex.put("f", "21 a1");
alphaToHex.put("g", "22 a2");
alphaToHex.put("h", "23 a3");
alphaToHex.put("j", "24 a4");
alphaToHex.put("k", "25 a5");
alphaToHex.put("l", "26 a6");
alphaToHex.put("Q", "2a 10 aa");
alphaToHex.put("W", "2a 11 aa");
alphaToHex.put("E", "2a 12 aa");
alphaToHex.put("R", "2a 13 aa");
alphaToHex.put("T", "2a 14 aa");
alphaToHex.put("Y", "2a 15 aa");
alphaToHex.put("U", "2a 16 aa");
alphaToHex.put("I", "2a 17 aa");
alphaToHex.put("O", "2a 18 aa");
alphaToHex.put("P", "2a 19 aa");
alphaToHex.put("A", "2a 1e aa 9e");
alphaToHex.put("S", "2a 1f aa 9f");
alphaToHex.put("D", "2a 20 aa a0");
alphaToHex.put("F", "2a 21 aa a1");
alphaToHex.put("G", "2a 22 aa a2");
alphaToHex.put("H", "2a 23 aa a3");
alphaToHex.put("J", "2a 24 aa a4");
alphaToHex.put("K", "2a 25 aa a5");
alphaToHex.put("L", "2a 26 aa a6");
alphaToHex.put("a", "1e 9e");
alphaToHex.put("s", "1f 9f");
alphaToHex.put("d", "20 a0");
alphaToHex.put("f", "21 a1");
alphaToHex.put("g", "22 a2");
alphaToHex.put("h", "23 a3");
alphaToHex.put("j", "24 a4");
alphaToHex.put("k", "25 a5");
alphaToHex.put("l", "26 a6");
alphaToHex.put(");", "27 a7");
alphaToHex.put("\"", "2a 28 aa a8");
alphaToHex.put("\"", "28 a8");
alphaToHex.put("\\", "2b ab");
alphaToHex.put("|", "2a 2b aa 8b");
alphaToHex.put("[", "1a 9a");
alphaToHex.put("", "1b 9b");
alphaToHex.put("<", "2a 33 aa b3");
alphaToHex.put(">", "2a 34 aa b4");
alphaToHex.put("$", "2a 05 aa 85");
alphaToHex.put("+", "2a 0d aa 8d");
alphaToHex.put("A", "2a 1e aa 9e");
alphaToHex.put("S", "2a 1f aa 9f");
alphaToHex.put("D", "2a 20 aa a0");
alphaToHex.put("F", "2a 21 aa a1");
alphaToHex.put("G", "2a 22 aa a2");
alphaToHex.put("H", "2a 23 aa a3");
alphaToHex.put("J", "2a 24 aa a4");
alphaToHex.put("K", "2a 25 aa a5");
alphaToHex.put("L", "2a 26 aa a6");
alphaToHex.put("z", "2c ac");
alphaToHex.put("x", "2d ad");
alphaToHex.put("c", "2e ae");
alphaToHex.put("v", "2f af");
alphaToHex.put("b", "30 b0");
alphaToHex.put("n", "31 b1");
alphaToHex.put("m", "32 b2");
alphaToHex.put("Z", "2a 2c aa ac");
alphaToHex.put("X", "2a 2d aa ad");
alphaToHex.put("C", "2a 2e aa ae");
alphaToHex.put("V", "2a 2f aa af");
alphaToHex.put("B", "2a 30 aa b0");
alphaToHex.put("N", "2a 31 aa b1");
alphaToHex.put("M", "2a 32 aa b2");
alphaToHex.put(");", "27 a7");
alphaToHex.put("\"", "2a 28 aa a8");
alphaToHex.put("\"", "28 a8");
alphaToHex.put("\\", "2b ab");
alphaToHex.put("|", "2a 2b aa 8b");
alphaToHex.put("[", "1a 9a");
alphaToHex.put("", "1b 9b");
alphaToHex.put("<", "2a 33 aa b3");
alphaToHex.put(">", "2a 34 aa b4");
alphaToHex.put("$", "2a 05 aa 85");
alphaToHex.put("+", "2a 0d aa 8d");
alphaToHex.put(",", "33 b3");
alphaToHex.put(".", "34 b4");
alphaToHex.put("/", "35 b5");
alphaToHex.put(":", "2a 27 aa a7");
alphaToHex.put("%", "2a 06 aa 86");
alphaToHex.put("_", "2a 0c aa 8c");
alphaToHex.put("&", "2a 08 aa 88");
alphaToHex.put("(", "2a 0a aa 8a");
alphaToHex.put(")", "2a 0b aa 8b");
return Collections.unmodifiableMap(alphaToHex);
}
private static Map<String, String> createSpecialMap() {
Map<String, String> special = new HashMap<String, String>();
special.put("<Enter>", "1c 9c");
special.put("<Backspace>", "0e 8e");
special.put("<Spacebar>", "39 b9");
special.put("<Return>", "1c 9c");
special.put("<Esc>", "01 81");
special.put("<Tab>", "0f 8f");
special.put("<KillX>", "1d 38 0e");
special.put("<Wait>", "wait");
special.put("<Up>", "48 c8");
special.put("<Down>", "50 d0");
special.put("<PageUp>", "49 c9");
special.put("<PageDown>", "51 d1");
special.put("<End>", "4f cf");
special.put("<Insert>", "52 d2");
special.put("<Delete>", "53 d3");
special.put("<Left>", "4b cb");
special.put("<Right>", "4d cd");
special.put("<Home>", "47 c7");
special.put("<F1>", "3b");
special.put("<F2>", "3c");
special.put("<F3>", "3d");
special.put("<F4>", "3e");
special.put("<F5>", "3f");
special.put("<F6>", "40");
special.put("<F7>", "41");
special.put("<F8>", "42");
special.put("<F9>", "43");
special.put("<F10>", "44");
return Collections.unmodifiableMap(special);
}
alphaToHex.put("z", "2c ac");
alphaToHex.put("x", "2d ad");
alphaToHex.put("c", "2e ae");
alphaToHex.put("v", "2f af");
alphaToHex.put("b", "30 b0");
alphaToHex.put("n", "31 b1");
alphaToHex.put("m", "32 b2");
alphaToHex.put("Z", "2a 2c aa ac");
alphaToHex.put("X", "2a 2d aa ad");
alphaToHex.put("C", "2a 2e aa ae");
alphaToHex.put("V", "2a 2f aa af");
alphaToHex.put("B", "2a 30 aa b0");
alphaToHex.put("N", "2a 31 aa b1");
alphaToHex.put("M", "2a 32 aa b2");
alphaToHex.put(",", "33 b3");
alphaToHex.put(".", "34 b4");
alphaToHex.put("/", "35 b5");
alphaToHex.put(":", "2a 27 aa a7");
alphaToHex.put("%", "2a 06 aa 86");
alphaToHex.put("_", "2a 0c aa 8c");
alphaToHex.put("&", "2a 08 aa 88");
alphaToHex.put("(", "2a 0a aa 8a");
alphaToHex.put(")", "2a 0b aa 8b");
return Collections.unmodifiableMap(alphaToHex);
}
private static Map<String, String> createSpecialMap() {
Map<String, String> special = new HashMap<String, String>();
special.put("<Enter>", "1c 9c");
special.put("<Backspace>", "0e 8e");
special.put("<Spacebar>", "39 b9");
special.put("<Return>", "1c 9c");
special.put("<Esc>", "01 81");
special.put("<Tab>", "0f 8f");
special.put("<KillX>", "1d 38 0e");
special.put("<Wait>", "wait");
special.put("<Up>", "48 c8");
special.put("<Down>", "50 d0");
special.put("<PageUp>", "49 c9");
special.put("<PageDown>", "51 d1");
special.put("<End>", "4f cf");
special.put("<Insert>", "52 d2");
special.put("<Delete>", "53 d3");
special.put("<Left>", "4b cb");
special.put("<Right>", "4d cd");
special.put("<Home>", "47 c7");
special.put("<F1>", "3b");
special.put("<F2>", "3c");
special.put("<F3>", "3d");
special.put("<F4>", "3e");
special.put("<F5>", "3f");
special.put("<F6>", "40");
special.put("<F7>", "41");
special.put("<F8>", "42");
special.put("<F9>", "43");
special.put("<F10>", "44");
return Collections.unmodifiableMap(special);
}
}

View File

@ -19,11 +19,12 @@
package org.jclouds.virtualbox.compute;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import com.google.inject.Guice;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import java.net.URI;
import java.util.Map;
import org.jclouds.compute.config.BaseComputeServiceContextModule;
import org.jclouds.compute.domain.ExecResponse;
import org.jclouds.compute.domain.Image;
@ -44,11 +45,11 @@ import org.testng.annotations.Test;
import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.VirtualBoxManager;
import java.net.URI;
import java.util.Map;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import com.google.inject.Guice;
@Test(groups = "live", singleThreaded = true, testName = "VirtualBoxComputeServiceAdapterLiveTest")
public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClientLiveTest {
@ -57,15 +58,15 @@ public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClien
private IMachine machine;
private final Map<OsFamily, Map<String, String>> osVersionMap = new BaseComputeServiceContextModule() {
}.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule())
.getInstance(Json.class));
.getInstance(Json.class));
@BeforeGroups(groups = {"live"})
@BeforeGroups(groups = { "live" })
public void setupClient() {
super.setupClient();
final VirtualBoxManager manager = getManager();
Function<IMachine, Image> iMachineToImage = new IMachineToImage(manager, osVersionMap);
adapter = new VirtualBoxComputeServiceAdapter(manager,
new JustProvider(provider, URI.create(endpoint), ImmutableSet.<String>of()), iMachineToImage);
adapter = new VirtualBoxComputeServiceAdapter(manager, new JustProvider(provider, URI.create(endpoint),
ImmutableSet.<String> of()), iMachineToImage);
}
protected VirtualBoxManager getManager() {
@ -89,15 +90,16 @@ public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClien
// check other things, like cpu correct, mem correct, image/os is correct
// (as possible)
assert credentialStore.containsKey("node#" + machine.getId()) : "credentials to log into machine not found "
+ machine;
// TODO: what's the IP address?
// assert InetAddresses.isInetAddress(machine.getPrimaryBackendIpAddress()) : machine;
+ machine;
// TODO: what's the IP address?
// assert
// InetAddresses.isInetAddress(machine.getPrimaryBackendIpAddress()) :
// machine;
doConnectViaSsh(machine, credentialStore.get("node#" + machine.getId()));
}
protected void doConnectViaSsh(IMachine machine, Credentials creds) {
SshClient ssh = context.utils().sshFactory()
.create(new IPSocket("//TODO", 22), creds);
SshClient ssh = context.utils().sshFactory().create(new IPSocket("//TODO", 22), creds);
try {
ssh.connect();
ExecResponse hello = ssh.exec("echo hello");

View File

@ -19,9 +19,17 @@
package org.jclouds.virtualbox.compute;
import com.google.common.base.Function;
import com.google.common.collect.Iterators;
import com.google.inject.Guice;
import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createNiceMock;
import static org.easymock.classextension.EasyMock.replay;
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX;
import static org.testng.Assert.assertEquals;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.easymock.EasyMock;
import org.jclouds.compute.config.BaseComputeServiceContextModule;
import org.jclouds.compute.domain.Image;
@ -37,23 +45,16 @@ import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.IVirtualBox;
import org.virtualbox_4_1.VirtualBoxManager;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import static org.easymock.classextension.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createNiceMock;
import static org.easymock.classextension.EasyMock.replay;
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX;
import static org.testng.Assert.assertEquals;
import com.google.common.base.Function;
import com.google.common.collect.Iterators;
import com.google.inject.Guice;
@Test(groups = "unit")
public class VirtualBoxComputeServiceAdapterTest {
Map<OsFamily, Map<String, String>> osMap = new BaseComputeServiceContextModule() {
}.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule())
.getInstance(Json.class));
.getInstance(Json.class));
@Test
public void testListImages() throws Exception {
@ -76,14 +77,15 @@ public class VirtualBoxComputeServiceAdapterTest {
expect(manager.getVBox()).andReturn(vBox).anyTimes();
expect(vBox.getMachines()).andReturn(machines).anyTimes();
expect(vBox.getGuestOSType(EasyMock.<String>anyObject())).andReturn(osType).anyTimes();
expect(vBox.getGuestOSType(EasyMock.<String> anyObject())).andReturn(osType).anyTimes();
expect(osType.getDescription()).andReturn("Ubuntu 10.04").anyTimes();
expect(osType.getIs64Bit()).andReturn(true).anyTimes();
replay(manager, justProvider, vBox, clonedMachine, imageMachine, osType);
Function<IMachine, Image> iMachineToImage = new IMachineToImage(manager, osMap);
VirtualBoxComputeServiceAdapter adapter = new VirtualBoxComputeServiceAdapter(manager, justProvider, iMachineToImage);
VirtualBoxComputeServiceAdapter adapter = new VirtualBoxComputeServiceAdapter(manager, justProvider,
iMachineToImage);
Iterator<Image> iterator = adapter.listImages().iterator();
Image image = Iterators.getOnlyElement(iterator);

View File

@ -27,7 +27,7 @@ import org.testng.annotations.Test;
* @author Adrian Cole
*/
@Test(groups = "live", testName = "VirtualBoxExperimentLiveTest")
public class VirtualBoxExperimentLiveTest extends BaseVirtualBoxClientLiveTest{
public class VirtualBoxExperimentLiveTest extends BaseVirtualBoxClientLiveTest {
@Test
public void testAndExperiment() {

View File

@ -34,7 +34,6 @@ import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableSet;
/**
*
* @author Andrea Turli
@ -43,40 +42,40 @@ import com.google.common.collect.ImmutableSet;
@Test(groups = "live", testName = "VirtualBoxTemplateBuilderLiveTest")
public class VirtualBoxTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
public VirtualBoxTemplateBuilderLiveTest() {
provider = "virtualbox";
}
public VirtualBoxTemplateBuilderLiveTest() {
provider = "virtualbox";
}
@Override
protected Predicate<OsFamilyVersion64Bit> defineUnsupportedOperatingSystems() {
return Predicates.not(new Predicate<OsFamilyVersion64Bit>() {
@Override
protected Predicate<OsFamilyVersion64Bit> defineUnsupportedOperatingSystems() {
return Predicates.not(new Predicate<OsFamilyVersion64Bit>() {
@Override
public boolean apply(OsFamilyVersion64Bit input) {
switch (input.family) {
case UBUNTU:
return input.version.equals("11.04") && !input.is64Bit;
default:
return false;
}
}
@Override
public boolean apply(OsFamilyVersion64Bit input) {
switch (input.family) {
case UBUNTU:
return input.version.equals("11.04") && !input.is64Bit;
default:
return false;
}
}
});
}
});
}
@Test
public void testTemplateBuilder() {
System.out.println(this.context.getComputeService().listImages());
Template defaultTemplate = this.context.getComputeService().templateBuilder().build();
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), false);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "10.04");
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
}
@Test
public void testTemplateBuilder() {
System.out.println(this.context.getComputeService().listImages());
Template defaultTemplate = this.context.getComputeService().templateBuilder().build();
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), false);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "10.04");
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
}
@Override
protected Set<String> getIso3166Codes() {
return ImmutableSet.<String> of();
}
@Override
protected Set<String> getIso3166Codes() {
return ImmutableSet.<String> of();
}
}

View File

@ -1,12 +1,8 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
@ -19,8 +15,8 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*/
package org.jclouds.virtualbox.experiment;
import static com.google.common.base.Preconditions.checkNotNull;
@ -40,8 +36,8 @@ import org.jclouds.compute.options.RunScriptOptions;
import org.jclouds.domain.Credentials;
import org.jclouds.logging.Logger;
import org.jclouds.virtualbox.config.VirtualBoxConstants;
import org.jclouds.virtualbox.functions.admin.StartVBoxIfNotAlreadyRunning;
import org.jclouds.virtualbox.functions.admin.StartJettyIfNotAlreadyRunning;
import org.jclouds.virtualbox.functions.admin.StartVBoxIfNotAlreadyRunning;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
@ -72,7 +68,7 @@ public class SetupVirtualBoxForLiveTest {
private String vboxVersionName;
private String basebaseResource;
private String port;
private String vboxWebServerCredential;
private String vboxWebServerIdentity;
@ -88,18 +84,18 @@ public class SetupVirtualBoxForLiveTest {
public void setupConfigurationProperties() {
workingDir = System.getProperty("user.home") + File.separator
+ System.getProperty("test." + provider + ".workingDir", "jclouds-virtualbox-test");
+ System.getProperty("test." + provider + ".workingDir", "jclouds-virtualbox-test");
if (new File(workingDir).mkdir())
;
gaIsoName = System.getProperty("test." + provider + ".gaIsoName", "VBoxGuestAdditions_" + majorVersion + ".iso");
gaIsoUrl = URI.create(System.getProperty("test." + provider + ".gaIsoUrl",
"http://download.virtualbox.org/virtualbox/" + majorVersion + "/" + gaIsoName));
"http://download.virtualbox.org/virtualbox/" + majorVersion + "/" + gaIsoName));
distroIsoName = System.getProperty("test." + provider + ".distroIsoName", "ubuntu-11.04-server-i386.iso");
distroIsoUrl = URI.create(System.getProperty("test." + provider + ".distroIsoUrl",
"http://releases.ubuntu.com/11.04/ubuntu-11.04-server-i386.iso"));
"http://releases.ubuntu.com/11.04/ubuntu-11.04-server-i386.iso"));
vboxDmg = URI.create(System.getProperty("test." + provider + ".vboxDmg",
"http://download.virtualbox.org/virtualbox/4.1.2/VirtualBox-4.1.2-73507-OSX.dmg"));
"http://download.virtualbox.org/virtualbox/4.1.2/VirtualBox-4.1.2-73507-OSX.dmg"));
vboxVersionName = System.getProperty("test" + provider + ".vboxVersionName", "VirtualBox-4.1.2-73507-OSX.dmg");
basebaseResource = System.getProperty(VirtualBoxConstants.VIRTUALBOX_JETTY_BASE_RESOURCE, ".");
port = System.getProperty(VirtualBoxConstants.VIRTUALBOX_JETTY_PORT, "8080");
@ -120,7 +116,7 @@ public class SetupVirtualBoxForLiveTest {
new StartVBoxIfNotAlreadyRunning(context, hostId, new Credentials(vboxWebServerIdentity, vboxWebServerCredential));
new StartJettyIfNotAlreadyRunning(port).apply(basebaseResource);
}
@AfterSuite
public void stopVboxWebServer() throws IOException {
runScriptOnNode(hostId, "pidof vboxwebsrv | xargs kill");
@ -133,29 +129,29 @@ public class SetupVirtualBoxForLiveTest {
downloadFileUnlessPresent(vboxDmg, workingDir, vboxVersionName);
runScriptOnNode(hostId, "hdiutil attach " + workingDir + "/" + vboxVersionName);
runScriptOnNode(hostId,
"installer -pkg /Volumes/VirtualBox/VirtualBox.mpkg -target /Volumes/Macintosh\\ HD");
"installer -pkg /Volumes/VirtualBox/VirtualBox.mpkg -target /Volumes/Macintosh\\ HD");
} else {
// TODO other platforms
runScriptOnNode(hostId, "cat > /etc/apt/sources.list.d/TODO");
runScriptOnNode(hostId,
"wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | apt-key add -");
"wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | apt-key add -");
runScriptOnNode(hostId, "apt-get update");
runScriptOnNode(hostId, "apt-get --yes install virtualbox-4.1");
}
}
}
public void checkVboxVersionExpected() throws IOException, InterruptedException {
public void checkVboxVersionExpected() throws IOException, InterruptedException {
logger().debug("checking virtualbox version");
assertEquals(runScriptOnNode(hostId, "VBoxManage -version").getOutput().trim(), apiVersion);
}
public boolean isOSX(String id) {
return context.getComputeService().getNodeMetadata(hostId).getOperatingSystem().getDescription().equals(
"Mac OS X");
return context.getComputeService().getNodeMetadata(hostId).getOperatingSystem().getDescription()
.equals("Mac OS X");
}
public File downloadFileUnlessPresent(URI sourceURL, String destinationDir, String filename) throws Exception {
public File downloadFileUnlessPresent(URI sourceURL, String destinationDir, String filename) throws Exception {
File iso = new File(destinationDir, filename);

View File

@ -18,10 +18,11 @@
*/
package org.jclouds.virtualbox.experiment;
import com.google.common.cache.Cache;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map;
import org.jclouds.byon.Node;
import org.jclouds.byon.config.CacheNodeStoreModule;
import org.jclouds.compute.ComputeServiceContext;
@ -31,75 +32,48 @@ import org.jclouds.domain.Credentials;
import org.jclouds.encryption.bouncycastle.config.BouncyCastleCryptoModule;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.jclouds.sshj.config.SshjSshClientModule;
import org.jclouds.virtualbox.config.VirtualBoxConstants;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map;
import com.google.common.cache.Cache;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;
public class TestUtils {
public static ComputeServiceContext computeServiceForLocalhostAndGuest() throws IOException {
Node host = Node.builder().id("host")
.name("host installing virtualbox")
.hostname("localhost")
.osFamily(OsFamily.LINUX.toString())
.osDescription(System.getProperty("os.name"))
.osVersion(System.getProperty("os.version"))
.group("ssh")
.username(System.getProperty("user.name"))
.credentialUrl(privateKeyFile())
.build();
Node guest = Node.builder().id("guest")
.name("new guest")
.hostname("localhost")
.loginPort(2222)
.osFamily(OsFamily.UBUNTU.toString())
.osDescription("ubuntu/11.04")
.osVersion(System.getProperty("11.04"))
.group("guest")
.username("toor")
.sudoPassword("password")
.credential("password")
.build();
Node host = Node.builder().id("host").name("host installing virtualbox").hostname("localhost")
.osFamily(OsFamily.LINUX.toString()).osDescription(System.getProperty("os.name"))
.osVersion(System.getProperty("os.version")).group("ssh").username(System.getProperty("user.name"))
.credentialUrl(privateKeyFile()).build();
Node guest = Node.builder().id("guest").name("new guest").hostname("localhost").loginPort(2222)
.osFamily(OsFamily.UBUNTU.toString()).osDescription("ubuntu/11.04").osVersion(System.getProperty("11.04"))
.group("guest").username("toor").sudoPassword("password").credential("password").build();
final Map<String, Node> nodeMap = ImmutableMap.<String, Node>builder().put("host", host).put("guest", guest).build();
return new ComputeServiceContextFactory().createContext("byon", "foo", "bar", ImmutableSet.<Module>of(
new SshjSshClientModule(), new SLF4JLoggingModule(), new BouncyCastleCryptoModule(), new CacheNodeStoreModule(nodeMap)));
final Map<String, Node> nodeMap = ImmutableMap.<String, Node> builder().put("host", host).put("guest", guest)
.build();
return new ComputeServiceContextFactory().createContext("byon", "foo", "bar", ImmutableSet.<Module> of(
new SshjSshClientModule(), new SLF4JLoggingModule(), new BouncyCastleCryptoModule(),
new CacheNodeStoreModule(nodeMap)));
}
public static ComputeServiceContext computeServiceForLocalhostAndGuest(String hostId, String hostname, String guestId, String guestHostname,
Credentials guestLogin) throws IOException {
public static ComputeServiceContext computeServiceForLocalhostAndGuest(String hostId, String hostname,
String guestId, String guestHostname, Credentials guestLogin) throws IOException {
Node host = Node.builder().id(hostId)
.name("host installing virtualbox")
.hostname(hostname)
.osFamily(OsFamily.LINUX.toString())
.osDescription(System.getProperty("os.name"))
.osVersion(System.getProperty("os.version"))
.group("ssh")
.username(System.getProperty("user.name"))
.credentialUrl(privateKeyFile())
.build();
Node guest = Node.builder().id(guestId)
.name("new guest")
.hostname(guestHostname)
.loginPort(2222)
.osFamily(OsFamily.UBUNTU.toString())
.osDescription("ubuntu/11.04")
.osVersion(System.getProperty("11.04"))
.group("jclouds-linux-image")
.username(guestLogin.identity)
.sudoPassword(guestLogin.credential)
.credential(guestLogin.credential)
.build();
Node host = Node.builder().id(hostId).name("host installing virtualbox").hostname(hostname)
.osFamily(OsFamily.LINUX.toString()).osDescription(System.getProperty("os.name"))
.osVersion(System.getProperty("os.version")).group("ssh").username(System.getProperty("user.name"))
.credentialUrl(privateKeyFile()).build();
Node guest = Node.builder().id(guestId).name("new guest").hostname(guestHostname).loginPort(2222)
.osFamily(OsFamily.UBUNTU.toString()).osDescription("ubuntu/11.04").osVersion(System.getProperty("11.04"))
.group("jclouds-linux-image").username(guestLogin.identity).sudoPassword(guestLogin.credential)
.credential(guestLogin.credential).build();
final Map<String, Node> nodeMap = ImmutableMap.<String, Node>builder().put(hostId, host).put(guestId, guest).build();
return new ComputeServiceContextFactory().createContext("byon", "foo", "bar", ImmutableSet.<Module>of(
new SshjSshClientModule(), new SLF4JLoggingModule(), new BouncyCastleCryptoModule(), new CacheNodeStoreModule(nodeMap)));
final Map<String, Node> nodeMap = ImmutableMap.<String, Node> builder().put(hostId, host).put(guestId, guest)
.build();
return new ComputeServiceContextFactory().createContext("byon", "foo", "bar", ImmutableSet.<Module> of(
new SshjSshClientModule(), new SLF4JLoggingModule(), new BouncyCastleCryptoModule(),
new CacheNodeStoreModule(nodeMap)));
}
private static URI privateKeyFile() {
@ -112,7 +86,8 @@ public class TestUtils {
}
public static ComputeServiceContext computeServiceForVirtualBox(Cache<String, Node> cache) {
return new ComputeServiceContextFactory().createContext("byon", "foo", "bar", ImmutableSet.<Module>of(
new SshjSshClientModule(), new SLF4JLoggingModule(), new BouncyCastleCryptoModule(), new CacheNodeStoreModule(cache)));
return new ComputeServiceContextFactory().createContext("byon", "foo", "bar", ImmutableSet.<Module> of(
new SshjSshClientModule(), new SLF4JLoggingModule(), new BouncyCastleCryptoModule(),
new CacheNodeStoreModule(cache)));
}
}

View File

@ -1,4 +1,4 @@
/*
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -19,12 +19,16 @@
package org.jclouds.virtualbox.functions;
import static org.easymock.EasyMock.expectLastCall;
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 org.testng.annotations.Test;
import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.VBoxException;
import static org.easymock.classextension.EasyMock.*;
/**
* @author Mattias Holmqvist
*/
@ -49,8 +53,8 @@ public class ApplyMemoryToMachineTest {
@Test(expectedExceptions = VBoxException.class)
public void testRethrowInvalidRamSizeError() throws Exception {
// Mainly here for documentation purposes
final String error = "VirtualBox error: Invalid RAM size: " +
"3567587327 MB (must be in range [4, 2097152] MB) (0x80070057)";
final String error = "VirtualBox error: Invalid RAM size: "
+ "3567587327 MB (must be in range [4, 2097152] MB) (0x80070057)";
long memorySize = 1024l;
IMachine machine = createMock(IMachine.class);

View File

@ -18,15 +18,18 @@
*/
package org.jclouds.virtualbox.functions;
import static org.easymock.EasyMock.expectLastCall;
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 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.VBoxException;
import static org.easymock.classextension.EasyMock.*;
/**
* @author Mattias Holmqvist
*/
@ -67,7 +70,8 @@ public class AttachDistroMediumToMachineTest {
errorBuilder.append("of this virtual machine (0x80BB000C)");
String isoAlreadyAttachedException = errorBuilder.toString();
VBoxException isoAttachedException = new VBoxException(createNiceMock(Throwable.class), isoAlreadyAttachedException);
VBoxException isoAttachedException = new VBoxException(createNiceMock(Throwable.class),
isoAlreadyAttachedException);
machine.attachDevice(controllerIDE, 0, 0, DeviceType.DVD, distroMedium);
expectLastCall().andThrow(isoAttachedException);
@ -92,7 +96,8 @@ public class AttachDistroMediumToMachineTest {
errorBuilder.append("Some other VBox error");
String isoAlreadyAttachedException = errorBuilder.toString();
VBoxException isoAttachedException = new VBoxException(createNiceMock(Throwable.class), isoAlreadyAttachedException);
VBoxException isoAttachedException = new VBoxException(createNiceMock(Throwable.class),
isoAlreadyAttachedException);
machine.attachDevice(controllerIDE, 0, 0, DeviceType.DVD, distroMedium);
expectLastCall().andThrow(isoAttachedException);
@ -102,5 +107,4 @@ public class AttachDistroMediumToMachineTest {
}
}

View File

@ -19,12 +19,23 @@
package org.jclouds.virtualbox.functions;
import org.testng.annotations.Test;
import org.virtualbox_4_1.*;
import static org.easymock.classextension.EasyMock.*;
import static org.easymock.EasyMock.anyLong;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.expectLastCall;
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.testng.annotations.Test;
import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.IMedium;
import org.virtualbox_4_1.IProgress;
import org.virtualbox_4_1.IVirtualBox;
import org.virtualbox_4_1.VBoxException;
import org.virtualbox_4_1.VirtualBoxManager;
/**
* @author Mattias Holmqvist
*/
@ -54,7 +65,8 @@ public class AttachMediumToMachineIfNotAlreadyAttachedTest {
machine.saveSettings();
replay(manager, machine, vBox, hardDisk);
new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE, hardDisk, controllerPort, device, HardDisk).apply(machine);
new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE, hardDisk, controllerPort, device, HardDisk)
.apply(machine);
verify(machine);
@ -79,13 +91,15 @@ public class AttachMediumToMachineIfNotAlreadyAttachedTest {
errorBuilder.append("of this virtual machine (0x80BB000C)");
String isoAlreadyAttachedException = errorBuilder.toString();
VBoxException isoAttachedException = new VBoxException(createNiceMock(Throwable.class), isoAlreadyAttachedException);
VBoxException isoAttachedException = new VBoxException(createNiceMock(Throwable.class),
isoAlreadyAttachedException);
machine.attachDevice(controllerIDE, controllerPort, device, HardDisk, hardDisk);
expectLastCall().andThrow(isoAttachedException);
replay(manager, machine, vBox, hardDisk);
new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE, hardDisk, controllerPort, device, HardDisk).apply(machine);
new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE, hardDisk, controllerPort, device, HardDisk)
.apply(machine);
verify(machine);
@ -108,13 +122,15 @@ public class AttachMediumToMachineIfNotAlreadyAttachedTest {
errorBuilder.append("Some other VBox error");
String isoAlreadyAttachedException = errorBuilder.toString();
VBoxException isoAttachedException = new VBoxException(createNiceMock(Throwable.class), isoAlreadyAttachedException);
VBoxException isoAttachedException = new VBoxException(createNiceMock(Throwable.class),
isoAlreadyAttachedException);
machine.attachDevice(controllerIDE, controllerPort, device, HardDisk, hardDisk);
expectLastCall().andThrow(isoAttachedException);
replay(manager, machine, vBox, hardDisk);
new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE, hardDisk, controllerPort, device, HardDisk).apply(machine);
new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE, hardDisk, controllerPort, device, HardDisk)
.apply(machine);
}

View File

@ -1,4 +1,4 @@
/*
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@ -19,13 +19,20 @@
package org.jclouds.virtualbox.functions;
import org.testng.annotations.Test;
import org.virtualbox_4_1.*;
import static org.easymock.classextension.EasyMock.*;
import static org.easymock.EasyMock.expect;
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.NATProtocol.TCP;
import static org.virtualbox_4_1.NetworkAttachmentType.NAT;
import org.testng.annotations.Test;
import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.INATEngine;
import org.virtualbox_4_1.INetworkAdapter;
import org.virtualbox_4_1.VBoxException;
/**
* @author Mattias Holmqvist
*/
@ -60,8 +67,8 @@ public class AttachNATRedirectRuleToMachineTest {
INetworkAdapter networkAdapter = createMock(INetworkAdapter.class);
INATEngine natEngine = createMock(INATEngine.class);
String error = "VirtualBox error: Argument slot is invalid " +
"(must be slot < RT_ELEMENTS(mNetworkAdapters)) (0x80070057)";
String error = "VirtualBox error: Argument slot is invalid "
+ "(must be slot < RT_ELEMENTS(mNetworkAdapters)) (0x80070057)";
VBoxException invalidSlotException = new VBoxException(createNiceMock(Throwable.class), error);
expect(machine.getNetworkAdapter(adapterId)).andThrow(invalidSlotException);
@ -73,5 +80,4 @@ public class AttachNATRedirectRuleToMachineTest {
verify(machine, networkAdapter, natEngine);
}
}

View File

@ -19,6 +19,15 @@
package org.jclouds.virtualbox.functions;
import static org.easymock.EasyMock.anyBoolean;
import static org.easymock.EasyMock.eq;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.expectLastCall;
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 org.easymock.EasyMock;
import org.testng.annotations.Test;
import org.virtualbox_4_1.IMachine;
@ -26,10 +35,6 @@ import org.virtualbox_4_1.IVirtualBox;
import org.virtualbox_4_1.VBoxException;
import org.virtualbox_4_1.VirtualBoxManager;
import static org.easymock.EasyMock.anyBoolean;
import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.*;
/**
* @author Mattias Holmqvist
*/
@ -55,9 +60,10 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
vBox.findMachine(vmName);
expectLastCall().andThrow(vBoxException);
expect(vBox.createMachine(anyString(), eq(vmName), anyString(), anyString(), anyBoolean())).andReturn(createdMachine).anyTimes();
expect(vBox.createMachine(anyString(), eq(vmName), anyString(), anyString(), anyBoolean())).andReturn(
createdMachine).anyTimes();
vBox.registerMachine(createdMachine);
replay(manager, vBox);
@ -103,10 +109,9 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists("", "", "", false, manager).apply(vmName);
}
private String anyString() {
return EasyMock.<String>anyObject();
return EasyMock.<String> anyObject();
}
}

View File

@ -19,14 +19,23 @@
package org.jclouds.virtualbox.functions;
import org.testng.annotations.Test;
import org.virtualbox_4_1.*;
import static org.easymock.EasyMock.anyLong;
import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.*;
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.testng.Assert.assertNotSame;
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;
import org.virtualbox_4_1.IVirtualBox;
import org.virtualbox_4_1.VBoxException;
import org.virtualbox_4_1.VirtualBoxManager;
/**
* @author Mattias Holmqvist
*/
@ -137,5 +146,4 @@ public class CreateMediumIfNotAlreadyExistsTest {
new CreateMediumIfNotAlreadyExists(manager, diskFormat, true).apply(adminDiskPath);
}
}

View File

@ -33,7 +33,6 @@ import org.virtualbox_4_1.VirtualBoxManager;
import com.google.common.collect.ImmutableSet;
//@Test(groups = "live")
public class IMachineToNodeMetadataTest {
@Test

View File

@ -19,10 +19,6 @@
package org.jclouds.virtualbox.functions;
/**
* @author Andrea Turli, Mattias Holmqvist
*/
import static com.google.common.base.Predicates.equalTo;
import static com.google.common.collect.Iterables.any;
import static org.jclouds.virtualbox.experiment.TestUtils.computeServiceForLocalhostAndGuest;
@ -47,13 +43,16 @@ import org.virtualbox_4_1.VirtualBoxManager;
import com.google.inject.Guice;
/**
* @author Andrea Turli, Mattias Holmqvist
*/
@Test(groups = "live", singleThreaded = true, testName = "IsoToIMachineLiveTest")
public class IsoToIMachineLiveTest extends BaseVirtualBoxClientLiveTest {
Map<OsFamily, Map<String, String>> map = new BaseComputeServiceContextModule() {
}.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule())
.getInstance(Json.class));
.getInstance(Json.class));
private String settingsFile = null;
private boolean forceOverwrite = true;
private String vmId = "jclouds-image-iso-1";
@ -76,24 +75,16 @@ public class IsoToIMachineLiveTest extends BaseVirtualBoxClientLiveTest {
public void testCreateImageMachineFromIso() throws Exception {
VirtualBoxManager manager = (VirtualBoxManager) context.getProviderSpecificContext().getApi();
ComputeServiceContext localHostContext = computeServiceForLocalhostAndGuest(hostId, "localhost", guestId, "localhost", new Credentials("toor", "password"));
IMachine imageMachine = new IsoToIMachine(manager,
adminDisk,
diskFormat,
settingsFile,
vmName,
osTypeId,
vmId,
forceOverwrite,
controllerIDE,
localHostContext,
hostId,
guestId,
new Credentials("toor", "password")).apply("ubuntu-11.04-server-i386.iso");
ComputeServiceContext localHostContext = computeServiceForLocalhostAndGuest(hostId, "localhost", guestId,
"localhost", new Credentials("toor", "password"));
IMachine imageMachine = new IsoToIMachine(manager, adminDisk, diskFormat, settingsFile, vmName, osTypeId, vmId,
forceOverwrite, controllerIDE, localHostContext, hostId, guestId, new Credentials("toor", "password"))
.apply("ubuntu-11.04-server-i386.iso");
IMachineToImage iMachineToImage = new IMachineToImage(manager, map);
Image newImage = iMachineToImage.apply(imageMachine);
//TODO add the description to the cache of the images or serialize to YAML the image desc
// TODO add the description to the cache of the images or serialize to
// YAML the image desc
Set<? extends Image> images = context.getComputeService().listImages();
assertTrue(any(images, equalTo(newImage)));

View File

@ -19,6 +19,11 @@
package org.jclouds.virtualbox.functions;
import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createMock;
import static org.easymock.classextension.EasyMock.replay;
import static org.easymock.classextension.EasyMock.verify;
import org.jclouds.virtualbox.domain.ExecutionType;
import org.testng.annotations.Test;
import org.virtualbox_4_1.IMachine;
@ -26,11 +31,6 @@ import org.virtualbox_4_1.IProgress;
import org.virtualbox_4_1.ISession;
import org.virtualbox_4_1.VirtualBoxManager;
import static org.easymock.classextension.EasyMock.verify;
import static org.easymock.classextension.EasyMock.replay;
import static org.easymock.classextension.EasyMock.createMock;
import static org.easymock.classextension.EasyMock.expect;
@Test(groups = "unit", testName = "LaunchMachineIfNotAlreadyRunningTest")
public class LaunchMachineIfNotAlreadyRunningTest {
@ -39,9 +39,10 @@ public class LaunchMachineIfNotAlreadyRunningTest {
}
// VirtualBox error: The given session is busy (0x80BB0007)
// VirtualBox error: The machine 'jclouds-image-virtualbox-iso-to-machine-test' is not registered (0x8000FFFF)
// VirtualBox error: The given session is busy (0x80BB0007)
// VirtualBox error: The machine
// 'jclouds-image-virtualbox-iso-to-machine-test' is not registered
// (0x8000FFFF)
@Test
public void testLaunchIfNotStarted() throws Exception {

View File

@ -1,3 +1,22 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.virtualbox.functions.admin;
import static org.testng.Assert.assertEquals;
@ -13,23 +32,6 @@ import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
/**
*
* Licensed to jclouds, Inc. (jclouds) under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional
* information regarding copyright ownership. jclouds licenses this file to you
* under the Apache License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*
*
* @author Andrea Turli
*/
@Test(groups = "unit")

View File

@ -19,17 +19,15 @@
package org.jclouds.virtualbox.functions.admin;
/**
* @author Andrea Turli
*/
import static org.testng.Assert.assertEquals;
import org.eclipse.jetty.server.Server;
import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
import org.testng.annotations.Test;
/**
* @author Andrea Turli
*/
@Test(groups = "live", singleThreaded = true, testName = "StartJettyIfNotAlreadyRunningLiveTest")
public class StartJettyIfNotAlreadyRunningLiveTest extends BaseVirtualBoxClientLiveTest {
@ -42,7 +40,7 @@ public class StartJettyIfNotAlreadyRunningLiveTest extends BaseVirtualBoxClientL
server.stop();
assertEquals(server.getState(), server.STOPPED);
}
@Test
public void testLaunchingSameJettyServer() throws Exception {
Server server = new StartJettyIfNotAlreadyRunning(port).apply(basebaseResource);

View File

@ -16,31 +16,33 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.virtualbox.functions.admin;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.domain.Credentials;
import org.jclouds.virtualbox.functions.admin.StartVBoxIfNotAlreadyRunning;
import org.testng.annotations.Test;
import org.virtualbox_4_1.SessionState;
import org.virtualbox_4_1.VirtualBoxManager;
import java.net.URI;
import static org.jclouds.virtualbox.experiment.TestUtils.computeServiceForLocalhostAndGuest;
import static org.testng.Assert.assertEquals;
import java.net.URI;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.domain.Credentials;
import org.testng.annotations.Test;
import org.virtualbox_4_1.SessionState;
import org.virtualbox_4_1.VirtualBoxManager;
@Test(groups = "live", singleThreaded = true, testName = "startVBoxIfNotAlreadyRunningLiveTest")
public class StartVBoxIfNotAlreadyRunningLiveTest {
@Test
public void testStartVbox() throws Exception {
Credentials localhostCredentials = new Credentials("toor", "password");
ComputeServiceContext localHostContext = computeServiceForLocalhostAndGuest("hostId", "localhost", "guestId", "localhost", localhostCredentials);
ComputeServiceContext localHostContext = computeServiceForLocalhostAndGuest("hostId", "localhost", "guestId",
"localhost", localhostCredentials);
URI endpointUri = URI.create("http://localhost:18083/");
VirtualBoxManager manager = new StartVBoxIfNotAlreadyRunning(localHostContext, "hostId", localhostCredentials).apply(endpointUri);
VirtualBoxManager manager = new StartVBoxIfNotAlreadyRunning(localHostContext, "hostId", localhostCredentials)
.apply(endpointUri);
assertEquals(manager.getSessionObject().getState(), SessionState.Unlocked);
}