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

@ -19,13 +19,15 @@
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.
@ -51,7 +53,9 @@ 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> "
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="
@ -61,10 +65,8 @@ public class VirtualBoxPropertiesBuilder extends PropertiesBuilder {
+ "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");

View File

@ -19,19 +19,24 @@
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
@ -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))
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();
.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");

View File

@ -57,7 +57,8 @@ 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);
@ -65,8 +66,8 @@ public class VirtualBoxComputeServiceContextModule extends ComputeServiceAdapter
@Provides
@Singleton
protected VirtualBoxManager createInstance(@Provider URI endpoint, @Named(Constants.PROPERTY_IDENTITY) String identity,
@Named(Constants.PROPERTY_CREDENTIAL) String credential) {
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);
@ -100,10 +101,8 @@ 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)
.<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)
@ -113,17 +112,12 @@ public class VirtualBoxComputeServiceContextModule extends ComputeServiceAdapter
.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.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();

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 {
* ...
@ -46,27 +47,12 @@ import java.util.Map;
*/
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;
@ -85,7 +71,8 @@ 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

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,9 +31,7 @@ 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.
@ -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> {
@ -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)

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> {
@ -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);
@ -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) {

View File

@ -19,33 +19,35 @@
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
*
@ -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) {
@ -79,8 +82,8 @@ public class LaunchMachineIfNotAlreadyRunning implements Function<IMachine, Void
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);
logger.warn(e, "Could not start machine. Got error code %s from launchMachine(). "
+ "The machine might already be running.", errorCode);
break;
default:
propagate(e);

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
*/

View File

@ -50,8 +50,7 @@ public class StartJettyIfNotAlreadyRunning implements Function<String, Server> {
private final int port;
@Inject
public StartJettyIfNotAlreadyRunning(
@Named(VirtualBoxConstants.VIRTUALBOX_JETTY_PORT) final String port) {
public StartJettyIfNotAlreadyRunning(@Named(VirtualBoxConstants.VIRTUALBOX_JETTY_PORT) final String port) {
this.port = Integer.parseInt(port);
}
@ -59,7 +58,8 @@ public class StartJettyIfNotAlreadyRunning implements Function<String, Server> {
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))) {
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" });

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;
@ -124,6 +125,7 @@ public class KeyboardScancodes {
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");

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 {
@ -64,8 +65,8 @@ public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClien
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() {
@ -91,13 +92,14 @@ public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClien
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;
// 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,16 +45,9 @@ 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 {
@ -83,7 +84,8 @@ public class VirtualBoxComputeServiceAdapterTest {
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

@ -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

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;
@ -151,8 +147,8 @@ public class SetupVirtualBoxForLiveTest {
}
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 {

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();
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)));
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())
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();
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)));
new SshjSshClientModule(), new SLF4JLoggingModule(), new BouncyCastleCryptoModule(),
new CacheNodeStoreModule(nodeMap)));
}
private static URI privateKeyFile() {
@ -113,6 +87,7 @@ 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)));
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
*/
@ -56,7 +61,8 @@ 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);
@ -103,7 +109,6 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists("", "", "", false, manager).apply(vmName);
}
private String anyString() {

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,6 +43,9 @@ 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 {
@ -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 {
@ -40,8 +40,9 @@ 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 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 {

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);
}