mirror of https://github.com/apache/jclouds.git
formatting in virtualbox
This commit is contained in:
parent
71ac2b89e1
commit
d300681bcc
|
@ -30,11 +30,11 @@ import com.google.inject.Module;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates compute service context for VirtualBox
|
* Creates compute service context for VirtualBox
|
||||||
*
|
*
|
||||||
* @author Mattias Holmqvist, Andrea Turli
|
* @author Mattias Holmqvist, Andrea Turli
|
||||||
*/
|
*/
|
||||||
public class VirtualBoxContextBuilder extends StandaloneComputeServiceContextBuilder<VirtualBoxManager> {
|
public class VirtualBoxContextBuilder extends StandaloneComputeServiceContextBuilder<VirtualBoxManager> {
|
||||||
|
|
||||||
public VirtualBoxContextBuilder(Properties properties) {
|
public VirtualBoxContextBuilder(Properties properties) {
|
||||||
super(VirtualBoxManager.class, properties);
|
super(VirtualBoxManager.class, properties);
|
||||||
}
|
}
|
||||||
|
@ -43,5 +43,5 @@ public class VirtualBoxContextBuilder extends StandaloneComputeServiceContextBui
|
||||||
protected void addContextModule(List<Module> modules) {
|
protected void addContextModule(List<Module> modules) {
|
||||||
modules.add(new VirtualBoxComputeServiceContextModule());
|
modules.add(new VirtualBoxComputeServiceContextModule());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,17 +19,19 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox;
|
package org.jclouds.virtualbox;
|
||||||
|
|
||||||
import org.jclouds.PropertiesBuilder;
|
import static org.jclouds.Constants.PROPERTY_CREDENTIAL;
|
||||||
import org.jclouds.virtualbox.config.VirtualBoxConstants;
|
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
|
||||||
|
import static org.jclouds.Constants.PROPERTY_IDENTITY;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import static org.jclouds.Constants.*;
|
import org.jclouds.PropertiesBuilder;
|
||||||
|
import org.jclouds.virtualbox.config.VirtualBoxConstants;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds properties for VirtualBox integration.
|
* Builds properties for VirtualBox integration.
|
||||||
*
|
*
|
||||||
* @author Mattias Holmqvist
|
* @author Mattias Holmqvist
|
||||||
*/
|
*/
|
||||||
public class VirtualBoxPropertiesBuilder extends PropertiesBuilder {
|
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_PRESEED_URL, "http://dl.dropbox.com/u/693111/preseed.cfg");
|
||||||
properties.put(VirtualBoxConstants.VIRTUALBOX_SNAPSHOT_DESCRIPTION, "jclouds-virtualbox-snaphot");
|
properties.put(VirtualBoxConstants.VIRTUALBOX_SNAPSHOT_DESCRIPTION, "jclouds-virtualbox-snaphot");
|
||||||
properties.put(VirtualBoxConstants.VIRTUALBOX_HOSTNAME, "jclouds-virtualbox-kickstart-admin");
|
properties.put(VirtualBoxConstants.VIRTUALBOX_HOSTNAME, "jclouds-virtualbox-kickstart-admin");
|
||||||
properties.put(VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE, "<Esc><Esc><Enter> "
|
properties
|
||||||
+ "/install/vmlinuz noapic preseed/url=http://10.0.2.2:8080/src/test/resources/preseed.cfg "
|
.put(VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE,
|
||||||
+ "debian-installer=en_US auto locale=en_US kbd-chooser/method=us "
|
"<Esc><Esc><Enter> "
|
||||||
+ "hostname="
|
+ "/install/vmlinuz noapic preseed/url=http://10.0.2.2:8080/src/test/resources/preseed.cfg "
|
||||||
+ properties.get(VirtualBoxConstants.VIRTUALBOX_HOSTNAME)
|
+ "debian-installer=en_US auto locale=en_US kbd-chooser/method=us "
|
||||||
+ " "
|
+ "hostname="
|
||||||
+ "fb=false debconf/frontend=noninteractive "
|
+ properties.get(VirtualBoxConstants.VIRTUALBOX_HOSTNAME)
|
||||||
+ "keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false "
|
+ " "
|
||||||
+ "initrd=/install/initrd.gz -- <Enter>");
|
+ "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.
|
// 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_DISTRO_ISO_NAME, "ubuntu-11.04-server-i386.iso");
|
||||||
|
|
||||||
properties.put(VirtualBoxConstants.VIRTUALBOX_JETTY_PORT, "8080");
|
properties.put(VirtualBoxConstants.VIRTUALBOX_JETTY_PORT, "8080");
|
||||||
|
|
||||||
return properties;
|
return properties;
|
||||||
|
|
|
@ -19,23 +19,28 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.compute;
|
package org.jclouds.virtualbox.compute;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_MACHINE_CREDENTIAL;
|
||||||
import com.google.common.cache.CacheLoader;
|
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.byon.Node;
|
||||||
import org.jclouds.compute.domain.OsFamily;
|
import org.jclouds.compute.domain.OsFamily;
|
||||||
import org.virtualbox_4_1.IGuestOSType;
|
import org.virtualbox_4_1.IGuestOSType;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_1.IMachine;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_1.VirtualBoxManager;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import com.google.common.base.Function;
|
||||||
import java.net.URI;
|
import com.google.common.cache.CacheLoader;
|
||||||
import java.net.URISyntaxException;
|
|
||||||
|
|
||||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads a node from a VirtualBox IMachine
|
* Loads a node from a VirtualBox IMachine
|
||||||
*
|
*
|
||||||
* @author Mattias Holmqvist
|
* @author Mattias Holmqvist
|
||||||
*/
|
*/
|
||||||
public class LoadMachineFromVirtualBox extends CacheLoader<String, Node> {
|
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 {
|
public Node load(final String id) throws Exception {
|
||||||
|
|
||||||
if (id.equals("host")) {
|
if (id.equals("host")) {
|
||||||
final Node hostNode = Node.builder().id("host")
|
final Node hostNode = Node.builder().id("host").name("host installing virtualbox").hostname("localhost")
|
||||||
.name("host installing virtualbox")
|
.osFamily(OsFamily.LINUX.toString()).osDescription(System.getProperty("os.name"))
|
||||||
.hostname("localhost")
|
.osVersion(System.getProperty("os.version")).group("ssh").username(System.getProperty("user.name"))
|
||||||
.osFamily(OsFamily.LINUX.toString())
|
.credentialUrl(privateKeyFile()).build();
|
||||||
.osDescription(System.getProperty("os.name"))
|
|
||||||
.osVersion(System.getProperty("os.version"))
|
|
||||||
.group("ssh")
|
|
||||||
.username(System.getProperty("user.name"))
|
|
||||||
.credentialUrl(privateKeyFile())
|
|
||||||
.build();
|
|
||||||
return hostNode;
|
return hostNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,23 +70,14 @@ public class LoadMachineFromVirtualBox extends CacheLoader<String, Node> {
|
||||||
final String osTypeId = machine.getOSTypeId();
|
final String osTypeId = machine.getOSTypeId();
|
||||||
final IGuestOSType guestOSType = manager.getVBox().getGuestOSType(osTypeId);
|
final IGuestOSType guestOSType = manager.getVBox().getGuestOSType(osTypeId);
|
||||||
|
|
||||||
final Node node = Node.builder()
|
final Node node = Node.builder().id(machine.getId()).name(machine.getName())
|
||||||
.id(machine.getId())
|
.description(machine.getDescription()).loginPort(22).group(System.getProperty(VIRTUALBOX_MACHINE_GROUP))
|
||||||
.name(machine.getName())
|
.username(System.getProperty(VIRTUALBOX_MACHINE_USERNAME))
|
||||||
.description(machine.getDescription())
|
.credential(System.getProperty(VIRTUALBOX_MACHINE_CREDENTIAL))
|
||||||
.loginPort(22)
|
.sudoPassword(System.getProperty(VIRTUALBOX_MACHINE_CREDENTIAL))
|
||||||
.group(System.getProperty(VIRTUALBOX_MACHINE_GROUP))
|
.locationId(System.getProperty(VIRTUALBOX_MACHINE_LOCATION)).os64Bit(guestOSType.getIs64Bit())
|
||||||
.username(System.getProperty(VIRTUALBOX_MACHINE_USERNAME))
|
.osArch(guestOSType.getDescription()).osFamily(guestOSType.getFamilyDescription())
|
||||||
.credential(System.getProperty(VIRTUALBOX_MACHINE_CREDENTIAL))
|
.osVersion(guestOSType.getId()).osDescription(guestOSType.getDescription()).hostname(ipAddress).build();
|
||||||
.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;
|
return node;
|
||||||
|
|
||||||
|
|
|
@ -19,10 +19,16 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.compute;
|
package org.jclouds.virtualbox.compute;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import com.google.common.base.Predicate;
|
import static com.google.common.collect.Iterables.filter;
|
||||||
import com.google.common.base.Throwables;
|
import static com.google.common.collect.Iterables.transform;
|
||||||
import com.google.inject.Singleton;
|
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.ComputeServiceAdapter;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
import org.jclouds.compute.domain.Template;
|
import org.jclouds.compute.domain.Template;
|
||||||
|
@ -30,15 +36,17 @@ import org.jclouds.domain.Credentials;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.javax.annotation.Nullable;
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
import org.jclouds.location.suppliers.JustProvider;
|
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 com.google.common.base.Function;
|
||||||
import java.util.*;
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.base.Throwables;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import com.google.inject.Singleton;
|
||||||
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;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the connection between the
|
* Defines the connection between the
|
||||||
|
@ -55,7 +63,8 @@ public class VirtualBoxComputeServiceAdapter implements ComputeServiceAdapter<IM
|
||||||
private Function<IMachine, Image> iMachineToImage;
|
private Function<IMachine, Image> iMachineToImage;
|
||||||
|
|
||||||
@Inject
|
@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.iMachineToImage = iMachineToImage;
|
||||||
this.manager = checkNotNull(manager, "manager");
|
this.manager = checkNotNull(manager, "manager");
|
||||||
this.justProvider = checkNotNull(justProvider, "justProvider");
|
this.justProvider = checkNotNull(justProvider, "justProvider");
|
||||||
|
@ -77,8 +86,8 @@ public class VirtualBoxComputeServiceAdapter implements ComputeServiceAdapter<IM
|
||||||
return manager.getVBox().getMachines();
|
return manager.getVBox().getMachines();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<Image> listImages() {
|
public Iterable<Image> listImages() {
|
||||||
final Predicate<? super IMachine> imagePredicate = new Predicate<IMachine>() {
|
final Predicate<? super IMachine> imagePredicate = new Predicate<IMachine>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(@Nullable IMachine iMachine) {
|
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);
|
final Iterable<IMachine> imageMachines = filter(manager.getVBox().getMachines(), imagePredicate);
|
||||||
return transform(imageMachines, iMachineToImage);
|
return transform(imageMachines, iMachineToImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -57,20 +57,21 @@ import com.google.inject.TypeLiteral;
|
||||||
/**
|
/**
|
||||||
* @author Mattias Holmqvist, Andrea Turli
|
* @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() {
|
public VirtualBoxComputeServiceContextModule() {
|
||||||
super(VirtualBoxManager.class, VirtualBoxManager.class);
|
super(VirtualBoxManager.class, VirtualBoxManager.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
protected VirtualBoxManager createInstance(@Provider URI endpoint, @Named(Constants.PROPERTY_IDENTITY) String identity,
|
protected VirtualBoxManager createInstance(@Provider URI endpoint,
|
||||||
@Named(Constants.PROPERTY_CREDENTIAL) String credential) {
|
@Named(Constants.PROPERTY_IDENTITY) String identity, @Named(Constants.PROPERTY_CREDENTIAL) String credential) {
|
||||||
|
|
||||||
VirtualBoxManager manager = VirtualBoxManager.createInstance("");
|
VirtualBoxManager manager = VirtualBoxManager.createInstance("");
|
||||||
manager.connect(endpoint.toASCIIString(), identity, credential);
|
manager.connect(endpoint.toASCIIString(), identity, credential);
|
||||||
return manager;
|
return manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
|
@ -100,31 +101,24 @@ public class VirtualBoxComputeServiceContextModule extends ComputeServiceAdapter
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public static final Map<MachineState, NodeState> machineToNodeState = ImmutableMap
|
public static final Map<MachineState, NodeState> machineToNodeState = ImmutableMap
|
||||||
.<MachineState, NodeState>builder()
|
.<MachineState, NodeState> builder().put(MachineState.Running, NodeState.RUNNING)
|
||||||
.put(MachineState.Running, NodeState.RUNNING)
|
.put(MachineState.PoweredOff, NodeState.SUSPENDED).put(MachineState.DeletingSnapshot, NodeState.PENDING)
|
||||||
.put(MachineState.PoweredOff, NodeState.SUSPENDED)
|
.put(MachineState.DeletingSnapshotOnline, NodeState.PENDING)
|
||||||
.put(MachineState.DeletingSnapshot, NodeState.PENDING)
|
.put(MachineState.DeletingSnapshotPaused, NodeState.PENDING)
|
||||||
.put(MachineState.DeletingSnapshotOnline, NodeState.PENDING)
|
.put(MachineState.FaultTolerantSyncing, NodeState.PENDING)
|
||||||
.put(MachineState.DeletingSnapshotPaused, NodeState.PENDING)
|
.put(MachineState.LiveSnapshotting, NodeState.PENDING)
|
||||||
.put(MachineState.FaultTolerantSyncing, NodeState.PENDING)
|
.put(MachineState.SettingUp, NodeState.PENDING)
|
||||||
.put(MachineState.LiveSnapshotting, NodeState.PENDING)
|
.put(MachineState.Starting, NodeState.PENDING)
|
||||||
.put(MachineState.SettingUp, NodeState.PENDING)
|
.put(MachineState.Stopping, NodeState.PENDING)
|
||||||
.put(MachineState.Starting, NodeState.PENDING)
|
.put(MachineState.Restoring, NodeState.PENDING)
|
||||||
.put(MachineState.Stopping, NodeState.PENDING)
|
// TODO What to map these states to?
|
||||||
.put(MachineState.Restoring, NodeState.PENDING)
|
.put(MachineState.FirstOnline, NodeState.PENDING).put(MachineState.FirstTransient, NodeState.PENDING)
|
||||||
// TODO What to map these states to?
|
.put(MachineState.LastOnline, NodeState.PENDING).put(MachineState.LastTransient, NodeState.PENDING)
|
||||||
.put(MachineState.FirstOnline, NodeState.PENDING)
|
.put(MachineState.Teleported, NodeState.PENDING).put(MachineState.TeleportingIn, NodeState.PENDING)
|
||||||
.put(MachineState.FirstTransient, NodeState.PENDING)
|
.put(MachineState.TeleportingPausedVM, 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.Null, NodeState.UNRECOGNIZED).build();
|
||||||
.put(MachineState.Stuck, NodeState.ERROR)
|
|
||||||
|
|
||||||
.put(MachineState.Null, NodeState.UNRECOGNIZED).build();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ package org.jclouds.virtualbox.config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configuration properties used for interacting with VirtualBox instances.
|
* Configuration properties used for interacting with VirtualBox instances.
|
||||||
*
|
*
|
||||||
* @author Mattias Holmqvist, Andrea Turli
|
* @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_SNAPSHOT_DESCRIPTION = "jclouds.virtualbox.snapshotDescription";
|
||||||
|
|
||||||
public static final String VIRTUALBOX_INSTALLATION_KEY_SEQUENCE = "jclouds.virtualbox.installationkeysequence";
|
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_HOSTNAME = "jclouds.virtualbox.hostname";
|
||||||
|
|
||||||
public static final String VIRTUALBOX_WORKINGDIR = "jclouds.virtualbox.workingdir";
|
public static final String VIRTUALBOX_WORKINGDIR = "jclouds.virtualbox.workingdir";
|
||||||
|
|
||||||
public static final String VIRTUALBOX_ISOFILE = "jclouds.virtualbox.isofile";
|
public static final String VIRTUALBOX_ISOFILE = "jclouds.virtualbox.isofile";
|
||||||
|
|
||||||
public static final String VIRTUALBOX_MACHINE_GROUP = "jclouds.virtualbox.machinegroup";
|
public static final String VIRTUALBOX_MACHINE_GROUP = "jclouds.virtualbox.machinegroup";
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/**
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -19,17 +19,18 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.domain;
|
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.HashMap;
|
||||||
import java.util.Map;
|
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.
|
* Maps the error codes in the Virtual Box Java API into enum values.
|
||||||
* <p/>
|
* <p/>
|
||||||
* <p/>
|
* <p/>
|
||||||
* To get the error code from a VBoxException, use:
|
* To get the error code from a VBoxException, use:
|
||||||
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* try {
|
* try {
|
||||||
* ...
|
* ...
|
||||||
|
@ -41,32 +42,17 @@ import java.util.Map;
|
||||||
* ErrorCode errorCode = ErrorCode.valueOf(faultCode);
|
* ErrorCode errorCode = ErrorCode.valueOf(faultCode);
|
||||||
* }
|
* }
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @author Mattias Holmqvist
|
* @author Mattias Holmqvist
|
||||||
*/
|
*/
|
||||||
public enum ErrorCode {
|
public enum ErrorCode {
|
||||||
|
|
||||||
VBOX_E_OBJECT_NOT_FOUND(2159738881L),
|
VBOX_E_OBJECT_NOT_FOUND(2159738881L), VBOX_E_INVALID_VM_STATE(2159738882L), VBOX_E_VM_ERROR(2159738883L), VBOX_E_FILE_ERROR(
|
||||||
VBOX_E_INVALID_VM_STATE(2159738882L),
|
2159738884L), VBOX_E_IPRT_ERROR(2159738885L), VBOX_E_PDM_ERROR(2159738886L), VBOX_E_INVALID_OBJECT_STATE(
|
||||||
VBOX_E_VM_ERROR(2159738883L),
|
2159738887L), VBOX_E_HOST_ERROR(2159738888L), VBOX_E_NOT_SUPPORTED(2159738889L), VBOX_E_XML_ERROR(2159738890L), VBOX_E_INVALID_SESSION_STATE(
|
||||||
VBOX_E_FILE_ERROR(2159738884L),
|
2159738891L), VBOX_E_OBJECT_IN_USE(2159738892L), VBOX_E_ACCESSDENIED(2147942405L), VBOX_E_POINTER(2147500035L), VBOX_E_FAIL(
|
||||||
VBOX_E_IPRT_ERROR(2159738885L),
|
2147500037L), VBOX_E_NOTIMPL(2147500033L), VBOX_E_OUTOFMEMORY(2147942414L), VBOX_E_INVALIDARG(2147942487L), VBOX_E_UNEXPECTED(
|
||||||
VBOX_E_PDM_ERROR(2159738886L),
|
2147549183L), VBOX_E_UNKNOWN_ERROR_CODE(-1L), VBOX_E_ERROR_CODE_UNAVAILABLE(-2L);
|
||||||
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;
|
private long code;
|
||||||
|
|
||||||
|
@ -84,8 +70,9 @@ public enum ErrorCode {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an ErrorCode from the fault code given by the VirtualBox API.
|
* 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.
|
* @return an ErrorCode representing the given fault code.
|
||||||
*/
|
*/
|
||||||
public static ErrorCode valueOf(VBoxException vboxException) {
|
public static ErrorCode valueOf(VBoxException vboxException) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/**
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -21,10 +21,7 @@ package org.jclouds.virtualbox.domain;
|
||||||
|
|
||||||
public enum ExecutionType {
|
public enum ExecutionType {
|
||||||
|
|
||||||
GUI("gui"),
|
GUI("gui"), HEADLESS("headless"), SDL("sdl"), EMERGENCYSTOP("emergencystop");
|
||||||
HEADLESS("headless"),
|
|
||||||
SDL("sdl"),
|
|
||||||
EMERGENCYSTOP("emergencystop");
|
|
||||||
|
|
||||||
private final String type;
|
private final String type;
|
||||||
|
|
||||||
|
|
|
@ -41,73 +41,73 @@ import com.google.common.collect.Maps;
|
||||||
* Serializes to the following
|
* Serializes to the following
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
id: myTestId
|
* id: myTestId
|
||||||
name: ubuntu-11.04-server-i386
|
* name: ubuntu-11.04-server-i386
|
||||||
description: ubuntu 11.04 server (i386)
|
* description: ubuntu 11.04 server (i386)
|
||||||
os_arch: x86
|
* os_arch: x86
|
||||||
os_family: linux
|
* os_family: linux
|
||||||
os_description: ubuntu
|
* os_description: ubuntu
|
||||||
os_version: 11.04
|
* os_version: 11.04
|
||||||
iso: http://releases.ubuntu.com/11.04/ubuntu-11.04-server-i386.iso
|
* iso: http://releases.ubuntu.com/11.04/ubuntu-11.04-server-i386.iso
|
||||||
keystroke_sequence: |
|
* keystroke_sequence: |
|
||||||
<Esc><Esc><Enter>
|
* <Esc><Esc><Enter>
|
||||||
/install/vmlinuz noapic preseed/url=http://10.0.2.2:8080/src/test/resources/preseed.cfg
|
* /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
|
* debian-installer=en_US auto locale=en_US kbd-chooser/method=us
|
||||||
hostname=vmName
|
* hostname=vmName
|
||||||
fb=false debconf/frontend=noninteractive
|
* fb=false debconf/frontend=noninteractive
|
||||||
keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false
|
* keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false
|
||||||
initrd=/install/initrd.gz -- <Enter>
|
* initrd=/install/initrd.gz -- <Enter>
|
||||||
preseed_cfg: |
|
* preseed_cfg: |
|
||||||
## Options to set on the command line
|
* ## Options to set on the command line
|
||||||
d-i debian-installer/locale string en_US.utf8
|
* d-i debian-installer/locale string en_US.utf8
|
||||||
d-i console-setup/ask_detect boolean false
|
* d-i console-setup/ask_detect boolean false
|
||||||
d-i console-setup/layout string USA
|
* d-i console-setup/layout string USA
|
||||||
d-i netcfg/get_hostname string unassigned-hostname
|
* d-i netcfg/get_hostname string unassigned-hostname
|
||||||
d-i netcfg/get_domain string unassigned-domain
|
* d-i netcfg/get_domain string unassigned-domain
|
||||||
# Continue without a default route
|
* # Continue without a default route
|
||||||
# Not working , specify a dummy in the DHCP
|
* # Not working , specify a dummy in the DHCP
|
||||||
d-i time/zone string UTC
|
* d-i time/zone string UTC
|
||||||
d-i clock-setup/utc-auto boolean true
|
* d-i clock-setup/utc-auto boolean true
|
||||||
d-i clock-setup/utc boolean true
|
* d-i clock-setup/utc boolean true
|
||||||
d-i kbd-chooser/method select American English
|
* d-i kbd-chooser/method select American English
|
||||||
d-i netcfg/wireless_wep string
|
* d-i netcfg/wireless_wep string
|
||||||
d-i base-installer/kernel/override-image string linux-server
|
* d-i base-installer/kernel/override-image string linux-server
|
||||||
# Choices: Dialog, Readline, Gnome, Kde, Editor, Noninteractive
|
* # Choices: Dialog, Readline, Gnome, Kde, Editor, Noninteractive
|
||||||
d-i debconf debconf/frontend select Noninteractive
|
* d-i debconf debconf/frontend select Noninteractive
|
||||||
d-i pkgsel/install-language-support boolean false
|
* d-i pkgsel/install-language-support boolean false
|
||||||
tasksel tasksel/first multiselect standard, ubuntu-server
|
* tasksel tasksel/first multiselect standard, ubuntu-server
|
||||||
d-i partman-auto/method string lvm
|
* d-i partman-auto/method string lvm
|
||||||
d-i partman-lvm/confirm boolean true
|
* d-i partman-lvm/confirm boolean true
|
||||||
d-i partman-lvm/device_remove_lvm boolean true
|
* d-i partman-lvm/device_remove_lvm boolean true
|
||||||
d-i partman-auto/choose_recipe select atomic
|
* d-i partman-auto/choose_recipe select atomic
|
||||||
d-i partman/confirm_write_new_label boolean true
|
* d-i partman/confirm_write_new_label boolean true
|
||||||
d-i partman/confirm_nooverwrite boolean true
|
* d-i partman/confirm_nooverwrite boolean true
|
||||||
d-i partman/choose_partition select finish
|
* d-i partman/choose_partition select finish
|
||||||
d-i partman/confirm boolean true
|
* d-i partman/confirm boolean true
|
||||||
# Write the changes to disks and configure LVM?
|
* # Write the changes to disks and configure LVM?
|
||||||
d-i partman-lvm/confirm boolean true
|
* d-i partman-lvm/confirm boolean true
|
||||||
d-i partman-lvm/confirm_nooverwrite boolean true
|
* d-i partman-lvm/confirm_nooverwrite boolean true
|
||||||
d-i partman-auto-lvm/guided_size string max
|
* d-i partman-auto-lvm/guided_size string max
|
||||||
## Default user, we can get away with a recipe to change this
|
* ## Default user, we can get away with a recipe to change this
|
||||||
d-i passwd/user-fullname string toor
|
* d-i passwd/user-fullname string toor
|
||||||
d-i passwd/username string toor
|
* d-i passwd/username string toor
|
||||||
d-i passwd/user-password password password
|
* d-i passwd/user-password password password
|
||||||
d-i passwd/user-password-again password password
|
* d-i passwd/user-password-again password password
|
||||||
d-i user-setup/encrypt-home boolean false
|
* d-i user-setup/encrypt-home boolean false
|
||||||
d-i user-setup/allow-password-weak boolean true
|
* d-i user-setup/allow-password-weak boolean true
|
||||||
# Individual additional packages to install
|
* # Individual additional packages to install
|
||||||
d-i pkgsel/include string openssh-server ntp
|
* d-i pkgsel/include string openssh-server ntp
|
||||||
# Whether to upgrade packages after debootstrap.
|
* # Whether to upgrade packages after debootstrap.
|
||||||
# Allowed values: none, safe-upgrade, full-upgrade
|
* # Allowed values: none, safe-upgrade, full-upgrade
|
||||||
d-i pkgsel/upgrade select full-upgrade
|
* d-i pkgsel/upgrade select full-upgrade
|
||||||
d-i grub-installer/only_debian boolean true
|
* d-i grub-installer/only_debian boolean true
|
||||||
d-i grub-installer/with_other_os boolean true
|
* d-i grub-installer/with_other_os boolean true
|
||||||
d-i finish-install/reboot_in_progress note
|
* d-i finish-install/reboot_in_progress note
|
||||||
#For the update
|
* #For the update
|
||||||
d-i pkgsel/update-policy select none
|
* d-i pkgsel/update-policy select none
|
||||||
# debconf-get-selections --install
|
* # debconf-get-selections --install
|
||||||
#Use mirror
|
* #Use mirror
|
||||||
choose-mirror-bin mirror/http/proxy string
|
* choose-mirror-bin mirror/http/proxy string
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @author Kelvin Kakugawa
|
* @author Kelvin Kakugawa
|
||||||
|
@ -143,14 +143,11 @@ public class YamlImage {
|
||||||
return null;
|
return null;
|
||||||
OsFamily family = parseOsFamilyOrUnrecognized(arg0.os_family);
|
OsFamily family = parseOsFamilyOrUnrecognized(arg0.os_family);
|
||||||
|
|
||||||
OperatingSystem operatingSystem = OperatingSystem.builder()
|
OperatingSystem operatingSystem = OperatingSystem.builder().description(arg0.os_description).family(family)
|
||||||
.description(arg0.os_description)
|
.version(arg0.os_version).is64Bit(arg0.os_64bit).build();
|
||||||
.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();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions;
|
package org.jclouds.virtualbox.functions;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/**
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -19,10 +19,11 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions;
|
package org.jclouds.virtualbox.functions;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_1.IMachine;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mattias Holmqvist
|
* @author Mattias Holmqvist
|
||||||
|
|
|
@ -19,13 +19,14 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions;
|
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.DeviceType;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_1.IMachine;
|
||||||
import org.virtualbox_4_1.IMedium;
|
import org.virtualbox_4_1.IMedium;
|
||||||
import org.virtualbox_4_1.VBoxException;
|
import org.virtualbox_4_1.VBoxException;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mattias Holmqvist
|
* @author Mattias Holmqvist
|
||||||
|
|
|
@ -19,12 +19,14 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions;
|
package org.jclouds.virtualbox.functions;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import org.virtualbox_4_1.*;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
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
|
* @author Mattias Holmqvist
|
||||||
|
@ -37,7 +39,8 @@ public class AttachMediumToMachineIfNotAlreadyAttached implements Function<IMach
|
||||||
private int device;
|
private int device;
|
||||||
private DeviceType deviceType;
|
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.controllerIDE = controllerIDE;
|
||||||
this.hardDisk = hardDisk;
|
this.hardDisk = hardDisk;
|
||||||
this.controllerPort = controllerPort;
|
this.controllerPort = controllerPort;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/**
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -19,14 +19,15 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions;
|
package org.jclouds.virtualbox.functions;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import static org.virtualbox_4_1.NATProtocol.TCP;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import static org.virtualbox_4_1.NetworkAttachmentType.NAT;
|
||||||
import org.virtualbox_4_1.INetworkAdapter;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import static org.virtualbox_4_1.NATProtocol.TCP;
|
import org.virtualbox_4_1.IMachine;
|
||||||
import static org.virtualbox_4_1.NetworkAttachmentType.NAT;
|
import org.virtualbox_4_1.INetworkAdapter;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mattias Holmqvist
|
* @author Mattias Holmqvist
|
||||||
|
|
|
@ -19,14 +19,14 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions;
|
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.IMachine;
|
||||||
import org.virtualbox_4_1.IVirtualBox;
|
import org.virtualbox_4_1.IVirtualBox;
|
||||||
import org.virtualbox_4_1.VBoxException;
|
import org.virtualbox_4_1.VBoxException;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_1.VirtualBoxManager;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mattias Holmqvist
|
* @author Mattias Holmqvist
|
||||||
|
@ -40,7 +40,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExists implements Functi
|
||||||
private VirtualBoxManager manager;
|
private VirtualBoxManager manager;
|
||||||
|
|
||||||
public CreateAndRegisterMachineFromIsoIfNotAlreadyExists(String settingsFile, String osTypeId, String vmId,
|
public CreateAndRegisterMachineFromIsoIfNotAlreadyExists(String settingsFile, String osTypeId, String vmId,
|
||||||
boolean forceOverwrite, VirtualBoxManager manager) {
|
boolean forceOverwrite, VirtualBoxManager manager) {
|
||||||
this.settingsFile = settingsFile;
|
this.settingsFile = settingsFile;
|
||||||
this.osTypeId = osTypeId;
|
this.osTypeId = osTypeId;
|
||||||
this.vmId = vmId;
|
this.vmId = vmId;
|
||||||
|
|
|
@ -19,11 +19,17 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions;
|
package org.jclouds.virtualbox.functions;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import org.virtualbox_4_1.*;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
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
|
* @author Mattias Holmqvist
|
||||||
*/
|
*/
|
||||||
|
@ -71,15 +77,18 @@ public class CreateMediumIfNotAlreadyExists implements Function<String, IMedium>
|
||||||
private void createBaseStorage(IMedium hardDisk) {
|
private void createBaseStorage(IMedium hardDisk) {
|
||||||
try {
|
try {
|
||||||
long size = 4L * 1024L * 1024L * 1024L - 4L;
|
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);
|
storageCreation.waitForCompletion(-1);
|
||||||
} catch (VBoxException e) {
|
} catch (VBoxException e) {
|
||||||
if (fileNotFoundException(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();
|
hardDisk.deleteStorage();
|
||||||
}
|
}
|
||||||
if (!storageAlreadyExists(e)) {
|
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;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,8 +99,8 @@ public class CreateMediumIfNotAlreadyExists implements Function<String, IMedium>
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean storageAlreadyExists(VBoxException e) {
|
private boolean storageAlreadyExists(VBoxException e) {
|
||||||
return e.getMessage().indexOf("VirtualBox error: Storage for the medium ") != -1 &&
|
return e.getMessage().indexOf("VirtualBox error: Storage for the medium ") != -1
|
||||||
e.getMessage().indexOf("is already created") != -1;
|
&& e.getMessage().indexOf("is already created") != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,6 @@ public class IMachineToHardware implements Function<IMachine, Hardware> {
|
||||||
public Hardware apply(@Nullable IMachine vm) {
|
public Hardware apply(@Nullable IMachine vm) {
|
||||||
String osTypeId = vm.getOSTypeId();
|
String osTypeId = vm.getOSTypeId();
|
||||||
|
|
||||||
|
|
||||||
IGuestOSType guestOSType = virtualBoxManager.getVBox().getGuestOSType(osTypeId);
|
IGuestOSType guestOSType = virtualBoxManager.getVBox().getGuestOSType(osTypeId);
|
||||||
Boolean is64Bit = guestOSType.getIs64Bit();
|
Boolean is64Bit = guestOSType.getIs64Bit();
|
||||||
HardwareBuilder hardwareBuilder = new HardwareBuilder();
|
HardwareBuilder hardwareBuilder = new HardwareBuilder();
|
||||||
|
|
|
@ -58,8 +58,7 @@ public class IMachineToImage implements Function<IMachine, Image> {
|
||||||
|
|
||||||
IGuestOSType guestOSType = virtualboxManager.getVBox().getGuestOSType(from.getOSTypeId());
|
IGuestOSType guestOSType = virtualboxManager.getVBox().getGuestOSType(from.getOSTypeId());
|
||||||
OsFamily family = parseOsFamilyOrUnrecognized(guestOSType.getDescription());
|
OsFamily family = parseOsFamilyOrUnrecognized(guestOSType.getDescription());
|
||||||
String version = parseVersionOrReturnEmptyString(family, guestOSType.getDescription(),
|
String version = parseVersionOrReturnEmptyString(family, guestOSType.getDescription(), osVersionMap);
|
||||||
osVersionMap);
|
|
||||||
OperatingSystem os = OperatingSystem.builder().description(guestOSType.getDescription()).family(family)
|
OperatingSystem os = OperatingSystem.builder().description(guestOSType.getDescription()).family(family)
|
||||||
.version(version).is64Bit(guestOSType.getIs64Bit()).build();
|
.version(version).is64Bit(guestOSType.getIs64Bit()).build();
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,10 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions;
|
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.ComputeService;
|
||||||
import org.jclouds.compute.domain.ExecResponse;
|
import org.jclouds.compute.domain.ExecResponse;
|
||||||
import org.jclouds.compute.options.RunScriptOptions;
|
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.IMachine;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_1.VirtualBoxManager;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an IP address from an IMachine using arp of the host machine.
|
* Get an IP address from an IMachine using arp of the host machine.
|
||||||
*
|
*
|
||||||
* @author Mattias Holmqvist, Andrea Turli
|
* @author Mattias Holmqvist, Andrea Turli
|
||||||
*/
|
*/
|
||||||
public class IMachineToIpAddress implements Function<IMachine, String> {
|
public class IMachineToIpAddress implements Function<IMachine, String> {
|
||||||
|
@ -63,18 +64,25 @@ public class IMachineToIpAddress implements Function<IMachine, String> {
|
||||||
IMachine hostMachine = manager.getVBox().findMachine(hostId);
|
IMachine hostMachine = manager.getVBox().findMachine(hostId);
|
||||||
if (isOSX(hostMachine)) {
|
if (isOSX(hostMachine)) {
|
||||||
if (simplifiedMacAddressOfClonedVM.contains("00"))
|
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.contains("0"))
|
||||||
if (simplifiedMacAddressOfClonedVM.indexOf("0") + 1 != ':' && simplifiedMacAddressOfClonedVM.indexOf("0") - 1 != ':')
|
if (simplifiedMacAddressOfClonedVM.indexOf("0") + 1 != ':'
|
||||||
simplifiedMacAddressOfClonedVM = new StringBuffer(simplifiedMacAddressOfClonedVM).delete(simplifiedMacAddressOfClonedVM.indexOf("0"), simplifiedMacAddressOfClonedVM.indexOf("0") + 1).toString();
|
&& 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.
|
// 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);
|
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(")"));
|
String ipAddress = arpLine.substring(arpLine.indexOf("(") + 1, arpLine.indexOf(")"));
|
||||||
System.out.println("IP address " + ipAddress);
|
System.out.println("IP address " + ipAddress);
|
||||||
return ipAddress;
|
return ipAddress;
|
||||||
|
|
|
@ -19,8 +19,19 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions;
|
package org.jclouds.virtualbox.functions;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import static org.jclouds.virtualbox.config.VirtualBoxComputeServiceContextModule.machineToNodeState;
|
||||||
import org.jclouds.compute.domain.*;
|
|
||||||
|
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.compute.reference.ComputeServiceConstants;
|
||||||
import org.jclouds.domain.Credentials;
|
import org.jclouds.domain.Credentials;
|
||||||
import org.jclouds.domain.LocationBuilder;
|
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.INetworkAdapter;
|
||||||
import org.virtualbox_4_1.MachineState;
|
import org.virtualbox_4_1.MachineState;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import com.google.common.base.Function;
|
||||||
import javax.inject.Named;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import static org.jclouds.virtualbox.config.VirtualBoxComputeServiceContextModule.machineToNodeState;
|
|
||||||
|
|
||||||
public class IMachineToNodeMetadata implements Function<IMachine, NodeMetadata> {
|
public class IMachineToNodeMetadata implements Function<IMachine, NodeMetadata> {
|
||||||
|
|
||||||
|
@ -57,7 +63,7 @@ public class IMachineToNodeMetadata implements Function<IMachine, NodeMetadata>
|
||||||
locationBuilder.id("");
|
locationBuilder.id("");
|
||||||
locationBuilder.scope(LocationScope.HOST);
|
locationBuilder.scope(LocationScope.HOST);
|
||||||
nodeMetadataBuilder.location(locationBuilder.build());
|
nodeMetadataBuilder.location(locationBuilder.build());
|
||||||
|
|
||||||
HardwareBuilder hardwareBuilder = new HardwareBuilder();
|
HardwareBuilder hardwareBuilder = new HardwareBuilder();
|
||||||
hardwareBuilder.ram(vm.getMemorySize().intValue());
|
hardwareBuilder.ram(vm.getMemorySize().intValue());
|
||||||
|
|
||||||
|
@ -75,7 +81,6 @@ public class IMachineToNodeMetadata implements Function<IMachine, NodeMetadata>
|
||||||
nodeMetadataBuilder.hostname(vm.getName());
|
nodeMetadataBuilder.hostname(vm.getName());
|
||||||
nodeMetadataBuilder.loginPort(18083);
|
nodeMetadataBuilder.loginPort(18083);
|
||||||
|
|
||||||
|
|
||||||
MachineState vmState = vm.getState();
|
MachineState vmState = vm.getState();
|
||||||
NodeState nodeState = machineToNodeState.get(vmState);
|
NodeState nodeState = machineToNodeState.get(vmState);
|
||||||
if (nodeState == null)
|
if (nodeState == null)
|
||||||
|
@ -90,8 +95,8 @@ public class IMachineToNodeMetadata implements Function<IMachine, NodeMetadata>
|
||||||
System.out.println("Interface: " + bridgedInterface);
|
System.out.println("Interface: " + bridgedInterface);
|
||||||
}
|
}
|
||||||
|
|
||||||
// nodeMetadataBuilder.imageId("");
|
// nodeMetadataBuilder.imageId("");
|
||||||
// nodeMetadataBuilder.group("");
|
// nodeMetadataBuilder.group("");
|
||||||
|
|
||||||
String provider = "virtualbox";
|
String provider = "virtualbox";
|
||||||
String identity = System.getProperty("test." + provider + ".identity", "administrator");
|
String identity = System.getProperty("test." + provider + ".identity", "administrator");
|
||||||
|
@ -101,5 +106,5 @@ public class IMachineToNodeMetadata implements Function<IMachine, NodeMetadata>
|
||||||
nodeMetadataBuilder.id(vm.getId());
|
nodeMetadataBuilder.id(vm.getId());
|
||||||
return nodeMetadataBuilder.build();
|
return nodeMetadataBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,22 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions;
|
package org.jclouds.virtualbox.functions;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import com.google.inject.Inject;
|
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.eclipse.jetty.server.Server;
|
||||||
import org.jclouds.compute.ComputeServiceContext;
|
import org.jclouds.compute.ComputeServiceContext;
|
||||||
import org.jclouds.compute.domain.ExecResponse;
|
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.domain.ExecutionType;
|
||||||
import org.jclouds.virtualbox.functions.admin.StartJettyIfNotAlreadyRunning;
|
import org.jclouds.virtualbox.functions.admin.StartJettyIfNotAlreadyRunning;
|
||||||
import org.jclouds.virtualbox.settings.KeyboardScancodes;
|
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 com.google.common.base.Function;
|
||||||
import javax.inject.Named;
|
import com.google.inject.Inject;
|
||||||
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;
|
|
||||||
|
|
||||||
public class IsoToIMachine implements Function<String, IMachine> {
|
public class IsoToIMachine implements Function<String, IMachine> {
|
||||||
|
|
||||||
|
@ -73,8 +83,8 @@ public class IsoToIMachine implements Function<String, IMachine> {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public IsoToIMachine(VirtualBoxManager manager, String adminDisk, String diskFormat, String settingsFile,
|
public IsoToIMachine(VirtualBoxManager manager, String adminDisk, String diskFormat, String settingsFile,
|
||||||
String vmName, String osTypeId, String vmId, boolean forceOverwrite, String controllerIDE,
|
String vmName, String osTypeId, String vmId, boolean forceOverwrite, String controllerIDE,
|
||||||
ComputeServiceContext context, String hostId, String guestId, Credentials credentials) {
|
ComputeServiceContext context, String hostId, String guestId, Credentials credentials) {
|
||||||
super();
|
super();
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
this.adminDisk = adminDisk;
|
this.adminDisk = adminDisk;
|
||||||
|
@ -98,7 +108,8 @@ public class IsoToIMachine implements Function<String, IMachine> {
|
||||||
String baseResource = ".";
|
String baseResource = ".";
|
||||||
Server server = new StartJettyIfNotAlreadyRunning(port).apply(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 defaultWorkingDir = System.getProperty("user.home") + "/jclouds-virtualbox-test";
|
||||||
String workingDir = System.getProperty(VIRTUALBOX_WORKINGDIR, defaultWorkingDir);
|
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";
|
String guestAdditionsDvd = workingDir + "/VBoxGuestAdditions_4.1.2.iso";
|
||||||
final IMedium guestAdditionsDvdMedium = manager.getVBox().openMedium(guestAdditionsDvd, DeviceType.DVD,
|
final IMedium guestAdditionsDvdMedium = manager.getVBox().openMedium(guestAdditionsDvd, DeviceType.DVD,
|
||||||
AccessMode.ReadOnly, forceOverwrite);
|
AccessMode.ReadOnly, forceOverwrite);
|
||||||
|
|
||||||
// Guest additions
|
// Guest additions
|
||||||
ensureGuestAdditionsMediumIsAttached(vmName, guestAdditionsDvdMedium);
|
ensureGuestAdditionsMediumIsAttached(vmName, guestAdditionsDvdMedium);
|
||||||
|
@ -178,13 +189,13 @@ public class IsoToIMachine implements Function<String, IMachine> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ensureGuestAdditionsMediumIsAttached(String vmName, final IMedium guestAdditionsDvdMedium) {
|
private void ensureGuestAdditionsMediumIsAttached(String vmName, final IMedium guestAdditionsDvdMedium) {
|
||||||
lockMachineAndApply(manager, Write, vmName,
|
lockMachineAndApply(manager, Write, vmName, new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE,
|
||||||
new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE, guestAdditionsDvdMedium, 1, 1, DeviceType.DVD));
|
guestAdditionsDvdMedium, 1, 1, DeviceType.DVD));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ensureMachineHasHardDiskAttached(String vmName, IMedium hardDisk) {
|
private void ensureMachineHasHardDiskAttached(String vmName, IMedium hardDisk) {
|
||||||
lockMachineAndApply(manager, Write, vmName,
|
lockMachineAndApply(manager, Write, vmName, new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE,
|
||||||
new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE, hardDisk, 0, 1, HardDisk));
|
hardDisk, 0, 1, HardDisk));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ensureMachineHasMemory(String vmName, final long memorySize) {
|
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) {
|
private void ensureMachineHasAttachedDistroMedium(String isoName, String workingDir, String controllerIDE) {
|
||||||
final String pathToIsoFile = checkFileExists(workingDir + "/" + isoName);
|
final String pathToIsoFile = checkFileExists(workingDir + "/" + isoName);
|
||||||
final IMedium distroMedium = manager.getVBox().openMedium(pathToIsoFile, DVD, ReadOnly, forceOverwrite);
|
final IMedium distroMedium = manager.getVBox().openMedium(pathToIsoFile, DVD, ReadOnly, forceOverwrite);
|
||||||
lockMachineAndApply(manager, Write, vmName,
|
lockMachineAndApply(
|
||||||
new AttachDistroMediumToMachine(
|
manager,
|
||||||
checkNotNull(controllerIDE, "controllerIDE"),
|
Write,
|
||||||
checkNotNull(distroMedium, "distroMedium")));
|
vmName,
|
||||||
|
new AttachDistroMediumToMachine(checkNotNull(controllerIDE, "controllerIDE"), checkNotNull(distroMedium,
|
||||||
|
"distroMedium")));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String checkFileExists(String filePath) {
|
public static String checkFileExists(String filePath) {
|
||||||
|
@ -213,7 +226,7 @@ public class IsoToIMachine implements Function<String, IMachine> {
|
||||||
|
|
||||||
public void ensureMachineHasIDEControllerNamed(String vmName, String controllerIDE) {
|
public void ensureMachineHasIDEControllerNamed(String vmName, String controllerIDE) {
|
||||||
lockMachineAndApply(manager, Write, checkNotNull(vmName, "vmName"),
|
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) {
|
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,
|
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>() {
|
return lockSessionOnMachineAndApply(manager, type, machineId, new Function<ISession, T>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -250,7 +263,7 @@ public class IsoToIMachine implements Function<String, IMachine> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T lockSessionOnMachineAndApply(VirtualBoxManager manager, LockType type, String machineId,
|
public static <T> T lockSessionOnMachineAndApply(VirtualBoxManager manager, LockType type, String machineId,
|
||||||
Function<ISession, T> function) {
|
Function<ISession, T> function) {
|
||||||
try {
|
try {
|
||||||
ISession session = manager.getSessionObject();
|
ISession session = manager.getSessionObject();
|
||||||
IMachine immutableMachine = manager.getVBox().findMachine(machineId);
|
IMachine immutableMachine = manager.getVBox().findMachine(machineId);
|
||||||
|
@ -262,17 +275,17 @@ public class IsoToIMachine implements Function<String, IMachine> {
|
||||||
}
|
}
|
||||||
} catch (VBoxException e) {
|
} catch (VBoxException e) {
|
||||||
throw new RuntimeException(String.format("error applying %s to %s with %s lock: %s", function, machineId,
|
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() {
|
private String defaultInstallSequence() {
|
||||||
return "<Esc><Esc><Enter> "
|
return "<Esc><Esc><Enter> "
|
||||||
+ "/install/vmlinuz noapic preseed/url=http://10.0.2.2:8080/src/test/resources/preseed.cfg "
|
+ "/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 + " "
|
+ "debian-installer=en_US auto locale=en_US kbd-chooser/method=us " + "hostname=" + vmName + " "
|
||||||
+ "fb=false debconf/frontend=noninteractive "
|
+ "fb=false debconf/frontend=noninteractive "
|
||||||
+ "keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false "
|
+ "keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false "
|
||||||
+ "initrd=/install/initrd.gz -- <Enter>";
|
+ "initrd=/install/initrd.gz -- <Enter>";
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendKeyboardSequence(String keyboardSequence) {
|
private void sendKeyboardSequence(String keyboardSequence) {
|
||||||
|
|
|
@ -19,34 +19,36 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions;
|
package org.jclouds.virtualbox.functions;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import static com.google.common.base.Throwables.propagate;
|
||||||
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 javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.lang.model.type.ExecutableType;
|
|
||||||
|
|
||||||
import static com.google.common.base.Throwables.propagate;
|
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||||
import static javax.xml.bind.DatatypeConverter.parseUnsignedInt;
|
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/>
|
* <p/>
|
||||||
* Note that launchMachine() may throw VBoxException with the following error codes:
|
* Note that launchMachine() may throw VBoxException with the following error
|
||||||
|
* codes:
|
||||||
* <p/>
|
* <p/>
|
||||||
* VBOX_E_UNEXPECTED: Virtual machine not registered.
|
* VBOX_E_UNEXPECTED: Virtual machine not registered. VBOX_E_INVALIDARG: Invalid
|
||||||
* VBOX_E_INVALIDARG: Invalid session type type.
|
* session type type. VBOX_E_OBJECT_NOT_FOUND: No machine matching machineId
|
||||||
* VBOX_E_OBJECT_NOT_FOUND: No machine matching machineId found.
|
* found. VBOX_E_INVALID_OBJECT_STATE: Session already open or being opened.
|
||||||
* VBOX_E_INVALID_OBJECT_STATE: Session already open or being opened.
|
* VBOX_E_IPRT_ERROR: Launching process for machine failed. VBOX_E_VM_ERROR:
|
||||||
* VBOX_E_IPRT_ERROR: Launching process for machine failed.
|
* Failed to assign machine to session.
|
||||||
* VBOX_E_VM_ERROR: Failed to assign machine to session.
|
*
|
||||||
*
|
|
||||||
* @author Mattias Holmqvist
|
* @author Mattias Holmqvist
|
||||||
*
|
*
|
||||||
* @see ErrorCode
|
* @see ErrorCode
|
||||||
|
@ -70,7 +72,8 @@ public class LaunchMachineIfNotAlreadyRunning implements Function<IMachine, Void
|
||||||
@Override
|
@Override
|
||||||
public Void apply(@Nullable IMachine machine) {
|
public Void apply(@Nullable IMachine machine) {
|
||||||
try {
|
try {
|
||||||
final IProgress progress = machine.launchVMProcess(manager.getSessionObject(), type.stringValue(), environment);
|
final IProgress progress = machine
|
||||||
|
.launchVMProcess(manager.getSessionObject(), type.stringValue(), environment);
|
||||||
progress.waitForCompletion(-1);
|
progress.waitForCompletion(-1);
|
||||||
Thread.sleep(5000);
|
Thread.sleep(5000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
@ -78,12 +81,12 @@ public class LaunchMachineIfNotAlreadyRunning implements Function<IMachine, Void
|
||||||
} catch (VBoxException e) {
|
} catch (VBoxException e) {
|
||||||
ErrorCode errorCode = ErrorCode.valueOf(e);
|
ErrorCode errorCode = ErrorCode.valueOf(e);
|
||||||
switch (errorCode) {
|
switch (errorCode) {
|
||||||
case VBOX_E_INVALID_OBJECT_STATE:
|
case VBOX_E_INVALID_OBJECT_STATE:
|
||||||
logger.warn(e, "Could not start machine. Got error code %s from launchMachine(). " +
|
logger.warn(e, "Could not start machine. Got error code %s from launchMachine(). "
|
||||||
"The machine might already be running.", errorCode);
|
+ "The machine might already be running.", errorCode);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
propagate(e);
|
propagate(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -58,8 +58,8 @@ public class FileDownloadFromURI implements Function<URI, File> {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public FileDownloadFromURI(final ComputeServiceContext context,
|
public FileDownloadFromURI(final ComputeServiceContext context,
|
||||||
@Named(VIRTUALBOX_WORKINGDIR) final String workingDir,
|
@Named(VIRTUALBOX_WORKINGDIR) final String workingDir,
|
||||||
@Named(VirtualBoxConstants.VIRTUALBOX_ISOFILE) final String isoFile) {
|
@Named(VirtualBoxConstants.VIRTUALBOX_ISOFILE) final String isoFile) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.workingDir = workingDir;
|
this.workingDir = workingDir;
|
||||||
this.isoFile = isoFile;
|
this.isoFile = isoFile;
|
||||||
|
|
|
@ -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
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* 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
|
* KIND, either express or implied. See the License for the
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* 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
|
* @author Andrea Turli
|
||||||
*/
|
*/
|
||||||
|
@ -53,12 +56,12 @@ public class ImageFromYamlStream implements Function<InputStream, Cache<String,
|
||||||
public static class Config {
|
public static class Config {
|
||||||
public List<YamlImage> images;
|
public List<YamlImage> images;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object construct(String data) {
|
private Object construct(String data) {
|
||||||
Yaml yaml = new Yaml();
|
Yaml yaml = new Yaml();
|
||||||
return yaml.load(data);
|
return yaml.load(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Cache<String, Image> apply(InputStream source) {
|
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");
|
checkState(config.images != null, "missing images: collection");
|
||||||
|
|
||||||
Map<String, Image> backingMap = Maps.uniqueIndex(Iterables.transform(config.images, YamlImage.toImage),
|
Map<String, Image> backingMap = Maps.uniqueIndex(Iterables.transform(config.images, YamlImage.toImage),
|
||||||
new Function<Image, String>() {
|
new Function<Image, String>() {
|
||||||
public String apply(Image image) {
|
public String apply(Image image) {
|
||||||
return image.getId();
|
return image.getId();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Cache<String, Image> cache = CacheBuilder.newBuilder().build(CacheLoader.from(Functions.forMap(backingMap)));
|
Cache<String, Image> cache = CacheBuilder.newBuilder().build(CacheLoader.from(Functions.forMap(backingMap)));
|
||||||
for (String node : backingMap.keySet())
|
for (String node : backingMap.keySet())
|
||||||
cache.getUnchecked(node);
|
cache.getUnchecked(node);
|
||||||
return cache;
|
return cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -43,65 +43,65 @@ import com.google.inject.Singleton;
|
||||||
*/
|
*/
|
||||||
public class StartJettyIfNotAlreadyRunning implements Function<String, Server> {
|
public class StartJettyIfNotAlreadyRunning implements Function<String, Server> {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
private final int port;
|
private final int port;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public StartJettyIfNotAlreadyRunning(
|
public StartJettyIfNotAlreadyRunning(@Named(VirtualBoxConstants.VIRTUALBOX_JETTY_PORT) final String port) {
|
||||||
@Named(VirtualBoxConstants.VIRTUALBOX_JETTY_PORT) final String port) {
|
this.port = Integer.parseInt(port);
|
||||||
this.port = Integer.parseInt(port);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Server apply(@Nullable String baseResource) {
|
public Server apply(@Nullable String baseResource) {
|
||||||
final Server server = ServerJetty.getInstance().getServer();
|
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)
|
||||||
ResourceHandler resource_handler = new ResourceHandler();
|
&& !new InetSocketAddressConnect().apply(new IPSocket("localhost", port))) {
|
||||||
resource_handler.setDirectoriesListed(true);
|
ResourceHandler resource_handler = new ResourceHandler();
|
||||||
resource_handler.setWelcomeFiles(new String[] { "index.html" });
|
resource_handler.setDirectoriesListed(true);
|
||||||
|
resource_handler.setWelcomeFiles(new String[] { "index.html" });
|
||||||
|
|
||||||
resource_handler.setResourceBase(baseResource);
|
resource_handler.setResourceBase(baseResource);
|
||||||
logger.info("serving " + resource_handler.getBaseResource());
|
logger.info("serving " + resource_handler.getBaseResource());
|
||||||
|
|
||||||
HandlerList handlers = new HandlerList();
|
HandlerList handlers = new HandlerList();
|
||||||
handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() });
|
handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() });
|
||||||
server.setHandler(handlers);
|
server.setHandler(handlers);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
server.start();
|
server.start();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error(e, "Server jetty could not be started at this %s", baseResource);
|
logger.error(e, "Server jetty could not be started at this %s", baseResource);
|
||||||
}
|
}
|
||||||
return server;
|
return server;
|
||||||
} else {
|
} else {
|
||||||
logger.debug("Server jetty serving %s already running. Skipping start", baseResource);
|
logger.debug("Server jetty serving %s already running. Skipping start", baseResource);
|
||||||
return server;
|
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() {
|
@Singleton
|
||||||
this.server = new Server(Integer.parseInt(port));
|
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() {
|
private ServerJetty() {
|
||||||
if (instance == null)
|
this.server = new Server(Integer.parseInt(port));
|
||||||
instance = new ServerJetty();
|
}
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Server getServer() {
|
public static ServerJetty getInstance() {
|
||||||
return server;
|
if (instance == null)
|
||||||
}
|
instance = new ServerJetty();
|
||||||
}
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Server getServer() {
|
||||||
|
return server;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,14 @@
|
||||||
package org.jclouds.virtualbox.functions.admin;
|
package org.jclouds.virtualbox.functions.admin;
|
||||||
|
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot;
|
||||||
import com.google.common.cache.Cache;
|
|
||||||
|
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.ComputeServiceContext;
|
||||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||||
import org.jclouds.domain.Credentials;
|
import org.jclouds.domain.Credentials;
|
||||||
|
@ -30,14 +36,7 @@ import org.jclouds.net.IPSocket;
|
||||||
import org.jclouds.predicates.InetSocketAddressConnect;
|
import org.jclouds.predicates.InetSocketAddressConnect;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_1.VirtualBoxManager;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import com.google.common.base.Function;
|
||||||
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;
|
|
||||||
|
|
||||||
public class StartVBoxIfNotAlreadyRunning implements Function<URI, VirtualBoxManager> {
|
public class StartVBoxIfNotAlreadyRunning implements Function<URI, VirtualBoxManager> {
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jclouds.virtualbox.settings;
|
package org.jclouds.virtualbox.settings;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -24,138 +25,139 @@ import java.util.Map;
|
||||||
|
|
||||||
public class KeyboardScancodes {
|
public class KeyboardScancodes {
|
||||||
|
|
||||||
// http://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html
|
// 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();
|
|
||||||
|
|
||||||
private static Map<String, String> createMap() {
|
public static final Map<String, String> NORMAL_KEYBOARD_BUTTON_MAP = createMap();
|
||||||
Map<String, String> alphaToHex = new HashMap<String, String>();
|
public static final Map<String, String> SPECIAL_KEYBOARD_BUTTON_MAP = createSpecialMap();
|
||||||
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("Q", "2a 10 aa");
|
private static Map<String, String> createMap() {
|
||||||
alphaToHex.put("W", "2a 11 aa");
|
Map<String, String> alphaToHex = new HashMap<String, String>();
|
||||||
alphaToHex.put("E", "2a 12 aa");
|
alphaToHex.put("1", "02 82");
|
||||||
alphaToHex.put("R", "2a 13 aa");
|
alphaToHex.put("2", "03 83");
|
||||||
alphaToHex.put("T", "2a 14 aa");
|
alphaToHex.put("3", "04 84");
|
||||||
alphaToHex.put("Y", "2a 15 aa");
|
alphaToHex.put("4", "05 85");
|
||||||
alphaToHex.put("U", "2a 16 aa");
|
alphaToHex.put("5", "06 86");
|
||||||
alphaToHex.put("I", "2a 17 aa");
|
alphaToHex.put("6", "07 87");
|
||||||
alphaToHex.put("O", "2a 18 aa");
|
alphaToHex.put("7", "08 88");
|
||||||
alphaToHex.put("P", "2a 19 aa");
|
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("Q", "2a 10 aa");
|
||||||
alphaToHex.put("s", "1f 9f");
|
alphaToHex.put("W", "2a 11 aa");
|
||||||
alphaToHex.put("d", "20 a0");
|
alphaToHex.put("E", "2a 12 aa");
|
||||||
alphaToHex.put("f", "21 a1");
|
alphaToHex.put("R", "2a 13 aa");
|
||||||
alphaToHex.put("g", "22 a2");
|
alphaToHex.put("T", "2a 14 aa");
|
||||||
alphaToHex.put("h", "23 a3");
|
alphaToHex.put("Y", "2a 15 aa");
|
||||||
alphaToHex.put("j", "24 a4");
|
alphaToHex.put("U", "2a 16 aa");
|
||||||
alphaToHex.put("k", "25 a5");
|
alphaToHex.put("I", "2a 17 aa");
|
||||||
alphaToHex.put("l", "26 a6");
|
alphaToHex.put("O", "2a 18 aa");
|
||||||
|
alphaToHex.put("P", "2a 19 aa");
|
||||||
|
|
||||||
alphaToHex.put("A", "2a 1e aa 9e");
|
alphaToHex.put("a", "1e 9e");
|
||||||
alphaToHex.put("S", "2a 1f aa 9f");
|
alphaToHex.put("s", "1f 9f");
|
||||||
alphaToHex.put("D", "2a 20 aa a0");
|
alphaToHex.put("d", "20 a0");
|
||||||
alphaToHex.put("F", "2a 21 aa a1");
|
alphaToHex.put("f", "21 a1");
|
||||||
alphaToHex.put("G", "2a 22 aa a2");
|
alphaToHex.put("g", "22 a2");
|
||||||
alphaToHex.put("H", "2a 23 aa a3");
|
alphaToHex.put("h", "23 a3");
|
||||||
alphaToHex.put("J", "2a 24 aa a4");
|
alphaToHex.put("j", "24 a4");
|
||||||
alphaToHex.put("K", "2a 25 aa a5");
|
alphaToHex.put("k", "25 a5");
|
||||||
alphaToHex.put("L", "2a 26 aa a6");
|
alphaToHex.put("l", "26 a6");
|
||||||
|
|
||||||
alphaToHex.put(");", "27 a7");
|
alphaToHex.put("A", "2a 1e aa 9e");
|
||||||
alphaToHex.put("\"", "2a 28 aa a8");
|
alphaToHex.put("S", "2a 1f aa 9f");
|
||||||
alphaToHex.put("\"", "28 a8");
|
alphaToHex.put("D", "2a 20 aa a0");
|
||||||
alphaToHex.put("\\", "2b ab");
|
alphaToHex.put("F", "2a 21 aa a1");
|
||||||
alphaToHex.put("|", "2a 2b aa 8b");
|
alphaToHex.put("G", "2a 22 aa a2");
|
||||||
alphaToHex.put("[", "1a 9a");
|
alphaToHex.put("H", "2a 23 aa a3");
|
||||||
alphaToHex.put("", "1b 9b");
|
alphaToHex.put("J", "2a 24 aa a4");
|
||||||
alphaToHex.put("<", "2a 33 aa b3");
|
alphaToHex.put("K", "2a 25 aa a5");
|
||||||
alphaToHex.put(">", "2a 34 aa b4");
|
alphaToHex.put("L", "2a 26 aa a6");
|
||||||
alphaToHex.put("$", "2a 05 aa 85");
|
|
||||||
alphaToHex.put("+", "2a 0d aa 8d");
|
|
||||||
|
|
||||||
alphaToHex.put("z", "2c ac");
|
alphaToHex.put(");", "27 a7");
|
||||||
alphaToHex.put("x", "2d ad");
|
alphaToHex.put("\"", "2a 28 aa a8");
|
||||||
alphaToHex.put("c", "2e ae");
|
alphaToHex.put("\"", "28 a8");
|
||||||
alphaToHex.put("v", "2f af");
|
alphaToHex.put("\\", "2b ab");
|
||||||
alphaToHex.put("b", "30 b0");
|
alphaToHex.put("|", "2a 2b aa 8b");
|
||||||
alphaToHex.put("n", "31 b1");
|
alphaToHex.put("[", "1a 9a");
|
||||||
alphaToHex.put("m", "32 b2");
|
alphaToHex.put("", "1b 9b");
|
||||||
alphaToHex.put("Z", "2a 2c aa ac");
|
alphaToHex.put("<", "2a 33 aa b3");
|
||||||
alphaToHex.put("X", "2a 2d aa ad");
|
alphaToHex.put(">", "2a 34 aa b4");
|
||||||
alphaToHex.put("C", "2a 2e aa ae");
|
alphaToHex.put("$", "2a 05 aa 85");
|
||||||
alphaToHex.put("V", "2a 2f aa af");
|
alphaToHex.put("+", "2a 0d aa 8d");
|
||||||
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("z", "2c ac");
|
||||||
alphaToHex.put(".", "34 b4");
|
alphaToHex.put("x", "2d ad");
|
||||||
alphaToHex.put("/", "35 b5");
|
alphaToHex.put("c", "2e ae");
|
||||||
alphaToHex.put(":", "2a 27 aa a7");
|
alphaToHex.put("v", "2f af");
|
||||||
alphaToHex.put("%", "2a 06 aa 86");
|
alphaToHex.put("b", "30 b0");
|
||||||
alphaToHex.put("_", "2a 0c aa 8c");
|
alphaToHex.put("n", "31 b1");
|
||||||
alphaToHex.put("&", "2a 08 aa 88");
|
alphaToHex.put("m", "32 b2");
|
||||||
alphaToHex.put("(", "2a 0a aa 8a");
|
alphaToHex.put("Z", "2a 2c aa ac");
|
||||||
alphaToHex.put(")", "2a 0b aa 8b");
|
alphaToHex.put("X", "2a 2d aa ad");
|
||||||
return Collections.unmodifiableMap(alphaToHex);
|
alphaToHex.put("C", "2a 2e aa ae");
|
||||||
}
|
alphaToHex.put("V", "2a 2f aa af");
|
||||||
private static Map<String, String> createSpecialMap() {
|
alphaToHex.put("B", "2a 30 aa b0");
|
||||||
Map<String, String> special = new HashMap<String, String>();
|
alphaToHex.put("N", "2a 31 aa b1");
|
||||||
special.put("<Enter>", "1c 9c");
|
alphaToHex.put("M", "2a 32 aa b2");
|
||||||
special.put("<Backspace>", "0e 8e");
|
|
||||||
special.put("<Spacebar>", "39 b9");
|
alphaToHex.put(",", "33 b3");
|
||||||
special.put("<Return>", "1c 9c");
|
alphaToHex.put(".", "34 b4");
|
||||||
special.put("<Esc>", "01 81");
|
alphaToHex.put("/", "35 b5");
|
||||||
special.put("<Tab>", "0f 8f");
|
alphaToHex.put(":", "2a 27 aa a7");
|
||||||
special.put("<KillX>", "1d 38 0e");
|
alphaToHex.put("%", "2a 06 aa 86");
|
||||||
special.put("<Wait>", "wait");
|
alphaToHex.put("_", "2a 0c aa 8c");
|
||||||
|
alphaToHex.put("&", "2a 08 aa 88");
|
||||||
special.put("<Up>", "48 c8");
|
alphaToHex.put("(", "2a 0a aa 8a");
|
||||||
special.put("<Down>", "50 d0");
|
alphaToHex.put(")", "2a 0b aa 8b");
|
||||||
special.put("<PageUp>", "49 c9");
|
return Collections.unmodifiableMap(alphaToHex);
|
||||||
special.put("<PageDown>", "51 d1");
|
}
|
||||||
special.put("<End>", "4f cf");
|
|
||||||
special.put("<Insert>", "52 d2");
|
private static Map<String, String> createSpecialMap() {
|
||||||
special.put("<Delete>", "53 d3");
|
Map<String, String> special = new HashMap<String, String>();
|
||||||
special.put("<Left>", "4b cb");
|
special.put("<Enter>", "1c 9c");
|
||||||
special.put("<Right>", "4d cd");
|
special.put("<Backspace>", "0e 8e");
|
||||||
special.put("<Home>", "47 c7");
|
special.put("<Spacebar>", "39 b9");
|
||||||
|
special.put("<Return>", "1c 9c");
|
||||||
special.put("<F1>", "3b");
|
special.put("<Esc>", "01 81");
|
||||||
special.put("<F2>", "3c");
|
special.put("<Tab>", "0f 8f");
|
||||||
special.put("<F3>", "3d");
|
special.put("<KillX>", "1d 38 0e");
|
||||||
special.put("<F4>", "3e");
|
special.put("<Wait>", "wait");
|
||||||
special.put("<F5>", "3f");
|
|
||||||
special.put("<F6>", "40");
|
special.put("<Up>", "48 c8");
|
||||||
special.put("<F7>", "41");
|
special.put("<Down>", "50 d0");
|
||||||
special.put("<F8>", "42");
|
special.put("<PageUp>", "49 c9");
|
||||||
special.put("<F9>", "43");
|
special.put("<PageDown>", "51 d1");
|
||||||
special.put("<F10>", "44");
|
special.put("<End>", "4f cf");
|
||||||
return Collections.unmodifiableMap(special);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,11 +19,12 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.compute;
|
package org.jclouds.virtualbox.compute;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import static org.testng.Assert.assertEquals;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import static org.testng.Assert.assertFalse;
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
import com.google.common.collect.Maps;
|
import java.net.URI;
|
||||||
import com.google.inject.Guice;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.jclouds.compute.config.BaseComputeServiceContextModule;
|
import org.jclouds.compute.config.BaseComputeServiceContextModule;
|
||||||
import org.jclouds.compute.domain.ExecResponse;
|
import org.jclouds.compute.domain.ExecResponse;
|
||||||
import org.jclouds.compute.domain.Image;
|
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.IMachine;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_1.VirtualBoxManager;
|
||||||
|
|
||||||
import java.net.URI;
|
import com.google.common.base.Function;
|
||||||
import java.util.Map;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
import static org.testng.Assert.assertEquals;
|
import com.google.common.collect.Maps;
|
||||||
import static org.testng.Assert.assertFalse;
|
import com.google.inject.Guice;
|
||||||
|
|
||||||
@Test(groups = "live", singleThreaded = true, testName = "VirtualBoxComputeServiceAdapterLiveTest")
|
@Test(groups = "live", singleThreaded = true, testName = "VirtualBoxComputeServiceAdapterLiveTest")
|
||||||
public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClientLiveTest {
|
public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClientLiveTest {
|
||||||
|
@ -57,15 +58,15 @@ public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClien
|
||||||
private IMachine machine;
|
private IMachine machine;
|
||||||
private final Map<OsFamily, Map<String, String>> osVersionMap = new BaseComputeServiceContextModule() {
|
private final Map<OsFamily, Map<String, String>> osVersionMap = new BaseComputeServiceContextModule() {
|
||||||
}.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule())
|
}.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule())
|
||||||
.getInstance(Json.class));
|
.getInstance(Json.class));
|
||||||
|
|
||||||
@BeforeGroups(groups = {"live"})
|
@BeforeGroups(groups = { "live" })
|
||||||
public void setupClient() {
|
public void setupClient() {
|
||||||
super.setupClient();
|
super.setupClient();
|
||||||
final VirtualBoxManager manager = getManager();
|
final VirtualBoxManager manager = getManager();
|
||||||
Function<IMachine, Image> iMachineToImage = new IMachineToImage(manager, osVersionMap);
|
Function<IMachine, Image> iMachineToImage = new IMachineToImage(manager, osVersionMap);
|
||||||
adapter = new VirtualBoxComputeServiceAdapter(manager,
|
adapter = new VirtualBoxComputeServiceAdapter(manager, new JustProvider(provider, URI.create(endpoint),
|
||||||
new JustProvider(provider, URI.create(endpoint), ImmutableSet.<String>of()), iMachineToImage);
|
ImmutableSet.<String> of()), iMachineToImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected VirtualBoxManager getManager() {
|
protected VirtualBoxManager getManager() {
|
||||||
|
@ -89,15 +90,16 @@ public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClien
|
||||||
// check other things, like cpu correct, mem correct, image/os is correct
|
// check other things, like cpu correct, mem correct, image/os is correct
|
||||||
// (as possible)
|
// (as possible)
|
||||||
assert credentialStore.containsKey("node#" + machine.getId()) : "credentials to log into machine not found "
|
assert credentialStore.containsKey("node#" + machine.getId()) : "credentials to log into machine not found "
|
||||||
+ machine;
|
+ machine;
|
||||||
// TODO: what's the IP address?
|
// 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()));
|
doConnectViaSsh(machine, credentialStore.get("node#" + machine.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void doConnectViaSsh(IMachine machine, Credentials creds) {
|
protected void doConnectViaSsh(IMachine machine, Credentials creds) {
|
||||||
SshClient ssh = context.utils().sshFactory()
|
SshClient ssh = context.utils().sshFactory().create(new IPSocket("//TODO", 22), creds);
|
||||||
.create(new IPSocket("//TODO", 22), creds);
|
|
||||||
try {
|
try {
|
||||||
ssh.connect();
|
ssh.connect();
|
||||||
ExecResponse hello = ssh.exec("echo hello");
|
ExecResponse hello = ssh.exec("echo hello");
|
||||||
|
|
|
@ -19,9 +19,17 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.compute;
|
package org.jclouds.virtualbox.compute;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import static org.easymock.EasyMock.expect;
|
||||||
import com.google.common.collect.Iterators;
|
import static org.easymock.classextension.EasyMock.createNiceMock;
|
||||||
import com.google.inject.Guice;
|
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.easymock.EasyMock;
|
||||||
import org.jclouds.compute.config.BaseComputeServiceContextModule;
|
import org.jclouds.compute.config.BaseComputeServiceContextModule;
|
||||||
import org.jclouds.compute.domain.Image;
|
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.IVirtualBox;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_1.VirtualBoxManager;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import com.google.common.base.Function;
|
||||||
import java.util.Iterator;
|
import com.google.common.collect.Iterators;
|
||||||
import java.util.List;
|
import com.google.inject.Guice;
|
||||||
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;
|
|
||||||
|
|
||||||
@Test(groups = "unit")
|
@Test(groups = "unit")
|
||||||
public class VirtualBoxComputeServiceAdapterTest {
|
public class VirtualBoxComputeServiceAdapterTest {
|
||||||
|
|
||||||
Map<OsFamily, Map<String, String>> osMap = new BaseComputeServiceContextModule() {
|
Map<OsFamily, Map<String, String>> osMap = new BaseComputeServiceContextModule() {
|
||||||
}.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule())
|
}.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule())
|
||||||
.getInstance(Json.class));
|
.getInstance(Json.class));
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testListImages() throws Exception {
|
public void testListImages() throws Exception {
|
||||||
|
@ -76,14 +77,15 @@ public class VirtualBoxComputeServiceAdapterTest {
|
||||||
|
|
||||||
expect(manager.getVBox()).andReturn(vBox).anyTimes();
|
expect(manager.getVBox()).andReturn(vBox).anyTimes();
|
||||||
expect(vBox.getMachines()).andReturn(machines).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.getDescription()).andReturn("Ubuntu 10.04").anyTimes();
|
||||||
expect(osType.getIs64Bit()).andReturn(true).anyTimes();
|
expect(osType.getIs64Bit()).andReturn(true).anyTimes();
|
||||||
|
|
||||||
replay(manager, justProvider, vBox, clonedMachine, imageMachine, osType);
|
replay(manager, justProvider, vBox, clonedMachine, imageMachine, osType);
|
||||||
|
|
||||||
Function<IMachine, Image> iMachineToImage = new IMachineToImage(manager, osMap);
|
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();
|
Iterator<Image> iterator = adapter.listImages().iterator();
|
||||||
Image image = Iterators.getOnlyElement(iterator);
|
Image image = Iterators.getOnlyElement(iterator);
|
||||||
|
|
|
@ -27,7 +27,7 @@ import org.testng.annotations.Test;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = "live", testName = "VirtualBoxExperimentLiveTest")
|
@Test(groups = "live", testName = "VirtualBoxExperimentLiveTest")
|
||||||
public class VirtualBoxExperimentLiveTest extends BaseVirtualBoxClientLiveTest{
|
public class VirtualBoxExperimentLiveTest extends BaseVirtualBoxClientLiveTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAndExperiment() {
|
public void testAndExperiment() {
|
||||||
|
|
|
@ -34,7 +34,6 @@ import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Predicates;
|
import com.google.common.base.Predicates;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Andrea Turli
|
* @author Andrea Turli
|
||||||
|
@ -43,40 +42,40 @@ import com.google.common.collect.ImmutableSet;
|
||||||
@Test(groups = "live", testName = "VirtualBoxTemplateBuilderLiveTest")
|
@Test(groups = "live", testName = "VirtualBoxTemplateBuilderLiveTest")
|
||||||
public class VirtualBoxTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
|
public class VirtualBoxTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
|
||||||
|
|
||||||
public VirtualBoxTemplateBuilderLiveTest() {
|
public VirtualBoxTemplateBuilderLiveTest() {
|
||||||
provider = "virtualbox";
|
provider = "virtualbox";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Predicate<OsFamilyVersion64Bit> defineUnsupportedOperatingSystems() {
|
protected Predicate<OsFamilyVersion64Bit> defineUnsupportedOperatingSystems() {
|
||||||
return Predicates.not(new Predicate<OsFamilyVersion64Bit>() {
|
return Predicates.not(new Predicate<OsFamilyVersion64Bit>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(OsFamilyVersion64Bit input) {
|
public boolean apply(OsFamilyVersion64Bit input) {
|
||||||
switch (input.family) {
|
switch (input.family) {
|
||||||
case UBUNTU:
|
case UBUNTU:
|
||||||
return input.version.equals("11.04") && !input.is64Bit;
|
return input.version.equals("11.04") && !input.is64Bit;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTemplateBuilder() {
|
public void testTemplateBuilder() {
|
||||||
System.out.println(this.context.getComputeService().listImages());
|
System.out.println(this.context.getComputeService().listImages());
|
||||||
Template defaultTemplate = this.context.getComputeService().templateBuilder().build();
|
Template defaultTemplate = this.context.getComputeService().templateBuilder().build();
|
||||||
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), false);
|
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), false);
|
||||||
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "10.04");
|
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "10.04");
|
||||||
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
|
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
|
||||||
assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
|
assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Set<String> getIso3166Codes() {
|
protected Set<String> getIso3166Codes() {
|
||||||
return ImmutableSet.<String> of();
|
return ImmutableSet.<String> of();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,8 @@
|
||||||
/**
|
/**
|
||||||
*
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
|
* contributor license agreements. See the NOTICE file
|
||||||
*
|
|
||||||
* ====================================================================
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
||||||
* or more contributor license agreements. See the NOTICE file
|
|
||||||
* distributed with this work for additional information
|
* 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
|
* to you under the Apache License, Version 2.0 (the
|
||||||
* "License"); you may not use this file except in compliance
|
* "License"); you may not use this file except in compliance
|
||||||
* with the License. You may obtain a copy of the License at
|
* 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
|
* KIND, either express or implied. See the License for the
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
* ====================================================================
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jclouds.virtualbox.experiment;
|
package org.jclouds.virtualbox.experiment;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
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.domain.Credentials;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.virtualbox.config.VirtualBoxConstants;
|
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.StartJettyIfNotAlreadyRunning;
|
||||||
|
import org.jclouds.virtualbox.functions.admin.StartVBoxIfNotAlreadyRunning;
|
||||||
import org.testng.annotations.AfterSuite;
|
import org.testng.annotations.AfterSuite;
|
||||||
import org.testng.annotations.BeforeSuite;
|
import org.testng.annotations.BeforeSuite;
|
||||||
|
|
||||||
|
@ -72,7 +68,7 @@ public class SetupVirtualBoxForLiveTest {
|
||||||
private String vboxVersionName;
|
private String vboxVersionName;
|
||||||
private String basebaseResource;
|
private String basebaseResource;
|
||||||
private String port;
|
private String port;
|
||||||
|
|
||||||
private String vboxWebServerCredential;
|
private String vboxWebServerCredential;
|
||||||
private String vboxWebServerIdentity;
|
private String vboxWebServerIdentity;
|
||||||
|
|
||||||
|
@ -88,18 +84,18 @@ public class SetupVirtualBoxForLiveTest {
|
||||||
|
|
||||||
public void setupConfigurationProperties() {
|
public void setupConfigurationProperties() {
|
||||||
workingDir = System.getProperty("user.home") + File.separator
|
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())
|
if (new File(workingDir).mkdir())
|
||||||
;
|
;
|
||||||
gaIsoName = System.getProperty("test." + provider + ".gaIsoName", "VBoxGuestAdditions_" + majorVersion + ".iso");
|
gaIsoName = System.getProperty("test." + provider + ".gaIsoName", "VBoxGuestAdditions_" + majorVersion + ".iso");
|
||||||
gaIsoUrl = URI.create(System.getProperty("test." + provider + ".gaIsoUrl",
|
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");
|
distroIsoName = System.getProperty("test." + provider + ".distroIsoName", "ubuntu-11.04-server-i386.iso");
|
||||||
distroIsoUrl = URI.create(System.getProperty("test." + provider + ".distroIsoUrl",
|
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",
|
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");
|
vboxVersionName = System.getProperty("test" + provider + ".vboxVersionName", "VirtualBox-4.1.2-73507-OSX.dmg");
|
||||||
basebaseResource = System.getProperty(VirtualBoxConstants.VIRTUALBOX_JETTY_BASE_RESOURCE, ".");
|
basebaseResource = System.getProperty(VirtualBoxConstants.VIRTUALBOX_JETTY_BASE_RESOURCE, ".");
|
||||||
port = System.getProperty(VirtualBoxConstants.VIRTUALBOX_JETTY_PORT, "8080");
|
port = System.getProperty(VirtualBoxConstants.VIRTUALBOX_JETTY_PORT, "8080");
|
||||||
|
@ -120,7 +116,7 @@ public class SetupVirtualBoxForLiveTest {
|
||||||
new StartVBoxIfNotAlreadyRunning(context, hostId, new Credentials(vboxWebServerIdentity, vboxWebServerCredential));
|
new StartVBoxIfNotAlreadyRunning(context, hostId, new Credentials(vboxWebServerIdentity, vboxWebServerCredential));
|
||||||
new StartJettyIfNotAlreadyRunning(port).apply(basebaseResource);
|
new StartJettyIfNotAlreadyRunning(port).apply(basebaseResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterSuite
|
@AfterSuite
|
||||||
public void stopVboxWebServer() throws IOException {
|
public void stopVboxWebServer() throws IOException {
|
||||||
runScriptOnNode(hostId, "pidof vboxwebsrv | xargs kill");
|
runScriptOnNode(hostId, "pidof vboxwebsrv | xargs kill");
|
||||||
|
@ -133,29 +129,29 @@ public class SetupVirtualBoxForLiveTest {
|
||||||
downloadFileUnlessPresent(vboxDmg, workingDir, vboxVersionName);
|
downloadFileUnlessPresent(vboxDmg, workingDir, vboxVersionName);
|
||||||
runScriptOnNode(hostId, "hdiutil attach " + workingDir + "/" + vboxVersionName);
|
runScriptOnNode(hostId, "hdiutil attach " + workingDir + "/" + vboxVersionName);
|
||||||
runScriptOnNode(hostId,
|
runScriptOnNode(hostId,
|
||||||
"installer -pkg /Volumes/VirtualBox/VirtualBox.mpkg -target /Volumes/Macintosh\\ HD");
|
"installer -pkg /Volumes/VirtualBox/VirtualBox.mpkg -target /Volumes/Macintosh\\ HD");
|
||||||
} else {
|
} else {
|
||||||
// TODO other platforms
|
// TODO other platforms
|
||||||
runScriptOnNode(hostId, "cat > /etc/apt/sources.list.d/TODO");
|
runScriptOnNode(hostId, "cat > /etc/apt/sources.list.d/TODO");
|
||||||
runScriptOnNode(hostId,
|
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 update");
|
||||||
runScriptOnNode(hostId, "apt-get --yes install virtualbox-4.1");
|
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");
|
logger().debug("checking virtualbox version");
|
||||||
assertEquals(runScriptOnNode(hostId, "VBoxManage -version").getOutput().trim(), apiVersion);
|
assertEquals(runScriptOnNode(hostId, "VBoxManage -version").getOutput().trim(), apiVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isOSX(String id) {
|
public boolean isOSX(String id) {
|
||||||
return context.getComputeService().getNodeMetadata(hostId).getOperatingSystem().getDescription().equals(
|
return context.getComputeService().getNodeMetadata(hostId).getOperatingSystem().getDescription()
|
||||||
"Mac OS X");
|
.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);
|
File iso = new File(destinationDir, filename);
|
||||||
|
|
||||||
|
|
|
@ -18,10 +18,11 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.virtualbox.experiment;
|
package org.jclouds.virtualbox.experiment;
|
||||||
|
|
||||||
import com.google.common.cache.Cache;
|
import java.io.IOException;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import java.net.URI;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import java.net.URISyntaxException;
|
||||||
import com.google.inject.Module;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.jclouds.byon.Node;
|
import org.jclouds.byon.Node;
|
||||||
import org.jclouds.byon.config.CacheNodeStoreModule;
|
import org.jclouds.byon.config.CacheNodeStoreModule;
|
||||||
import org.jclouds.compute.ComputeServiceContext;
|
import org.jclouds.compute.ComputeServiceContext;
|
||||||
|
@ -31,75 +32,48 @@ import org.jclouds.domain.Credentials;
|
||||||
import org.jclouds.encryption.bouncycastle.config.BouncyCastleCryptoModule;
|
import org.jclouds.encryption.bouncycastle.config.BouncyCastleCryptoModule;
|
||||||
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
|
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
|
||||||
import org.jclouds.sshj.config.SshjSshClientModule;
|
import org.jclouds.sshj.config.SshjSshClientModule;
|
||||||
import org.jclouds.virtualbox.config.VirtualBoxConstants;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import com.google.common.cache.Cache;
|
||||||
import java.net.URI;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import java.net.URISyntaxException;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import java.util.Map;
|
import com.google.inject.Module;
|
||||||
|
|
||||||
public class TestUtils {
|
public class TestUtils {
|
||||||
|
|
||||||
public static ComputeServiceContext computeServiceForLocalhostAndGuest() throws IOException {
|
public static ComputeServiceContext computeServiceForLocalhostAndGuest() throws IOException {
|
||||||
|
|
||||||
Node host = Node.builder().id("host")
|
Node host = Node.builder().id("host").name("host installing virtualbox").hostname("localhost")
|
||||||
.name("host installing virtualbox")
|
.osFamily(OsFamily.LINUX.toString()).osDescription(System.getProperty("os.name"))
|
||||||
.hostname("localhost")
|
.osVersion(System.getProperty("os.version")).group("ssh").username(System.getProperty("user.name"))
|
||||||
.osFamily(OsFamily.LINUX.toString())
|
.credentialUrl(privateKeyFile()).build();
|
||||||
.osDescription(System.getProperty("os.name"))
|
Node guest = Node.builder().id("guest").name("new guest").hostname("localhost").loginPort(2222)
|
||||||
.osVersion(System.getProperty("os.version"))
|
.osFamily(OsFamily.UBUNTU.toString()).osDescription("ubuntu/11.04").osVersion(System.getProperty("11.04"))
|
||||||
.group("ssh")
|
.group("guest").username("toor").sudoPassword("password").credential("password").build();
|
||||||
.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)
|
||||||
return new ComputeServiceContextFactory().createContext("byon", "foo", "bar", ImmutableSet.<Module>of(
|
.build();
|
||||||
new SshjSshClientModule(), new SLF4JLoggingModule(), new BouncyCastleCryptoModule(), new CacheNodeStoreModule(nodeMap)));
|
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,
|
public static ComputeServiceContext computeServiceForLocalhostAndGuest(String hostId, String hostname,
|
||||||
Credentials guestLogin) throws IOException {
|
String guestId, String guestHostname, Credentials guestLogin) throws IOException {
|
||||||
|
|
||||||
Node host = Node.builder().id(hostId)
|
Node host = Node.builder().id(hostId).name("host installing virtualbox").hostname(hostname)
|
||||||
.name("host installing virtualbox")
|
.osFamily(OsFamily.LINUX.toString()).osDescription(System.getProperty("os.name"))
|
||||||
.hostname(hostname)
|
.osVersion(System.getProperty("os.version")).group("ssh").username(System.getProperty("user.name"))
|
||||||
.osFamily(OsFamily.LINUX.toString())
|
.credentialUrl(privateKeyFile()).build();
|
||||||
.osDescription(System.getProperty("os.name"))
|
Node guest = Node.builder().id(guestId).name("new guest").hostname(guestHostname).loginPort(2222)
|
||||||
.osVersion(System.getProperty("os.version"))
|
.osFamily(OsFamily.UBUNTU.toString()).osDescription("ubuntu/11.04").osVersion(System.getProperty("11.04"))
|
||||||
.group("ssh")
|
.group("jclouds-linux-image").username(guestLogin.identity).sudoPassword(guestLogin.credential)
|
||||||
.username(System.getProperty("user.name"))
|
.credential(guestLogin.credential).build();
|
||||||
.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)
|
||||||
final Map<String, Node> nodeMap = ImmutableMap.<String, Node>builder().put(hostId, host).put(guestId, guest).build();
|
.build();
|
||||||
return new ComputeServiceContextFactory().createContext("byon", "foo", "bar", ImmutableSet.<Module>of(
|
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() {
|
private static URI privateKeyFile() {
|
||||||
|
@ -112,7 +86,8 @@ public class TestUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ComputeServiceContext computeServiceForVirtualBox(Cache<String, Node> cache) {
|
public static ComputeServiceContext computeServiceForVirtualBox(Cache<String, Node> cache) {
|
||||||
return new ComputeServiceContextFactory().createContext("byon", "foo", "bar", ImmutableSet.<Module>of(
|
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)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/**
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -19,12 +19,16 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions;
|
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.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_1.IMachine;
|
||||||
import org.virtualbox_4_1.VBoxException;
|
import org.virtualbox_4_1.VBoxException;
|
||||||
|
|
||||||
import static org.easymock.classextension.EasyMock.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mattias Holmqvist
|
* @author Mattias Holmqvist
|
||||||
*/
|
*/
|
||||||
|
@ -49,8 +53,8 @@ public class ApplyMemoryToMachineTest {
|
||||||
@Test(expectedExceptions = VBoxException.class)
|
@Test(expectedExceptions = VBoxException.class)
|
||||||
public void testRethrowInvalidRamSizeError() throws Exception {
|
public void testRethrowInvalidRamSizeError() throws Exception {
|
||||||
// Mainly here for documentation purposes
|
// Mainly here for documentation purposes
|
||||||
final String error = "VirtualBox error: Invalid RAM size: " +
|
final String error = "VirtualBox error: Invalid RAM size: "
|
||||||
"3567587327 MB (must be in range [4, 2097152] MB) (0x80070057)";
|
+ "3567587327 MB (must be in range [4, 2097152] MB) (0x80070057)";
|
||||||
|
|
||||||
long memorySize = 1024l;
|
long memorySize = 1024l;
|
||||||
IMachine machine = createMock(IMachine.class);
|
IMachine machine = createMock(IMachine.class);
|
||||||
|
|
|
@ -18,15 +18,18 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.virtualbox.functions;
|
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.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.DeviceType;
|
import org.virtualbox_4_1.DeviceType;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_1.IMachine;
|
||||||
import org.virtualbox_4_1.IMedium;
|
import org.virtualbox_4_1.IMedium;
|
||||||
import org.virtualbox_4_1.VBoxException;
|
import org.virtualbox_4_1.VBoxException;
|
||||||
|
|
||||||
import static org.easymock.classextension.EasyMock.*;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mattias Holmqvist
|
* @author Mattias Holmqvist
|
||||||
*/
|
*/
|
||||||
|
@ -67,7 +70,8 @@ public class AttachDistroMediumToMachineTest {
|
||||||
errorBuilder.append("of this virtual machine (0x80BB000C)");
|
errorBuilder.append("of this virtual machine (0x80BB000C)");
|
||||||
String isoAlreadyAttachedException = errorBuilder.toString();
|
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);
|
machine.attachDevice(controllerIDE, 0, 0, DeviceType.DVD, distroMedium);
|
||||||
expectLastCall().andThrow(isoAttachedException);
|
expectLastCall().andThrow(isoAttachedException);
|
||||||
|
|
||||||
|
@ -92,7 +96,8 @@ public class AttachDistroMediumToMachineTest {
|
||||||
errorBuilder.append("Some other VBox error");
|
errorBuilder.append("Some other VBox error");
|
||||||
String isoAlreadyAttachedException = errorBuilder.toString();
|
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);
|
machine.attachDevice(controllerIDE, 0, 0, DeviceType.DVD, distroMedium);
|
||||||
expectLastCall().andThrow(isoAttachedException);
|
expectLastCall().andThrow(isoAttachedException);
|
||||||
|
|
||||||
|
@ -102,5 +107,4 @@ public class AttachDistroMediumToMachineTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,12 +19,23 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions;
|
package org.jclouds.virtualbox.functions;
|
||||||
|
|
||||||
import org.testng.annotations.Test;
|
import static org.easymock.EasyMock.anyLong;
|
||||||
import org.virtualbox_4_1.*;
|
import static org.easymock.EasyMock.expect;
|
||||||
|
import static org.easymock.EasyMock.expectLastCall;
|
||||||
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.virtualbox_4_1.DeviceType.HardDisk;
|
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
|
* @author Mattias Holmqvist
|
||||||
*/
|
*/
|
||||||
|
@ -54,7 +65,8 @@ public class AttachMediumToMachineIfNotAlreadyAttachedTest {
|
||||||
machine.saveSettings();
|
machine.saveSettings();
|
||||||
replay(manager, machine, vBox, hardDisk);
|
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);
|
verify(machine);
|
||||||
|
|
||||||
|
@ -79,13 +91,15 @@ public class AttachMediumToMachineIfNotAlreadyAttachedTest {
|
||||||
errorBuilder.append("of this virtual machine (0x80BB000C)");
|
errorBuilder.append("of this virtual machine (0x80BB000C)");
|
||||||
String isoAlreadyAttachedException = errorBuilder.toString();
|
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);
|
machine.attachDevice(controllerIDE, controllerPort, device, HardDisk, hardDisk);
|
||||||
expectLastCall().andThrow(isoAttachedException);
|
expectLastCall().andThrow(isoAttachedException);
|
||||||
|
|
||||||
replay(manager, machine, vBox, hardDisk);
|
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);
|
verify(machine);
|
||||||
|
|
||||||
|
@ -108,13 +122,15 @@ public class AttachMediumToMachineIfNotAlreadyAttachedTest {
|
||||||
errorBuilder.append("Some other VBox error");
|
errorBuilder.append("Some other VBox error");
|
||||||
String isoAlreadyAttachedException = errorBuilder.toString();
|
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);
|
machine.attachDevice(controllerIDE, controllerPort, device, HardDisk, hardDisk);
|
||||||
expectLastCall().andThrow(isoAttachedException);
|
expectLastCall().andThrow(isoAttachedException);
|
||||||
|
|
||||||
replay(manager, machine, vBox, hardDisk);
|
replay(manager, machine, vBox, hardDisk);
|
||||||
|
|
||||||
new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE, hardDisk, controllerPort, device, HardDisk).apply(machine);
|
new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE, hardDisk, controllerPort, device, HardDisk)
|
||||||
|
.apply(machine);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/**
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -19,13 +19,20 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions;
|
package org.jclouds.virtualbox.functions;
|
||||||
|
|
||||||
import org.testng.annotations.Test;
|
import static org.easymock.EasyMock.expect;
|
||||||
import org.virtualbox_4_1.*;
|
import static org.easymock.classextension.EasyMock.createMock;
|
||||||
|
import static org.easymock.classextension.EasyMock.createNiceMock;
|
||||||
import static org.easymock.classextension.EasyMock.*;
|
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.NATProtocol.TCP;
|
||||||
import static org.virtualbox_4_1.NetworkAttachmentType.NAT;
|
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
|
* @author Mattias Holmqvist
|
||||||
*/
|
*/
|
||||||
|
@ -60,8 +67,8 @@ public class AttachNATRedirectRuleToMachineTest {
|
||||||
INetworkAdapter networkAdapter = createMock(INetworkAdapter.class);
|
INetworkAdapter networkAdapter = createMock(INetworkAdapter.class);
|
||||||
INATEngine natEngine = createMock(INATEngine.class);
|
INATEngine natEngine = createMock(INATEngine.class);
|
||||||
|
|
||||||
String error = "VirtualBox error: Argument slot is invalid " +
|
String error = "VirtualBox error: Argument slot is invalid "
|
||||||
"(must be slot < RT_ELEMENTS(mNetworkAdapters)) (0x80070057)";
|
+ "(must be slot < RT_ELEMENTS(mNetworkAdapters)) (0x80070057)";
|
||||||
|
|
||||||
VBoxException invalidSlotException = new VBoxException(createNiceMock(Throwable.class), error);
|
VBoxException invalidSlotException = new VBoxException(createNiceMock(Throwable.class), error);
|
||||||
expect(machine.getNetworkAdapter(adapterId)).andThrow(invalidSlotException);
|
expect(machine.getNetworkAdapter(adapterId)).andThrow(invalidSlotException);
|
||||||
|
@ -73,5 +80,4 @@ public class AttachNATRedirectRuleToMachineTest {
|
||||||
verify(machine, networkAdapter, natEngine);
|
verify(machine, networkAdapter, natEngine);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,15 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions;
|
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.easymock.EasyMock;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.IMachine;
|
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.VBoxException;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
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
|
* @author Mattias Holmqvist
|
||||||
*/
|
*/
|
||||||
|
@ -55,9 +60,10 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
||||||
|
|
||||||
vBox.findMachine(vmName);
|
vBox.findMachine(vmName);
|
||||||
expectLastCall().andThrow(vBoxException);
|
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);
|
vBox.registerMachine(createdMachine);
|
||||||
|
|
||||||
replay(manager, vBox);
|
replay(manager, vBox);
|
||||||
|
@ -103,10 +109,9 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
||||||
|
|
||||||
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists("", "", "", false, manager).apply(vmName);
|
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists("", "", "", false, manager).apply(vmName);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String anyString() {
|
private String anyString() {
|
||||||
return EasyMock.<String>anyObject();
|
return EasyMock.<String> anyObject();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,14 +19,23 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions;
|
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.anyLong;
|
||||||
import static org.easymock.EasyMock.expect;
|
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 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
|
* @author Mattias Holmqvist
|
||||||
*/
|
*/
|
||||||
|
@ -137,5 +146,4 @@ public class CreateMediumIfNotAlreadyExistsTest {
|
||||||
new CreateMediumIfNotAlreadyExists(manager, diskFormat, true).apply(adminDiskPath);
|
new CreateMediumIfNotAlreadyExists(manager, diskFormat, true).apply(adminDiskPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,6 @@ import org.virtualbox_4_1.VirtualBoxManager;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
//@Test(groups = "live")
|
|
||||||
public class IMachineToNodeMetadataTest {
|
public class IMachineToNodeMetadataTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -19,10 +19,6 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions;
|
package org.jclouds.virtualbox.functions;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Andrea Turli, Mattias Holmqvist
|
|
||||||
*/
|
|
||||||
|
|
||||||
import static com.google.common.base.Predicates.equalTo;
|
import static com.google.common.base.Predicates.equalTo;
|
||||||
import static com.google.common.collect.Iterables.any;
|
import static com.google.common.collect.Iterables.any;
|
||||||
import static org.jclouds.virtualbox.experiment.TestUtils.computeServiceForLocalhostAndGuest;
|
import static org.jclouds.virtualbox.experiment.TestUtils.computeServiceForLocalhostAndGuest;
|
||||||
|
@ -47,13 +43,16 @@ import org.virtualbox_4_1.VirtualBoxManager;
|
||||||
|
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Andrea Turli, Mattias Holmqvist
|
||||||
|
*/
|
||||||
@Test(groups = "live", singleThreaded = true, testName = "IsoToIMachineLiveTest")
|
@Test(groups = "live", singleThreaded = true, testName = "IsoToIMachineLiveTest")
|
||||||
public class IsoToIMachineLiveTest extends BaseVirtualBoxClientLiveTest {
|
public class IsoToIMachineLiveTest extends BaseVirtualBoxClientLiveTest {
|
||||||
|
|
||||||
Map<OsFamily, Map<String, String>> map = new BaseComputeServiceContextModule() {
|
Map<OsFamily, Map<String, String>> map = new BaseComputeServiceContextModule() {
|
||||||
}.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule())
|
}.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule())
|
||||||
.getInstance(Json.class));
|
.getInstance(Json.class));
|
||||||
|
|
||||||
private String settingsFile = null;
|
private String settingsFile = null;
|
||||||
private boolean forceOverwrite = true;
|
private boolean forceOverwrite = true;
|
||||||
private String vmId = "jclouds-image-iso-1";
|
private String vmId = "jclouds-image-iso-1";
|
||||||
|
@ -76,24 +75,16 @@ public class IsoToIMachineLiveTest extends BaseVirtualBoxClientLiveTest {
|
||||||
public void testCreateImageMachineFromIso() throws Exception {
|
public void testCreateImageMachineFromIso() throws Exception {
|
||||||
|
|
||||||
VirtualBoxManager manager = (VirtualBoxManager) context.getProviderSpecificContext().getApi();
|
VirtualBoxManager manager = (VirtualBoxManager) context.getProviderSpecificContext().getApi();
|
||||||
ComputeServiceContext localHostContext = computeServiceForLocalhostAndGuest(hostId, "localhost", guestId, "localhost", new Credentials("toor", "password"));
|
ComputeServiceContext localHostContext = computeServiceForLocalhostAndGuest(hostId, "localhost", guestId,
|
||||||
IMachine imageMachine = new IsoToIMachine(manager,
|
"localhost", new Credentials("toor", "password"));
|
||||||
adminDisk,
|
IMachine imageMachine = new IsoToIMachine(manager, adminDisk, diskFormat, settingsFile, vmName, osTypeId, vmId,
|
||||||
diskFormat,
|
forceOverwrite, controllerIDE, localHostContext, hostId, guestId, new Credentials("toor", "password"))
|
||||||
settingsFile,
|
.apply("ubuntu-11.04-server-i386.iso");
|
||||||
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);
|
IMachineToImage iMachineToImage = new IMachineToImage(manager, map);
|
||||||
Image newImage = iMachineToImage.apply(imageMachine);
|
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();
|
Set<? extends Image> images = context.getComputeService().listImages();
|
||||||
|
|
||||||
assertTrue(any(images, equalTo(newImage)));
|
assertTrue(any(images, equalTo(newImage)));
|
||||||
|
|
|
@ -19,6 +19,11 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions;
|
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.jclouds.virtualbox.domain.ExecutionType;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.IMachine;
|
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.ISession;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
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")
|
@Test(groups = "unit", testName = "LaunchMachineIfNotAlreadyRunningTest")
|
||||||
public class LaunchMachineIfNotAlreadyRunningTest {
|
public class LaunchMachineIfNotAlreadyRunningTest {
|
||||||
|
|
||||||
|
@ -39,9 +39,10 @@ public class LaunchMachineIfNotAlreadyRunningTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// VirtualBox error: The given session is busy (0x80BB0007)
|
// 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
|
@Test
|
||||||
public void testLaunchIfNotStarted() throws Exception {
|
public void testLaunchIfNotStarted() throws Exception {
|
||||||
|
|
|
@ -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;
|
package org.jclouds.virtualbox.functions.admin;
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
@ -13,23 +32,6 @@ import org.testng.annotations.Test;
|
||||||
import com.google.common.collect.ImmutableMap;
|
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
|
* @author Andrea Turli
|
||||||
*/
|
*/
|
||||||
@Test(groups = "unit")
|
@Test(groups = "unit")
|
||||||
|
|
|
@ -19,17 +19,15 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions.admin;
|
package org.jclouds.virtualbox.functions.admin;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Andrea Turli
|
|
||||||
*/
|
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import org.eclipse.jetty.server.Server;
|
import org.eclipse.jetty.server.Server;
|
||||||
import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
|
import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Andrea Turli
|
||||||
|
*/
|
||||||
@Test(groups = "live", singleThreaded = true, testName = "StartJettyIfNotAlreadyRunningLiveTest")
|
@Test(groups = "live", singleThreaded = true, testName = "StartJettyIfNotAlreadyRunningLiveTest")
|
||||||
public class StartJettyIfNotAlreadyRunningLiveTest extends BaseVirtualBoxClientLiveTest {
|
public class StartJettyIfNotAlreadyRunningLiveTest extends BaseVirtualBoxClientLiveTest {
|
||||||
|
|
||||||
|
@ -42,7 +40,7 @@ public class StartJettyIfNotAlreadyRunningLiveTest extends BaseVirtualBoxClientL
|
||||||
server.stop();
|
server.stop();
|
||||||
assertEquals(server.getState(), server.STOPPED);
|
assertEquals(server.getState(), server.STOPPED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLaunchingSameJettyServer() throws Exception {
|
public void testLaunchingSameJettyServer() throws Exception {
|
||||||
Server server = new StartJettyIfNotAlreadyRunning(port).apply(basebaseResource);
|
Server server = new StartJettyIfNotAlreadyRunning(port).apply(basebaseResource);
|
||||||
|
|
|
@ -16,31 +16,33 @@
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions.admin;
|
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.jclouds.virtualbox.experiment.TestUtils.computeServiceForLocalhostAndGuest;
|
||||||
import static org.testng.Assert.assertEquals;
|
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")
|
@Test(groups = "live", singleThreaded = true, testName = "startVBoxIfNotAlreadyRunningLiveTest")
|
||||||
public class StartVBoxIfNotAlreadyRunningLiveTest {
|
public class StartVBoxIfNotAlreadyRunningLiveTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStartVbox() throws Exception {
|
public void testStartVbox() throws Exception {
|
||||||
Credentials localhostCredentials = new Credentials("toor", "password");
|
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/");
|
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);
|
assertEquals(manager.getSessionObject().getState(), SessionState.Unlocked);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue