mirror of https://github.com/apache/jclouds.git
added support for vbox 4.2.6;
added hostname support; added generic md5 support; dralves`s comments addressed adrian`s comments addressed dralver`s comments addressed second round of comments addressed fix CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest formatting swept check* updated jclouds-sshj pom.xml with latest bouncycastle version
This commit is contained in:
parent
b8b258d462
commit
ac0e5f5e67
|
@ -15,3 +15,4 @@ bin/
|
||||||
TAGS
|
TAGS
|
||||||
.metadata/
|
.metadata/
|
||||||
atlassian-ide-plugin.xml
|
atlassian-ide-plugin.xml
|
||||||
|
.DS_Store
|
||||||
|
|
|
@ -56,6 +56,12 @@
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<!-- until sshj will update to latest bouncycastle 1.47 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bouncycastle</groupId>
|
||||||
|
<artifactId>bcpkix-jdk15on</artifactId>
|
||||||
|
<version>1.47</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jclouds</groupId>
|
<groupId>org.jclouds</groupId>
|
||||||
<artifactId>jclouds-compute</artifactId>
|
<artifactId>jclouds-compute</artifactId>
|
||||||
|
|
Binary file not shown.
|
@ -35,9 +35,10 @@
|
||||||
<packaging>bundle</packaging>
|
<packaging>bundle</packaging>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
<virtualbox.version>4.2.6</virtualbox.version>
|
||||||
<test.virtualbox.endpoint>http://localhost:18083/</test.virtualbox.endpoint>
|
<test.virtualbox.endpoint>http://localhost:18083/</test.virtualbox.endpoint>
|
||||||
<test.virtualbox.api-version>4.1.4</test.virtualbox.api-version>
|
<test.virtualbox.api-version>4.2.6</test.virtualbox.api-version>
|
||||||
<test.virtualbox.build-version>4.1.20r80170</test.virtualbox.build-version>
|
<test.virtualbox.build-version>${virtualbox.version}</test.virtualbox.build-version>
|
||||||
<test.virtualbox.identity>${user.name}</test.virtualbox.identity>
|
<test.virtualbox.identity>${user.name}</test.virtualbox.identity>
|
||||||
<test.virtualbox.credential>CHANGE_ME</test.virtualbox.credential>
|
<test.virtualbox.credential>CHANGE_ME</test.virtualbox.credential>
|
||||||
<test.virtualbox.template>osFamily=UBUNTU,osVersionMatches=12.04.1,os64Bit=true,osArchMatches=amd64,loginUser=toor:password,authenticateSudo=true</test.virtualbox.template>
|
<test.virtualbox.template>osFamily=UBUNTU,osVersionMatches=12.04.1,os64Bit=true,osArchMatches=amd64,loginUser=toor:password,authenticateSudo=true</test.virtualbox.template>
|
||||||
|
@ -49,7 +50,7 @@
|
||||||
*
|
*
|
||||||
</jclouds.osgi.import>
|
</jclouds.osgi.import>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jclouds</groupId>
|
<groupId>org.jclouds</groupId>
|
||||||
|
@ -59,7 +60,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.virtualbox</groupId>
|
<groupId>org.virtualbox</groupId>
|
||||||
<artifactId>vboxjws</artifactId>
|
<artifactId>vboxjws</artifactId>
|
||||||
<version>${test.virtualbox.api-version}</version>
|
<version>${virtualbox.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jclouds.api</groupId>
|
<groupId>org.jclouds.api</groupId>
|
||||||
|
@ -86,6 +87,11 @@
|
||||||
<artifactId>jclouds-slf4j</artifactId>
|
<artifactId>jclouds-slf4j</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ch.qos.logback</groupId>
|
||||||
|
<artifactId>logback-classic</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jclouds</groupId>
|
<groupId>org.jclouds</groupId>
|
||||||
<artifactId>jclouds-core</artifactId>
|
<artifactId>jclouds-core</artifactId>
|
||||||
|
@ -100,11 +106,6 @@
|
||||||
<type>test-jar</type>
|
<type>test-jar</type>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>ch.qos.logback</groupId>
|
|
||||||
<artifactId>logback-classic</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.testng</groupId>
|
<groupId>org.testng</groupId>
|
||||||
<artifactId>testng</artifactId>
|
<artifactId>testng</artifactId>
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox;
|
package org.jclouds.virtualbox;
|
||||||
|
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_2.VirtualBoxManager;
|
||||||
|
|
||||||
public class VirtualBox {
|
public class VirtualBox {
|
||||||
|
|
||||||
|
|
|
@ -20,12 +20,11 @@ package org.jclouds.virtualbox;
|
||||||
|
|
||||||
import static org.jclouds.compute.config.ComputeServiceProperties.TEMPLATE;
|
import static org.jclouds.compute.config.ComputeServiceProperties.TEMPLATE;
|
||||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_DEFAULT_DIR;
|
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_DEFAULT_DIR;
|
||||||
|
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_GUEST_MEMORY;
|
||||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGES_DESCRIPTOR;
|
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGES_DESCRIPTOR;
|
||||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE;
|
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE;
|
||||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_PRECONFIGURATION_URL;
|
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_PRECONFIGURATION_URL;
|
||||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_WORKINGDIR;
|
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_WORKINGDIR;
|
||||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_GUEST_MEMORY;
|
|
||||||
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
@ -65,15 +64,16 @@ public class VirtualBoxApiMetadata extends BaseApiMetadata {
|
||||||
|
|
||||||
properties.put(VIRTUALBOX_INSTALLATION_KEY_SEQUENCE, "<Esc><Esc><Enter> "
|
properties.put(VIRTUALBOX_INSTALLATION_KEY_SEQUENCE, "<Esc><Esc><Enter> "
|
||||||
+ "/install/vmlinuz noapic preseed/url=PRECONFIGURATION_URL "
|
+ "/install/vmlinuz noapic preseed/url=PRECONFIGURATION_URL "
|
||||||
+ "debian-installer=en_US auto locale=en_US kbd-chooser/method=us " + "hostname=" + "HOSTNAME "
|
+ "debian-installer=en_US auto locale=en_US kbd-chooser/method=us "
|
||||||
|
+ "hostname=" + "HOSTNAME "
|
||||||
+ "fb=false debconf/frontend=noninteractive "
|
+ "fb=false debconf/frontend=noninteractive "
|
||||||
+ "keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false "
|
+ "console-setup/ask_detect=false keyboard-configuration/layoutcode=us "
|
||||||
+ "initrd=/install/initrd.gz -- <Enter>");
|
+ "initrd=/install/initrd.gz -- <Enter>");
|
||||||
|
|
||||||
String workingDir = System.getProperty("test.virtualbox.workingDir", VIRTUALBOX_DEFAULT_DIR);
|
String workingDir = System.getProperty("test.virtualbox.workingDir", VIRTUALBOX_DEFAULT_DIR);
|
||||||
properties.put(VIRTUALBOX_WORKINGDIR, workingDir);
|
properties.put(VIRTUALBOX_WORKINGDIR, workingDir);
|
||||||
|
|
||||||
String ram = System.getProperty(VIRTUALBOX_GUEST_MEMORY, "1024");
|
String ram = System.getProperty(VIRTUALBOX_GUEST_MEMORY, "512");
|
||||||
properties.put(VIRTUALBOX_GUEST_MEMORY, ram);
|
properties.put(VIRTUALBOX_GUEST_MEMORY, ram);
|
||||||
|
|
||||||
String yamlDescriptor = System.getProperty("test.virtualbox.image.descriptor.yaml", VIRTUALBOX_WORKINGDIR
|
String yamlDescriptor = System.getProperty("test.virtualbox.image.descriptor.yaml", VIRTUALBOX_WORKINGDIR
|
||||||
|
@ -81,7 +81,7 @@ public class VirtualBoxApiMetadata extends BaseApiMetadata {
|
||||||
|
|
||||||
properties.put(VIRTUALBOX_IMAGES_DESCRIPTOR, yamlDescriptor);
|
properties.put(VIRTUALBOX_IMAGES_DESCRIPTOR, yamlDescriptor);
|
||||||
properties.put(VIRTUALBOX_PRECONFIGURATION_URL, "http://10.0.2.2:23232/preseed.cfg");
|
properties.put(VIRTUALBOX_PRECONFIGURATION_URL, "http://10.0.2.2:23232/preseed.cfg");
|
||||||
properties.setProperty(TEMPLATE, "osFamily=UBUNTU,osVersionMatches=12.04.1,os64Bit=true,osArchMatches=amd64");
|
properties.setProperty(TEMPLATE, "osFamily=UBUNTU,osVersionMatches=12.04.1,os64Bit=true,osArchMatches=amd64");
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,10 +96,9 @@ public class VirtualBoxApiMetadata extends BaseApiMetadata {
|
||||||
.defaultIdentity(System.getProperty("user.name"))
|
.defaultIdentity(System.getProperty("user.name"))
|
||||||
.defaultCredential("CHANGE_ME")
|
.defaultCredential("CHANGE_ME")
|
||||||
.defaultEndpoint("http://localhost:18083/")
|
.defaultEndpoint("http://localhost:18083/")
|
||||||
.documentation(URI.create("https://github.com/jclouds/jclouds/tree/master/apis/byon"))
|
.documentation(URI.create("https://github.com/jclouds/jclouds/tree/master/labs/virtualbox"))
|
||||||
// later version not in maven, yet
|
.version("4.2.4")
|
||||||
.version("4.1.4")
|
.buildVersion("4.2.4")
|
||||||
.buildVersion("4.1.8r75467")
|
|
||||||
.defaultProperties(VirtualBoxApiMetadata.defaultProperties())
|
.defaultProperties(VirtualBoxApiMetadata.defaultProperties())
|
||||||
.view(ComputeServiceContext.class)
|
.view(ComputeServiceContext.class)
|
||||||
.defaultModules(ImmutableSet.<Class<? extends Module>>of(HardcodeLocalhostAsNodeMetadataSupplier.class, VirtualBoxComputeServiceContextModule.class));
|
.defaultModules(ImmutableSet.<Class<? extends Module>>of(HardcodeLocalhostAsNodeMetadataSupplier.class, VirtualBoxComputeServiceContextModule.class));
|
||||||
|
|
|
@ -31,9 +31,9 @@ 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_2.IGuestOSType;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_2.VirtualBoxManager;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.cache.CacheLoader;
|
import com.google.common.cache.CacheLoader;
|
||||||
|
|
|
@ -47,12 +47,12 @@ import org.jclouds.virtualbox.domain.NodeSpec;
|
||||||
import org.jclouds.virtualbox.domain.YamlImage;
|
import org.jclouds.virtualbox.domain.YamlImage;
|
||||||
import org.jclouds.virtualbox.functions.admin.UnregisterMachineIfExistsAndForceDeleteItsMedia;
|
import org.jclouds.virtualbox.functions.admin.UnregisterMachineIfExistsAndForceDeleteItsMedia;
|
||||||
import org.jclouds.virtualbox.util.MachineController;
|
import org.jclouds.virtualbox.util.MachineController;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.IProgress;
|
import org.virtualbox_4_2.IProgress;
|
||||||
import org.virtualbox_4_1.ISession;
|
import org.virtualbox_4_2.ISession;
|
||||||
import org.virtualbox_4_1.MachineState;
|
import org.virtualbox_4_2.MachineState;
|
||||||
import org.virtualbox_4_1.VBoxException;
|
import org.virtualbox_4_2.VBoxException;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_2.VirtualBoxManager;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
|
@ -90,7 +90,7 @@ public class VirtualBoxComputeServiceAdapter implements ComputeServiceAdapter<IM
|
||||||
Function<NodeSpec, NodeAndInitialCredentials<IMachine>> cloneCreator,
|
Function<NodeSpec, NodeAndInitialCredentials<IMachine>> cloneCreator,
|
||||||
Function<IMachine, Image> imachineToImage,
|
Function<IMachine, Image> imachineToImage,
|
||||||
MachineController machineController) {
|
MachineController machineController) {
|
||||||
this.manager = checkNotNull(manager, "manager");
|
this.manager = checkNotNull(manager, "virtualbox manager can't be null");
|
||||||
this.imagesToYamlImages = imagesMapper.get();
|
this.imagesToYamlImages = imagesMapper.get();
|
||||||
this.mastersLoader = mastersLoader;
|
this.mastersLoader = mastersLoader;
|
||||||
this.cloneCreator = cloneCreator;
|
this.cloneCreator = cloneCreator;
|
||||||
|
@ -254,10 +254,10 @@ public class VirtualBoxComputeServiceAdapter implements ComputeServiceAdapter<IM
|
||||||
logger.debug("vm was already powered down: ", machine.getId());
|
logger.debug("vm was already powered down: ", machine.getId());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
logger.debug("powering down vm: %s", machine.getName());
|
logger.debug("<< powering down vm(%s)", machine.getName());
|
||||||
machineController.ensureMachineHasPowerDown(machine.getName());
|
machineController.ensureMachineHasPowerDown(machine.getName());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error(e, "problem in powering down the %s", machine.getName());
|
logger.error(e, "problem in powering down vm(%s)", machine.getName());
|
||||||
throw Throwables.propagate(e);
|
throw Throwables.propagate(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,17 +47,18 @@ import org.jclouds.virtualbox.functions.IMachineToVmSpec;
|
||||||
import org.jclouds.virtualbox.functions.TakeSnapshotIfNotAlreadyAttached;
|
import org.jclouds.virtualbox.functions.TakeSnapshotIfNotAlreadyAttached;
|
||||||
import org.jclouds.virtualbox.functions.admin.UnregisterMachineIfExistsAndDeleteItsMedia;
|
import org.jclouds.virtualbox.functions.admin.UnregisterMachineIfExistsAndDeleteItsMedia;
|
||||||
import org.jclouds.virtualbox.util.MachineUtils;
|
import org.jclouds.virtualbox.util.MachineUtils;
|
||||||
import org.virtualbox_4_1.CloneMode;
|
import org.virtualbox_4_2.CloneMode;
|
||||||
import org.virtualbox_4_1.CloneOptions;
|
import org.virtualbox_4_2.CloneOptions;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.IProgress;
|
import org.virtualbox_4_2.IProgress;
|
||||||
import org.virtualbox_4_1.ISnapshot;
|
import org.virtualbox_4_2.ISnapshot;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_2.VirtualBoxManager;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Optional;
|
import com.google.common.base.Optional;
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.util.concurrent.Futures;
|
import com.google.common.util.concurrent.Futures;
|
||||||
|
@ -118,9 +119,12 @@ public class VirtualBoxImageExtension implements ImageExtension {
|
||||||
|
|
||||||
IMachine source = manager.get().getVBox().findMachine(cloneTemplate.getSourceNodeId());
|
IMachine source = manager.get().getVBox().findMachine(cloneTemplate.getSourceNodeId());
|
||||||
|
|
||||||
String settingsFile = manager.get().getVBox().composeMachineFilename(template.getName(), workingDir);
|
String flags = "";
|
||||||
|
List<String> groups = ImmutableList.of();
|
||||||
|
String group = "";
|
||||||
|
String settingsFile = manager.get().getVBox().composeMachineFilename(template.getName(), group , flags , workingDir);
|
||||||
IMachine clonedMachine = manager.get().getVBox()
|
IMachine clonedMachine = manager.get().getVBox()
|
||||||
.createMachine(settingsFile, template.getName(), source.getOSTypeId(), template.getName(), true);
|
.createMachine(settingsFile, template.getName(), groups, source.getOSTypeId(), flags);
|
||||||
|
|
||||||
List<CloneOptions> options = Lists.newArrayList();
|
List<CloneOptions> options = Lists.newArrayList();
|
||||||
if (isLinkedClone)
|
if (isLinkedClone)
|
||||||
|
@ -136,7 +140,7 @@ public class VirtualBoxImageExtension implements ImageExtension {
|
||||||
IProgress progress = currentSnapshot.getMachine().cloneTo(clonedMachine, CloneMode.MachineState, options);
|
IProgress progress = currentSnapshot.getMachine().cloneTo(clonedMachine, CloneMode.MachineState, options);
|
||||||
progress.waitForCompletion(-1);
|
progress.waitForCompletion(-1);
|
||||||
|
|
||||||
logger.debug(String.format("Machine %s is cloned correctly", clonedMachine.getName()));
|
logger.debug(String.format("<< master(%s) is cloned correctly to vm(%s)", source.getName(), clonedMachine.getName()));
|
||||||
|
|
||||||
// registering
|
// registering
|
||||||
manager.get().getVBox().registerMachine(clonedMachine);
|
manager.get().getVBox().registerMachine(clonedMachine);
|
||||||
|
|
|
@ -62,10 +62,10 @@ import org.jclouds.virtualbox.functions.admin.ImagesToYamlImagesFromYamlDescript
|
||||||
import org.jclouds.virtualbox.functions.admin.PreseedCfgServer;
|
import org.jclouds.virtualbox.functions.admin.PreseedCfgServer;
|
||||||
import org.jclouds.virtualbox.functions.admin.StartVBoxIfNotAlreadyRunning;
|
import org.jclouds.virtualbox.functions.admin.StartVBoxIfNotAlreadyRunning;
|
||||||
import org.jclouds.virtualbox.predicates.SshResponds;
|
import org.jclouds.virtualbox.predicates.SshResponds;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.LockType;
|
import org.virtualbox_4_2.LockType;
|
||||||
import org.virtualbox_4_1.MachineState;
|
import org.virtualbox_4_2.MachineState;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_2.VirtualBoxManager;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
@ -104,15 +104,15 @@ public class VirtualBoxComputeServiceContextModule extends
|
||||||
bind(new TypeLiteral<Function<IMachine, Image>>() {
|
bind(new TypeLiteral<Function<IMachine, Image>>() {
|
||||||
}).to(IMachineToImage.class);
|
}).to(IMachineToImage.class);
|
||||||
bind(new TypeLiteral<CacheLoader<IsoSpec, URI>>() {
|
bind(new TypeLiteral<CacheLoader<IsoSpec, URI>>() {
|
||||||
}).to((Class) PreseedCfgServer.class);
|
}).to(Class.class.cast(PreseedCfgServer.class));
|
||||||
bind(new TypeLiteral<Function<URI, File>>() {
|
bind(new TypeLiteral<Function<URI, File>>() {
|
||||||
}).to((Class) FileDownloadFromURI.class);
|
}).to(Class.class.cast(FileDownloadFromURI.class));
|
||||||
|
|
||||||
bind(new TypeLiteral<Supplier<VirtualBoxManager>>() {
|
bind(new TypeLiteral<Supplier<VirtualBoxManager>>() {
|
||||||
}).to((Class) StartVBoxIfNotAlreadyRunning.class);
|
}).to(Class.class.cast(StartVBoxIfNotAlreadyRunning.class));
|
||||||
// the yaml config to image mapper
|
// the yaml config to image mapper
|
||||||
bind(new TypeLiteral<Supplier<Map<Image, YamlImage>>>() {
|
bind(new TypeLiteral<Supplier<Map<Image, YamlImage>>>() {
|
||||||
}).to((Class) ImagesToYamlImagesFromYamlDescriptor.class);
|
}).to(Class.class.cast(ImagesToYamlImagesFromYamlDescriptor.class));
|
||||||
// the yaml config provider
|
// the yaml config provider
|
||||||
bind(YamlImagesFromFileConfig.class);
|
bind(YamlImagesFromFileConfig.class);
|
||||||
|
|
||||||
|
@ -126,15 +126,15 @@ public class VirtualBoxComputeServiceContextModule extends
|
||||||
|
|
||||||
// the master creating function
|
// the master creating function
|
||||||
bind(new TypeLiteral<Function<MasterSpec, IMachine>>() {
|
bind(new TypeLiteral<Function<MasterSpec, IMachine>>() {
|
||||||
}).to((Class) CreateAndInstallVm.class);
|
}).to(Class.class.cast(CreateAndInstallVm.class));
|
||||||
// the machine cloning function
|
// the machine cloning function
|
||||||
bind(new TypeLiteral<Function<NodeSpec, NodeAndInitialCredentials<IMachine>>>() {
|
bind(new TypeLiteral<Function<NodeSpec, NodeAndInitialCredentials<IMachine>>>() {
|
||||||
}).to((Class) NodeCreator.class);
|
}).to(Class.class.cast(NodeCreator.class));
|
||||||
bind(new TypeLiteral<Function<CloneSpec, IMachine>>() {
|
bind(new TypeLiteral<Function<CloneSpec, IMachine>>() {
|
||||||
}).to((Class) CloneAndRegisterMachineFromIMachineIfNotAlreadyExists.class);
|
}).to(Class.class.cast(CloneAndRegisterMachineFromIMachineIfNotAlreadyExists.class));
|
||||||
// the jetty server provider
|
// the jetty server provider
|
||||||
bind(new TypeLiteral<Server>() {
|
bind(new TypeLiteral<Server>() {
|
||||||
}).to((Class) PreseedCfgServer.class).asEagerSingleton();
|
}).to(Class.class.cast(PreseedCfgServer.class)).asEagerSingleton();
|
||||||
|
|
||||||
bind(new TypeLiteral<Function<IMachine, SshClient>>() {
|
bind(new TypeLiteral<Function<IMachine, SshClient>>() {
|
||||||
}).to(IMachineToSshClient.class);
|
}).to(IMachineToSshClient.class);
|
||||||
|
|
|
@ -115,15 +115,15 @@ public class BridgedIf {
|
||||||
public BridgedIf(String name, String guid, String dhcp, String ipAddress,
|
public BridgedIf(String name, String guid, String dhcp, String ipAddress,
|
||||||
String networkMask, String ipv6Address, String iv6NetworkMask,
|
String networkMask, String ipv6Address, String iv6NetworkMask,
|
||||||
String mediumType, String status) {
|
String mediumType, String status) {
|
||||||
this.name = checkNotNull(name, "bridgedIf name");
|
this.name = checkNotNull(name, "bridgedIf name can't be null");
|
||||||
this.guid = guid;
|
this.guid = guid;
|
||||||
this.dhcp = dhcp;
|
this.dhcp = dhcp;
|
||||||
this.ipAddress = checkNotNull(ipAddress, "bridgedIf ipAddress");
|
this.ipAddress = checkNotNull(ipAddress, "bridgedIf ipAddress can't be null");
|
||||||
this.networkMask = networkMask;
|
this.networkMask = networkMask;
|
||||||
this.ipv6Address = ipv6Address;
|
this.ipv6Address = ipv6Address;
|
||||||
this.ipv6NetworkMask = iv6NetworkMask;
|
this.ipv6NetworkMask = iv6NetworkMask;
|
||||||
this.mediumType = mediumType;
|
this.mediumType = mediumType;
|
||||||
this.status = checkNotNull(status, "bridgedIf status");
|
this.status = checkNotNull(status, "bridgedIf status can't be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
|
|
@ -21,7 +21,7 @@ package org.jclouds.virtualbox.domain;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
|
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
|
|
||||||
|
@ -74,12 +74,9 @@ public class CloneSpec {
|
||||||
}
|
}
|
||||||
|
|
||||||
public CloneSpec(VmSpec vmSpec, NetworkSpec networkSpec, IMachine master, boolean isLinked) {
|
public CloneSpec(VmSpec vmSpec, NetworkSpec networkSpec, IMachine master, boolean isLinked) {
|
||||||
checkNotNull(vmSpec, "vmSpec");
|
this.vmSpec = checkNotNull(vmSpec, "vmSpec can't be null");
|
||||||
checkNotNull(networkSpec, "networkSpec");
|
this.networkSpec = checkNotNull(networkSpec, "networkSpec can't be null");
|
||||||
checkNotNull(master, "master");
|
this.master = checkNotNull(master, "master can't be null");
|
||||||
this.vmSpec = vmSpec;
|
|
||||||
this.networkSpec = networkSpec;
|
|
||||||
this.master = master;
|
|
||||||
this.isLinked = isLinked;
|
this.isLinked = isLinked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ package org.jclouds.virtualbox.domain;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import org.virtualbox_4_1.DeviceType;
|
import org.virtualbox_4_2.DeviceType;
|
||||||
|
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
|
|
||||||
|
@ -43,10 +43,9 @@ public class DeviceDetails {
|
||||||
private final DeviceType deviceType;
|
private final DeviceType deviceType;
|
||||||
|
|
||||||
public DeviceDetails(int port, int deviceSlot, DeviceType deviceType) {
|
public DeviceDetails(int port, int deviceSlot, DeviceType deviceType) {
|
||||||
checkNotNull(deviceType, "deviceType");
|
|
||||||
this.port = port;
|
this.port = port;
|
||||||
this.deviceSlot = deviceSlot;
|
this.deviceSlot = deviceSlot;
|
||||||
this.deviceType = deviceType;
|
this.deviceType = checkNotNull(deviceType, "deviceType can't be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPort() {
|
public int getPort() {
|
||||||
|
@ -87,7 +86,7 @@ public class DeviceDetails {
|
||||||
}
|
}
|
||||||
|
|
||||||
public DeviceDetails build() {
|
public DeviceDetails build() {
|
||||||
checkNotNull(deviceType, "deviceType");
|
checkNotNull(deviceType, "deviceType can't be null");
|
||||||
return new DeviceDetails(port, deviceSlot, deviceType);
|
return new DeviceDetails(port, deviceSlot, deviceType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,8 @@ package org.jclouds.virtualbox.domain;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.virtualbox_4_1.VBoxException;
|
import org.virtualbox_4_2.VBoxException;
|
||||||
import org.virtualbox_4_1.jaxws.RuntimeFaultMsg;
|
import org.virtualbox_4_2.jaxws.RuntimeFaultMsg;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ public enum ErrorCode {
|
||||||
this.code = code;
|
this.code = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Map<Long, ErrorCode> TABLE;
|
private final static Map<Long, ErrorCode> TABLE;
|
||||||
static {
|
static {
|
||||||
ImmutableMap.Builder<Long, ErrorCode> builder = ImmutableMap.builder();
|
ImmutableMap.Builder<Long, ErrorCode> builder = ImmutableMap.builder();
|
||||||
for (ErrorCode errorCode : ErrorCode.values()) {
|
for (ErrorCode errorCode : ErrorCode.values()) {
|
||||||
|
|
|
@ -21,7 +21,7 @@ package org.jclouds.virtualbox.domain;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import org.virtualbox_4_1.DeviceType;
|
import org.virtualbox_4_2.DeviceType;
|
||||||
|
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
|
|
||||||
|
@ -46,12 +46,9 @@ public class HardDisk {
|
||||||
private final boolean autoDelete;
|
private final boolean autoDelete;
|
||||||
|
|
||||||
public HardDisk(DeviceDetails deviceDetails, String diskPath, String diskFormat, boolean autoDelete) {
|
public HardDisk(DeviceDetails deviceDetails, String diskPath, String diskFormat, boolean autoDelete) {
|
||||||
checkNotNull(deviceDetails, "deviceDetails");
|
this.diskPath = checkNotNull(diskPath, "diskPath can't be null");
|
||||||
checkNotNull(diskPath, "diskPath");
|
this.diskFormat = checkNotNull(diskFormat, "diskFormat can't be null");
|
||||||
checkNotNull(diskFormat, "diskFormat");
|
this.deviceDetails = checkNotNull(deviceDetails, "deviceDetails can't be null");
|
||||||
this.diskPath = diskPath;
|
|
||||||
this.diskFormat = diskFormat;
|
|
||||||
this.deviceDetails = deviceDetails;
|
|
||||||
this.name = diskPath.substring(diskPath.lastIndexOf("/") + 1);
|
this.name = diskPath.substring(diskPath.lastIndexOf("/") + 1);
|
||||||
this.autoDelete = autoDelete;
|
this.autoDelete = autoDelete;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,10 +33,8 @@ public class IsoImage {
|
||||||
private String sourcePath;
|
private String sourcePath;
|
||||||
|
|
||||||
public IsoImage(DeviceDetails deviceDetails, String sourcePath) {
|
public IsoImage(DeviceDetails deviceDetails, String sourcePath) {
|
||||||
checkNotNull(deviceDetails, "deviceDetails");
|
this.deviceDetails = checkNotNull(deviceDetails, "deviceDetails can't be null");
|
||||||
checkNotNull(sourcePath, "sourcePath");
|
this.sourcePath = checkNotNull(sourcePath, "sourcePath can't be null");
|
||||||
this.deviceDetails = deviceDetails;
|
|
||||||
this.sourcePath = sourcePath;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public DeviceDetails getDeviceDetails() {
|
public DeviceDetails getDeviceDetails() {
|
||||||
|
|
|
@ -32,8 +32,8 @@ public class IsoSpec {
|
||||||
private final String sourcePath;
|
private final String sourcePath;
|
||||||
|
|
||||||
public IsoSpec(String sourcePath, String installationKeySequence) {
|
public IsoSpec(String sourcePath, String installationKeySequence) {
|
||||||
this.sourcePath = checkNotNull(sourcePath, "sourcePath");
|
this.sourcePath = checkNotNull(sourcePath, "sourcePath can't be null");
|
||||||
this.installationKeySequence = checkNotNull(installationKeySequence, "installationKeySequence");
|
this.installationKeySequence = checkNotNull(installationKeySequence, "installationKeySequence can't be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Builder builder() {
|
public static Builder builder() {
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.domain;
|
package org.jclouds.virtualbox.domain;
|
||||||
|
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
|
|
||||||
public class Master {
|
public class Master {
|
||||||
|
|
||||||
|
|
|
@ -74,12 +74,9 @@ public class MasterSpec {
|
||||||
}
|
}
|
||||||
|
|
||||||
private MasterSpec(VmSpec vmSpec, IsoSpec isoSpec, NetworkSpec networkSpec, LoginCredentials loginCredentials) {
|
private MasterSpec(VmSpec vmSpec, IsoSpec isoSpec, NetworkSpec networkSpec, LoginCredentials loginCredentials) {
|
||||||
checkNotNull(vmSpec, "vmSpec");
|
this.vmSpec = checkNotNull(vmSpec, "vmSpec can't be null");
|
||||||
checkNotNull(isoSpec, "isoSpec");
|
this.isoSpec = checkNotNull(isoSpec, "isoSpec can't be null");
|
||||||
checkNotNull(networkSpec, "networkSpec");
|
this.networkSpec = checkNotNull(networkSpec, "networkSpec can't be null");
|
||||||
this.vmSpec = vmSpec;
|
|
||||||
this.isoSpec = isoSpec;
|
|
||||||
this.networkSpec = networkSpec;
|
|
||||||
this.loginCredentials = loginCredentials;
|
this.loginCredentials = loginCredentials;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.virtualbox_4_1.NATProtocol;
|
import org.virtualbox_4_2.NATProtocol;
|
||||||
|
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
|
|
@ -25,8 +25,8 @@ import java.util.Collections;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.jclouds.javax.annotation.Nullable;
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
import org.virtualbox_4_1.NATProtocol;
|
import org.virtualbox_4_2.NATProtocol;
|
||||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
import org.virtualbox_4_2.NetworkAttachmentType;
|
||||||
|
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
@ -48,7 +48,7 @@ public class NetworkAdapter {
|
||||||
String macAddress, Set<RedirectRule> redirectRules,
|
String macAddress, Set<RedirectRule> redirectRules,
|
||||||
String staticIp) {
|
String staticIp) {
|
||||||
this.networkAttachmentType = checkNotNull(networkAttachmentType,
|
this.networkAttachmentType = checkNotNull(networkAttachmentType,
|
||||||
"networkAttachmentType");
|
"networkAttachmentType can't be null");
|
||||||
this.macAddress = macAddress;
|
this.macAddress = macAddress;
|
||||||
this.redirectRules = ImmutableSet.<RedirectRule>copyOf(redirectRules);
|
this.redirectRules = ImmutableSet.<RedirectRule>copyOf(redirectRules);
|
||||||
this.staticIp = staticIp;
|
this.staticIp = staticIp;
|
||||||
|
|
|
@ -31,8 +31,8 @@ public class NetworkInterfaceCard {
|
||||||
private final boolean enabled;
|
private final boolean enabled;
|
||||||
|
|
||||||
public NetworkInterfaceCard(long slot, NetworkAdapter networkAdapter, String hostInterfaceName, boolean enabled) {
|
public NetworkInterfaceCard(long slot, NetworkAdapter networkAdapter, String hostInterfaceName, boolean enabled) {
|
||||||
this.slot = checkNotNull(slot, "slot");
|
this.slot = checkNotNull(slot, "slot can't be null");
|
||||||
this.networkAdapter = checkNotNull(networkAdapter, "networkAdapter");
|
this.networkAdapter = checkNotNull(networkAdapter, "networkAdapter can't be null");
|
||||||
this.hostInterfaceName = hostInterfaceName;
|
this.hostInterfaceName = hostInterfaceName;
|
||||||
this.enabled = enabled;
|
this.enabled = enabled;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class NetworkSpec {
|
||||||
private final List<NetworkInterfaceCard> networkInterfaceCards;
|
private final List<NetworkInterfaceCard> networkInterfaceCards;
|
||||||
|
|
||||||
public NetworkSpec(final List<NetworkInterfaceCard> networkInterfaceCards) {
|
public NetworkSpec(final List<NetworkInterfaceCard> networkInterfaceCards) {
|
||||||
this.networkInterfaceCards = ImmutableList.copyOf(checkNotNull(networkInterfaceCards, "networkInterfaceCards"));
|
this.networkInterfaceCards = ImmutableList.copyOf(checkNotNull(networkInterfaceCards, "networkInterfaceCards can't be null"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Builder builder() {
|
public static Builder builder() {
|
||||||
|
|
|
@ -20,7 +20,7 @@ package org.jclouds.virtualbox.domain;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import org.virtualbox_4_1.NATProtocol;
|
import org.virtualbox_4_2.NATProtocol;
|
||||||
|
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,8 @@ import static com.google.common.collect.Iterables.filter;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.jclouds.javax.annotation.Nullable;
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
import org.virtualbox_4_1.DeviceType;
|
import org.virtualbox_4_2.DeviceType;
|
||||||
import org.virtualbox_4_1.StorageBus;
|
import org.virtualbox_4_2.StorageBus;
|
||||||
|
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
|
@ -49,14 +49,10 @@ public class StorageController {
|
||||||
private Set<IsoImage> isoImages;
|
private Set<IsoImage> isoImages;
|
||||||
|
|
||||||
public StorageController(String name, StorageBus bus, Set<HardDisk> hardDisks, Set<IsoImage> isoImages) {
|
public StorageController(String name, StorageBus bus, Set<HardDisk> hardDisks, Set<IsoImage> isoImages) {
|
||||||
checkNotNull(name, "name");
|
this.name = checkNotNull(name, "storage name can't be null");
|
||||||
checkNotNull(bus, "bus");
|
this.bus = checkNotNull(bus, "bus can't be null");
|
||||||
checkNotNull(hardDisks, "hardDisks");
|
this.hardDisks = checkNotNull(hardDisks, "hardDisks can't be null");
|
||||||
checkNotNull(isoImages, "isoImages");
|
this.isoImages = checkNotNull(isoImages, "isoImages can't be null");
|
||||||
this.name = name;
|
|
||||||
this.bus = bus;
|
|
||||||
this.hardDisks = hardDisks;
|
|
||||||
this.isoImages = isoImages;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
|
|
@ -24,7 +24,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.virtualbox_4_1.CleanupMode;
|
import org.virtualbox_4_2.CleanupMode;
|
||||||
|
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
@ -44,13 +44,13 @@ public class VmSpec {
|
||||||
|
|
||||||
public VmSpec(String vmId, String vmName, String osTypeId, long memory, String guestUser, String guestPassword, boolean forceOverwrite,
|
public VmSpec(String vmId, String vmName, String osTypeId, long memory, String guestUser, String guestPassword, boolean forceOverwrite,
|
||||||
Set<StorageController> controllers, CleanupMode cleanupMode) {
|
Set<StorageController> controllers, CleanupMode cleanupMode) {
|
||||||
this.vmId = checkNotNull(vmId, "vmId");
|
this.vmId = checkNotNull(vmId, "vmId can't be null");
|
||||||
this.vmName = checkNotNull(vmName, "vmName");
|
this.vmName = checkNotNull(vmName, "vmName can't be null");
|
||||||
this.osTypeId = checkNotNull(osTypeId, "osTypeId");
|
this.osTypeId = checkNotNull(osTypeId, "osTypeId can't be null");
|
||||||
checkArgument(memory > 0, "memory must be > 0");
|
checkArgument(memory > 0, "memory must be > 0");
|
||||||
this.memory = memory;
|
this.memory = memory;
|
||||||
this.controllers = checkNotNull(controllers, "controllers");
|
this.controllers = checkNotNull(controllers, "controllers can't be null");
|
||||||
this.cleanupMode = checkNotNull(cleanupMode, "cleanupMode");
|
this.cleanupMode = checkNotNull(cleanupMode, "cleanupMode can't be null");
|
||||||
this.forceOverwrite = forceOverwrite;
|
this.forceOverwrite = forceOverwrite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,8 @@ package org.jclouds.virtualbox.functions;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import org.jclouds.virtualbox.domain.StorageController;
|
import org.jclouds.virtualbox.domain.StorageController;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.VBoxException;
|
import org.virtualbox_4_2.VBoxException;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ public class AddIDEControllerIfNotExists implements Function<IMachine, Void> {
|
||||||
private final StorageController storageController;
|
private final StorageController storageController;
|
||||||
|
|
||||||
public AddIDEControllerIfNotExists(StorageController storageController) {
|
public AddIDEControllerIfNotExists(StorageController storageController) {
|
||||||
this.storageController = checkNotNull(storageController, "storageController");
|
this.storageController = checkNotNull(storageController, "storageController can't be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions;
|
package org.jclouds.virtualbox.functions;
|
||||||
|
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
|
|
|
@ -18,12 +18,12 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.virtualbox.functions;
|
package org.jclouds.virtualbox.functions;
|
||||||
|
|
||||||
import static org.virtualbox_4_1.NetworkAdapterType.Am79C973;
|
import static org.virtualbox_4_2.NetworkAdapterType.Am79C973;
|
||||||
import static org.virtualbox_4_1.NetworkAttachmentType.Bridged;
|
import static org.virtualbox_4_2.NetworkAttachmentType.Bridged;
|
||||||
|
|
||||||
import org.jclouds.virtualbox.domain.NetworkInterfaceCard;
|
import org.jclouds.virtualbox.domain.NetworkInterfaceCard;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.INetworkAdapter;
|
import org.virtualbox_4_2.INetworkAdapter;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
|
@ -43,7 +43,6 @@ public class AttachBridgedAdapterToMachine implements Function<IMachine, Void> {
|
||||||
public Void apply(IMachine machine) {
|
public Void apply(IMachine machine) {
|
||||||
INetworkAdapter iNetworkAdapter = machine.getNetworkAdapter(networkInterfaceCard.getSlot());
|
INetworkAdapter iNetworkAdapter = machine.getNetworkAdapter(networkInterfaceCard.getSlot());
|
||||||
iNetworkAdapter.setAttachmentType(Bridged);
|
iNetworkAdapter.setAttachmentType(Bridged);
|
||||||
iNetworkAdapter.setAdapterType(Am79C973);
|
|
||||||
iNetworkAdapter.setMACAddress(networkInterfaceCard.getNetworkAdapter().getMacAddress());
|
iNetworkAdapter.setMACAddress(networkInterfaceCard.getNetworkAdapter().getMacAddress());
|
||||||
iNetworkAdapter.setBridgedInterface(networkInterfaceCard.getHostInterfaceName());
|
iNetworkAdapter.setBridgedInterface(networkInterfaceCard.getHostInterfaceName());
|
||||||
iNetworkAdapter.setEnabled(networkInterfaceCard.isEnabled());
|
iNetworkAdapter.setEnabled(networkInterfaceCard.isEnabled());
|
||||||
|
|
|
@ -18,12 +18,11 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.virtualbox.functions;
|
package org.jclouds.virtualbox.functions;
|
||||||
|
|
||||||
import static org.virtualbox_4_1.NetworkAdapterType.Am79C973;
|
|
||||||
import static org.virtualbox_4_1.NetworkAttachmentType.HostOnly;
|
|
||||||
|
|
||||||
import org.jclouds.virtualbox.domain.NetworkInterfaceCard;
|
import org.jclouds.virtualbox.domain.NetworkInterfaceCard;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.INetworkAdapter;
|
import org.virtualbox_4_2.INetworkAdapter;
|
||||||
|
import org.virtualbox_4_2.NetworkAdapterType;
|
||||||
|
import org.virtualbox_4_2.NetworkAttachmentType;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
|
@ -41,8 +40,7 @@ public class AttachHostOnlyAdapter implements Function<IMachine, Void> {
|
||||||
@Override
|
@Override
|
||||||
public Void apply(IMachine machine) {
|
public Void apply(IMachine machine) {
|
||||||
INetworkAdapter iNetworkAdapter = machine.getNetworkAdapter(networkInterfaceCard.getSlot());
|
INetworkAdapter iNetworkAdapter = machine.getNetworkAdapter(networkInterfaceCard.getSlot());
|
||||||
iNetworkAdapter.setAttachmentType(HostOnly);
|
iNetworkAdapter.setAttachmentType(NetworkAttachmentType.HostOnly);
|
||||||
iNetworkAdapter.setAdapterType(Am79C973);
|
|
||||||
iNetworkAdapter.setMACAddress(networkInterfaceCard.getNetworkAdapter().getMacAddress());
|
iNetworkAdapter.setMACAddress(networkInterfaceCard.getNetworkAdapter().getMacAddress());
|
||||||
iNetworkAdapter.setHostOnlyInterface(networkInterfaceCard.getHostInterfaceName());
|
iNetworkAdapter.setHostOnlyInterface(networkInterfaceCard.getHostInterfaceName());
|
||||||
iNetworkAdapter.setEnabled(networkInterfaceCard.isEnabled());
|
iNetworkAdapter.setEnabled(networkInterfaceCard.isEnabled());
|
||||||
|
|
|
@ -20,9 +20,9 @@
|
||||||
package org.jclouds.virtualbox.functions;
|
package org.jclouds.virtualbox.functions;
|
||||||
|
|
||||||
import org.jclouds.virtualbox.domain.DeviceDetails;
|
import org.jclouds.virtualbox.domain.DeviceDetails;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.IMedium;
|
import org.virtualbox_4_2.IMedium;
|
||||||
import org.virtualbox_4_1.VBoxException;
|
import org.virtualbox_4_2.VBoxException;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
|
@ -54,6 +54,7 @@ public class AttachMediumToMachineIfNotAlreadyAttached implements Function<IMach
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean alreadyAttached(VBoxException e) {
|
private boolean alreadyAttached(VBoxException e) {
|
||||||
|
System.out.println(medium.getName() + " " + e.getMessage());
|
||||||
return e.getMessage().contains("is already attached to port");
|
return e.getMessage().contains("is already attached to port");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,15 +19,18 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions;
|
package org.jclouds.virtualbox.functions;
|
||||||
|
|
||||||
import static org.virtualbox_4_1.NetworkAttachmentType.NAT;
|
import static org.virtualbox_4_2.NetworkAttachmentType.NAT;
|
||||||
|
|
||||||
import org.jclouds.virtualbox.domain.NetworkInterfaceCard;
|
import org.jclouds.virtualbox.domain.NetworkInterfaceCard;
|
||||||
import org.jclouds.virtualbox.domain.RedirectRule;
|
import org.jclouds.virtualbox.domain.RedirectRule;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.INetworkAdapter;
|
import org.virtualbox_4_2.INetworkAdapter;
|
||||||
import org.virtualbox_4_1.VBoxException;
|
import org.virtualbox_4_2.NetworkAdapterType;
|
||||||
|
import org.virtualbox_4_2.VBoxException;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.base.Splitter;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mattias Holmqvist, Andrea Turli
|
* @author Mattias Holmqvist, Andrea Turli
|
||||||
|
@ -43,12 +46,19 @@ public class AttachNATAdapterToMachineIfNotAlreadyExists implements Function<IMa
|
||||||
@Override
|
@Override
|
||||||
public Void apply(IMachine machine) {
|
public Void apply(IMachine machine) {
|
||||||
INetworkAdapter iNetworkAdapter = machine.getNetworkAdapter(networkInterfaceCard.getSlot());
|
INetworkAdapter iNetworkAdapter = machine.getNetworkAdapter(networkInterfaceCard.getSlot());
|
||||||
|
// clean up previously set rules
|
||||||
|
for (String redirectRule : iNetworkAdapter.getNATEngine().getRedirects()) {
|
||||||
|
String redirectRuleName = Iterables.getFirst(Splitter.on(",").split(redirectRule), null);
|
||||||
|
if(redirectRuleName != null) {
|
||||||
|
iNetworkAdapter.getNATEngine().removeRedirect(redirectRuleName);
|
||||||
|
}
|
||||||
|
}
|
||||||
iNetworkAdapter.setAttachmentType(NAT);
|
iNetworkAdapter.setAttachmentType(NAT);
|
||||||
for (RedirectRule rule : networkInterfaceCard.getNetworkAdapter().getRedirectRules()) {
|
for (RedirectRule rule : networkInterfaceCard.getNetworkAdapter().getRedirectRules()) {
|
||||||
try {
|
try {
|
||||||
String ruleName = String.format("%s@%s:%s->%s:%s",rule.getProtocol(), rule.getHost(), rule.getHostPort(),
|
String ruleName = String.format("%s@%s:%s->%s:%s",rule.getProtocol(), rule.getHost(), rule.getHostPort(),
|
||||||
rule.getGuest(), rule.getGuestPort());
|
rule.getGuest(), rule.getGuestPort());
|
||||||
iNetworkAdapter.getNatDriver().addRedirect(ruleName, rule.getProtocol(), rule.getHost(), rule.getHostPort(),
|
iNetworkAdapter.getNATEngine().addRedirect(ruleName, rule.getProtocol(), rule.getHost(), rule.getHostPort(),
|
||||||
rule.getGuest(), rule.getGuestPort());
|
rule.getGuest(), rule.getGuestPort());
|
||||||
} catch (VBoxException e) {
|
} catch (VBoxException e) {
|
||||||
if (!e.getMessage().contains("already exists"))
|
if (!e.getMessage().contains("already exists"))
|
||||||
|
|
|
@ -22,7 +22,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import org.jclouds.virtualbox.domain.NetworkInterfaceCard;
|
import org.jclouds.virtualbox.domain.NetworkInterfaceCard;
|
||||||
import org.jclouds.virtualbox.util.MachineUtils;
|
import org.jclouds.virtualbox.util.MachineUtils;
|
||||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
import org.virtualbox_4_2.NetworkAttachmentType;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
|
@ -35,8 +35,8 @@ public class AttachNicToMachine implements Function<NetworkInterfaceCard, Void>
|
||||||
private final MachineUtils machineUtils;
|
private final MachineUtils machineUtils;
|
||||||
|
|
||||||
public AttachNicToMachine(String vmName, MachineUtils machineUtils) {
|
public AttachNicToMachine(String vmName, MachineUtils machineUtils) {
|
||||||
this.vmName = checkNotNull(vmName, "vmName");
|
this.vmName = checkNotNull(vmName, "vmName can't be null");
|
||||||
this.machineUtils = checkNotNull(machineUtils, "machineUtils");
|
this.machineUtils = checkNotNull(machineUtils, "machineUtils can't be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -48,7 +48,7 @@ public class BridgedIfStringToBridgedIf implements Function<String, BridgedIf> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BridgedIf apply(String rawBridgedIf) {
|
public BridgedIf apply(String rawBridgedIf) {
|
||||||
checkNotNull(rawBridgedIf, "rawBridgedIf");
|
checkNotNull(rawBridgedIf, "bridged interface can't be null");
|
||||||
|
|
||||||
String transformedBridgedIf = transformRawBridgedIf(rawBridgedIf);
|
String transformedBridgedIf = transformRawBridgedIf(rawBridgedIf);
|
||||||
Map<String, String> bridgedIfMap = Splitter.on("\n")
|
Map<String, String> bridgedIfMap = Splitter.on("\n")
|
||||||
|
|
|
@ -35,16 +35,17 @@ import org.jclouds.virtualbox.domain.NetworkInterfaceCard;
|
||||||
import org.jclouds.virtualbox.domain.NetworkSpec;
|
import org.jclouds.virtualbox.domain.NetworkSpec;
|
||||||
import org.jclouds.virtualbox.domain.VmSpec;
|
import org.jclouds.virtualbox.domain.VmSpec;
|
||||||
import org.jclouds.virtualbox.util.MachineUtils;
|
import org.jclouds.virtualbox.util.MachineUtils;
|
||||||
import org.virtualbox_4_1.CloneMode;
|
import org.virtualbox_4_2.CloneMode;
|
||||||
import org.virtualbox_4_1.CloneOptions;
|
import org.virtualbox_4_2.CloneOptions;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.IProgress;
|
import org.virtualbox_4_2.IProgress;
|
||||||
import org.virtualbox_4_1.ISnapshot;
|
import org.virtualbox_4_2.ISnapshot;
|
||||||
import org.virtualbox_4_1.VBoxException;
|
import org.virtualbox_4_2.VBoxException;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_2.VirtualBoxManager;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
@ -96,13 +97,14 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExists implements Fu
|
||||||
NetworkSpec networkSpec = cloneSpec.getNetworkSpec();
|
NetworkSpec networkSpec = cloneSpec.getNetworkSpec();
|
||||||
boolean isLinkedClone = cloneSpec.isLinked();
|
boolean isLinkedClone = cloneSpec.isLinked();
|
||||||
IMachine master = cloneSpec.getMaster();
|
IMachine master = cloneSpec.getMaster();
|
||||||
String settingsFile = manager.get().getVBox().composeMachineFilename(vmSpec.getVmName(), workingDir);
|
String flags = "";
|
||||||
|
List<String> groups = ImmutableList.of();
|
||||||
|
String group = "";
|
||||||
|
String settingsFile = manager.get().getVBox().composeMachineFilename(vmSpec.getVmName(), group , flags , workingDir);
|
||||||
IMachine clonedMachine = manager
|
IMachine clonedMachine = manager
|
||||||
.get()
|
.get()
|
||||||
.getVBox()
|
.getVBox()
|
||||||
.createMachine(settingsFile, vmSpec.getVmName(), vmSpec.getOsTypeId(), vmSpec.getVmId(),
|
.createMachine(settingsFile, vmSpec.getVmName(), groups, vmSpec.getOsTypeId(), flags);
|
||||||
vmSpec.isForceOverwrite());
|
|
||||||
|
|
||||||
List<CloneOptions> options = Lists.newArrayList();
|
List<CloneOptions> options = Lists.newArrayList();
|
||||||
if (isLinkedClone)
|
if (isLinkedClone)
|
||||||
options.add(CloneOptions.Link);
|
options.add(CloneOptions.Link);
|
||||||
|
@ -112,8 +114,6 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExists implements Fu
|
||||||
IProgress progress = currentSnapshot.getMachine().cloneTo(clonedMachine,
|
IProgress progress = currentSnapshot.getMachine().cloneTo(clonedMachine,
|
||||||
CloneMode.MachineState, options);
|
CloneMode.MachineState, options);
|
||||||
progress.waitForCompletion(-1);
|
progress.waitForCompletion(-1);
|
||||||
logger.debug(String.format("Machine %s is cloned correctly",
|
|
||||||
clonedMachine.getName()));
|
|
||||||
|
|
||||||
// memory may not be the same as the master vm
|
// memory may not be the same as the master vm
|
||||||
clonedMachine.setMemorySize(cloneSpec.getVmSpec().getMemory());
|
clonedMachine.setMemorySize(cloneSpec.getVmSpec().getMemory());
|
||||||
|
@ -127,7 +127,7 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExists implements Fu
|
||||||
}
|
}
|
||||||
|
|
||||||
// set only once the creds for this machine, same coming from its master
|
// set only once the creds for this machine, same coming from its master
|
||||||
logger.debug(">> storing guest credentials on vm %s as extra data", clonedMachine.getName());
|
logger.debug("<< storing guest credentials on vm(%s) as extra data", clonedMachine.getName());
|
||||||
String masterUsername = master.getExtraData(GUEST_OS_USER);
|
String masterUsername = master.getExtraData(GUEST_OS_USER);
|
||||||
String masterPassword = master.getExtraData(GUEST_OS_PASSWORD);
|
String masterPassword = master.getExtraData(GUEST_OS_PASSWORD);
|
||||||
clonedMachine.setExtraData(GUEST_OS_USER, masterUsername);
|
clonedMachine.setExtraData(GUEST_OS_USER, masterUsername);
|
||||||
|
|
|
@ -45,17 +45,17 @@ import org.jclouds.virtualbox.domain.VmSpec;
|
||||||
import org.jclouds.virtualbox.statements.InstallGuestAdditions;
|
import org.jclouds.virtualbox.statements.InstallGuestAdditions;
|
||||||
import org.jclouds.virtualbox.util.MachineController;
|
import org.jclouds.virtualbox.util.MachineController;
|
||||||
import org.jclouds.virtualbox.util.MachineUtils;
|
import org.jclouds.virtualbox.util.MachineUtils;
|
||||||
import org.virtualbox_4_1.DeviceType;
|
import org.virtualbox_4_2.DeviceType;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.IMediumAttachment;
|
import org.virtualbox_4_2.IMediumAttachment;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
|
import com.google.common.base.Stopwatch;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.util.concurrent.Futures;
|
import com.google.common.util.concurrent.Futures;
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
import com.google.common.util.concurrent.Uninterruptibles;
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
|
@ -87,7 +87,7 @@ public class CreateAndInstallVm implements Function<MasterSpec, IMachine> {
|
||||||
this.machineUtils = machineUtils;
|
this.machineUtils = machineUtils;
|
||||||
this.imachineToNodeMetadata = imachineToNodeMetadata;
|
this.imachineToNodeMetadata = imachineToNodeMetadata;
|
||||||
this.machineController = machineController;
|
this.machineController = machineController;
|
||||||
this.version = Iterables.get(Splitter.on('r').split(version), 0);
|
this.version = Iterables.get(Splitter.on('-').split(version), 0);
|
||||||
this.preconfigurationUrl = preconfigurationUrl;
|
this.preconfigurationUrl = preconfigurationUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,31 +103,32 @@ public class CreateAndInstallVm implements Function<MasterSpec, IMachine> {
|
||||||
preconfigurationUrl);
|
preconfigurationUrl);
|
||||||
|
|
||||||
configureOsInstallationWithKeyboardSequence(masterName, installationKeySequence);
|
configureOsInstallationWithKeyboardSequence(masterName, installationKeySequence);
|
||||||
|
|
||||||
// the OS installation is a long process: let's delay the check for ssh of 40 sec
|
|
||||||
Uninterruptibles.sleepUninterruptibly(40, TimeUnit.SECONDS);
|
|
||||||
|
|
||||||
masterMachine.setExtraData(GUEST_OS_USER, masterSpec.getLoginCredentials().getUser());
|
masterMachine.setExtraData(GUEST_OS_USER, masterSpec.getLoginCredentials().getUser());
|
||||||
masterMachine.setExtraData(GUEST_OS_PASSWORD, masterSpec.getLoginCredentials().getPassword());
|
masterMachine.setExtraData(GUEST_OS_PASSWORD, masterSpec.getLoginCredentials().getPassword());
|
||||||
|
|
||||||
SshClient client = sshClientForIMachine.apply(masterMachine);
|
SshClient client = sshClientForIMachine.apply(masterMachine);
|
||||||
logger.debug(">> awaiting installation to finish node(%s)", masterName);
|
logger.debug(">> awaiting installation to finish node(%s)", masterName);
|
||||||
|
Stopwatch stopwatch = new Stopwatch();
|
||||||
|
stopwatch.start();
|
||||||
checkState(sshResponds.apply(client), "timed out waiting for guest %s to be accessible via ssh", masterName);
|
checkState(sshResponds.apply(client), "timed out waiting for guest %s to be accessible via ssh", masterName);
|
||||||
|
stopwatch.stop();
|
||||||
|
logger.debug(String.format("Elapsed time for the OS installation: %d minutes", TimeUnit.SECONDS.convert(stopwatch.elapsed(TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS)));
|
||||||
NodeMetadata nodeMetadata = imachineToNodeMetadata.apply(masterMachine);
|
NodeMetadata nodeMetadata = imachineToNodeMetadata.apply(masterMachine);
|
||||||
|
|
||||||
logger.debug(">> awaiting post-installation actions on vm: %s", masterName);
|
logger.debug(">> awaiting post-installation actions on vm: %s", masterName);
|
||||||
ListenableFuture<ExecResponse> execCleanup = machineUtils.runScriptOnNode(nodeMetadata,
|
ListenableFuture<ExecResponse> execCleanup = machineUtils.runScriptOnNode(nodeMetadata,
|
||||||
call("cleanupUdevIfNeeded"), RunScriptOptions.NONE);
|
call("cleanupUdevIfNeeded"), RunScriptOptions.NONE);
|
||||||
ExecResponse cleanupResponse = Futures.getUnchecked(execCleanup);
|
ExecResponse cleanupResponse = Futures.getUnchecked(execCleanup);
|
||||||
checkState(cleanupResponse.getExitStatus() == 0);
|
checkState(cleanupResponse.getExitStatus() == 0, "post-installation actions on vm(%s) failed", masterName);
|
||||||
|
|
||||||
logger.debug(">> awaiting installation of guest additions on vm: %s", masterName);
|
logger.debug(">> awaiting installation of guest additions on vm: %s", masterName);
|
||||||
ListenableFuture<ExecResponse> execInstallGA = machineUtils.runScriptOnNode(nodeMetadata,
|
ListenableFuture<ExecResponse> execInstallGA = machineUtils.runScriptOnNode(nodeMetadata,
|
||||||
new InstallGuestAdditions(vmSpec, version), RunScriptOptions.NONE);
|
new InstallGuestAdditions(vmSpec, version), RunScriptOptions.NONE);
|
||||||
ExecResponse gaInstallationResponse = Futures.getUnchecked(execInstallGA);
|
ExecResponse gaInstallationResponse = Futures.getUnchecked(execInstallGA);
|
||||||
checkState(gaInstallationResponse.getExitStatus() == 0);
|
checkState(gaInstallationResponse.getExitStatus() == 0, "installation of guest additions on vm(%s) failed", masterName);
|
||||||
|
|
||||||
machineController.ensureMachineIsShutdown(masterName);
|
machineController.ensureMachineIsShutdown(masterName);
|
||||||
|
|
||||||
// detach DVD and ISOs, if needed
|
// detach DVD and ISOs, if needed
|
||||||
Iterable<IMediumAttachment> mediumAttachments = Iterables.filter(
|
Iterable<IMediumAttachment> mediumAttachments = Iterables.filter(
|
||||||
|
@ -140,9 +141,9 @@ public class CreateAndInstallVm implements Function<MasterSpec, IMachine> {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
for (IMediumAttachment iMediumAttachment : mediumAttachments) {
|
for (IMediumAttachment iMediumAttachment : mediumAttachments) {
|
||||||
logger.debug("Detach %s from (%s)", iMediumAttachment.getMedium()
|
logger.debug("<< iMedium(%s) detached from (%s)", iMediumAttachment.getMedium()
|
||||||
.getName(), masterMachine.getName());
|
.getName(), masterMachine.getName());
|
||||||
machineUtils.writeLockMachineAndApply(
|
machineUtils.sharedLockMachineAndApply(
|
||||||
masterMachine.getName(),
|
masterMachine.getName(),
|
||||||
new DetachDistroMediumFromMachine(iMediumAttachment
|
new DetachDistroMediumFromMachine(iMediumAttachment
|
||||||
.getController(), iMediumAttachment.getPort(),
|
.getController(), iMediumAttachment.getPort(),
|
||||||
|
|
|
@ -23,7 +23,9 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static org.jclouds.virtualbox.util.MachineUtils.machineNotFoundException;
|
import static org.jclouds.virtualbox.util.MachineUtils.machineNotFoundException;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
@ -42,16 +44,18 @@ import org.jclouds.virtualbox.domain.NetworkSpec;
|
||||||
import org.jclouds.virtualbox.domain.StorageController;
|
import org.jclouds.virtualbox.domain.StorageController;
|
||||||
import org.jclouds.virtualbox.domain.VmSpec;
|
import org.jclouds.virtualbox.domain.VmSpec;
|
||||||
import org.jclouds.virtualbox.util.MachineUtils;
|
import org.jclouds.virtualbox.util.MachineUtils;
|
||||||
import org.virtualbox_4_1.AccessMode;
|
import org.virtualbox_4_2.AccessMode;
|
||||||
import org.virtualbox_4_1.DeviceType;
|
import org.virtualbox_4_2.DeviceType;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.IMedium;
|
import org.virtualbox_4_2.IMedium;
|
||||||
import org.virtualbox_4_1.IVirtualBox;
|
import org.virtualbox_4_2.IVirtualBox;
|
||||||
import org.virtualbox_4_1.VBoxException;
|
import org.virtualbox_4_2.VBoxException;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_2.VirtualBoxManager;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import com.google.common.util.concurrent.Uninterruptibles;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mattias Holmqvist
|
* @author Mattias Holmqvist
|
||||||
|
@ -95,10 +99,12 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExists implements Functi
|
||||||
|
|
||||||
private IMachine createMachine(IVirtualBox vBox, MasterSpec masterSpec) {
|
private IMachine createMachine(IVirtualBox vBox, MasterSpec masterSpec) {
|
||||||
VmSpec vmSpec = masterSpec.getVmSpec();
|
VmSpec vmSpec = masterSpec.getVmSpec();
|
||||||
String settingsFile = vBox.composeMachineFilename(vmSpec.getVmName(), workingDir);
|
String flags = "";
|
||||||
|
List<String> groups = Lists.newArrayList();
|
||||||
|
String group = "";
|
||||||
|
String settingsFile = manager.get().getVBox().composeMachineFilename(vmSpec.getVmName(), group , flags , workingDir);
|
||||||
|
|
||||||
IMachine newMachine = vBox.createMachine(settingsFile, vmSpec.getVmName(), vmSpec.getOsTypeId(),
|
IMachine newMachine = vBox.createMachine(settingsFile, vmSpec.getVmName(), groups, vmSpec.getOsTypeId(), flags);
|
||||||
vmSpec.getVmId(), vmSpec.isForceOverwrite());
|
|
||||||
|
|
||||||
manager.get().getVBox().registerMachine(newMachine);
|
manager.get().getVBox().registerMachine(newMachine);
|
||||||
ensureConfiguration(masterSpec);
|
ensureConfiguration(masterSpec);
|
||||||
|
@ -171,6 +177,6 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExists implements Functi
|
||||||
|
|
||||||
public void ensureMachineHasStorageControllerNamed(String vmName, StorageController storageController) {
|
public void ensureMachineHasStorageControllerNamed(String vmName, StorageController storageController) {
|
||||||
machineUtils.writeLockMachineAndApply(vmName,
|
machineUtils.writeLockMachineAndApply(vmName,
|
||||||
new AddIDEControllerIfNotExists(checkNotNull(storageController, "storageController")));
|
new AddIDEControllerIfNotExists(checkNotNull(storageController, "storageController can't be null")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,14 +27,15 @@ import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.virtualbox.domain.HardDisk;
|
import org.jclouds.virtualbox.domain.HardDisk;
|
||||||
import org.jclouds.virtualbox.util.MachineUtils;
|
import org.jclouds.virtualbox.util.MachineUtils;
|
||||||
import org.virtualbox_4_1.DeviceType;
|
import org.virtualbox_4_2.AccessMode;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.DeviceType;
|
||||||
import org.virtualbox_4_1.IMedium;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.IMediumAttachment;
|
import org.virtualbox_4_2.IMedium;
|
||||||
import org.virtualbox_4_1.IProgress;
|
import org.virtualbox_4_2.IMediumAttachment;
|
||||||
import org.virtualbox_4_1.IVirtualBox;
|
import org.virtualbox_4_2.IProgress;
|
||||||
import org.virtualbox_4_1.VBoxException;
|
import org.virtualbox_4_2.IVirtualBox;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_2.VBoxException;
|
||||||
|
import org.virtualbox_4_2.VirtualBoxManager;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
|
@ -65,7 +66,7 @@ public class CreateMediumIfNotAlreadyExists implements Function<HardDisk, IMediu
|
||||||
IVirtualBox vBox = manager.get().getVBox();
|
IVirtualBox vBox = manager.get().getVBox();
|
||||||
try {
|
try {
|
||||||
String diskPath = hardDisk.getDiskPath();
|
String diskPath = hardDisk.getDiskPath();
|
||||||
final IMedium medium = vBox.findMedium(diskPath, DeviceType.HardDisk);
|
final IMedium medium = vBox.openMedium(diskPath, DeviceType.HardDisk, AccessMode.ReadWrite, false);
|
||||||
if (overwriteIfExists) {
|
if (overwriteIfExists) {
|
||||||
try {
|
try {
|
||||||
deleteMediumAndBlockUntilComplete(medium);
|
deleteMediumAndBlockUntilComplete(medium);
|
||||||
|
@ -114,14 +115,14 @@ public class CreateMediumIfNotAlreadyExists implements Function<HardDisk, IMediu
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean notFoundException(VBoxException e) {
|
private boolean notFoundException(VBoxException e) {
|
||||||
return e.getMessage().contains("Could not find an open hard disk with location ");
|
return e.getMessage().contains("VirtualBox error: Could not find file for the medium ");
|
||||||
}
|
}
|
||||||
|
|
||||||
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,
|
IProgress storageCreation = hardDisk.createBaseStorage(size,
|
||||||
(long) org.virtualbox_4_1.jaxws.MediumVariant.STANDARD.ordinal());
|
(long) org.virtualbox_4_2.jaxws.MediumVariant.STANDARD.ordinal());
|
||||||
storageCreation.waitForCompletion(-1);
|
storageCreation.waitForCompletion(-1);
|
||||||
} catch (VBoxException e) {
|
} catch (VBoxException e) {
|
||||||
if (fileNotFoundException(e)) {
|
if (fileNotFoundException(e)) {
|
||||||
|
|
|
@ -18,8 +18,8 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.virtualbox.functions;
|
package org.jclouds.virtualbox.functions;
|
||||||
|
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.VBoxException;
|
import org.virtualbox_4_2.VBoxException;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
|
|
|
@ -26,9 +26,9 @@ import org.jclouds.compute.domain.HardwareBuilder;
|
||||||
import org.jclouds.compute.predicates.ImagePredicates;
|
import org.jclouds.compute.predicates.ImagePredicates;
|
||||||
import org.jclouds.javax.annotation.Nullable;
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
import org.jclouds.virtualbox.config.VirtualBoxConstants;
|
import org.jclouds.virtualbox.config.VirtualBoxConstants;
|
||||||
import org.virtualbox_4_1.IGuestOSType;
|
import org.virtualbox_4_2.IGuestOSType;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_2.VirtualBoxManager;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
|
|
|
@ -35,10 +35,10 @@ import org.jclouds.compute.domain.OperatingSystem;
|
||||||
import org.jclouds.compute.domain.OsFamily;
|
import org.jclouds.compute.domain.OsFamily;
|
||||||
import org.jclouds.javax.annotation.Nullable;
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
import org.jclouds.virtualbox.config.VirtualBoxConstants;
|
import org.jclouds.virtualbox.config.VirtualBoxConstants;
|
||||||
import org.virtualbox_4_1.IGuestOSType;
|
import org.virtualbox_4_2.IGuestOSType;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.MachineState;
|
import org.virtualbox_4_2.MachineState;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_2.VirtualBoxManager;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
|
|
|
@ -25,9 +25,9 @@ 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;
|
||||||
import org.jclouds.virtualbox.config.VirtualBoxConstants;
|
import org.jclouds.virtualbox.config.VirtualBoxConstants;
|
||||||
import org.virtualbox_4_1.IGuestOSType;
|
import org.virtualbox_4_2.IGuestOSType;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_2.VirtualBoxManager;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
|
@ -50,8 +50,7 @@ public class IMachineToIpAddress implements Function<IMachine, String> {
|
||||||
public String apply(IMachine machine) {
|
public String apply(IMachine machine) {
|
||||||
|
|
||||||
String macAddress = machine.getNetworkAdapter(0l).getMACAddress();
|
String macAddress = machine.getNetworkAdapter(0l).getMACAddress();
|
||||||
int offset = 0;
|
int offset = 0, step = 2;
|
||||||
int step = 2;
|
|
||||||
for (int j = 1; j <= 5; j++) {
|
for (int j = 1; j <= 5; j++) {
|
||||||
macAddress = new StringBuilder(macAddress).insert(j * step + offset, ":").toString().toLowerCase();
|
macAddress = new StringBuilder(macAddress).insert(j * step + offset, ":").toString().toLowerCase();
|
||||||
offset++;
|
offset++;
|
||||||
|
|
|
@ -19,6 +19,9 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions;
|
package org.jclouds.virtualbox.functions;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static org.jclouds.compute.util.ComputeServiceUtils.parseOsFamilyOrUnrecognized;
|
||||||
|
import static org.jclouds.compute.util.ComputeServiceUtils.parseVersionOrReturnEmptyString;
|
||||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.GUEST_OS_PASSWORD;
|
import static org.jclouds.virtualbox.config.VirtualBoxConstants.GUEST_OS_PASSWORD;
|
||||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.GUEST_OS_USER;
|
import static org.jclouds.virtualbox.config.VirtualBoxConstants.GUEST_OS_USER;
|
||||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_NODE_NAME_SEPARATOR;
|
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_NODE_NAME_SEPARATOR;
|
||||||
|
@ -31,6 +34,8 @@ import javax.annotation.Resource;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
import org.jclouds.compute.domain.NodeMetadata;
|
||||||
|
import org.jclouds.compute.domain.OperatingSystem;
|
||||||
|
import org.jclouds.compute.domain.OsFamily;
|
||||||
import org.jclouds.compute.domain.NodeMetadata.Status;
|
import org.jclouds.compute.domain.NodeMetadata.Status;
|
||||||
import org.jclouds.compute.domain.NodeMetadataBuilder;
|
import org.jclouds.compute.domain.NodeMetadataBuilder;
|
||||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||||
|
@ -40,13 +45,16 @@ import org.jclouds.domain.LoginCredentials;
|
||||||
import org.jclouds.javax.annotation.Nullable;
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.virtualbox.util.NetworkUtils;
|
import org.jclouds.virtualbox.util.NetworkUtils;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IGuestOSType;
|
||||||
import org.virtualbox_4_1.INetworkAdapter;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.MachineState;
|
import org.virtualbox_4_2.INetworkAdapter;
|
||||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
import org.virtualbox_4_2.MachineState;
|
||||||
|
import org.virtualbox_4_2.NetworkAttachmentType;
|
||||||
|
import org.virtualbox_4_2.VirtualBoxManager;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
@ -59,14 +67,18 @@ public class IMachineToNodeMetadata implements Function<IMachine, NodeMetadata>
|
||||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
|
private final Supplier<VirtualBoxManager> virtualboxManager;
|
||||||
private final Map<MachineState, Status> toPortableNodeStatus;
|
private final Map<MachineState, Status> toPortableNodeStatus;
|
||||||
private final NetworkUtils networkUtils;
|
private final NetworkUtils networkUtils;
|
||||||
|
private final Map<OsFamily, Map<String, String>> osVersionMap;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public IMachineToNodeMetadata(Map<MachineState, NodeMetadata.Status> toPortableNodeStatus,
|
public IMachineToNodeMetadata(Supplier<VirtualBoxManager> virtualboxManager, Map<MachineState, NodeMetadata.Status> toPortableNodeStatus,
|
||||||
NetworkUtils networkUtils) {
|
NetworkUtils networkUtils, Map<OsFamily, Map<String, String>> osVersionMap) {
|
||||||
this.toPortableNodeStatus = toPortableNodeStatus;
|
this.virtualboxManager = checkNotNull(virtualboxManager, "virtualboxManager");
|
||||||
this.networkUtils = networkUtils;
|
this.toPortableNodeStatus = checkNotNull(toPortableNodeStatus, "toPortableNodeStatus");
|
||||||
|
this.networkUtils = checkNotNull(networkUtils, "networkUtils");
|
||||||
|
this.osVersionMap = checkNotNull(osVersionMap, "osVersionMap");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -98,6 +110,13 @@ public class IMachineToNodeMetadata implements Function<IMachine, NodeMetadata>
|
||||||
nodeState = Status.UNRECOGNIZED;
|
nodeState = Status.UNRECOGNIZED;
|
||||||
nodeMetadataBuilder.status(nodeState);
|
nodeMetadataBuilder.status(nodeState);
|
||||||
nodeMetadataBuilder = getIpAddresses(vm, nodeMetadataBuilder);
|
nodeMetadataBuilder = getIpAddresses(vm, nodeMetadataBuilder);
|
||||||
|
|
||||||
|
IGuestOSType guestOSType = virtualboxManager.get().getVBox().getGuestOSType(vm.getOSTypeId());
|
||||||
|
OsFamily family = parseOsFamilyOrUnrecognized(guestOSType.getDescription());
|
||||||
|
String version = parseVersionOrReturnEmptyString(family, guestOSType.getDescription(), osVersionMap);
|
||||||
|
OperatingSystem os = OperatingSystem.builder().description(guestOSType.getDescription()).family(family)
|
||||||
|
.version(version).is64Bit(guestOSType.getIs64Bit()).build();
|
||||||
|
nodeMetadataBuilder.operatingSystem(os);
|
||||||
|
|
||||||
String guestOsUser = vm.getExtraData(GUEST_OS_USER);
|
String guestOsUser = vm.getExtraData(GUEST_OS_USER);
|
||||||
String guestOsPassword = vm.getExtraData(GUEST_OS_PASSWORD);
|
String guestOsPassword = vm.getExtraData(GUEST_OS_PASSWORD);
|
||||||
|
@ -114,11 +133,11 @@ public class IMachineToNodeMetadata implements Function<IMachine, NodeMetadata>
|
||||||
INetworkAdapter adapter = vm.getNetworkAdapter(slot);
|
INetworkAdapter adapter = vm.getNetworkAdapter(slot);
|
||||||
if(adapter != null) {
|
if(adapter != null) {
|
||||||
if (adapter.getAttachmentType() == NetworkAttachmentType.NAT) {
|
if (adapter.getAttachmentType() == NetworkAttachmentType.NAT) {
|
||||||
String hostIP = adapter.getNatDriver().getHostIP();
|
String hostIP = adapter.getNATEngine().getHostIP();
|
||||||
if(!hostIP.isEmpty())
|
if(!hostIP.isEmpty())
|
||||||
publicIpAddresses.add(hostIP);
|
publicIpAddresses.add(hostIP);
|
||||||
for (String nameProtocolnumberAddressInboundportGuestTargetport : adapter.getNatDriver().getRedirects()) {
|
for (String nameProtocolnumberAddressInboudportGuestTargetport : adapter.getNATEngine().getRedirects()) {
|
||||||
Iterable<String> stuff = Splitter.on(',').split(nameProtocolnumberAddressInboundportGuestTargetport);
|
Iterable<String> stuff = Splitter.on(',').split(nameProtocolnumberAddressInboudportGuestTargetport);
|
||||||
String protocolNumber = Iterables.get(stuff, 1);
|
String protocolNumber = Iterables.get(stuff, 1);
|
||||||
String hostAddress = Iterables.get(stuff, 2);
|
String hostAddress = Iterables.get(stuff, 2);
|
||||||
String inboundPort = Iterables.get(stuff, 3);
|
String inboundPort = Iterables.get(stuff, 3);
|
||||||
|
@ -130,13 +149,11 @@ public class IMachineToNodeMetadata implements Function<IMachine, NodeMetadata>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (adapter.getAttachmentType() == NetworkAttachmentType.Bridged) {
|
} else if (adapter.getAttachmentType() == NetworkAttachmentType.Bridged) {
|
||||||
// TODO quick test first
|
|
||||||
String clientIpAddress = networkUtils.getIpAddressFromNicSlot(vm.getName(), adapter.getSlot());
|
String clientIpAddress = networkUtils.getIpAddressFromNicSlot(vm.getName(), adapter.getSlot());
|
||||||
privateIpAddresses.add(clientIpAddress);
|
privateIpAddresses.add(clientIpAddress);
|
||||||
|
|
||||||
} else if (adapter.getAttachmentType() == NetworkAttachmentType.HostOnly) {
|
} else if (adapter.getAttachmentType() == NetworkAttachmentType.HostOnly) {
|
||||||
// TODO quick test first
|
String clientIpAddress = networkUtils.getValidHostOnlyIpFromVm(vm.getName());
|
||||||
String clientIpAddress = networkUtils.getIpAddressFromNicSlot(vm.getName(), adapter.getSlot());
|
|
||||||
publicIpAddresses.add(clientIpAddress);
|
publicIpAddresses.add(clientIpAddress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.virtualbox.functions;
|
package org.jclouds.virtualbox.functions;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
|
||||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.GUEST_OS_PASSWORD;
|
import static org.jclouds.virtualbox.config.VirtualBoxConstants.GUEST_OS_PASSWORD;
|
||||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.GUEST_OS_USER;
|
import static org.jclouds.virtualbox.config.VirtualBoxConstants.GUEST_OS_USER;
|
||||||
|
|
||||||
|
@ -31,12 +30,13 @@ import org.jclouds.domain.LoginCredentials;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.ssh.SshClient;
|
import org.jclouds.ssh.SshClient;
|
||||||
import org.jclouds.virtualbox.util.NetworkUtils;
|
import org.jclouds.virtualbox.util.NetworkUtils;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.INetworkAdapter;
|
import org.virtualbox_4_2.INetworkAdapter;
|
||||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
import org.virtualbox_4_2.NetworkAttachmentType;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.net.HostAndPort;
|
import com.google.common.net.HostAndPort;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
@ -44,65 +44,55 @@ import com.google.inject.Inject;
|
||||||
@Singleton
|
@Singleton
|
||||||
public class IMachineToSshClient implements Function<IMachine, SshClient> {
|
public class IMachineToSshClient implements Function<IMachine, SshClient> {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
private final SshClient.Factory sshClientFactory;
|
private final SshClient.Factory sshClientFactory;
|
||||||
private final NetworkUtils networkUtils;
|
private final NetworkUtils networkUtils;
|
||||||
|
|
||||||
@Inject
|
|
||||||
public IMachineToSshClient(SshClient.Factory sshClientFactory,
|
|
||||||
NetworkUtils networkUtils) {
|
|
||||||
this.sshClientFactory = sshClientFactory;
|
|
||||||
this.networkUtils = networkUtils;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Inject
|
||||||
|
public IMachineToSshClient(SshClient.Factory sshClientFactory, NetworkUtils networkUtils) {
|
||||||
|
this.sshClientFactory = sshClientFactory;
|
||||||
|
this.networkUtils = networkUtils;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public SshClient apply(final IMachine vm) {
|
public SshClient apply(final IMachine vm) {
|
||||||
INetworkAdapter networkAdapter = vm.getNetworkAdapter(0L);
|
|
||||||
|
|
||||||
SshClient client = null;
|
|
||||||
checkNotNull(networkAdapter);
|
|
||||||
|
|
||||||
String clientIpAddress = null;
|
|
||||||
String sshPort = "22";
|
String sshPort = "22";
|
||||||
String guestIdentity = vm.getExtraData(GUEST_OS_USER);
|
String guestIdentity = vm.getExtraData(GUEST_OS_USER);
|
||||||
String guestCredential = vm.getExtraData(GUEST_OS_PASSWORD);
|
String guestCredential = vm.getExtraData(GUEST_OS_PASSWORD);
|
||||||
|
LoginCredentials loginCredentials = LoginCredentials.builder().user(guestIdentity).password(guestCredential)
|
||||||
LoginCredentials loginCredentials = LoginCredentials.builder()
|
|
||||||
.user(guestIdentity).password(guestCredential)
|
|
||||||
.authenticateSudo(true).build();
|
.authenticateSudo(true).build();
|
||||||
|
|
||||||
if (networkAdapter.getAttachmentType()
|
String clientIpAddress = null;
|
||||||
.equals(NetworkAttachmentType.NAT)) {
|
|
||||||
for (String nameProtocolnumberAddressInboundPortGuestTargetport : networkAdapter
|
|
||||||
.getNatDriver().getRedirects()) {
|
|
||||||
Iterable<String> stuff = Splitter.on(',').split(
|
|
||||||
nameProtocolnumberAddressInboundPortGuestTargetport);
|
|
||||||
String protocolNumber = Iterables.get(stuff, 1);
|
|
||||||
String hostAddress = Iterables.get(stuff, 2);
|
|
||||||
String inboundPort = Iterables.get(stuff, 3);
|
|
||||||
String targetPort = Iterables.get(stuff, 5);
|
|
||||||
if ("1".equals(protocolNumber) && "22".equals(targetPort)) {
|
|
||||||
clientIpAddress = hostAddress;
|
|
||||||
sshPort = inboundPort;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (networkAdapter.getAttachmentType().equals(
|
|
||||||
NetworkAttachmentType.Bridged)) {
|
|
||||||
clientIpAddress = networkUtils.getIpAddressFromNicSlot(vm.getName(), networkAdapter.getSlot());
|
|
||||||
} else if (networkAdapter.getAttachmentType().equals(
|
|
||||||
NetworkAttachmentType.HostOnly)) {
|
|
||||||
clientIpAddress = networkUtils.getIpAddressFromNicSlot(vm.getName(), networkAdapter.getSlot());
|
|
||||||
}
|
|
||||||
|
|
||||||
checkNotNull(clientIpAddress, "clientIpAddress");
|
|
||||||
client = sshClientFactory.create(
|
|
||||||
HostAndPort.fromParts(clientIpAddress, Integer.parseInt(sshPort)),
|
|
||||||
loginCredentials);
|
|
||||||
checkNotNull(client);
|
|
||||||
return client;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
long nicSlot = 0;
|
||||||
|
while (nicSlot < 4 && Strings.isNullOrEmpty(clientIpAddress)) {
|
||||||
|
INetworkAdapter networkAdapter = vm.getNetworkAdapter(nicSlot);
|
||||||
|
|
||||||
|
if (networkAdapter.getAttachmentType().equals(NetworkAttachmentType.NAT)) {
|
||||||
|
for (String nameProtocolnumberAddressInboudportGuestTargetport : networkAdapter.getNATEngine()
|
||||||
|
.getRedirects()) {
|
||||||
|
Iterable<String> stuff = Splitter.on(',').split(nameProtocolnumberAddressInboudportGuestTargetport);
|
||||||
|
String protocolNumber = Iterables.get(stuff, 1);
|
||||||
|
String hostAddress = Iterables.get(stuff, 2);
|
||||||
|
String inboundPort = Iterables.get(stuff, 3);
|
||||||
|
String targetPort = Iterables.get(stuff, 5);
|
||||||
|
if ("1".equals(protocolNumber) && "22".equals(targetPort)) {
|
||||||
|
clientIpAddress = hostAddress;
|
||||||
|
sshPort = inboundPort;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (networkAdapter.getAttachmentType().equals(NetworkAttachmentType.Bridged)) {
|
||||||
|
clientIpAddress = networkUtils.getIpAddressFromNicSlot(vm.getName(), networkAdapter.getSlot());
|
||||||
|
} else if (networkAdapter.getAttachmentType().equals(NetworkAttachmentType.HostOnly)) {
|
||||||
|
clientIpAddress = networkUtils.getValidHostOnlyIpFromVm(vm.getName());
|
||||||
|
}
|
||||||
|
nicSlot++;
|
||||||
|
}
|
||||||
|
return sshClientFactory.create(HostAndPort.fromParts(clientIpAddress, Integer.parseInt(sshPort)),
|
||||||
|
loginCredentials);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -30,12 +30,12 @@ import org.jclouds.virtualbox.domain.HardDisk;
|
||||||
import org.jclouds.virtualbox.domain.StorageController;
|
import org.jclouds.virtualbox.domain.StorageController;
|
||||||
import org.jclouds.virtualbox.domain.StorageController.Builder;
|
import org.jclouds.virtualbox.domain.StorageController.Builder;
|
||||||
import org.jclouds.virtualbox.domain.VmSpec;
|
import org.jclouds.virtualbox.domain.VmSpec;
|
||||||
import org.virtualbox_4_1.CleanupMode;
|
import org.virtualbox_4_2.CleanupMode;
|
||||||
import org.virtualbox_4_1.DeviceType;
|
import org.virtualbox_4_2.DeviceType;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.IMedium;
|
import org.virtualbox_4_2.IMedium;
|
||||||
import org.virtualbox_4_1.IMediumAttachment;
|
import org.virtualbox_4_2.IMediumAttachment;
|
||||||
import org.virtualbox_4_1.IStorageController;
|
import org.virtualbox_4_2.IStorageController;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
|
@ -23,7 +23,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
@ -33,14 +32,13 @@ import javax.inject.Singleton;
|
||||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.virtualbox.util.MachineNameOrIdAndNicSlot;
|
import org.jclouds.virtualbox.util.MachineNameOrIdAndNicSlot;
|
||||||
import org.jclouds.virtualbox.util.NetworkUtils;
|
import org.virtualbox_4_2.VirtualBoxManager;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
|
||||||
|
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.cache.AbstractLoadingCache;
|
import com.google.common.cache.AbstractLoadingCache;
|
||||||
|
import com.google.common.cache.LoadingCache;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.util.concurrent.Uninterruptibles;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link LoadingCache} for ip addresses. If the requested ip address has been
|
* A {@link LoadingCache} for ip addresses. If the requested ip address has been
|
||||||
|
@ -71,19 +69,12 @@ public class IpAddressesLoadingCache extends
|
||||||
return masters.get(machineNameOrIdAndNicPort);
|
return masters.get(machineNameOrIdAndNicPort);
|
||||||
}
|
}
|
||||||
String query = String.format("/VirtualBox/GuestInfo/Net/%s/V4/IP", machineNameOrIdAndNicPort.getSlotText());
|
String query = String.format("/VirtualBox/GuestInfo/Net/%s/V4/IP", machineNameOrIdAndNicPort.getSlotText());
|
||||||
String currentIp = "";
|
String ipAddress = Strings.nullToEmpty(manager.get().getVBox()
|
||||||
while (!NetworkUtils.isIpv4(currentIp)) {
|
.findMachine(machineNameOrIdAndNicPort.getMachineNameOrId()).getGuestPropertyValue(query));
|
||||||
currentIp = manager.get().getVBox().findMachine(machineNameOrIdAndNicPort.getMachineNameOrId())
|
logger.debug("<< vm(%s) has IP address(%s) at slot(%s)", machineNameOrIdAndNicPort.getMachineNameOrId(),
|
||||||
.getGuestPropertyValue(query);
|
ipAddress, machineNameOrIdAndNicPort.getSlotText());
|
||||||
if(!Strings.nullToEmpty(currentIp).isEmpty())
|
masters.put(machineNameOrIdAndNicPort, ipAddress);
|
||||||
logger.debug("Found IP address %s for '%s' at slot %s", currentIp,
|
return ipAddress;
|
||||||
machineNameOrIdAndNicPort.getMachineNameOrId(),
|
|
||||||
machineNameOrIdAndNicPort.getSlotText());
|
|
||||||
Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
|
|
||||||
}
|
|
||||||
|
|
||||||
masters.put(machineNameOrIdAndNicPort, currentIp);
|
|
||||||
return currentIp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -27,12 +27,12 @@ import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.virtualbox.domain.ErrorCode;
|
import org.jclouds.virtualbox.domain.ErrorCode;
|
||||||
import org.jclouds.virtualbox.domain.ExecutionType;
|
import org.jclouds.virtualbox.domain.ExecutionType;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.IProgress;
|
import org.virtualbox_4_2.IProgress;
|
||||||
import org.virtualbox_4_1.ISession;
|
import org.virtualbox_4_2.ISession;
|
||||||
import org.virtualbox_4_1.SessionState;
|
import org.virtualbox_4_2.SessionState;
|
||||||
import org.virtualbox_4_1.VBoxException;
|
import org.virtualbox_4_2.VBoxException;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_2.VirtualBoxManager;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
|
|
|
@ -69,23 +69,27 @@ import org.jclouds.virtualbox.domain.VmSpec;
|
||||||
import org.jclouds.virtualbox.domain.YamlImage;
|
import org.jclouds.virtualbox.domain.YamlImage;
|
||||||
import org.jclouds.virtualbox.functions.admin.PreseedCfgServer;
|
import org.jclouds.virtualbox.functions.admin.PreseedCfgServer;
|
||||||
import org.jclouds.virtualbox.predicates.RetryIfSocketNotYetOpen;
|
import org.jclouds.virtualbox.predicates.RetryIfSocketNotYetOpen;
|
||||||
|
import org.jclouds.virtualbox.statements.Md5;
|
||||||
import org.jclouds.virtualbox.util.NetworkUtils;
|
import org.jclouds.virtualbox.util.NetworkUtils;
|
||||||
import org.virtualbox_4_1.CleanupMode;
|
import org.virtualbox_4_2.CleanupMode;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
import org.virtualbox_4_2.NetworkAttachmentType;
|
||||||
import org.virtualbox_4_1.StorageBus;
|
import org.virtualbox_4_2.StorageBus;
|
||||||
import org.virtualbox_4_1.VBoxException;
|
import org.virtualbox_4_2.VBoxException;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_2.VirtualBoxManager;
|
||||||
|
|
||||||
import com.google.common.base.CaseFormat;
|
import com.google.common.base.CaseFormat;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.cache.AbstractLoadingCache;
|
import com.google.common.cache.AbstractLoadingCache;
|
||||||
|
import com.google.common.cache.LoadingCache;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.net.HostAndPort;
|
import com.google.common.net.HostAndPort;
|
||||||
|
import com.google.common.util.concurrent.Futures;
|
||||||
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link LoadingCache} for masters. If the requested master has been
|
* A {@link LoadingCache} for masters. If the requested master has been
|
||||||
|
@ -100,218 +104,181 @@ import com.google.common.net.HostAndPort;
|
||||||
@Singleton
|
@Singleton
|
||||||
public class MastersLoadingCache extends AbstractLoadingCache<Image, Master> {
|
public class MastersLoadingCache extends AbstractLoadingCache<Image, Master> {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
private final Map<String, Master> masters = Maps.newHashMap();
|
private final Map<String, Master> masters = Maps.newHashMap();
|
||||||
private final Function<MasterSpec, IMachine> masterCreatorAndInstaller;
|
private final Function<MasterSpec, IMachine> masterCreatorAndInstaller;
|
||||||
private final Map<String, YamlImage> imageMapping;
|
private final Map<String, YamlImage> imageMapping;
|
||||||
private final String workingDir;
|
private final String workingDir;
|
||||||
private final String installationKeySequence;
|
private final String installationKeySequence;
|
||||||
private final String isosDir;
|
private final String isosDir;
|
||||||
private final Supplier<VirtualBoxManager> manager;
|
private final Supplier<VirtualBoxManager> manager;
|
||||||
private final String version;
|
private final String version;
|
||||||
private final String preconfigurationUrl;
|
private final String preconfigurationUrl;
|
||||||
|
|
||||||
private final Factory runScriptOnNodeFactory;
|
private final Factory runScriptOnNodeFactory;
|
||||||
private final RetryIfSocketNotYetOpen socketTester;
|
private final RetryIfSocketNotYetOpen socketTester;
|
||||||
private final Supplier<NodeMetadata> host;
|
private final Supplier<NodeMetadata> host;
|
||||||
private final Supplier<URI> providerSupplier;
|
private final Supplier<URI> providerSupplier;
|
||||||
private final HardcodedHostToHostNodeMetadata hardcodedHostToHostNodeMetadata;
|
private final HardcodedHostToHostNodeMetadata hardcodedHostToHostNodeMetadata;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public MastersLoadingCache(
|
public MastersLoadingCache(@BuildVersion String version,
|
||||||
@BuildVersion String version,
|
@Named(VIRTUALBOX_INSTALLATION_KEY_SEQUENCE) String installationKeySequence,
|
||||||
@Named(VIRTUALBOX_INSTALLATION_KEY_SEQUENCE) String installationKeySequence,
|
@Named(VIRTUALBOX_PRECONFIGURATION_URL) String preconfigurationUrl,
|
||||||
@Named(VIRTUALBOX_PRECONFIGURATION_URL) String preconfigurationUrl,
|
@Named(VIRTUALBOX_WORKINGDIR) String workingDir, Function<MasterSpec, IMachine> masterLoader,
|
||||||
@Named(VIRTUALBOX_WORKINGDIR) String workingDir,
|
Supplier<Map<Image, YamlImage>> yamlMapper, Supplier<VirtualBoxManager> manager,
|
||||||
Function<MasterSpec, IMachine> masterLoader,
|
Factory runScriptOnNodeFactory, RetryIfSocketNotYetOpen socketTester, Supplier<NodeMetadata> host,
|
||||||
Supplier<Map<Image, YamlImage>> yamlMapper,
|
@Provider Supplier<URI> providerSupplier, HardcodedHostToHostNodeMetadata hardcodedHostToHostNodeMetadata) {
|
||||||
Supplier<VirtualBoxManager> manager,
|
this.manager = checkNotNull(manager, "vboxmanager can't be null");
|
||||||
Factory runScriptOnNodeFactory,
|
this.masterCreatorAndInstaller = masterLoader;
|
||||||
RetryIfSocketNotYetOpen socketTester, Supplier<NodeMetadata> host,
|
this.installationKeySequence = checkNotNull(installationKeySequence, "installationKeySequence can't be null");
|
||||||
@Provider Supplier<URI> providerSupplier,
|
this.workingDir = workingDir == null ? VIRTUALBOX_DEFAULT_DIR : workingDir;
|
||||||
HardcodedHostToHostNodeMetadata hardcodedHostToHostNodeMetadata) {
|
this.isosDir = workingDir + File.separator + "isos";
|
||||||
checkNotNull(version, "version");
|
this.imageMapping = Maps.newLinkedHashMap();
|
||||||
checkNotNull(installationKeySequence, "installationKeySequence");
|
for (Entry<Image, YamlImage> entry : yamlMapper.get().entrySet()) {
|
||||||
checkNotNull(manager, "vboxmanager");
|
this.imageMapping.put(entry.getKey().getId(), entry.getValue());
|
||||||
this.manager = manager;
|
}
|
||||||
this.masterCreatorAndInstaller = masterLoader;
|
this.version = Iterables.get(Splitter.on('r').split(checkNotNull(version, "version")), 0);
|
||||||
this.installationKeySequence = installationKeySequence;
|
this.preconfigurationUrl = preconfigurationUrl;
|
||||||
this.workingDir = workingDir == null ? VIRTUALBOX_DEFAULT_DIR
|
|
||||||
: workingDir;
|
|
||||||
this.isosDir = workingDir + File.separator + "isos";
|
|
||||||
this.imageMapping = Maps.newLinkedHashMap();
|
|
||||||
for (Entry<Image, YamlImage> entry : yamlMapper.get().entrySet()) {
|
|
||||||
this.imageMapping.put(entry.getKey().getId(), entry.getValue());
|
|
||||||
}
|
|
||||||
this.version = Iterables.get(Splitter.on('r').split(version), 0);
|
|
||||||
this.preconfigurationUrl = preconfigurationUrl;
|
|
||||||
|
|
||||||
this.runScriptOnNodeFactory = checkNotNull(runScriptOnNodeFactory,
|
this.runScriptOnNodeFactory = checkNotNull(runScriptOnNodeFactory, "runScriptOnNodeFactory");
|
||||||
"runScriptOnNodeFactory");
|
this.socketTester = checkNotNull(socketTester, "socketTester");
|
||||||
this.socketTester = checkNotNull(socketTester, "socketTester");
|
this.socketTester.seconds(3L);
|
||||||
this.socketTester.seconds(3L);
|
this.host = checkNotNull(host, "host");
|
||||||
this.host = checkNotNull(host, "host");
|
this.providerSupplier = checkNotNull(providerSupplier, "endpoint to virtualbox websrvd is needed");
|
||||||
this.providerSupplier = checkNotNull(providerSupplier,
|
this.hardcodedHostToHostNodeMetadata = hardcodedHostToHostNodeMetadata;
|
||||||
"endpoint to virtualbox websrvd is needed");
|
}
|
||||||
this.hardcodedHostToHostNodeMetadata = hardcodedHostToHostNodeMetadata;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void createCacheDirStructure() {
|
public void createCacheDirStructure() {
|
||||||
if (!new File(workingDir).exists()) {
|
if (!new File(workingDir).exists()) {
|
||||||
new File(workingDir, "isos").mkdirs();
|
new File(workingDir, "isos").mkdirs();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized Master get(Image key) throws ExecutionException {
|
public synchronized Master get(Image key) throws ExecutionException {
|
||||||
// check if we have loaded this machine before
|
// check if we have loaded this machine before
|
||||||
if (masters.containsKey(key.getId())) {
|
if (masters.containsKey(key.getId())) {
|
||||||
return masters.get(key.getId());
|
return masters.get(key.getId());
|
||||||
}
|
}
|
||||||
checkState(!key.getId().contains(VIRTUALBOX_NODE_NAME_SEPARATOR),
|
checkState(!key.getId().contains(VIRTUALBOX_NODE_NAME_SEPARATOR), "master image names cannot contain \""
|
||||||
"master image names cannot contain \""
|
+ VIRTUALBOX_NODE_NAME_SEPARATOR + "\"");
|
||||||
+ VIRTUALBOX_NODE_NAME_SEPARATOR + "\"");
|
String vmName = VIRTUALBOX_IMAGE_PREFIX + key.getId();
|
||||||
String vmName = VIRTUALBOX_IMAGE_PREFIX + key.getId();
|
IMachine masterMachine;
|
||||||
IMachine masterMachine;
|
Master master;
|
||||||
Master master;
|
// ready the preseed file server
|
||||||
// ready the preseed file server
|
PreseedCfgServer server = new PreseedCfgServer();
|
||||||
PreseedCfgServer server = new PreseedCfgServer();
|
try {
|
||||||
try {
|
// try and find a master machine in vbox
|
||||||
// try and find a master machine in vbox
|
masterMachine = manager.get().getVBox().findMachine(vmName);
|
||||||
masterMachine = manager.get().getVBox().findMachine(vmName);
|
master = Master.builder().machine(masterMachine).build();
|
||||||
master = Master.builder().machine(masterMachine).build();
|
} catch (VBoxException e) {
|
||||||
} catch (VBoxException e) {
|
if (machineNotFoundException(e)) {
|
||||||
if (machineNotFoundException(e)) {
|
// machine was not found try to build one from a yaml file
|
||||||
// machine was not found try to build one from a yaml file
|
YamlImage currentImage = checkNotNull(imageMapping.get(key.getId()), "currentImage");
|
||||||
YamlImage currentImage = checkNotNull(imageMapping.get(key.getId()), "currentImage");
|
URI preseedServer;
|
||||||
URI preseedServer;
|
|
||||||
try {
|
try {
|
||||||
preseedServer = new URI(preconfigurationUrl);
|
preseedServer = new URI(preconfigurationUrl);
|
||||||
if (!socketTester.apply(HostAndPort.fromParts(preseedServer.getHost(),
|
if (!socketTester.apply(HostAndPort.fromParts(preseedServer.getHost(), preseedServer.getPort()))) {
|
||||||
preseedServer.getPort()))) {
|
|
||||||
server.start(preconfigurationUrl, currentImage.preseed_cfg);
|
server.start(preconfigurationUrl, currentImage.preseed_cfg);
|
||||||
}
|
}
|
||||||
} catch (URISyntaxException e1) {
|
} catch (URISyntaxException e1) {
|
||||||
logger.error("Cannot start the preseed server", e);
|
logger.error("Cannot start the preseed server", e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
MasterSpec masterSpec = buildMasterSpecFromYaml(currentImage,
|
|
||||||
vmName);
|
|
||||||
masterMachine = masterCreatorAndInstaller.apply(masterSpec);
|
|
||||||
master = Master.builder().machine(masterMachine)
|
|
||||||
.spec(masterSpec).build();
|
|
||||||
} else {
|
|
||||||
logger.error("Problem during master creation", e);
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
server.stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
masters.put(key.getId(), master);
|
MasterSpec masterSpec = buildMasterSpecFromYaml(currentImage, vmName);
|
||||||
return master;
|
masterMachine = masterCreatorAndInstaller.apply(masterSpec);
|
||||||
}
|
master = Master.builder().machine(masterMachine).spec(masterSpec).build();
|
||||||
|
} else {
|
||||||
|
logger.error("Problem during master creation", e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
server.stop();
|
||||||
|
}
|
||||||
|
|
||||||
private MasterSpec buildMasterSpecFromYaml(YamlImage currentImage,
|
masters.put(key.getId(), master);
|
||||||
String vmName) throws ExecutionException {
|
return master;
|
||||||
String guestAdditionsFileName = String.format(
|
}
|
||||||
"VBoxGuestAdditions_%s.iso", version);
|
|
||||||
String guestAdditionsIso = String.format("%s/%s", isosDir,
|
|
||||||
guestAdditionsFileName);
|
|
||||||
String guestAdditionsUri = "http://download.virtualbox.org/virtualbox/"
|
|
||||||
+ version + "/" + guestAdditionsFileName;
|
|
||||||
if (!new File(guestAdditionsIso).exists()) {
|
|
||||||
getFilePathOrDownload(guestAdditionsUri, null);
|
|
||||||
}
|
|
||||||
// check if the iso is here, download if not
|
|
||||||
String localIsoUrl = checkNotNull(getFilePathOrDownload(currentImage.iso, currentImage.iso_md5), "distro iso");
|
|
||||||
String adminDisk = workingDir + File.separator + vmName + ".vdi";
|
|
||||||
HardDisk hardDisk = HardDisk.builder().diskpath(adminDisk)
|
|
||||||
.autoDelete(true).controllerPort(0).deviceSlot(1).build();
|
|
||||||
|
|
||||||
StorageController ideController = StorageController.builder()
|
private MasterSpec buildMasterSpecFromYaml(YamlImage currentImage, String vmName) throws ExecutionException {
|
||||||
.name("IDE Controller").bus(StorageBus.IDE)
|
String guestAdditionsFileName = String.format("VBoxGuestAdditions_%s.iso", version);
|
||||||
.attachISO(0, 0, localIsoUrl).attachHardDisk(hardDisk)
|
String guestAdditionsIso = String.format("%s/%s", isosDir, guestAdditionsFileName);
|
||||||
.attachISO(1, 0, guestAdditionsIso).build();
|
String guestAdditionsUri = "http://download.virtualbox.org/virtualbox/" + version + "/" + guestAdditionsFileName;
|
||||||
|
if (!new File(guestAdditionsIso).exists()) {
|
||||||
|
getFilePathOrDownload(guestAdditionsUri, null);
|
||||||
|
}
|
||||||
|
// check if the iso is here, download if not
|
||||||
|
String localIsoUrl = checkNotNull(getFilePathOrDownload(currentImage.iso, currentImage.iso_md5), "distro iso");
|
||||||
|
String adminDisk = workingDir + File.separator + vmName + ".vdi";
|
||||||
|
HardDisk hardDisk = HardDisk.builder().diskpath(adminDisk).autoDelete(true).controllerPort(0).deviceSlot(1)
|
||||||
|
.build();
|
||||||
|
|
||||||
VmSpec vmSpecification = VmSpec.builder().id(currentImage.id)
|
StorageController ideController = StorageController.builder().name("IDE Controller").bus(StorageBus.IDE)
|
||||||
.name(vmName).memoryMB(512).osTypeId(getOsTypeId(currentImage.os_family, currentImage.os_64bit))
|
.attachISO(0, 0, localIsoUrl).attachHardDisk(hardDisk).build();
|
||||||
.controller(ideController).forceOverwrite(true)
|
|
||||||
.guestUser(currentImage.username).guestPassword(currentImage.credential)
|
|
||||||
.cleanUpMode(CleanupMode.Full).build();
|
|
||||||
|
|
||||||
NetworkAdapter networkAdapter = NetworkAdapter
|
VmSpec vmSpecification = VmSpec.builder().id(currentImage.id).name(vmName).memoryMB(512)
|
||||||
.builder()
|
.osTypeId(getOsTypeId(currentImage.os_family, currentImage.os_64bit)).controller(ideController)
|
||||||
.networkAttachmentType(NetworkAttachmentType.NAT)
|
.forceOverwrite(true).guestUser(currentImage.username).guestPassword(currentImage.credential)
|
||||||
.tcpRedirectRule(providerSupplier.get().getHost(), NetworkUtils.MASTER_PORT,
|
.cleanUpMode(CleanupMode.Full).build();
|
||||||
"", 22).build();
|
|
||||||
|
|
||||||
NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard
|
NetworkAdapter networkAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.NAT)
|
||||||
.builder().addNetworkAdapter(networkAdapter).slot(0L).build();
|
.tcpRedirectRule(providerSupplier.get().getHost(), NetworkUtils.MASTER_PORT, "", 22).build();
|
||||||
|
|
||||||
NetworkSpec networkSpec = NetworkSpec.builder()
|
NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(networkAdapter)
|
||||||
.addNIC(networkInterfaceCard).build();
|
.slot(0L).build();
|
||||||
|
|
||||||
return MasterSpec
|
NetworkSpec networkSpec = NetworkSpec.builder().addNIC(networkInterfaceCard).build();
|
||||||
.builder()
|
|
||||||
.vm(vmSpecification)
|
return MasterSpec
|
||||||
.iso(IsoSpec
|
.builder()
|
||||||
.builder()
|
.vm(vmSpecification)
|
||||||
.sourcePath(localIsoUrl)
|
.iso(IsoSpec.builder().sourcePath(localIsoUrl)
|
||||||
.installationScript(
|
.installationScript(installationKeySequence.replace("HOSTNAME", vmSpecification.getVmName())).build())
|
||||||
installationKeySequence.replace("HOSTNAME",
|
.network(networkSpec)
|
||||||
vmSpecification.getVmName())).build())
|
.credentials(new LoginCredentials(currentImage.username, currentImage.credential, null, true)).build();
|
||||||
.network(networkSpec)
|
}
|
||||||
.credentials(new LoginCredentials(currentImage.username, currentImage.credential, null, true))
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized Master getIfPresent(Object key) {
|
public synchronized Master getIfPresent(Object key) {
|
||||||
checkArgument(key instanceof Image,
|
checkArgument(key instanceof Image, "this cache is for entries who's keys are Images");
|
||||||
"this cache is for entries who's keys are Images");
|
Image image = Image.class.cast(key);
|
||||||
Image image = Image.class.cast(key);
|
if (masters.containsKey(image.getId())) {
|
||||||
if (masters.containsKey(image.getId())) {
|
return masters.get(image.getId());
|
||||||
return masters.get(image.getId());
|
}
|
||||||
}
|
return null;
|
||||||
return null;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private String getFilePathOrDownload(String httpUrl, String md5)
|
private String getFilePathOrDownload(String httpUrl, String expectedMd5) throws ExecutionException {
|
||||||
throws ExecutionException {
|
String fileName = httpUrl.substring(httpUrl.lastIndexOf('/') + 1, httpUrl.length());
|
||||||
String fileName = httpUrl.substring(httpUrl.lastIndexOf('/') + 1,
|
|
||||||
httpUrl.length());
|
|
||||||
URI provider = providerSupplier.get();
|
URI provider = providerSupplier.get();
|
||||||
if (!socketTester.apply(HostAndPort.fromParts(provider.getHost(),
|
if (!socketTester.apply(HostAndPort.fromParts(provider.getHost(), provider.getPort()))) {
|
||||||
provider.getPort()))) {
|
|
||||||
throw new RuntimeException("could not connect to virtualbox");
|
throw new RuntimeException("could not connect to virtualbox");
|
||||||
}
|
}
|
||||||
File file = new File(isosDir, fileName);
|
File file = new File(isosDir, fileName);
|
||||||
List<Statement> statements = Lists.newArrayList();
|
List<Statement> statements = new ImmutableList.Builder<Statement>().add(
|
||||||
statements.add(Statements.saveHttpResponseTo(URI.create(httpUrl),
|
Statements.saveHttpResponseTo(URI.create(httpUrl), isosDir, fileName)).build();
|
||||||
isosDir, fileName));
|
|
||||||
StatementList statementList = new StatementList(statements);
|
StatementList statementList = new StatementList(statements);
|
||||||
NodeMetadata hostNodeMetadata = hardcodedHostToHostNodeMetadata
|
NodeMetadata hostNodeMetadata = hardcodedHostToHostNodeMetadata.apply(host.get());
|
||||||
.apply(host.get());
|
ListenableFuture<ExecResponse> future = runScriptOnNodeFactory.submit(hostNodeMetadata, statementList,
|
||||||
runScriptOnNodeFactory
|
runAsRoot(false));
|
||||||
.create(hostNodeMetadata, statementList, runAsRoot(false)).init()
|
Futures.getUnchecked(future);
|
||||||
.call();
|
|
||||||
|
|
||||||
ExecResponse response = runScriptOnNodeFactory
|
if (expectedMd5 != null) {
|
||||||
.create(
|
String filePath = isosDir + File.separator + fileName;
|
||||||
hostNodeMetadata,
|
ListenableFuture<ExecResponse> md5future = runScriptOnNodeFactory.submit(hostNodeMetadata, new Md5(filePath),
|
||||||
Statements.exec("md5 " + isosDir + File.separator + fileName),
|
runAsRoot(false));
|
||||||
runAsRoot(false)).init().call();
|
|
||||||
if (md5 != null) {
|
ExecResponse responseMd5 = Futures.getUnchecked(md5future);
|
||||||
if (!Iterables.get(
|
assert responseMd5.getExitStatus() == 0 : hostNodeMetadata.getId() + ": " + responseMd5;
|
||||||
Splitter.on("=").trimResults().split(response.getOutput()), 1)
|
checkNotNull(responseMd5.getOutput(), "iso_md5 missing");
|
||||||
.equals(md5))
|
String actualMd5 = responseMd5.getOutput().trim();
|
||||||
return null;
|
checkState(actualMd5.equals(expectedMd5), "md5 of %s is %s but expected %s", filePath, actualMd5, expectedMd5);
|
||||||
}
|
}
|
||||||
return file.getAbsolutePath();
|
return file.getAbsolutePath();
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,13 +52,13 @@ import org.jclouds.virtualbox.statements.DeleteGShadowLock;
|
||||||
import org.jclouds.virtualbox.util.MachineController;
|
import org.jclouds.virtualbox.util.MachineController;
|
||||||
import org.jclouds.virtualbox.util.MachineUtils;
|
import org.jclouds.virtualbox.util.MachineUtils;
|
||||||
import org.jclouds.virtualbox.util.NetworkUtils;
|
import org.jclouds.virtualbox.util.NetworkUtils;
|
||||||
import org.virtualbox_4_1.CleanupMode;
|
import org.virtualbox_4_2.CleanupMode;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.IProgress;
|
import org.virtualbox_4_2.IProgress;
|
||||||
import org.virtualbox_4_1.ISession;
|
import org.virtualbox_4_2.ISession;
|
||||||
import org.virtualbox_4_1.LockType;
|
import org.virtualbox_4_2.LockType;
|
||||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
import org.virtualbox_4_2.NetworkAttachmentType;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_2.VirtualBoxManager;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Optional;
|
import com.google.common.base.Optional;
|
||||||
|
@ -118,7 +118,7 @@ public class NodeCreator implements Function<NodeSpec, NodeAndInitialCredentials
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("error opening vbox machine session: " + e.getMessage(), e);
|
throw new RuntimeException("error opening vbox machine session: " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
logger.debug("Deleted an existing snapshot from %s", master.getMachine().getName());
|
logger.debug("<< deleted an existing snapshot of vm(%s)", master.getMachine().getName());
|
||||||
}
|
}
|
||||||
String masterNameWithoutPrefix = master.getMachine().getName().replace(VIRTUALBOX_IMAGE_PREFIX, "");
|
String masterNameWithoutPrefix = master.getMachine().getName().replace(VIRTUALBOX_IMAGE_PREFIX, "");
|
||||||
String cloneName = VIRTUALBOX_NODE_PREFIX + masterNameWithoutPrefix + VIRTUALBOX_NODE_NAME_SEPARATOR
|
String cloneName = VIRTUALBOX_NODE_PREFIX + masterNameWithoutPrefix + VIRTUALBOX_NODE_NAME_SEPARATOR
|
||||||
|
@ -148,8 +148,8 @@ public class NodeCreator implements Function<NodeSpec, NodeAndInitialCredentials
|
||||||
CloneSpec cloneSpec = CloneSpec.builder().linked(true).master(master.getMachine()).network(networkSpec)
|
CloneSpec cloneSpec = CloneSpec.builder().linked(true).master(master.getMachine()).network(networkSpec)
|
||||||
.vm(cloneVmSpec).build();
|
.vm(cloneVmSpec).build();
|
||||||
|
|
||||||
logger.debug("Cloning a new guest an existing snapshot from %s ...", master.getMachine().getName());
|
|
||||||
IMachine cloned = cloner.apply(cloneSpec);
|
IMachine cloned = cloner.apply(cloneSpec);
|
||||||
|
logger.debug("<< cloned a vm(%s) from master(%s)", cloneName, master.getMachine().getName());
|
||||||
machineController.ensureMachineIsLaunched(cloneVmSpec.getVmName());
|
machineController.ensureMachineIsLaunched(cloneVmSpec.getVmName());
|
||||||
|
|
||||||
// IMachineToNodeMetadata produces the final ip's but these need to be set before so we build a
|
// IMachineToNodeMetadata produces the final ip's but these need to be set before so we build a
|
||||||
|
@ -161,7 +161,7 @@ public class NodeCreator implements Function<NodeSpec, NodeAndInitialCredentials
|
||||||
|
|
||||||
if(optionalNatIfaceCard.isPresent())
|
if(optionalNatIfaceCard.isPresent())
|
||||||
checkState(networkUtils.enableNetworkInterface(partialNodeMetadata, optionalNatIfaceCard.get()),
|
checkState(networkUtils.enableNetworkInterface(partialNodeMetadata, optionalNatIfaceCard.get()),
|
||||||
"cannot enable Nat Interface");
|
"cannot enable NAT Interface on vm(%s)", cloneName);
|
||||||
|
|
||||||
LoginCredentials credentials = partialNodeMetadata.getCredentials();
|
LoginCredentials credentials = partialNodeMetadata.getCredentials();
|
||||||
return new NodeAndInitialCredentials<IMachine>(cloned,
|
return new NodeAndInitialCredentials<IMachine>(cloned,
|
||||||
|
@ -185,8 +185,10 @@ public class NodeCreator implements Function<NodeSpec, NodeAndInitialCredentials
|
||||||
long slot = -1;
|
long slot = -1;
|
||||||
long i = 0;
|
long i = 0;
|
||||||
while (slot == -1 && i < 4) {
|
while (slot == -1 && i < 4) {
|
||||||
if(clone.getNetworkAdapter(i).getAttachmentType().equals(networkAttachmentType))
|
if(clone.getNetworkAdapter(i).getAttachmentType().equals(networkAttachmentType)) {
|
||||||
slot = i;
|
slot = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
checkState(slot!=-1);
|
checkState(slot!=-1);
|
||||||
|
|
|
@ -31,7 +31,7 @@ import javax.annotation.Resource;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.virtualbox_4_1.ISession;
|
import org.virtualbox_4_2.ISession;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.util.concurrent.Uninterruptibles;
|
import com.google.common.util.concurrent.Uninterruptibles;
|
||||||
|
@ -57,9 +57,10 @@ class SendScancodes implements Function<ISession, Void> {
|
||||||
logger.debug("List of scancodes sent: ", maxOrLess);
|
logger.debug("List of scancodes sent: ", maxOrLess);
|
||||||
assert codesSent == maxOrLess.size();
|
assert codesSent == maxOrLess.size();
|
||||||
if (any(maxOrLess, in(SPECIAL_KEYBOARD_BUTTON_MAP_LIST.values()))) {
|
if (any(maxOrLess, in(SPECIAL_KEYBOARD_BUTTON_MAP_LIST.values()))) {
|
||||||
Uninterruptibles.sleepUninterruptibly(300, TimeUnit.MILLISECONDS);
|
// in case of special keystroke we assume more time needed than normal (page refresh)
|
||||||
|
Uninterruptibles.sleepUninterruptibly(500, TimeUnit.MILLISECONDS);
|
||||||
} else {
|
} else {
|
||||||
Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
|
Uninterruptibles.sleepUninterruptibly(250, TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -66,5 +66,4 @@ public class StringToKeyCode implements Function<String, List<Integer>> {
|
||||||
private boolean containsSpecialCharacter(String s) {
|
private boolean containsSpecialCharacter(String s) {
|
||||||
return s.startsWith("<");
|
return s.startsWith("<");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,12 +22,12 @@ package org.jclouds.virtualbox.functions;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.IProgress;
|
import org.virtualbox_4_2.IProgress;
|
||||||
import org.virtualbox_4_1.ISession;
|
import org.virtualbox_4_2.ISession;
|
||||||
import org.virtualbox_4_1.ISnapshot;
|
import org.virtualbox_4_2.ISnapshot;
|
||||||
import org.virtualbox_4_1.MachineState;
|
import org.virtualbox_4_2.MachineState;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_2.VirtualBoxManager;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
|
@ -61,8 +61,6 @@ public class TakeSnapshotIfNotAlreadyAttached implements Function<IMachine, ISna
|
||||||
if (snap == null) {
|
if (snap == null) {
|
||||||
try {
|
try {
|
||||||
session = manager.get().openMachineSession(machine);
|
session = manager.get().openMachineSession(machine);
|
||||||
logger.debug("No snapshot available taking new one: %s (description: %s) taken from %s", snapshotName,
|
|
||||||
snapshotDesc, machine.getName());
|
|
||||||
int retries = 10;
|
int retries = 10;
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
|
@ -83,7 +81,7 @@ public class TakeSnapshotIfNotAlreadyAttached implements Function<IMachine, ISna
|
||||||
}
|
}
|
||||||
|
|
||||||
snap = machine.getCurrentSnapshot();
|
snap = machine.getCurrentSnapshot();
|
||||||
logger.debug("Snapshot %s (description: %s) taken from %s", snapshotName, snapshotDesc,
|
logger.debug("<< snapshot(%s) with description(%s) taken from master(%s)", snapshotName, snapshotDesc,
|
||||||
machine.getName());
|
machine.getName());
|
||||||
break;
|
break;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -22,6 +22,9 @@ package org.jclouds.virtualbox.functions.admin;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot;
|
import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot;
|
||||||
|
import static org.jclouds.scriptbuilder.domain.Statements.exec;
|
||||||
|
import static org.jclouds.scriptbuilder.domain.Statements.findPid;
|
||||||
|
import static org.jclouds.scriptbuilder.domain.Statements.kill;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -40,16 +43,16 @@ import org.jclouds.location.Provider;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.scriptbuilder.domain.Statement;
|
import org.jclouds.scriptbuilder.domain.Statement;
|
||||||
import org.jclouds.scriptbuilder.domain.StatementList;
|
import org.jclouds.scriptbuilder.domain.StatementList;
|
||||||
import org.jclouds.scriptbuilder.domain.Statements;
|
|
||||||
import org.jclouds.virtualbox.functions.HardcodedHostToHostNodeMetadata;
|
import org.jclouds.virtualbox.functions.HardcodedHostToHostNodeMetadata;
|
||||||
import org.jclouds.virtualbox.predicates.RetryIfSocketNotYetOpen;
|
import org.jclouds.virtualbox.predicates.RetryIfSocketNotYetOpen;
|
||||||
import org.virtualbox_4_1.SessionState;
|
import org.virtualbox_4_2.SessionState;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_2.VirtualBoxManager;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.net.HostAndPort;
|
import com.google.common.net.HostAndPort;
|
||||||
|
import com.google.common.util.concurrent.UncheckedTimeoutException;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public class StartVBoxIfNotAlreadyRunning implements Supplier<VirtualBoxManager> {
|
public class StartVBoxIfNotAlreadyRunning implements Supplier<VirtualBoxManager> {
|
||||||
|
@ -69,9 +72,8 @@ public class StartVBoxIfNotAlreadyRunning implements Supplier<VirtualBoxManager>
|
||||||
// the functions and suppliers here are to ensure we don't do heavy i/o in injection
|
// the functions and suppliers here are to ensure we don't do heavy i/o in injection
|
||||||
@Inject
|
@Inject
|
||||||
public StartVBoxIfNotAlreadyRunning(Function<Supplier<NodeMetadata>, VirtualBoxManager> managerForNode,
|
public StartVBoxIfNotAlreadyRunning(Function<Supplier<NodeMetadata>, VirtualBoxManager> managerForNode,
|
||||||
Factory runScriptOnNodeFactory, RetryIfSocketNotYetOpen socketTester, Supplier<NodeMetadata> host,
|
Factory runScriptOnNodeFactory, RetryIfSocketNotYetOpen socketTester, Supplier<NodeMetadata> host,
|
||||||
@Provider Supplier<URI> providerSupplier,
|
@Provider Supplier<URI> providerSupplier, HardcodedHostToHostNodeMetadata hardcodedHostToHostNodeMetadata) {
|
||||||
HardcodedHostToHostNodeMetadata hardcodedHostToHostNodeMetadata) {
|
|
||||||
this.runScriptOnNodeFactory = checkNotNull(runScriptOnNodeFactory, "runScriptOnNodeFactory");
|
this.runScriptOnNodeFactory = checkNotNull(runScriptOnNodeFactory, "runScriptOnNodeFactory");
|
||||||
this.socketTester = checkNotNull(socketTester, "socketTester");
|
this.socketTester = checkNotNull(socketTester, "socketTester");
|
||||||
this.socketTester.seconds(3L);
|
this.socketTester.seconds(3L);
|
||||||
|
@ -82,63 +84,57 @@ public class StartVBoxIfNotAlreadyRunning implements Supplier<VirtualBoxManager>
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public synchronized void start() {
|
public void start() {
|
||||||
URI provider = providerSupplier.get();
|
URI provider = providerSupplier.get();
|
||||||
NodeMetadata hostNodeMetadata = hardcodedHostToHostNodeMetadata.apply(host.get());
|
NodeMetadata hostNodeMetadata = hardcodedHostToHostNodeMetadata.apply(host.get());
|
||||||
cleanUpHost(provider, hostNodeMetadata);
|
|
||||||
|
|
||||||
logger.debug("disabling password access");
|
|
||||||
runScriptOnNodeFactory
|
|
||||||
.create(
|
|
||||||
hostNodeMetadata,
|
|
||||||
Statements
|
|
||||||
.exec("VBoxManage setproperty websrvauthlibrary null"),
|
|
||||||
runAsRoot(false).wrapInInitScript(false)).init().call();
|
|
||||||
logger.debug(">> starting vboxwebsrv");
|
|
||||||
String vboxwebsrv = "vboxwebsrv -t0 -v -b -H "
|
|
||||||
+ providerSupplier.get().getHost();
|
|
||||||
runScriptOnNodeFactory
|
|
||||||
.create(
|
|
||||||
hostNodeMetadata,
|
|
||||||
Statements.exec(vboxwebsrv),
|
|
||||||
runAsRoot(false).wrapInInitScript(false)
|
|
||||||
.blockOnComplete(false).nameTask("vboxwebsrv")).init()
|
|
||||||
.call();
|
|
||||||
|
|
||||||
if (!socketTester.apply(HostAndPort.fromParts(provider.getHost(),
|
if (!socketTester.apply(HostAndPort.fromParts(provider.getHost(), provider.getPort()))) {
|
||||||
provider.getPort()))) {
|
logger.debug("disabling password access");
|
||||||
throw new RuntimeException("could not connect to virtualbox");
|
runScriptOnNodeFactory
|
||||||
|
.create(hostNodeMetadata, exec("VBoxManage setproperty websrvauthlibrary null"),
|
||||||
|
runAsRoot(false).wrapInInitScript(false)).init().call();
|
||||||
|
|
||||||
|
logger.debug(">> starting vboxwebsrv");
|
||||||
|
String vboxwebsrv = "vboxwebsrv -t0 -v -b -H " + providerSupplier.get().getHost();
|
||||||
|
runScriptOnNodeFactory
|
||||||
|
.create(hostNodeMetadata, exec(vboxwebsrv),
|
||||||
|
runAsRoot(false).wrapInInitScript(false).blockOnComplete(false).nameTask("vboxwebsrv")).init()
|
||||||
|
.call();
|
||||||
|
|
||||||
|
if (!socketTester.apply(HostAndPort.fromParts(provider.getHost(), provider.getPort()))) {
|
||||||
|
throw new UncheckedTimeoutException(String.format("could not connect to virtualbox at %s", provider));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
manager = managerForNode.apply(host);
|
manager = managerForNode.apply(host);
|
||||||
manager.connect(provider.toASCIIString(), "", "");
|
manager.connect(provider.toASCIIString(), "", "");
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
if (manager.getSessionObject().getState() != SessionState.Unlocked)
|
if (manager.getSessionObject().getState() != SessionState.Unlocked)
|
||||||
logger.warn("manager is not in unlocked state "
|
logger.warn("manager is not in unlocked state " + manager.getSessionObject().getState());
|
||||||
+ manager.getSessionObject().getState());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cleanUpHost(URI provider, NodeMetadata hostNodeMetadata) {
|
public void cleanUpHost() {
|
||||||
// kill previously started vboxwebsrv (possibly dirty session)
|
// kill previously started vboxwebsrv (possibly dirty session)
|
||||||
List<Statement> statements = Lists.newArrayList();
|
URI provider = providerSupplier.get();
|
||||||
statements.add(Statements.findPid("vboxwebsrv"));
|
NodeMetadata hostNodeMetadata = hardcodedHostToHostNodeMetadata.apply(host.get());
|
||||||
statements.add(Statements.kill());
|
List<Statement> statements = new ImmutableList.Builder<Statement>()
|
||||||
|
.add(findPid("vboxwebsrv"))
|
||||||
|
.add(kill()).build();
|
||||||
StatementList statementList = new StatementList(statements);
|
StatementList statementList = new StatementList(statements);
|
||||||
|
|
||||||
if (socketTester.apply(HostAndPort.fromParts(provider.getHost(),
|
if (socketTester.apply(HostAndPort.fromParts(provider.getHost(), provider.getPort()))) {
|
||||||
provider.getPort()))) {
|
|
||||||
logger.debug(String.format("shutting down previously started vboxwewbsrv at %s", provider));
|
logger.debug(String.format("shutting down previously started vboxwewbsrv at %s", provider));
|
||||||
ExecResponse execResponse = runScriptOnNodeFactory
|
ExecResponse execResponse = runScriptOnNodeFactory.create(hostNodeMetadata, statementList, runAsRoot(false))
|
||||||
.create(hostNodeMetadata, statementList, runAsRoot(false))
|
|
||||||
.init().call();
|
.init().call();
|
||||||
if(execResponse.getExitStatus()!=0)
|
if (execResponse.getExitStatus() != 0)
|
||||||
throw new RuntimeException("Cannot execute jclouds");
|
throw new RuntimeException(String.format("Cannot shutdown a running vboxwebsrv at %s. ExecResponse: %s", provider, execResponse));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VirtualBoxManager get() {
|
public VirtualBoxManager get() {
|
||||||
checkState(manager != null, "start not called");
|
checkState(manager != null, "VirtualBoxManager is not initialised");
|
||||||
return manager;
|
return manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,11 +52,11 @@ import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.virtualbox.domain.ErrorCode;
|
import org.jclouds.virtualbox.domain.ErrorCode;
|
||||||
import org.jclouds.virtualbox.domain.StorageController;
|
import org.jclouds.virtualbox.domain.StorageController;
|
||||||
import org.jclouds.virtualbox.domain.VmSpec;
|
import org.jclouds.virtualbox.domain.VmSpec;
|
||||||
import org.virtualbox_4_1.DeviceType;
|
import org.virtualbox_4_2.DeviceType;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.IMedium;
|
import org.virtualbox_4_2.IMedium;
|
||||||
import org.virtualbox_4_1.IProgress;
|
import org.virtualbox_4_2.IProgress;
|
||||||
import org.virtualbox_4_1.VBoxException;
|
import org.virtualbox_4_2.VBoxException;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
|
|
|
@ -49,12 +49,12 @@ import javax.inject.Singleton;
|
||||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.virtualbox.domain.ErrorCode;
|
import org.jclouds.virtualbox.domain.ErrorCode;
|
||||||
import org.virtualbox_4_1.CleanupMode;
|
import org.virtualbox_4_2.CleanupMode;
|
||||||
import org.virtualbox_4_1.DeviceType;
|
import org.virtualbox_4_2.DeviceType;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.IMedium;
|
import org.virtualbox_4_2.IMedium;
|
||||||
import org.virtualbox_4_1.IProgress;
|
import org.virtualbox_4_2.IProgress;
|
||||||
import org.virtualbox_4_1.VBoxException;
|
import org.virtualbox_4_2.VBoxException;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
|
|
|
@ -25,10 +25,10 @@ import static org.jclouds.virtualbox.predicates.IMediumPredicates.deviceTypeEqua
|
||||||
import static org.jclouds.virtualbox.predicates.IMediumPredicates.hasParent;
|
import static org.jclouds.virtualbox.predicates.IMediumPredicates.hasParent;
|
||||||
import static org.jclouds.virtualbox.predicates.IMediumPredicates.machineIdsContain;
|
import static org.jclouds.virtualbox.predicates.IMediumPredicates.machineIdsContain;
|
||||||
import static org.jclouds.virtualbox.util.IMediumAttachments.toMedium;
|
import static org.jclouds.virtualbox.util.IMediumAttachments.toMedium;
|
||||||
import static org.virtualbox_4_1.DeviceType.HardDisk;
|
import static org.virtualbox_4_2.DeviceType.HardDisk;
|
||||||
|
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.IMedium;
|
import org.virtualbox_4_2.IMedium;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
|
|
||||||
|
@ -58,11 +58,9 @@ public class IMachinePredicates {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "isLinkedClone()";
|
return "isLinkedClone()";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Predicate<IMachine> isLinkedClone() {
|
public static Predicate<IMachine> isLinkedClone() {
|
||||||
return IsLinkedClone.INSTANCE;
|
return IsLinkedClone.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
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 org.virtualbox_4_1.DeviceType;
|
import org.virtualbox_4_2.DeviceType;
|
||||||
import org.virtualbox_4_1.IMedium;
|
import org.virtualbox_4_2.IMedium;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
|
|
||||||
|
|
|
@ -82,5 +82,4 @@ public class EnableNetworkInterface implements Statement {
|
||||||
throw new UnsupportedOperationException("windows not yet implemented");
|
throw new UnsupportedOperationException("windows not yet implemented");
|
||||||
return statements.render(family);
|
return statements.render(family);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,7 +78,7 @@ public class InstallGuestAdditions implements Statement {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}).isPresent()) {
|
}).isPresent()) {
|
||||||
statements.add(exec("mount -t iso9660 /dev/sr1 " + mountPoint));
|
statements.add(exec("mount -t iso9660 /dev/cdrom1 " + mountPoint));
|
||||||
} else {
|
} else {
|
||||||
String vboxGuestAdditionsIso = "VBoxGuestAdditions_" + vboxVersion + ".iso";
|
String vboxGuestAdditionsIso = "VBoxGuestAdditions_" + vboxVersion + ".iso";
|
||||||
URI download = URI.create("http://download.virtualbox.org/virtualbox/" + vboxVersion + "/"
|
URI download = URI.create("http://download.virtualbox.org/virtualbox/" + vboxVersion + "/"
|
||||||
|
@ -87,7 +87,7 @@ public class InstallGuestAdditions implements Statement {
|
||||||
statements.add(saveHttpResponseTo(download, "{tmp}{fs}", vboxGuestAdditionsIso));//
|
statements.add(saveHttpResponseTo(download, "{tmp}{fs}", vboxGuestAdditionsIso));//
|
||||||
statements.add(exec(String.format("mount -o loop {tmp}{fs}%s %s", vboxGuestAdditionsIso, mountPoint)));
|
statements.add(exec(String.format("mount -o loop {tmp}{fs}%s %s", vboxGuestAdditionsIso, mountPoint)));
|
||||||
}
|
}
|
||||||
statements.add(exec(String.format("%s%s", mountPoint, "/VBoxLinuxAdditions.run --nox11"))); //
|
statements.add(exec(String.format("%s%s", mountPoint, "/VBoxLinuxAdditions.run --nox11")));
|
||||||
return statements;
|
return statements;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
/**
|
||||||
|
* 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.statements;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import org.jclouds.scriptbuilder.domain.OsFamily;
|
||||||
|
import org.jclouds.scriptbuilder.domain.Statement;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
|
public class Md5 implements Statement {
|
||||||
|
|
||||||
|
private final String filePath;
|
||||||
|
|
||||||
|
public Md5(String filePath) {
|
||||||
|
this.filePath = checkNotNull(filePath, "filePath");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<String> functionDependencies(OsFamily family) {
|
||||||
|
return ImmutableList.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String render(OsFamily family) {
|
||||||
|
if (checkNotNull(family, "family") == OsFamily.WINDOWS)
|
||||||
|
throw new UnsupportedOperationException("windows not yet implemented");
|
||||||
|
return String.format("command -v md5sum >/dev/null 2>&1 && md5sum %s | awk '{print $1}' "
|
||||||
|
+ "|| command -v md5 >/dev/null 2>&1 && md5 %s | awk '{ print $4 }'", filePath, filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,55 @@
|
||||||
|
/**
|
||||||
|
* 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.statements;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import org.jclouds.scriptbuilder.domain.OsFamily;
|
||||||
|
import org.jclouds.scriptbuilder.domain.Statement;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set hostname
|
||||||
|
*
|
||||||
|
* @author andrea turli
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class SetHostname implements Statement {
|
||||||
|
|
||||||
|
private final String publicIpAddress;
|
||||||
|
|
||||||
|
public SetHostname(String publicIpAddress) {
|
||||||
|
this.publicIpAddress = checkNotNull(publicIpAddress, "publicIpAddress");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<String> functionDependencies(OsFamily family) {
|
||||||
|
return ImmutableList.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String render(OsFamily family) {
|
||||||
|
if (checkNotNull(family, "family") == OsFamily.WINDOWS)
|
||||||
|
throw new UnsupportedOperationException("windows not yet implemented");
|
||||||
|
return String.format("sudo hostname %s", publicIpAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -18,8 +18,8 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.virtualbox.util;
|
package org.jclouds.virtualbox.util;
|
||||||
|
|
||||||
import org.virtualbox_4_1.IMedium;
|
import org.virtualbox_4_2.IMedium;
|
||||||
import org.virtualbox_4_1.IMediumAttachment;
|
import org.virtualbox_4_2.IMediumAttachment;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
package org.jclouds.virtualbox.util;
|
package org.jclouds.virtualbox.util;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -29,19 +30,20 @@ import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
|
import org.jclouds.predicates.RetryableNumTimesPredicate;
|
||||||
import org.jclouds.virtualbox.domain.ExecutionType;
|
import org.jclouds.virtualbox.domain.ExecutionType;
|
||||||
import org.jclouds.virtualbox.functions.LaunchMachineIfNotAlreadyRunning;
|
import org.jclouds.virtualbox.functions.LaunchMachineIfNotAlreadyRunning;
|
||||||
import org.virtualbox_4_1.AdditionsFacilityStatus;
|
import org.virtualbox_4_2.AdditionsFacilityStatus;
|
||||||
import org.virtualbox_4_1.AdditionsFacilityType;
|
import org.virtualbox_4_2.AdditionsFacilityType;
|
||||||
import org.virtualbox_4_1.AdditionsRunLevelType;
|
import org.virtualbox_4_2.AdditionsRunLevelType;
|
||||||
import org.virtualbox_4_1.IAdditionsFacility;
|
import org.virtualbox_4_2.IAdditionsFacility;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.IProgress;
|
import org.virtualbox_4_2.IProgress;
|
||||||
import org.virtualbox_4_1.ISession;
|
import org.virtualbox_4_2.ISession;
|
||||||
import org.virtualbox_4_1.LockType;
|
import org.virtualbox_4_2.IVirtualBox;
|
||||||
import org.virtualbox_4_1.MachineState;
|
import org.virtualbox_4_2.LockType;
|
||||||
import org.virtualbox_4_1.SessionState;
|
import org.virtualbox_4_2.MachineState;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_2.VirtualBoxManager;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Optional;
|
import com.google.common.base.Optional;
|
||||||
|
@ -49,7 +51,6 @@ import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.util.concurrent.Uninterruptibles;
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -81,66 +82,11 @@ public class MachineController {
|
||||||
IMachine machine = manager.get().getVBox().findMachine(vmName);
|
IMachine machine = manager.get().getVBox().findMachine(vmName);
|
||||||
while (!machine.getState().equals(MachineState.Running)) {
|
while (!machine.getState().equals(MachineState.Running)) {
|
||||||
try {
|
try {
|
||||||
session = machineUtils.applyForMachine(vmName,
|
session = machineUtils.applyForMachine(vmName, new LaunchMachineIfNotAlreadyRunning(manager.get(),
|
||||||
new LaunchMachineIfNotAlreadyRunning(manager.get(),
|
executionType, ""));
|
||||||
executionType, ""));
|
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
if (e.getMessage()
|
if (e.getMessage().contains(
|
||||||
.contains(
|
"org.virtualbox_4_2.VBoxException: VirtualBox error: The given session is busy (0x80BB0007)")) {
|
||||||
"org.virtualbox_4_1.VBoxException: VirtualBox error: The given session is busy (0x80BB0007)")) {
|
|
||||||
throw e;
|
|
||||||
} else if (e.getMessage().contains(
|
|
||||||
"VirtualBox error: The object is not ready")) {
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// for scancode
|
|
||||||
Uninterruptibles.sleepUninterruptibly(5, TimeUnit.SECONDS);
|
|
||||||
|
|
||||||
String guestAdditionsInstalled = machineUtils.sharedLockMachineAndApplyToSession(vmName,
|
|
||||||
new Function<ISession, String>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String apply(ISession session) {
|
|
||||||
int attempts = 0;
|
|
||||||
String guestAdditionsInstalled = null;
|
|
||||||
while (!!session.getConsole().getGuest()
|
|
||||||
.getAdditionsVersion().isEmpty() && attempts < 3) {
|
|
||||||
Uninterruptibles.sleepUninterruptibly(2, TimeUnit.SECONDS);
|
|
||||||
guestAdditionsInstalled = session.getConsole().getGuest()
|
|
||||||
.getAdditionsVersion();
|
|
||||||
attempts++;
|
|
||||||
}
|
|
||||||
return guestAdditionsInstalled;
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
if(!Strings.nullToEmpty(guestAdditionsInstalled).isEmpty()) {
|
|
||||||
waitVBoxServiceIsActive(vmName);
|
|
||||||
}
|
|
||||||
|
|
||||||
return checkNotNull(session, "session");
|
|
||||||
}
|
|
||||||
|
|
||||||
public ISession ensureMachineHasPowerDown(String vmName) {
|
|
||||||
ISession session = manager.get().getSessionObject();
|
|
||||||
IMachine machine = manager.get().getVBox().findMachine(vmName);
|
|
||||||
while (!machine.getState().equals(MachineState.PoweredOff)) {
|
|
||||||
try {
|
|
||||||
session = machineUtils.lockSessionOnMachineAndApply(vmName, LockType.Shared,
|
|
||||||
new Function<ISession, ISession>() {
|
|
||||||
@Override
|
|
||||||
public ISession apply(ISession session) {
|
|
||||||
IProgress powerDownProgress = session.getConsole().powerDown();
|
|
||||||
powerDownProgress.waitForCompletion(-1);
|
|
||||||
return session;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (RuntimeException e) {
|
|
||||||
if (e.getMessage().contains("Invalid machine state: PoweredOff")) {
|
|
||||||
throw e;
|
throw e;
|
||||||
} else if (e.getMessage().contains("VirtualBox error: The object is not ready")) {
|
} else if (e.getMessage().contains("VirtualBox error: The object is not ready")) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -149,30 +95,58 @@ public class MachineController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
safeCheckMachineIsUnlocked(machine);
|
|
||||||
|
String guestAdditionsInstalled = machineUtils.sharedLockMachineAndApplyToSession(vmName,
|
||||||
|
new Function<ISession, String>() {
|
||||||
|
@Override
|
||||||
|
public String apply(ISession session) {
|
||||||
|
new RetryableNumTimesPredicate<Integer>(new FacilitiesPredicate(session),
|
||||||
|
5, 3L, TimeUnit.SECONDS).apply(4);
|
||||||
|
String guestAdditionsInstalled = session.getConsole().getGuest().getAdditionsVersion();
|
||||||
|
return guestAdditionsInstalled;
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
if (!Strings.nullToEmpty(guestAdditionsInstalled).isEmpty()) {
|
||||||
|
logger.debug("<< guest additions(%s) installed on vm(%s)", guestAdditionsInstalled, vmName);
|
||||||
|
waitVBoxServiceIsActive(vmName);
|
||||||
|
} else {
|
||||||
|
logger.debug("<< guest additions not available on(%s)", vmName);
|
||||||
|
}
|
||||||
return checkNotNull(session, "session");
|
return checkNotNull(session, "session");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public ISession ensureMachineHasPowerDown(String vmName) {
|
||||||
|
ISession session = machineUtils.sharedLockMachineAndApplyToSession(vmName, new Function<ISession, ISession>() {
|
||||||
|
@Override
|
||||||
|
public ISession apply(ISession session) {
|
||||||
|
IProgress powerdownIProgress = session.getConsole().powerDown();
|
||||||
|
powerdownIProgress.waitForCompletion(-1);
|
||||||
|
return session;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return checkNotNull(session, "session");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
* if machine supports ACPI it can be shutdown gently - not powerdown()
|
* if machine supports ACPI it can be shutdown gently - not powerdown()
|
||||||
* http://askubuntu.com/questions/82015/shutting-down-ubuntu-server-running-in-headless-virtualbox
|
* http://askubuntu.com/questions/82015/shutting-down-ubuntu-server-running-in-headless-virtualbox
|
||||||
*/
|
*/
|
||||||
public ISession ensureMachineIsShutdown(String vmName) {
|
public ISession ensureMachineIsShutdown(String vmName) {
|
||||||
IMachine machine = manager.get().getVBox().findMachine(vmName);
|
ISession session = machineUtils.sharedLockMachineAndApplyToSession(vmName, new Function<ISession, ISession>() {
|
||||||
ISession session = machineUtils.lockSessionOnMachineAndApply(vmName, LockType.Shared,
|
@Override
|
||||||
new Function<ISession, ISession>() {
|
public ISession apply(ISession session) {
|
||||||
@Override
|
session.getConsole().powerButton();
|
||||||
public ISession apply(ISession session) {
|
return session;
|
||||||
session.getConsole().powerButton();
|
}
|
||||||
return session;
|
});
|
||||||
}
|
checkState(new RetryableNumTimesPredicate<MachineState>(
|
||||||
});
|
new MachineStatePredicate(manager.get().getVBox(), vmName), 5,
|
||||||
safeCheckMachineIsUnlocked(machine);
|
3L, TimeUnit.SECONDS).apply(MachineState.PoweredOff), "vm(%s) is not shutdown correctly", vmName);
|
||||||
return checkNotNull(session, "session");
|
return checkNotNull(session, "session");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ensureMachineIsPaused(String vmName) {
|
public void ensureMachineIsPaused(String vmName) {
|
||||||
IMachine machine = manager.get().getVBox().findMachine(vmName);
|
|
||||||
while (!manager.get().getVBox().findMachine(vmName).getState().equals(MachineState.Paused)) {
|
while (!manager.get().getVBox().findMachine(vmName).getState().equals(MachineState.Paused)) {
|
||||||
try {
|
try {
|
||||||
machineUtils.lockSessionOnMachineAndApply(vmName, LockType.Shared, new Function<ISession, Void>() {
|
machineUtils.lockSessionOnMachineAndApply(vmName, LockType.Shared, new Function<ISession, Void>() {
|
||||||
|
@ -195,11 +169,9 @@ public class MachineController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
safeCheckMachineIsUnlocked(machine);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ensureMachineIsResumed(String vmName) {
|
public void ensureMachineIsResumed(String vmName) {
|
||||||
IMachine machine = manager.get().getVBox().findMachine(vmName);
|
|
||||||
while (!manager.get().getVBox().findMachine(vmName).getState().equals(MachineState.Running)) {
|
while (!manager.get().getVBox().findMachine(vmName).getState().equals(MachineState.Running)) {
|
||||||
try {
|
try {
|
||||||
machineUtils.lockSessionOnMachineAndApply(vmName, LockType.Shared, new Function<ISession, Void>() {
|
machineUtils.lockSessionOnMachineAndApply(vmName, LockType.Shared, new Function<ISession, Void>() {
|
||||||
|
@ -211,8 +183,7 @@ public class MachineController {
|
||||||
});
|
});
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
// sometimes the machine might be powered of between the while
|
// sometimes the machine might be powered of between the while
|
||||||
// test and the call to
|
// test and the call to lockSessionOnMachineAndApply
|
||||||
// lockSessionOnMachineAndApply
|
|
||||||
if (e.getMessage().contains("Invalid machine state: Resumed")) {
|
if (e.getMessage().contains("Invalid machine state: Resumed")) {
|
||||||
return;
|
return;
|
||||||
} else if (e.getMessage().contains("VirtualBox error: The object is not ready")) {
|
} else if (e.getMessage().contains("VirtualBox error: The object is not ready")) {
|
||||||
|
@ -222,58 +193,74 @@ public class MachineController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
safeCheckMachineIsUnlocked(machine);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void safeCheckMachineIsUnlocked(IMachine machine) {
|
private void waitVBoxServiceIsActive(final String vmName) {
|
||||||
int guard = 0;
|
|
||||||
while (!machine.getSessionState().equals(SessionState.Unlocked)) {
|
|
||||||
if(guard >= 5) {
|
|
||||||
logger.warn("Machine session (%s) possibly still unlocked!!!", machine.getName());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
logger.debug("Machine session (%s) not unlocked - wait ...", machine.getName());
|
|
||||||
Uninterruptibles.sleepUninterruptibly(3, TimeUnit.SECONDS);
|
|
||||||
guard++;
|
|
||||||
}
|
|
||||||
logger.debug("Machine session (%s) is %s", machine.getName(), machine.getSessionState());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void waitVBoxServiceIsActive(String vmName) {
|
|
||||||
machineUtils.sharedLockMachineAndApplyToSession(vmName, new Function<ISession, Void>() {
|
machineUtils.sharedLockMachineAndApplyToSession(vmName, new Function<ISession, Void>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Void apply(ISession session) {
|
public Void apply(ISession session) {
|
||||||
session.getConsole().getGuest().setStatisticsUpdateInterval(1l);
|
checkState(new RetryableNumTimesPredicate<AdditionsRunLevelType>(new AdditionsStatusPredicate(session),
|
||||||
while (!session.getConsole().getGuest().getAdditionsStatus(AdditionsRunLevelType.Userland)) {
|
5, 2L, TimeUnit.SECONDS).apply(AdditionsRunLevelType.Userland), "timed out waiting for additionsRunLevelType to be %s", AdditionsRunLevelType.Userland);
|
||||||
Uninterruptibles.sleepUninterruptibly(200, TimeUnit.MILLISECONDS);
|
checkState(new RetryableNumTimesPredicate<Integer>(new FacilitiesPredicate(session),
|
||||||
}
|
5, 3L, TimeUnit.SECONDS).apply(4), "timed out waiting for 4 running facilities");
|
||||||
|
|
||||||
List<IAdditionsFacility> facilities = session.getConsole().getGuest().getFacilities();
|
|
||||||
while (facilities.size() != 4) {
|
|
||||||
Uninterruptibles.sleepUninterruptibly(200, TimeUnit.MILLISECONDS);
|
|
||||||
facilities = session.getConsole().getGuest().getFacilities();
|
|
||||||
}
|
|
||||||
facilities = session.getConsole().getGuest().getFacilities();
|
|
||||||
|
|
||||||
Optional<IAdditionsFacility> vboxServiceFacility = Optional.absent();
|
Optional<IAdditionsFacility> vboxServiceFacility = Optional.absent();
|
||||||
while (!vboxServiceFacility.isPresent()) {
|
while (!vboxServiceFacility.isPresent()) {
|
||||||
vboxServiceFacility = Iterables.tryFind(session.getConsole().getGuest().getFacilities(),
|
List<IAdditionsFacility> facilities = session.getConsole().getGuest().getFacilities();
|
||||||
new Predicate<IAdditionsFacility>() {
|
vboxServiceFacility = Iterables.tryFind(facilities, new Predicate<IAdditionsFacility>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(IAdditionsFacility additionsFacility) {
|
public boolean apply(IAdditionsFacility additionsFacility) {
|
||||||
return additionsFacility.getType().equals(AdditionsFacilityType.VBoxService);
|
return additionsFacility.getType().equals(AdditionsFacilityType.VBoxService)
|
||||||
};
|
&& additionsFacility.getStatus().equals(AdditionsFacilityStatus.Active);
|
||||||
});
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
logger.debug("<< virtualbox service ready on vm(%s)", vmName);
|
||||||
while(!vboxServiceFacility.get().getStatus().equals(AdditionsFacilityStatus.Active)) {
|
|
||||||
Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
|
|
||||||
}
|
|
||||||
Uninterruptibles.sleepUninterruptibly(3, TimeUnit.SECONDS);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class AdditionsStatusPredicate implements Predicate<AdditionsRunLevelType> {
|
||||||
|
private final ISession session;
|
||||||
|
|
||||||
|
AdditionsStatusPredicate(ISession session) {
|
||||||
|
this.session = session;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(AdditionsRunLevelType input) {
|
||||||
|
return session.getConsole().getGuest().getAdditionsStatus(input);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class FacilitiesPredicate implements Predicate<Integer> {
|
||||||
|
private final ISession session;
|
||||||
|
|
||||||
|
FacilitiesPredicate(ISession session) {
|
||||||
|
this.session = session;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(Integer input) {
|
||||||
|
return session.getConsole().getGuest().getFacilities().size() == input;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class MachineStatePredicate implements Predicate<MachineState> {
|
||||||
|
private final IVirtualBox virtualBox;
|
||||||
|
private final String vmName;
|
||||||
|
|
||||||
|
MachineStatePredicate(IVirtualBox virtualBox, String vmName) {
|
||||||
|
this.virtualBox = virtualBox;
|
||||||
|
this.vmName = vmName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(MachineState input) {
|
||||||
|
MachineState state = virtualBox.findMachine(vmName).getState();
|
||||||
|
return state.equals(input);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import static com.google.common.base.Preconditions.checkState;
|
||||||
|
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
|
|
||||||
|
@ -61,32 +62,19 @@ public final class MachineNameOrIdAndNicSlot {
|
||||||
return new MachineNameOrIdAndNicSlot(checkNotNull(machineNameOrId, "machineNameOrId"), slot);
|
return new MachineNameOrIdAndNicSlot(checkNotNull(machineNameOrId, "machineNameOrId"), slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MachineNameOrIdAndNicSlot fromString(
|
public static MachineNameOrIdAndNicSlot fromString(String machineNameOrIdAndNicSlotString) {
|
||||||
String machineNameOrIdAndNicSlotString) {
|
Iterable<String> splittedString = Splitter.on(SEPARATOR).split(machineNameOrIdAndNicSlotString);
|
||||||
checkNotNull(machineNameOrIdAndNicSlotString);
|
|
||||||
String machineNameOrId = null;
|
|
||||||
String nicSlotString = null;
|
|
||||||
|
|
||||||
Iterable<String> splittedString = Splitter.on(SEPARATOR).split(
|
|
||||||
machineNameOrIdAndNicSlotString);
|
|
||||||
checkState(Iterables.size(splittedString) == 2);
|
checkState(Iterables.size(splittedString) == 2);
|
||||||
machineNameOrId = Iterables.get(splittedString, 0);
|
String machineNameOrId = Strings.nullToEmpty(Iterables.get(splittedString, 0));
|
||||||
nicSlotString = Iterables.get(splittedString, 1);
|
String nicSlotString = Strings.nullToEmpty(Iterables.get(splittedString, 1));
|
||||||
|
checkArgument(!nicSlotString.startsWith("+"), "Unparseable slot number: %s", nicSlotString);
|
||||||
long slot = -1;
|
try {
|
||||||
if (nicSlotString != null) {
|
long slot = Long.parseLong(nicSlotString);
|
||||||
checkArgument(!nicSlotString.startsWith("+"),
|
checkArgument(isValidSlot(slot), "Slot number out of range: %s", nicSlotString);
|
||||||
"Unparseable slot number: %s", nicSlotString);
|
return new MachineNameOrIdAndNicSlot(machineNameOrId, slot);
|
||||||
try {
|
} catch (NumberFormatException e) {
|
||||||
slot = Long.parseLong(nicSlotString);
|
throw new IllegalArgumentException("Unparseable slot number: " + nicSlotString);
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
throw new IllegalArgumentException("Unparseable slot number: "
|
|
||||||
+ nicSlotString);
|
|
||||||
}
|
|
||||||
checkArgument(isValidSlot(slot), "Slot number out of range: %s",
|
|
||||||
nicSlotString);
|
|
||||||
}
|
}
|
||||||
return new MachineNameOrIdAndNicSlot(machineNameOrId, slot);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MachineNameOrIdAndNicSlot withDefaultSlot(int defaultSlot) {
|
public MachineNameOrIdAndNicSlot withDefaultSlot(int defaultSlot) {
|
||||||
|
|
|
@ -34,17 +34,19 @@ import org.jclouds.compute.domain.NodeMetadata;
|
||||||
import org.jclouds.compute.options.RunScriptOptions;
|
import org.jclouds.compute.options.RunScriptOptions;
|
||||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
|
import org.jclouds.predicates.RetryableNumTimesPredicate;
|
||||||
import org.jclouds.scriptbuilder.domain.Statement;
|
import org.jclouds.scriptbuilder.domain.Statement;
|
||||||
import org.jclouds.util.Throwables2;
|
import org.jclouds.util.Throwables2;
|
||||||
import org.jclouds.virtualbox.functions.IpAddressesLoadingCache;
|
import org.jclouds.virtualbox.functions.IpAddressesLoadingCache;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.ISession;
|
import org.virtualbox_4_2.ISession;
|
||||||
import org.virtualbox_4_1.LockType;
|
import org.virtualbox_4_2.LockType;
|
||||||
import org.virtualbox_4_1.SessionState;
|
import org.virtualbox_4_2.SessionState;
|
||||||
import org.virtualbox_4_1.VBoxException;
|
import org.virtualbox_4_2.VBoxException;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_2.VirtualBoxManager;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
import com.google.common.util.concurrent.Uninterruptibles;
|
import com.google.common.util.concurrent.Uninterruptibles;
|
||||||
|
@ -202,12 +204,15 @@ public class MachineUtils {
|
||||||
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);
|
||||||
} finally {
|
} finally {
|
||||||
|
// this is a workaround for shared lock type, where session state is not updated immediately
|
||||||
|
if(type == LockType.Shared) {
|
||||||
|
Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
if (session.getState().equals(SessionState.Locked)) {
|
if (session.getState().equals(SessionState.Locked)) {
|
||||||
session.unlockMachine();
|
session.unlockMachine();
|
||||||
while (!session.getState().equals(SessionState.Unlocked)) {
|
}
|
||||||
logger.debug("Session not unlocked - wait ...");
|
if(!session.getState().equals(SessionState.Unlocked)) {
|
||||||
Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
|
checkSessionIsUnlocked(session, 5, 3L, TimeUnit.SECONDS);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -215,8 +220,7 @@ public class MachineUtils {
|
||||||
private ISession lockSession(String machineId, LockType type, int retries) {
|
private ISession lockSession(String machineId, LockType type, int retries) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
IMachine immutableMachine = manager.get().getVBox().findMachine(machineId);
|
IMachine immutableMachine = manager.get().getVBox().findMachine(machineId);
|
||||||
ISession session = null;
|
ISession session = null;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
session = manager.get().getSessionObject();
|
session = manager.get().getSessionObject();
|
||||||
|
@ -239,12 +243,6 @@ public class MachineUtils {
|
||||||
checkState(session.getState().equals(SessionState.Locked));
|
checkState(session.getState().equals(SessionState.Locked));
|
||||||
return checkNotNull(session, "session");
|
return checkNotNull(session, "session");
|
||||||
}
|
}
|
||||||
|
|
||||||
void print() {
|
|
||||||
for (StackTraceElement element : Thread.currentThread().getStackTrace()){
|
|
||||||
System.err.println(element.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param machineId
|
* @param machineId
|
||||||
|
@ -270,5 +268,24 @@ public class MachineUtils {
|
||||||
return e.getMessage().contains("VirtualBox error: Could not find a registered machine named ")
|
return e.getMessage().contains("VirtualBox error: Could not find a registered machine named ")
|
||||||
|| e.getMessage().contains("Could not find a registered machine with UUID {");
|
|| e.getMessage().contains("Could not find a registered machine with UUID {");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkSessionIsUnlocked(ISession session, int attempts, long period, TimeUnit timeUnit) {
|
||||||
|
checkState(new RetryableNumTimesPredicate<SessionState>(new SessionStatePredicate(session),
|
||||||
|
attempts, period, timeUnit).apply(SessionState.Unlocked),
|
||||||
|
"timed out or number of retries(%s) reached waiting for session to be unlocked", attempts);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SessionStatePredicate implements Predicate<SessionState> {
|
||||||
|
private final ISession session;
|
||||||
|
|
||||||
|
SessionStatePredicate(ISession session) {
|
||||||
|
this.session = session;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(SessionState input) {
|
||||||
|
return session.getState().equals(input);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,6 @@ import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
@ -51,23 +50,21 @@ import org.jclouds.virtualbox.functions.RetrieveActiveBridgedInterfaces;
|
||||||
import org.jclouds.virtualbox.statements.EnableNetworkInterface;
|
import org.jclouds.virtualbox.statements.EnableNetworkInterface;
|
||||||
import org.jclouds.virtualbox.statements.GetIPAddressFromMAC;
|
import org.jclouds.virtualbox.statements.GetIPAddressFromMAC;
|
||||||
import org.jclouds.virtualbox.statements.ScanNetworkWithPing;
|
import org.jclouds.virtualbox.statements.ScanNetworkWithPing;
|
||||||
import org.virtualbox_4_1.HostNetworkInterfaceType;
|
import org.virtualbox_4_2.HostNetworkInterfaceType;
|
||||||
import org.virtualbox_4_1.IDHCPServer;
|
import org.virtualbox_4_2.IDHCPServer;
|
||||||
import org.virtualbox_4_1.IHostNetworkInterface;
|
import org.virtualbox_4_2.IHostNetworkInterface;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.INetworkAdapter;
|
||||||
import org.virtualbox_4_1.INetworkAdapter;
|
import org.virtualbox_4_2.NetworkAttachmentType;
|
||||||
import org.virtualbox_4_1.ISession;
|
import org.virtualbox_4_2.VirtualBoxManager;
|
||||||
import org.virtualbox_4_1.LockType;
|
|
||||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.util.concurrent.Uninterruptibles;
|
import com.google.common.util.concurrent.Futures;
|
||||||
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,11 +75,11 @@ import com.google.inject.Inject;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public class NetworkUtils {
|
public class NetworkUtils {
|
||||||
|
|
||||||
// TODO parameterize
|
// TODO parameterize
|
||||||
public static final int MASTER_PORT = 2222;
|
public static final int MASTER_PORT = 2222;
|
||||||
private static final String VIRTUALBOX_HOST_GATEWAY = "10.0.2.15";
|
private static final String VIRTUALBOX_HOST_GATEWAY = "10.0.2.15";
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
|
@ -97,68 +94,59 @@ public class NetworkUtils {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public NetworkUtils(Supplier<VirtualBoxManager> manager, MachineUtils machineUtils,
|
public NetworkUtils(Supplier<VirtualBoxManager> manager, MachineUtils machineUtils,
|
||||||
MachineController machineController,
|
MachineController machineController, Supplier<NodeMetadata> host, @Provider Supplier<URI> providerSupplier,
|
||||||
Supplier<NodeMetadata> host,
|
IpAddressesLoadingCache ipAddressesLoadingCache, Supplier<NodeMetadata> hostSupplier,
|
||||||
@Provider Supplier<URI> providerSupplier,
|
|
||||||
IpAddressesLoadingCache ipAddressesLoadingCache,
|
|
||||||
Supplier<NodeMetadata> hostSupplier,
|
|
||||||
RunScriptOnNode.Factory scriptRunnerFactory) {
|
RunScriptOnNode.Factory scriptRunnerFactory) {
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
this.machineUtils = machineUtils;
|
this.machineUtils = machineUtils;
|
||||||
this.host = checkNotNull(host, "host");
|
this.host = checkNotNull(host, "host can't be null");
|
||||||
this.providerSupplier = checkNotNull(providerSupplier,
|
this.providerSupplier = checkNotNull(providerSupplier, "endpoint to virtualbox web server can't be null");
|
||||||
"endpoint to virtualbox websrvd is needed");
|
|
||||||
this.ipAddressesLoadingCache = ipAddressesLoadingCache;
|
this.ipAddressesLoadingCache = ipAddressesLoadingCache;
|
||||||
this.scriptRunnerFactory = scriptRunnerFactory;
|
this.scriptRunnerFactory = scriptRunnerFactory;
|
||||||
this.hostSupplier = hostSupplier;
|
this.hostSupplier = hostSupplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NetworkSpec createNetworkSpecWhenVboxIsLocalhost() {
|
public NetworkSpec createNetworkSpecWhenVboxIsLocalhost() {
|
||||||
NetworkAdapter natAdapter = NetworkAdapter.builder()
|
NetworkAdapter natAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.NAT).build();
|
||||||
.networkAttachmentType(NetworkAttachmentType.NAT)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
NetworkInterfaceCard natIfaceCard = NetworkInterfaceCard.builder()
|
NetworkInterfaceCard natIfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(natAdapter).slot(1L).build();
|
||||||
.addNetworkAdapter(natAdapter)
|
NetworkAdapter hostOnlyAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.HostOnly)
|
||||||
.slot(1L)
|
|
||||||
.build();
|
.build();
|
||||||
NetworkAdapter hostOnlyAdapter = NetworkAdapter.builder()
|
// create new hostOnly interface if needed, otherwise use the one already
|
||||||
.networkAttachmentType(NetworkAttachmentType.HostOnly)
|
// there with dhcp enabled ...
|
||||||
.build();
|
|
||||||
// create new hostOnly interface if needed, otherwise use the one already there with dhcp enabled ...
|
|
||||||
String hostOnlyIfName = getHostOnlyIfOrCreate();
|
String hostOnlyIfName = getHostOnlyIfOrCreate();
|
||||||
NetworkInterfaceCard hostOnlyIfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(hostOnlyAdapter)
|
NetworkInterfaceCard hostOnlyIfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(hostOnlyAdapter)
|
||||||
.addHostInterfaceName(hostOnlyIfName).slot(0L).build();
|
.addHostInterfaceName(hostOnlyIfName).slot(0L).build();
|
||||||
return createNetworkSpecForHostOnlyNATNICs(natIfaceCard, hostOnlyIfaceCard);
|
return createNetworkSpecForHostOnlyNATNICs(natIfaceCard, hostOnlyIfaceCard);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean enableNetworkInterface(NodeMetadata nodeMetadata, NetworkInterfaceCard networkInterfaceCard) {
|
public NetworkInterfaceCard createHostOnlyNIC(long port) {
|
||||||
ExecResponse execResponse = null;
|
NetworkAdapter hostOnlyAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.HostOnly)
|
||||||
try {
|
|
||||||
execResponse = machineUtils.runScriptOnNode(nodeMetadata,
|
|
||||||
new EnableNetworkInterface(networkInterfaceCard), RunScriptOptions.NONE).get();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
logger.error(e.getMessage());
|
|
||||||
} catch (ExecutionException e) {
|
|
||||||
logger.error(e.getMessage());
|
|
||||||
}
|
|
||||||
if(execResponse == null)
|
|
||||||
return false;
|
|
||||||
return execResponse.getExitStatus() == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private NetworkSpec createNetworkSpecForHostOnlyNATNICs(NetworkInterfaceCard natIfaceCard,
|
|
||||||
NetworkInterfaceCard hostOnlyIfaceCard) {
|
|
||||||
return NetworkSpec.builder()
|
|
||||||
.addNIC(hostOnlyIfaceCard)
|
|
||||||
.addNIC(natIfaceCard)
|
|
||||||
.build();
|
.build();
|
||||||
|
// create new hostOnly interface if needed, otherwise use the one already
|
||||||
|
// there with dhcp enabled ...
|
||||||
|
String hostOnlyIfName = getHostOnlyIfOrCreate();
|
||||||
|
return NetworkInterfaceCard.builder().addNetworkAdapter(hostOnlyAdapter).addHostInterfaceName(hostOnlyIfName)
|
||||||
|
.slot(port).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHostOnlyIfOrCreate() {
|
public boolean enableNetworkInterface(NodeMetadata nodeMetadata, NetworkInterfaceCard networkInterfaceCard) {
|
||||||
|
ListenableFuture<ExecResponse> execEnableNetworkInterface = null;
|
||||||
|
execEnableNetworkInterface = machineUtils.runScriptOnNode(nodeMetadata, new EnableNetworkInterface(
|
||||||
|
networkInterfaceCard), RunScriptOptions.NONE);
|
||||||
|
ExecResponse execEnableNetworkInterfaceResponse = Futures.getUnchecked(execEnableNetworkInterface);
|
||||||
|
return execEnableNetworkInterfaceResponse.getExitStatus() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private NetworkSpec createNetworkSpecForHostOnlyNATNICs(NetworkInterfaceCard natIfaceCard,
|
||||||
|
NetworkInterfaceCard hostOnlyIfaceCard) {
|
||||||
|
return NetworkSpec.builder().addNIC(hostOnlyIfaceCard).addNIC(natIfaceCard).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHostOnlyIfOrCreate() {
|
||||||
IHostNetworkInterface availableHostInterfaceIf = returnExistingHostNetworkInterfaceWithDHCPenabledOrNull(manager
|
IHostNetworkInterface availableHostInterfaceIf = returnExistingHostNetworkInterfaceWithDHCPenabledOrNull(manager
|
||||||
.get().getVBox().getHost().getNetworkInterfaces());
|
.get().getVBox().getHost().getNetworkInterfaces());
|
||||||
if (availableHostInterfaceIf==null) {
|
if (availableHostInterfaceIf == null) {
|
||||||
final String hostOnlyIfName = createHostOnlyIf();
|
final String hostOnlyIfName = createHostOnlyIf();
|
||||||
assignDHCPtoHostOnlyInterface(hostOnlyIfName);
|
assignDHCPtoHostOnlyInterface(hostOnlyIfName);
|
||||||
return hostOnlyIfName;
|
return hostOnlyIfName;
|
||||||
|
@ -168,17 +156,17 @@ public class NetworkUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assignDHCPtoHostOnlyInterface(final String hostOnlyIfName) {
|
private void assignDHCPtoHostOnlyInterface(final String hostOnlyIfName) {
|
||||||
List<IHostNetworkInterface> availableNetworkInterfaces = manager.get().getVBox().getHost()
|
List<IHostNetworkInterface> availableNetworkInterfaces = manager.get().getVBox().getHost().getNetworkInterfaces();
|
||||||
.getNetworkInterfaces();
|
|
||||||
|
IHostNetworkInterface iHostNetworkInterfaceWithHostOnlyIfName = Iterables.getOnlyElement(Iterables.filter(
|
||||||
IHostNetworkInterface iHostNetworkInterfaceWithHostOnlyIfName = Iterables.getOnlyElement(Iterables.filter(availableNetworkInterfaces, new Predicate<IHostNetworkInterface>() {
|
availableNetworkInterfaces, new Predicate<IHostNetworkInterface>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(IHostNetworkInterface iHostNetworkInterface) {
|
||||||
|
return iHostNetworkInterface.getName().equals(hostOnlyIfName);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean apply(IHostNetworkInterface iHostNetworkInterface) {
|
|
||||||
return iHostNetworkInterface.getName().equals(hostOnlyIfName);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
String hostOnlyIfIpAddress = iHostNetworkInterfaceWithHostOnlyIfName.getIPAddress();
|
String hostOnlyIfIpAddress = iHostNetworkInterfaceWithHostOnlyIfName.getIPAddress();
|
||||||
String dhcpIpAddress = hostOnlyIfIpAddress.substring(0, hostOnlyIfIpAddress.lastIndexOf(".")) + ".254";
|
String dhcpIpAddress = hostOnlyIfIpAddress.substring(0, hostOnlyIfIpAddress.lastIndexOf(".")) + ".254";
|
||||||
String dhcpNetmask = "255.255.255.0";
|
String dhcpNetmask = "255.255.255.0";
|
||||||
|
@ -187,152 +175,135 @@ public class NetworkUtils {
|
||||||
NodeMetadata hostNodeMetadata = getHostNodeMetadata();
|
NodeMetadata hostNodeMetadata = getHostNodeMetadata();
|
||||||
|
|
||||||
ExecResponse response = scriptRunnerFactory
|
ExecResponse response = scriptRunnerFactory
|
||||||
.create(hostNodeMetadata,
|
.create(
|
||||||
Statements.exec(String
|
hostNodeMetadata,
|
||||||
.format("VBoxManage dhcpserver add --ifname %s --ip %s --netmask %s --lowerip %s --upperip %s --enable",
|
Statements.exec(String
|
||||||
hostOnlyIfName, dhcpIpAddress, dhcpNetmask, dhcpLowerIp, dhcpUpperIp)), runAsRoot(false).wrapInInitScript(false)).init().call();
|
.format(
|
||||||
checkState(response.getExitStatus()==0);
|
"VBoxManage dhcpserver add --ifname %s --ip %s --netmask %s --lowerip %s --upperip %s --enable",
|
||||||
|
hostOnlyIfName, dhcpIpAddress, dhcpNetmask, dhcpLowerIp, dhcpUpperIp)),
|
||||||
|
runAsRoot(false).wrapInInitScript(false)).init().call();
|
||||||
|
checkState(response.getExitStatus() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String createHostOnlyIf() {
|
private String createHostOnlyIf() {
|
||||||
final String hostOnlyIfName;
|
|
||||||
NodeMetadata hostNodeMetadata = getHostNodeMetadata();
|
NodeMetadata hostNodeMetadata = getHostNodeMetadata();
|
||||||
ExecResponse createHostOnlyResponse = scriptRunnerFactory
|
ExecResponse createHostOnlyResponse = scriptRunnerFactory
|
||||||
.create(hostNodeMetadata, Statements.exec("VBoxManage hostonlyif create"),
|
.create(hostNodeMetadata, Statements.exec("VBoxManage hostonlyif create"),
|
||||||
runAsRoot(false).wrapInInitScript(false)).init().call();
|
runAsRoot(false).wrapInInitScript(false)).init().call();
|
||||||
String output = createHostOnlyResponse.getOutput();
|
String output = createHostOnlyResponse.getOutput();
|
||||||
checkState(createHostOnlyResponse.getExitStatus()==0);
|
checkState(createHostOnlyResponse.getExitStatus() == 0, "cannot create hostonly interface ");
|
||||||
checkState(output.contains("'"), "cannot create hostonlyif");
|
checkState(output.contains("'"), "cannot create hostonly interface");
|
||||||
hostOnlyIfName = output.substring(output.indexOf("'") + 1, output.lastIndexOf("'"));
|
return output.substring(output.indexOf("'") + 1, output.lastIndexOf("'"));
|
||||||
return hostOnlyIfName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private NodeMetadata getHostNodeMetadata() {
|
private NodeMetadata getHostNodeMetadata() {
|
||||||
NodeMetadata hostNodeMetadata = NodeMetadataBuilder
|
return NodeMetadataBuilder.fromNodeMetadata(host.get())
|
||||||
.fromNodeMetadata(host.get())
|
.publicAddresses(ImmutableList.of(providerSupplier.get().getHost())).build();
|
||||||
.publicAddresses(
|
|
||||||
ImmutableList.of(providerSupplier.get().getHost()))
|
|
||||||
.build();
|
|
||||||
return hostNodeMetadata;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private IHostNetworkInterface returnExistingHostNetworkInterfaceWithDHCPenabledOrNull(Iterable<IHostNetworkInterface> availableNetworkInterfaces) {
|
private IHostNetworkInterface returnExistingHostNetworkInterfaceWithDHCPenabledOrNull(
|
||||||
|
Iterable<IHostNetworkInterface> availableNetworkInterfaces) {
|
||||||
checkNotNull(availableNetworkInterfaces);
|
checkNotNull(availableNetworkInterfaces);
|
||||||
return Iterables.getFirst(filterAvailableNetworkInterfaceByHostOnlyAndDHCPenabled(availableNetworkInterfaces), null);
|
return Iterables.getFirst(filterAvailableNetworkInterfaceByHostOnlyAndDHCPenabled(availableNetworkInterfaces),
|
||||||
|
null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param availableNetworkInterfaces
|
* @param availableNetworkInterfaces
|
||||||
* @param hostOnlyIfIpAddress
|
* @param hostOnlyIfIpAddress
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private Iterable<IHostNetworkInterface> filterAvailableNetworkInterfaceByHostOnlyAndDHCPenabled(Iterable<IHostNetworkInterface> availableNetworkInterfaces) {
|
private Iterable<IHostNetworkInterface> filterAvailableNetworkInterfaceByHostOnlyAndDHCPenabled(
|
||||||
Iterable<IHostNetworkInterface> filteredNetworkInterfaces = Iterables.filter(availableNetworkInterfaces, new Predicate<IHostNetworkInterface>() {
|
Iterable<IHostNetworkInterface> availableNetworkInterfaces) {
|
||||||
@Override
|
Iterable<IHostNetworkInterface> filteredNetworkInterfaces = Iterables.filter(availableNetworkInterfaces,
|
||||||
public boolean apply(IHostNetworkInterface iHostNetworkInterface) {
|
new Predicate<IHostNetworkInterface>() {
|
||||||
// this is an horrible workaround cause iHostNetworkInterface.getDhcpEnabled is working only for windows host
|
@Override
|
||||||
boolean match = false;
|
public boolean apply(IHostNetworkInterface iHostNetworkInterface) {
|
||||||
List<IDHCPServer> availableDHCPservers = manager.get().getVBox().getDHCPServers();
|
// this is an horrible workaround cause
|
||||||
for (IDHCPServer idhcpServer : availableDHCPservers) {
|
// iHostNetworkInterface.getDhcpEnabled is working only for
|
||||||
if(idhcpServer.getEnabled() && idhcpServer.getNetworkName().equals(iHostNetworkInterface.getNetworkName()))
|
// windows host
|
||||||
match = true;
|
boolean match = false;
|
||||||
}
|
List<IDHCPServer> availableDHCPservers = manager.get().getVBox().getDHCPServers();
|
||||||
return iHostNetworkInterface.getInterfaceType().equals(HostNetworkInterfaceType.HostOnly) &&
|
for (IDHCPServer idhcpServer : availableDHCPservers) {
|
||||||
match;
|
if (idhcpServer.getEnabled()
|
||||||
}
|
&& idhcpServer.getNetworkName().equals(iHostNetworkInterface.getNetworkName()))
|
||||||
});
|
match = true;
|
||||||
|
}
|
||||||
|
return iHostNetworkInterface.getInterfaceType().equals(HostNetworkInterfaceType.HostOnly) && match;
|
||||||
|
}
|
||||||
|
});
|
||||||
return filteredNetworkInterfaces;
|
return filteredNetworkInterfaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getValidHostOnlyIpFromVm(String machineNameOrId) {
|
||||||
public String getIpAddressFromNicSlot(String machineNameOrId, long nicSlot) {
|
long nicSlot = 0;
|
||||||
MachineNameOrIdAndNicSlot machineNameOrIdAndNicSlot =
|
String ipAddress = "";
|
||||||
MachineNameOrIdAndNicSlot.fromParts(machineNameOrId, nicSlot);
|
while (nicSlot < 4 && ipAddress.isEmpty()) {
|
||||||
logger.debug("Looking for an available IP address for %s at slot %s ...",
|
MachineNameOrIdAndNicSlot machineNameOrIdAndNicSlot = MachineNameOrIdAndNicSlot.fromParts(machineNameOrId,
|
||||||
machineNameOrIdAndNicSlot.getMachineNameOrId(),
|
nicSlot);
|
||||||
machineNameOrIdAndNicSlot.getSlotText());
|
ipAddress = getIpAddressFromNicSlot(machineNameOrIdAndNicSlot);
|
||||||
try {
|
if (!isValidIpForHostOnly(machineNameOrIdAndNicSlot, ipAddress)) {
|
||||||
String ipAddress = ipAddressesLoadingCache.get(machineNameOrIdAndNicSlot);
|
|
||||||
while(!isValidIpForHostOnly(machineNameOrIdAndNicSlot, ipAddress)) {
|
|
||||||
ipAddressesLoadingCache.invalidate(machineNameOrIdAndNicSlot);
|
ipAddressesLoadingCache.invalidate(machineNameOrIdAndNicSlot);
|
||||||
ipAddress = ipAddressesLoadingCache.get(machineNameOrIdAndNicSlot);
|
ipAddress = "";
|
||||||
}
|
}
|
||||||
logger.debug("Found an available IP address %s for guest: %s at slot: %s",
|
nicSlot++;
|
||||||
ipAddress,
|
}
|
||||||
machineNameOrIdAndNicSlot.getMachineNameOrId(),
|
return checkNotNull(Strings.emptyToNull(ipAddress),
|
||||||
machineNameOrIdAndNicSlot.getSlotText());
|
String.format("Cannot find a valid IP address for the %s's HostOnly NIC", machineNameOrId));
|
||||||
return ipAddress;
|
}
|
||||||
|
|
||||||
|
public String getIpAddressFromNicSlot(String machineNameOrId, long nicSlot) {
|
||||||
|
MachineNameOrIdAndNicSlot machineNameOrIdAndNicSlot = MachineNameOrIdAndNicSlot.fromParts(machineNameOrId,
|
||||||
|
nicSlot);
|
||||||
|
return getIpAddressFromNicSlot(machineNameOrIdAndNicSlot);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIpAddressFromNicSlot(MachineNameOrIdAndNicSlot machineNameOrIdAndNicSlot) {
|
||||||
|
try {
|
||||||
|
return ipAddressesLoadingCache.get(machineNameOrIdAndNicSlot);
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
logger.error("Problem in using the ipAddressCache", e.getCause());
|
logger.error("Problem in using the ipAddressCache", e.getCause());
|
||||||
throw Throwables.propagate(e);
|
throw Throwables.propagate(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isValidIpForHostOnly(MachineNameOrIdAndNicSlot machineNameOrIdAndNicSlot, String ip) {
|
||||||
|
return !ip.isEmpty() && isIpv4(ip) && !ipBelongsToNatRange(ip) && !ipEqualsToNatGateway(ip);
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isIpv4(String s) {
|
public static boolean isIpv4(String s) {
|
||||||
String IP_V4_ADDRESS_PATTERN = "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\."
|
String IP_V4_ADDRESS_PATTERN = "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\."
|
||||||
+ "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\."
|
+ "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$";
|
||||||
+ "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$";
|
|
||||||
Pattern pattern = Pattern.compile(IP_V4_ADDRESS_PATTERN);
|
Pattern pattern = Pattern.compile(IP_V4_ADDRESS_PATTERN);
|
||||||
Matcher matcher = pattern.matcher(s);
|
Matcher matcher = pattern.matcher(s);
|
||||||
return matcher.matches();
|
return matcher.matches();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isValidIpForHostOnly(MachineNameOrIdAndNicSlot machineNameOrIdAndNicSlot, String ip) {
|
|
||||||
final String vmNameOrId = machineNameOrIdAndNicSlot.getMachineNameOrId();
|
|
||||||
IMachine machine = manager.get().getVBox().findMachine(vmNameOrId);
|
|
||||||
long slot = machineNameOrIdAndNicSlot.getSlot();
|
|
||||||
|
|
||||||
if(ip.equals(VIRTUALBOX_HOST_GATEWAY) || !isValidHostOnlyIpAddress(ip, slot, machine)) {
|
|
||||||
// restart vm
|
|
||||||
logger.debug("reset node (%s) to refresh guest properties.", vmNameOrId);
|
|
||||||
machineUtils.lockSessionOnMachineAndApply(vmNameOrId, LockType.Shared,
|
|
||||||
new Function<ISession, Void>() {
|
|
||||||
@Override
|
|
||||||
public Void apply(ISession session) {
|
|
||||||
session.getConsole().reset();
|
|
||||||
long time = 15;
|
|
||||||
logger.debug("Waiting %s secs for the reset of (%s) ...", time, vmNameOrId);
|
|
||||||
Uninterruptibles.sleepUninterruptibly(time, TimeUnit.SECONDS);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isValidHostOnlyIpAddress(String ip, long slot,
|
private static boolean ipEqualsToNatGateway(String ip) {
|
||||||
IMachine machine) {
|
return ip.equals(VIRTUALBOX_HOST_GATEWAY);
|
||||||
boolean result = isIpv4(ip) && machine.getNetworkAdapter(slot).getAttachmentType().equals(NetworkAttachmentType.HostOnly)
|
|
||||||
&& !ipBelongsToNatRange(ip);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean ipBelongsToNatRange(String ip) {
|
private static boolean ipBelongsToNatRange(String ip) {
|
||||||
return ip.startsWith("10.0.3");
|
return ip.startsWith("10.0.3");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getIpAddressFromBridgedNIC(INetworkAdapter networkAdapter,
|
protected String getIpAddressFromBridgedNIC(INetworkAdapter networkAdapter, String network) {
|
||||||
String network) {
|
|
||||||
// RetrieveActiveBridgedInterfaces
|
// RetrieveActiveBridgedInterfaces
|
||||||
List<BridgedIf> activeBridgedInterfaces = new RetrieveActiveBridgedInterfaces(scriptRunnerFactory).apply(hostSupplier.get());
|
List<BridgedIf> activeBridgedInterfaces = new RetrieveActiveBridgedInterfaces(scriptRunnerFactory)
|
||||||
|
.apply(hostSupplier.get());
|
||||||
BridgedIf activeBridgedIf = checkNotNull(Iterables.get(activeBridgedInterfaces, 0), "activeBridgedInterfaces");
|
BridgedIf activeBridgedIf = checkNotNull(Iterables.get(activeBridgedInterfaces, 0), "activeBridgedInterfaces");
|
||||||
network = activeBridgedIf.getIpAddress();
|
network = activeBridgedIf.getIpAddress();
|
||||||
|
|
||||||
// scan ip
|
// scan ip
|
||||||
RunScriptOnNode ipScanRunScript = scriptRunnerFactory.create(
|
RunScriptOnNode ipScanRunScript = scriptRunnerFactory.create(hostSupplier.get(),
|
||||||
hostSupplier.get(), new ScanNetworkWithPing(network),
|
new ScanNetworkWithPing(network), RunScriptOptions.NONE);
|
||||||
RunScriptOptions.NONE);
|
|
||||||
ExecResponse execResponse = ipScanRunScript.init().call();
|
ExecResponse execResponse = ipScanRunScript.init().call();
|
||||||
checkState(execResponse.getExitStatus() == 0);
|
checkState(execResponse.getExitStatus() == 0);
|
||||||
|
|
||||||
// retrieve ip from mac
|
// retrieve ip from mac
|
||||||
RunScriptOnNode getIpFromMACAddressRunScript = scriptRunnerFactory
|
RunScriptOnNode getIpFromMACAddressRunScript = scriptRunnerFactory.create(hostSupplier.get(),
|
||||||
.create(hostSupplier.get(), new GetIPAddressFromMAC(
|
new GetIPAddressFromMAC(networkAdapter.getMACAddress()), RunScriptOptions.NONE);
|
||||||
networkAdapter.getMACAddress()),
|
ExecResponse ipExecResponse = getIpFromMACAddressRunScript.init().call();
|
||||||
RunScriptOptions.NONE);
|
|
||||||
ExecResponse ipExecResponse = getIpFromMACAddressRunScript.init()
|
|
||||||
.call();
|
|
||||||
checkState(ipExecResponse.getExitStatus() == 0);
|
checkState(ipExecResponse.getExitStatus() == 0);
|
||||||
return checkNotNull(ipExecResponse.getOutput(), "ipAddress");
|
return checkNotNull(ipExecResponse.getOutput(), "ipAddress");
|
||||||
}
|
}
|
||||||
|
|
|
@ -229,7 +229,7 @@ images:
|
||||||
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
|
||||||
|
@ -276,24 +276,20 @@ images:
|
||||||
os_description: ubuntu
|
os_description: ubuntu
|
||||||
os_version: 12.04.1
|
os_version: 12.04.1
|
||||||
os_64bit: true
|
os_64bit: true
|
||||||
iso: http://releases.ubuntu.com/12.04/ubuntu-12.04.1-server-amd64.iso
|
iso: http://releases.ubuntu.com/12.04.1/ubuntu-12.04.1-server-amd64.iso
|
||||||
iso_md5: a8c667e871f48f3a662f3fbf1c3ddb17
|
iso_md5: a8c667e871f48f3a662f3fbf1c3ddb17
|
||||||
username: toor
|
username: toor
|
||||||
credential: password
|
credential: password
|
||||||
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
|
console-setup/ask_detect=false keyboard-configuration/layoutcode=us
|
||||||
hostname=vmName
|
|
||||||
fb=false debconf/frontend=noninteractive
|
|
||||||
keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false
|
|
||||||
initrd=/install/initrd.gz -- <Enter>
|
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 dummy
|
|
||||||
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
|
||||||
|
@ -355,4 +351,4 @@ images:
|
||||||
#choose-mirror-bin mirror/http/directory string /ubuntu
|
#choose-mirror-bin mirror/http/directory string /ubuntu
|
||||||
#choose-mirror-bin mirror/suite select maverick
|
#choose-mirror-bin mirror/suite select maverick
|
||||||
#d-i debian-installer/allow_unauthenticated string true
|
#d-i debian-installer/allow_unauthenticated string true
|
||||||
choose-mirror-bin mirror/http/proxy string
|
choose-mirror-bin mirror/http/proxy string
|
|
@ -2,8 +2,5 @@ function cleanupUdevIfNeeded {
|
||||||
if [ -f '/etc/udev/rules.d/70-persistent-net.rules' ]
|
if [ -f '/etc/udev/rules.d/70-persistent-net.rules' ]
|
||||||
then
|
then
|
||||||
rm /etc/udev/rules.d/70-persistent-net.rules
|
rm /etc/udev/rules.d/70-persistent-net.rules
|
||||||
mkdir /etc/udev/rules.d/70-persistent-net.rules
|
|
||||||
rm -rf /dev/.udev/
|
|
||||||
rm /lib/udev/rules.d/75-persistent-net-generator.rules
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
|
@ -20,16 +20,23 @@
|
||||||
package org.jclouds.virtualbox;
|
package org.jclouds.virtualbox;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot;
|
||||||
|
import static org.jclouds.scriptbuilder.domain.Statements.findPid;
|
||||||
|
import static org.jclouds.scriptbuilder.domain.Statements.kill;
|
||||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX;
|
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX;
|
||||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE;
|
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
|
import org.jclouds.compute.callables.RunScriptOnNode.Factory;
|
||||||
|
import org.jclouds.compute.domain.ExecResponse;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
import org.jclouds.compute.domain.NodeMetadata;
|
||||||
import org.jclouds.compute.domain.Template;
|
import org.jclouds.compute.domain.Template;
|
||||||
|
@ -39,6 +46,8 @@ import org.jclouds.concurrent.MoreExecutors;
|
||||||
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
||||||
import org.jclouds.config.ValueOfConfigurationKeyOrNull;
|
import org.jclouds.config.ValueOfConfigurationKeyOrNull;
|
||||||
import org.jclouds.rest.annotations.BuildVersion;
|
import org.jclouds.rest.annotations.BuildVersion;
|
||||||
|
import org.jclouds.scriptbuilder.domain.Statement;
|
||||||
|
import org.jclouds.scriptbuilder.domain.StatementList;
|
||||||
import org.jclouds.sshj.config.SshjSshClientModule;
|
import org.jclouds.sshj.config.SshjSshClientModule;
|
||||||
import org.jclouds.virtualbox.config.VirtualBoxConstants;
|
import org.jclouds.virtualbox.config.VirtualBoxConstants;
|
||||||
import org.jclouds.virtualbox.domain.HardDisk;
|
import org.jclouds.virtualbox.domain.HardDisk;
|
||||||
|
@ -50,28 +59,32 @@ import org.jclouds.virtualbox.domain.NetworkInterfaceCard;
|
||||||
import org.jclouds.virtualbox.domain.NetworkSpec;
|
import org.jclouds.virtualbox.domain.NetworkSpec;
|
||||||
import org.jclouds.virtualbox.domain.StorageController;
|
import org.jclouds.virtualbox.domain.StorageController;
|
||||||
import org.jclouds.virtualbox.domain.VmSpec;
|
import org.jclouds.virtualbox.domain.VmSpec;
|
||||||
|
import org.jclouds.virtualbox.functions.HardcodedHostToHostNodeMetadata;
|
||||||
import org.jclouds.virtualbox.functions.IMachineToVmSpec;
|
import org.jclouds.virtualbox.functions.IMachineToVmSpec;
|
||||||
import org.jclouds.virtualbox.functions.admin.UnregisterMachineIfExistsAndDeleteItsMedia;
|
import org.jclouds.virtualbox.functions.admin.UnregisterMachineIfExistsAndDeleteItsMedia;
|
||||||
|
import org.jclouds.virtualbox.predicates.RetryIfSocketNotYetOpen;
|
||||||
import org.jclouds.virtualbox.util.MachineController;
|
import org.jclouds.virtualbox.util.MachineController;
|
||||||
import org.jclouds.virtualbox.util.MachineUtils;
|
import org.jclouds.virtualbox.util.MachineUtils;
|
||||||
import org.jclouds.virtualbox.util.NetworkUtils;
|
import org.jclouds.virtualbox.util.NetworkUtils;
|
||||||
import org.testng.annotations.AfterSuite;
|
import org.testng.annotations.AfterSuite;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.CleanupMode;
|
import org.virtualbox_4_2.CleanupMode;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
import org.virtualbox_4_2.NetworkAttachmentType;
|
||||||
import org.virtualbox_4_1.SessionState;
|
import org.virtualbox_4_2.SessionState;
|
||||||
import org.virtualbox_4_1.StorageBus;
|
import org.virtualbox_4_2.StorageBus;
|
||||||
import org.virtualbox_4_1.VBoxException;
|
import org.virtualbox_4_2.VBoxException;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_2.VirtualBoxManager;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.cache.LoadingCache;
|
import com.google.common.cache.LoadingCache;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
|
import com.google.common.net.HostAndPort;
|
||||||
import com.google.common.util.concurrent.Uninterruptibles;
|
import com.google.common.util.concurrent.Uninterruptibles;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Key;
|
import com.google.inject.Key;
|
||||||
|
@ -116,16 +129,17 @@ public class BaseVirtualBoxClientLiveTest extends BaseComputeServiceContextLiveT
|
||||||
@Named(VirtualBoxConstants.VIRTUALBOX_WORKINGDIR)
|
@Named(VirtualBoxConstants.VIRTUALBOX_WORKINGDIR)
|
||||||
protected String workingDir;
|
protected String workingDir;
|
||||||
protected String isosDir;
|
protected String isosDir;
|
||||||
@Inject
|
@Inject protected Supplier<NodeMetadata> host;
|
||||||
protected Supplier<NodeMetadata> host;
|
@Inject protected Factory runScriptOnNodeFactory;
|
||||||
|
@Inject protected RetryIfSocketNotYetOpen socketTester;
|
||||||
|
@Inject protected HardcodedHostToHostNodeMetadata hardcodedHostToHostNodeMetadata;
|
||||||
@Inject
|
@Inject
|
||||||
protected PrioritizeCredentialsFromTemplate prioritizeCredentialsFromTemplate;
|
protected PrioritizeCredentialsFromTemplate prioritizeCredentialsFromTemplate;
|
||||||
@Inject
|
@Inject
|
||||||
protected LoadingCache<Image, Master> mastersCache;
|
protected LoadingCache<Image, Master> mastersCache;
|
||||||
|
|
||||||
private final ExecutorService singleThreadExec = MoreExecutors.sameThreadExecutor();
|
private final ExecutorService singleThreadExec = MoreExecutors.sameThreadExecutor();
|
||||||
private String masterName;
|
private String masterName;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Iterable<Module> setupModules() {
|
protected Iterable<Module> setupModules() {
|
||||||
|
@ -147,7 +161,7 @@ public class BaseVirtualBoxClientLiveTest extends BaseComputeServiceContextLiveT
|
||||||
masterName = VIRTUALBOX_IMAGE_PREFIX + template.getImage().getId();
|
masterName = VIRTUALBOX_IMAGE_PREFIX + template.getImage().getId();
|
||||||
isosDir = workingDir + File.separator + "isos";
|
isosDir = workingDir + File.separator + "isos";
|
||||||
|
|
||||||
hostVersion = Iterables.get(Splitter.on('r').split(view.utils().injector().getInstance(Key.get(String.class, BuildVersion.class))), 0);
|
hostVersion = Iterables.get(Splitter.on('-').split(view.utils().injector().getInstance(Key.get(String.class, BuildVersion.class))), 0);
|
||||||
operatingSystemIso = String.format("%s/%s.iso", isosDir, template.getImage().getName());
|
operatingSystemIso = String.format("%s/%s.iso", isosDir, template.getImage().getName());
|
||||||
guestAdditionsIso = String.format("%s/VBoxGuestAdditions_%s.iso", isosDir, hostVersion);
|
guestAdditionsIso = String.format("%s/VBoxGuestAdditions_%s.iso", isosDir, hostVersion);
|
||||||
}
|
}
|
||||||
|
@ -217,5 +231,4 @@ public class BaseVirtualBoxClientLiveTest extends BaseComputeServiceContextLiveT
|
||||||
undoVm(masterName);
|
undoVm(masterName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,7 @@ import com.google.common.collect.Iterables;
|
||||||
@Test(groups = "live", singleThreaded = true, testName = "PreseedCfgServerTest")
|
@Test(groups = "live", singleThreaded = true, testName = "PreseedCfgServerTest")
|
||||||
public class PreseedCfgServerTest {
|
public class PreseedCfgServerTest {
|
||||||
private static final String lineSeparator = System.getProperty("line.separator");
|
private static final String lineSeparator = System.getProperty("line.separator");
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJettyServerServesPreseedFile() throws Exception {
|
public void testJettyServerServesPreseedFile() throws Exception {
|
||||||
Properties props = VirtualBoxApiMetadata.defaultProperties();
|
Properties props = VirtualBoxApiMetadata.defaultProperties();
|
||||||
|
|
|
@ -37,7 +37,7 @@ import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
|
||||||
import org.jclouds.virtualbox.functions.IMachineToSshClient;
|
import org.jclouds.virtualbox.functions.IMachineToSshClient;
|
||||||
import org.testng.annotations.AfterGroups;
|
import org.testng.annotations.AfterGroups;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClien
|
||||||
doConnectViaSsh(machine.getNode(), prioritizeCredentialsFromTemplate.apply(template, machine.getCredentials()));
|
doConnectViaSsh(machine.getNode(), prioritizeCredentialsFromTemplate.apply(template, machine.getCredentials()));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void doConnectViaSsh(IMachine machine, LoginCredentials creds) {
|
protected void doConnectViaSsh(IMachine machine, LoginCredentials creds) {
|
||||||
SshClient ssh = view.utils().injector().getInstance(IMachineToSshClient.class).apply(machine);
|
SshClient ssh = view.utils().injector().getInstance(IMachineToSshClient.class).apply(machine);
|
||||||
try {
|
try {
|
||||||
ssh.connect();
|
ssh.connect();
|
||||||
|
|
|
@ -24,6 +24,7 @@ import static org.easymock.EasyMock.expect;
|
||||||
import static org.easymock.EasyMock.replay;
|
import static org.easymock.EasyMock.replay;
|
||||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX;
|
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -37,14 +38,14 @@ import org.jclouds.json.config.GsonModule;
|
||||||
import org.jclouds.virtualbox.config.VirtualBoxComputeServiceContextModule;
|
import org.jclouds.virtualbox.config.VirtualBoxComputeServiceContextModule;
|
||||||
import org.jclouds.virtualbox.functions.IMachineToImage;
|
import org.jclouds.virtualbox.functions.IMachineToImage;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.IGuestOSType;
|
import org.virtualbox_4_2.IGuestOSType;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.IVirtualBox;
|
import org.virtualbox_4_2.IVirtualBox;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_2.VirtualBoxManager;
|
||||||
|
|
||||||
|
import com.beust.jcommander.internal.Lists;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Suppliers;
|
import com.google.common.base.Suppliers;
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
|
|
||||||
@Test(groups = "unit")
|
@Test(groups = "unit")
|
||||||
|
@ -82,25 +83,6 @@ public class VirtualBoxComputeServiceAdapterTest {
|
||||||
|
|
||||||
Function<IMachine, Image> iMachineToImage = new IMachineToImage(
|
Function<IMachine, Image> iMachineToImage = new IMachineToImage(
|
||||||
VirtualBoxComputeServiceContextModule.toPortableImageStatus, Suppliers.ofInstance(manager), osMap);
|
VirtualBoxComputeServiceContextModule.toPortableImageStatus, Suppliers.ofInstance(manager), osMap);
|
||||||
// VirtualBoxComputeServiceAdapter adapter = new VirtualBoxComputeServiceAdapter(Suppliers.ofInstance(manager), iMachineToImage, new ImageFromYamlString(), new Supplier<String>() {
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public String get() {
|
|
||||||
// return "images:\n" +
|
|
||||||
// " - id: myTestId\n" +
|
|
||||||
// " name: ubuntu-11.04-server-i386\n" +
|
|
||||||
// " description: ubuntu 11.04 server (i386)\n" +
|
|
||||||
// " os_arch: x86\n" +
|
|
||||||
// " os_family: ubuntu\n" +
|
|
||||||
// " os_description: ubuntu\n" +
|
|
||||||
// " os_version: 11.04\n" +
|
|
||||||
// " iso: http://releases.ubuntu.com/11.04/ubuntu-11.04-server-i386.iso";
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// Iterator<Image> iterator = adapter.listImages().iterator();
|
|
||||||
// Image image = Iterators.getOnlyElement(iterator);
|
|
||||||
// assertEquals(image.getDescription(), "ubuntu 11.04 server (i386)");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,10 +72,10 @@ public class VirtualBoxExperimentLiveTest extends BaseVirtualBoxClientLiveTest {
|
||||||
int numNodes = 3;
|
int numNodes = 3;
|
||||||
final String clusterName = "test-launch-cluster";
|
final String clusterName = "test-launch-cluster";
|
||||||
Set<? extends NodeMetadata> nodes = context.getComputeService().createNodesInGroup(clusterName, numNodes,
|
Set<? extends NodeMetadata> nodes = context.getComputeService().createNodesInGroup(clusterName, numNodes,
|
||||||
TemplateOptions.Builder.overrideLoginUser("toor").runScript(AdminAccess.standard()));
|
TemplateOptions.Builder.overrideLoginUser("toor"));
|
||||||
assertEquals(numNodes, nodes.size(), "wrong number of nodes");
|
assertEquals(numNodes, nodes.size(), "wrong number of nodes");
|
||||||
for (NodeMetadata node : nodes) {
|
for (NodeMetadata node : nodes) {
|
||||||
assertEquals("test-launch-cluster", node.getGroup());
|
assertTrue(node.getGroup().equals("test-launch-cluster"));
|
||||||
logger.debug("Created Node: %s", node);
|
logger.debug("Created Node: %s", node);
|
||||||
SshClient client = context.utils().sshForNode().apply(node);
|
SshClient client = context.utils().sshForNode().apply(node);
|
||||||
client.connect();
|
client.connect();
|
||||||
|
@ -90,4 +90,4 @@ public class VirtualBoxExperimentLiveTest extends BaseVirtualBoxClientLiveTest {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -20,12 +20,11 @@
|
||||||
package org.jclouds.virtualbox.domain;
|
package org.jclouds.virtualbox.domain;
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
import static org.testng.Assert.assertFalse;
|
|
||||||
import static org.testng.Assert.assertNotEquals;
|
import static org.testng.Assert.assertNotEquals;
|
||||||
|
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.CleanupMode;
|
import org.virtualbox_4_2.CleanupMode;
|
||||||
import org.virtualbox_4_1.StorageBus;
|
import org.virtualbox_4_2.StorageBus;
|
||||||
|
|
||||||
public class VmSpecTest {
|
public class VmSpecTest {
|
||||||
|
|
||||||
|
|
|
@ -27,10 +27,10 @@ import static org.easymock.EasyMock.verify;
|
||||||
|
|
||||||
import org.jclouds.virtualbox.domain.StorageController;
|
import org.jclouds.virtualbox.domain.StorageController;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.IStorageController;
|
import org.virtualbox_4_2.IStorageController;
|
||||||
import org.virtualbox_4_1.StorageBus;
|
import org.virtualbox_4_2.StorageBus;
|
||||||
import org.virtualbox_4_1.VBoxException;
|
import org.virtualbox_4_2.VBoxException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
|
|
|
@ -26,8 +26,8 @@ import static org.easymock.EasyMock.replay;
|
||||||
import static org.easymock.EasyMock.verify;
|
import static org.easymock.EasyMock.verify;
|
||||||
|
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.VBoxException;
|
import org.virtualbox_4_2.VBoxException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mattias Holmqvist
|
* @author Mattias Holmqvist
|
||||||
|
|
|
@ -22,15 +22,14 @@ import static org.easymock.EasyMock.createMock;
|
||||||
import static org.easymock.EasyMock.expect;
|
import static org.easymock.EasyMock.expect;
|
||||||
import static org.easymock.EasyMock.replay;
|
import static org.easymock.EasyMock.replay;
|
||||||
import static org.easymock.EasyMock.verify;
|
import static org.easymock.EasyMock.verify;
|
||||||
import static org.virtualbox_4_1.NetworkAdapterType.Am79C973;
|
import static org.virtualbox_4_2.NetworkAttachmentType.Bridged;
|
||||||
import static org.virtualbox_4_1.NetworkAttachmentType.Bridged;
|
|
||||||
|
|
||||||
import org.jclouds.virtualbox.domain.NetworkAdapter;
|
import org.jclouds.virtualbox.domain.NetworkAdapter;
|
||||||
import org.jclouds.virtualbox.domain.NetworkInterfaceCard;
|
import org.jclouds.virtualbox.domain.NetworkInterfaceCard;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.INetworkAdapter;
|
import org.virtualbox_4_2.INetworkAdapter;
|
||||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
import org.virtualbox_4_2.NetworkAttachmentType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Andrea Turli
|
* @author Andrea Turli
|
||||||
|
@ -49,7 +48,6 @@ public class AttachBridgedAdapterToMachineTest {
|
||||||
|
|
||||||
expect(machine.getNetworkAdapter(adapterId)).andReturn(iNetworkAdapter);
|
expect(machine.getNetworkAdapter(adapterId)).andReturn(iNetworkAdapter);
|
||||||
iNetworkAdapter.setAttachmentType(Bridged);
|
iNetworkAdapter.setAttachmentType(Bridged);
|
||||||
iNetworkAdapter.setAdapterType(Am79C973);
|
|
||||||
iNetworkAdapter.setMACAddress(macAddress);
|
iNetworkAdapter.setMACAddress(macAddress);
|
||||||
iNetworkAdapter.setBridgedInterface(hostInterface);
|
iNetworkAdapter.setBridgedInterface(hostInterface);
|
||||||
iNetworkAdapter.setEnabled(true);
|
iNetworkAdapter.setEnabled(true);
|
||||||
|
|
|
@ -32,14 +32,14 @@ import org.jclouds.virtualbox.domain.DeviceDetails;
|
||||||
import org.jclouds.virtualbox.domain.HardDisk;
|
import org.jclouds.virtualbox.domain.HardDisk;
|
||||||
import org.jclouds.virtualbox.domain.StorageController;
|
import org.jclouds.virtualbox.domain.StorageController;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.DeviceType;
|
import org.virtualbox_4_2.DeviceType;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.IMedium;
|
import org.virtualbox_4_2.IMedium;
|
||||||
import org.virtualbox_4_1.IProgress;
|
import org.virtualbox_4_2.IProgress;
|
||||||
import org.virtualbox_4_1.IVirtualBox;
|
import org.virtualbox_4_2.IVirtualBox;
|
||||||
import org.virtualbox_4_1.StorageBus;
|
import org.virtualbox_4_2.StorageBus;
|
||||||
import org.virtualbox_4_1.VBoxException;
|
import org.virtualbox_4_2.VBoxException;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_2.VirtualBoxManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mattias Holmqvist
|
* @author Mattias Holmqvist
|
||||||
|
|
|
@ -25,17 +25,20 @@ import static org.easymock.EasyMock.expect;
|
||||||
import static org.easymock.EasyMock.expectLastCall;
|
import static org.easymock.EasyMock.expectLastCall;
|
||||||
import static org.easymock.EasyMock.replay;
|
import static org.easymock.EasyMock.replay;
|
||||||
import static org.easymock.EasyMock.verify;
|
import static org.easymock.EasyMock.verify;
|
||||||
import static org.virtualbox_4_1.NATProtocol.TCP;
|
import static org.virtualbox_4_2.NATProtocol.TCP;
|
||||||
import static org.virtualbox_4_1.NetworkAttachmentType.NAT;
|
import static org.virtualbox_4_2.NetworkAttachmentType.NAT;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.jclouds.virtualbox.domain.NetworkAdapter;
|
import org.jclouds.virtualbox.domain.NetworkAdapter;
|
||||||
import org.jclouds.virtualbox.domain.NetworkInterfaceCard;
|
import org.jclouds.virtualbox.domain.NetworkInterfaceCard;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.INATEngine;
|
import org.virtualbox_4_2.INATEngine;
|
||||||
import org.virtualbox_4_1.INetworkAdapter;
|
import org.virtualbox_4_2.INetworkAdapter;
|
||||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
import org.virtualbox_4_2.NetworkAttachmentType;
|
||||||
import org.virtualbox_4_1.VBoxException;
|
import org.virtualbox_4_2.VBoxException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mattias Holmqvist, Andrea Turli
|
* @author Mattias Holmqvist, Andrea Turli
|
||||||
|
@ -52,8 +55,10 @@ public class AttachNATAdapterToMachineIfNotAlreadyExistsTest {
|
||||||
|
|
||||||
expect(machine.getNetworkAdapter(slotId)).andReturn(iNetworkAdapter);
|
expect(machine.getNetworkAdapter(slotId)).andReturn(iNetworkAdapter);
|
||||||
iNetworkAdapter.setAttachmentType(NAT);
|
iNetworkAdapter.setAttachmentType(NAT);
|
||||||
expect(iNetworkAdapter.getNatDriver()).andReturn(natEngine);
|
expect(iNetworkAdapter.getNATEngine()).andReturn(natEngine).anyTimes();
|
||||||
|
|
||||||
|
List<String> redirects = new ArrayList<String>();
|
||||||
|
expect(natEngine.getRedirects()).andReturn(redirects);
|
||||||
natEngine.addRedirect("TCP@127.0.0.1:2222->:22", TCP, "127.0.0.1",
|
natEngine.addRedirect("TCP@127.0.0.1:2222->:22", TCP, "127.0.0.1",
|
||||||
2222, "", 22);
|
2222, "", 22);
|
||||||
iNetworkAdapter.setEnabled(true);
|
iNetworkAdapter.setEnabled(true);
|
||||||
|
@ -81,7 +86,10 @@ public class AttachNATAdapterToMachineIfNotAlreadyExistsTest {
|
||||||
|
|
||||||
expect(machine.getNetworkAdapter(slotId)).andReturn(iNetworkAdapter);
|
expect(machine.getNetworkAdapter(slotId)).andReturn(iNetworkAdapter);
|
||||||
iNetworkAdapter.setAttachmentType(NAT);
|
iNetworkAdapter.setAttachmentType(NAT);
|
||||||
expect(iNetworkAdapter.getNatDriver()).andReturn(natEngine);
|
expect(iNetworkAdapter.getNATEngine()).andReturn(natEngine).anyTimes();
|
||||||
|
|
||||||
|
List<String> redirects = new ArrayList<String>();
|
||||||
|
expect(natEngine.getRedirects()).andReturn(redirects);
|
||||||
|
|
||||||
natEngine.addRedirect("TCP@127.0.0.1:2222->:22", TCP, "127.0.0.1",
|
natEngine.addRedirect("TCP@127.0.0.1:2222->:22", TCP, "127.0.0.1",
|
||||||
2222, "", 22);
|
2222, "", 22);
|
||||||
|
|
|
@ -37,10 +37,10 @@ import org.jclouds.virtualbox.domain.VmSpec;
|
||||||
import org.testng.annotations.AfterGroups;
|
import org.testng.annotations.AfterGroups;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.CleanupMode;
|
import org.virtualbox_4_2.CleanupMode;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
import org.virtualbox_4_2.NetworkAttachmentType;
|
||||||
import org.virtualbox_4_1.StorageBus;
|
import org.virtualbox_4_2.StorageBus;
|
||||||
|
|
||||||
import com.google.common.base.CaseFormat;
|
import com.google.common.base.CaseFormat;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
|
|
@ -22,8 +22,7 @@ package org.jclouds.virtualbox.functions;
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX;
|
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX;
|
||||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE;
|
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE;
|
||||||
import static org.testng.Assert.assertFalse;
|
import static org.testng.Assert.assertTrue;
|
||||||
import static org.testng.Assert.assertNotNull;
|
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -52,10 +51,10 @@ import org.jclouds.virtualbox.predicates.SshResponds;
|
||||||
import org.testng.annotations.AfterGroups;
|
import org.testng.annotations.AfterGroups;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.CleanupMode;
|
import org.virtualbox_4_2.CleanupMode;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
import org.virtualbox_4_2.NetworkAttachmentType;
|
||||||
import org.virtualbox_4_1.StorageBus;
|
import org.virtualbox_4_2.StorageBus;
|
||||||
|
|
||||||
import com.google.common.base.CaseFormat;
|
import com.google.common.base.CaseFormat;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
@ -137,8 +136,7 @@ public class CreateAndInstallVmLiveTest extends BaseVirtualBoxClientLiveTest {
|
||||||
|
|
||||||
String version = machine.getGuestPropertyValue("/VirtualBox/GuestAdd/Version");
|
String version = machine.getGuestPropertyValue("/VirtualBox/GuestAdd/Version");
|
||||||
|
|
||||||
assertNotNull(version);
|
assertTrue(version != null && !version.isEmpty());
|
||||||
assertFalse(version.isEmpty());
|
|
||||||
} finally {
|
} finally {
|
||||||
for (VmSpec spec : ImmutableSet.of(machineSpec.getVmSpec())) {
|
for (VmSpec spec : ImmutableSet.of(machineSpec.getVmSpec())) {
|
||||||
machineController.ensureMachineIsShutdown(spec.getVmName());
|
machineController.ensureMachineIsShutdown(spec.getVmName());
|
||||||
|
|
|
@ -35,11 +35,11 @@ import org.jclouds.virtualbox.domain.StorageController;
|
||||||
import org.jclouds.virtualbox.domain.VmSpec;
|
import org.jclouds.virtualbox.domain.VmSpec;
|
||||||
import org.testng.annotations.AfterGroups;
|
import org.testng.annotations.AfterGroups;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.CleanupMode;
|
import org.virtualbox_4_2.CleanupMode;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
import org.virtualbox_4_2.NetworkAttachmentType;
|
||||||
import org.virtualbox_4_1.StorageBus;
|
import org.virtualbox_4_2.StorageBus;
|
||||||
import org.virtualbox_4_1.VBoxException;
|
import org.virtualbox_4_2.VBoxException;
|
||||||
|
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
|
|
||||||
|
@ -83,11 +83,11 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends B
|
||||||
MasterSpec machineSpec = MasterSpec.builder()
|
MasterSpec machineSpec = MasterSpec.builder()
|
||||||
.iso(IsoSpec.builder().sourcePath(operatingSystemIso).installationScript("").build()).vm(vmSpec)
|
.iso(IsoSpec.builder().sourcePath(operatingSystemIso).installationScript("").build()).vm(vmSpec)
|
||||||
.network(networkSpec).build();
|
.network(networkSpec).build();
|
||||||
// undoVm(vmSpec);
|
|
||||||
IMachine debianNode = view.utils().injector()
|
IMachine debianNode = view.utils().injector()
|
||||||
.getInstance(CreateAndRegisterMachineFromIsoIfNotAlreadyExists.class).apply(machineSpec);
|
.getInstance(CreateAndRegisterMachineFromIsoIfNotAlreadyExists.class).apply(machineSpec);
|
||||||
IMachine machine = manager.get().getVBox().findMachine(vmName);
|
IMachine machine = manager.get().getVBox().findMachine(vmName);
|
||||||
assertEquals(debianNode.getName(), machine.getName());
|
assertEquals(debianNode.getName(), machine.getName());
|
||||||
|
undoVm(vmName);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,12 +116,12 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends B
|
||||||
// if osTypeId is not found.
|
// if osTypeId is not found.
|
||||||
assertEquals(errorCode, ErrorCode.VBOX_E_OBJECT_NOT_FOUND);
|
assertEquals(errorCode, ErrorCode.VBOX_E_OBJECT_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
undoVm(vmName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterGroups(groups = "live")
|
@AfterGroups(groups = "live")
|
||||||
@Override
|
@Override
|
||||||
protected void tearDownContext() {
|
protected void tearDownContext() {
|
||||||
undoVm(vmName);
|
|
||||||
super.tearDownContext();
|
super.tearDownContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.virtualbox.functions;
|
package org.jclouds.virtualbox.functions;
|
||||||
|
|
||||||
import static org.easymock.EasyMock.anyBoolean;
|
|
||||||
import static org.easymock.EasyMock.createMock;
|
import static org.easymock.EasyMock.createMock;
|
||||||
import static org.easymock.EasyMock.createNiceMock;
|
import static org.easymock.EasyMock.createNiceMock;
|
||||||
import static org.easymock.EasyMock.eq;
|
import static org.easymock.EasyMock.eq;
|
||||||
|
@ -27,6 +26,8 @@ import static org.easymock.EasyMock.expectLastCall;
|
||||||
import static org.easymock.EasyMock.replay;
|
import static org.easymock.EasyMock.replay;
|
||||||
import static org.easymock.EasyMock.verify;
|
import static org.easymock.EasyMock.verify;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.easymock.EasyMock;
|
import org.easymock.EasyMock;
|
||||||
import org.jclouds.virtualbox.domain.IsoSpec;
|
import org.jclouds.virtualbox.domain.IsoSpec;
|
||||||
import org.jclouds.virtualbox.domain.MasterSpec;
|
import org.jclouds.virtualbox.domain.MasterSpec;
|
||||||
|
@ -35,15 +36,16 @@ import org.jclouds.virtualbox.domain.StorageController;
|
||||||
import org.jclouds.virtualbox.domain.VmSpec;
|
import org.jclouds.virtualbox.domain.VmSpec;
|
||||||
import org.jclouds.virtualbox.util.MachineUtils;
|
import org.jclouds.virtualbox.util.MachineUtils;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.CleanupMode;
|
import org.virtualbox_4_2.CleanupMode;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.ISession;
|
import org.virtualbox_4_2.ISession;
|
||||||
import org.virtualbox_4_1.IVirtualBox;
|
import org.virtualbox_4_2.IVirtualBox;
|
||||||
import org.virtualbox_4_1.LockType;
|
import org.virtualbox_4_2.LockType;
|
||||||
import org.virtualbox_4_1.StorageBus;
|
import org.virtualbox_4_2.StorageBus;
|
||||||
import org.virtualbox_4_1.VBoxException;
|
import org.virtualbox_4_2.VBoxException;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_2.VirtualBoxManager;
|
||||||
|
|
||||||
|
import com.beust.jcommander.internal.Lists;
|
||||||
import com.google.common.base.Suppliers;
|
import com.google.common.base.Suppliers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,116 +54,114 @@ import com.google.common.base.Suppliers;
|
||||||
@Test(groups = "unit", testName = "CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest")
|
@Test(groups = "unit", testName = "CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest")
|
||||||
public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
||||||
|
|
||||||
@Test(enabled = false)
|
@Test(enabled = false)
|
||||||
public void testCreateAndSetMemoryWhenNotAlreadyExists() throws Exception {
|
public void testCreateAndSetMemoryWhenNotAlreadyExists() throws Exception {
|
||||||
|
|
||||||
MachineUtils machineUtils = createMock(MachineUtils.class);
|
MachineUtils machineUtils = createMock(MachineUtils.class);
|
||||||
VirtualBoxManager manager = createMock(VirtualBoxManager.class);
|
VirtualBoxManager manager = createMock(VirtualBoxManager.class);
|
||||||
IVirtualBox vBox = createMock(IVirtualBox.class);
|
IVirtualBox vBox = createMock(IVirtualBox.class);
|
||||||
String vmName = "jclouds-image-my-ubuntu-image";
|
String vmName = "jclouds-image-my-ubuntu-image";
|
||||||
StorageController ideController = StorageController.builder().name("IDE Controller").bus(StorageBus.IDE).build();
|
StorageController ideController = StorageController.builder().name("IDE Controller").bus(StorageBus.IDE).build();
|
||||||
VmSpec vmSpec = VmSpec.builder().id(vmName).name(vmName).osTypeId("").memoryMB(1024).controller(ideController).cleanUpMode(
|
VmSpec vmSpec = VmSpec.builder().id(vmName).name(vmName).osTypeId("").memoryMB(1024).controller(ideController)
|
||||||
CleanupMode.Full).build();
|
.cleanUpMode(CleanupMode.Full).build();
|
||||||
MasterSpec machineSpec = MasterSpec.builder()
|
MasterSpec machineSpec = MasterSpec.builder()
|
||||||
.iso(IsoSpec.builder().sourcePath("some.iso").installationScript("").build())
|
.iso(IsoSpec.builder().sourcePath("some.iso").installationScript("").build()).vm(vmSpec)
|
||||||
.vm(vmSpec)
|
.network(NetworkSpec.builder().build()).build();
|
||||||
.network(NetworkSpec.builder().build()).build();
|
IMachine createdMachine = createMock(IMachine.class);
|
||||||
IMachine createdMachine = createMock(IMachine.class);
|
ISession session = createMock(ISession.class);
|
||||||
ISession session = createMock(ISession.class);
|
|
||||||
|
|
||||||
expect(manager.getVBox()).andReturn(vBox).anyTimes();
|
expect(manager.getVBox()).andReturn(vBox).anyTimes();
|
||||||
expect(vBox.composeMachineFilename(vmName, "/tmp/workingDir")).andReturn("settingsFile");
|
String flags = "";
|
||||||
|
List<String> groups = Lists.newArrayList();
|
||||||
|
String group = "";
|
||||||
|
expect(vBox.composeMachineFilename(vmName, group, flags, "/tmp/workingDir")).andReturn("settingsFile");
|
||||||
|
|
||||||
StringBuilder errorMessageBuilder = new StringBuilder();
|
StringBuilder errorMessageBuilder = new StringBuilder();
|
||||||
errorMessageBuilder.append("VirtualBox error: Could not find a registered machine with UUID {");
|
errorMessageBuilder.append("VirtualBox error: Could not find a registered machine with UUID {");
|
||||||
errorMessageBuilder.append("'jclouds-image-virtualbox-iso-to-machine-test'} (0x80BB0001)");
|
errorMessageBuilder.append("'jclouds-image-virtualbox-iso-to-machine-test'} (0x80BB0001)");
|
||||||
String errorMessage = errorMessageBuilder.toString();
|
String errorMessage = errorMessageBuilder.toString();
|
||||||
VBoxException vBoxException = new VBoxException(createNiceMock(Throwable.class), errorMessage);
|
VBoxException vBoxException = new VBoxException(createNiceMock(Throwable.class), errorMessage);
|
||||||
|
|
||||||
expect(vBox.findMachine(vmName)).andThrow(vBoxException);
|
expect(vBox.findMachine(vmName)).andThrow(vBoxException);
|
||||||
|
|
||||||
expect(vBox.createMachine(anyString(), eq(vmName), anyString(), anyString(), anyBoolean())).andReturn(
|
expect(vBox.createMachine(anyString(), eq(vmName), groups, anyString(), anyString())).andReturn(createdMachine)
|
||||||
createdMachine).anyTimes();
|
.anyTimes();
|
||||||
vBox.registerMachine(createdMachine);
|
vBox.registerMachine(createdMachine);
|
||||||
|
|
||||||
expect(vBox.findMachine(vmName)).andReturn(createdMachine).anyTimes();
|
expect(vBox.findMachine(vmName)).andReturn(createdMachine).anyTimes();
|
||||||
expect(manager.getSessionObject()).andReturn(session);
|
expect(manager.getSessionObject()).andReturn(session);
|
||||||
expect(session.getMachine()).andReturn(createdMachine);
|
expect(session.getMachine()).andReturn(createdMachine);
|
||||||
createdMachine.lockMachine(session, LockType.Write);
|
createdMachine.lockMachine(session, LockType.Write);
|
||||||
createdMachine.setMemorySize(1024l);
|
createdMachine.setMemorySize(1024l);
|
||||||
createdMachine.saveSettings();
|
createdMachine.saveSettings();
|
||||||
session.unlockMachine();
|
session.unlockMachine();
|
||||||
|
|
||||||
|
// TODO: this mock test is not finished.
|
||||||
|
replay(manager, createdMachine, vBox, session);
|
||||||
|
|
||||||
//TODO: this mock test is not finished.
|
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(Suppliers.ofInstance(manager), machineUtils,
|
||||||
replay(manager, createdMachine, vBox, session);
|
"/tmp/workingDir").apply(machineSpec);
|
||||||
|
|
||||||
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(Suppliers.ofInstance(manager), machineUtils, "/tmp/workingDir").apply(machineSpec);
|
verify(manager, createdMachine, vBox, session);
|
||||||
|
}
|
||||||
|
|
||||||
verify(manager, createdMachine, vBox, session);
|
@Test(expectedExceptions = IllegalStateException.class)
|
||||||
}
|
public void testFailIfMachineIsAlreadyRegistered() throws Exception {
|
||||||
|
|
||||||
@Test(expectedExceptions = IllegalStateException.class)
|
MachineUtils machineUtils = createMock(MachineUtils.class);
|
||||||
public void testFailIfMachineIsAlreadyRegistered() throws Exception {
|
|
||||||
|
|
||||||
MachineUtils machineUtils = createMock(MachineUtils.class);
|
VirtualBoxManager manager = createNiceMock(VirtualBoxManager.class);
|
||||||
|
IVirtualBox vBox = createNiceMock(IVirtualBox.class);
|
||||||
|
String vmName = "jclouds-image-my-ubuntu-image";
|
||||||
|
|
||||||
VirtualBoxManager manager = createNiceMock(VirtualBoxManager.class);
|
IMachine registeredMachine = createMock(IMachine.class);
|
||||||
IVirtualBox vBox = createNiceMock(IVirtualBox.class);
|
|
||||||
String vmName = "jclouds-image-my-ubuntu-image";
|
|
||||||
|
|
||||||
IMachine registeredMachine = createMock(IMachine.class);
|
expect(manager.getVBox()).andReturn(vBox).anyTimes();
|
||||||
|
expect(vBox.findMachine(vmName)).andReturn(registeredMachine).anyTimes();
|
||||||
|
|
||||||
expect(manager.getVBox()).andReturn(vBox).anyTimes();
|
replay(manager, vBox, machineUtils);
|
||||||
expect(vBox.findMachine(vmName)).andReturn(registeredMachine).anyTimes();
|
|
||||||
|
|
||||||
replay(manager, vBox, machineUtils);
|
VmSpec launchSpecification = VmSpec.builder().id(vmName).name(vmName).osTypeId("").memoryMB(1024)
|
||||||
|
.cleanUpMode(CleanupMode.Full).build();
|
||||||
|
|
||||||
VmSpec launchSpecification = VmSpec.builder().id(vmName).name(vmName).osTypeId("").memoryMB(1024).cleanUpMode(
|
MasterSpec machineSpec = MasterSpec.builder()
|
||||||
CleanupMode.Full).build();
|
.iso(IsoSpec.builder().sourcePath("some.iso").installationScript("dostuff").build())
|
||||||
|
.vm(launchSpecification).network(NetworkSpec.builder().build()).build();
|
||||||
|
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(Suppliers.ofInstance(manager), machineUtils,
|
||||||
|
"/tmp/workingDir").apply(machineSpec);
|
||||||
|
}
|
||||||
|
|
||||||
MasterSpec machineSpec = MasterSpec.builder()
|
@Test(expectedExceptions = VBoxException.class)
|
||||||
.iso(IsoSpec.builder()
|
public void testFailIfOtherVBoxExceptionIsThrown() throws Exception {
|
||||||
.sourcePath("some.iso")
|
|
||||||
.installationScript("dostuff").build())
|
|
||||||
.vm(launchSpecification)
|
|
||||||
.network(NetworkSpec.builder().build()).build();
|
|
||||||
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(Suppliers.ofInstance(manager), machineUtils, "/tmp/workingDir").apply(machineSpec);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expectedExceptions = VBoxException.class)
|
MachineUtils machineUtils = createMock(MachineUtils.class);
|
||||||
public void testFailIfOtherVBoxExceptionIsThrown() throws Exception {
|
|
||||||
|
|
||||||
MachineUtils machineUtils = createMock(MachineUtils.class);
|
VirtualBoxManager manager = createNiceMock(VirtualBoxManager.class);
|
||||||
|
IVirtualBox vBox = createNiceMock(IVirtualBox.class);
|
||||||
|
String vmName = "jclouds-image-my-ubuntu-image";
|
||||||
|
|
||||||
VirtualBoxManager manager = createNiceMock(VirtualBoxManager.class);
|
String errorMessage = "VirtualBox error: Some other VBox error";
|
||||||
IVirtualBox vBox = createNiceMock(IVirtualBox.class);
|
VBoxException vBoxException = new VBoxException(createNiceMock(Throwable.class), errorMessage);
|
||||||
String vmName = "jclouds-image-my-ubuntu-image";
|
|
||||||
|
|
||||||
String errorMessage = "VirtualBox error: Some other VBox error";
|
expect(manager.getVBox()).andReturn(vBox).anyTimes();
|
||||||
VBoxException vBoxException = new VBoxException(createNiceMock(Throwable.class), errorMessage);
|
|
||||||
|
|
||||||
expect(manager.getVBox()).andReturn(vBox).anyTimes();
|
vBox.findMachine(vmName);
|
||||||
|
expectLastCall().andThrow(vBoxException);
|
||||||
|
|
||||||
vBox.findMachine(vmName);
|
replay(manager, vBox, machineUtils);
|
||||||
expectLastCall().andThrow(vBoxException);
|
|
||||||
|
|
||||||
replay(manager, vBox, machineUtils);
|
VmSpec launchSpecification = VmSpec.builder().id(vmName).name(vmName).osTypeId("").cleanUpMode(CleanupMode.Full)
|
||||||
|
.memoryMB(1024).build();
|
||||||
|
MasterSpec machineSpec = MasterSpec.builder()
|
||||||
|
.iso(IsoSpec.builder().sourcePath("some.iso").installationScript("dostuff").build())
|
||||||
|
.vm(launchSpecification).network(NetworkSpec.builder().build()).build();
|
||||||
|
|
||||||
VmSpec launchSpecification = VmSpec.builder().id(vmName).name(vmName).osTypeId("").cleanUpMode(CleanupMode.Full)
|
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(Suppliers.ofInstance(manager), machineUtils,
|
||||||
.memoryMB(1024).build();
|
"/tmp/workingDir").apply(machineSpec);
|
||||||
MasterSpec machineSpec = MasterSpec.builder()
|
|
||||||
.iso(IsoSpec.builder()
|
|
||||||
.sourcePath("some.iso")
|
|
||||||
.installationScript("dostuff").build())
|
|
||||||
.vm(launchSpecification)
|
|
||||||
.network(NetworkSpec.builder().build()).build();
|
|
||||||
|
|
||||||
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(Suppliers.ofInstance(manager), machineUtils, "/tmp/workingDir").apply(machineSpec);
|
}
|
||||||
|
|
||||||
}
|
private String anyString() {
|
||||||
|
return EasyMock.<String> anyObject();
|
||||||
private String anyString() {
|
}
|
||||||
return EasyMock.<String>anyObject();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,10 +28,11 @@ import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
|
||||||
import org.jclouds.virtualbox.domain.ErrorCode;
|
import org.jclouds.virtualbox.domain.ErrorCode;
|
||||||
import org.jclouds.virtualbox.domain.HardDisk;
|
import org.jclouds.virtualbox.domain.HardDisk;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.DeviceType;
|
import org.virtualbox_4_2.AccessMode;
|
||||||
import org.virtualbox_4_1.IMedium;
|
import org.virtualbox_4_2.DeviceType;
|
||||||
import org.virtualbox_4_1.IProgress;
|
import org.virtualbox_4_2.IMedium;
|
||||||
import org.virtualbox_4_1.VBoxException;
|
import org.virtualbox_4_2.IProgress;
|
||||||
|
import org.virtualbox_4_2.VBoxException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mattias Holmqvist
|
* @author Mattias Holmqvist
|
||||||
|
@ -43,7 +44,7 @@ public class CreateMediumIfNotAlreadyExistsLiveTest extends BaseVirtualBoxClient
|
||||||
String path = System.getProperty("user.home") + "/jclouds-virtualbox-test/test-medium-1.vdi";
|
String path = System.getProperty("user.home") + "/jclouds-virtualbox-test/test-medium-1.vdi";
|
||||||
HardDisk hardDisk = HardDisk.builder().diskpath(path).controllerPort(0).deviceSlot(0).build();
|
HardDisk hardDisk = HardDisk.builder().diskpath(path).controllerPort(0).deviceSlot(0).build();
|
||||||
IMedium iMedium = new CreateMediumIfNotAlreadyExists(manager, machineUtils, true).apply(hardDisk);
|
IMedium iMedium = new CreateMediumIfNotAlreadyExists(manager, machineUtils, true).apply(hardDisk);
|
||||||
manager.get().getVBox().findMedium(path, DeviceType.HardDisk);
|
manager.get().getVBox().openMedium(path, DeviceType.HardDisk, AccessMode.ReadWrite, true);
|
||||||
try {
|
try {
|
||||||
assertFileCanBeDeleted(path);
|
assertFileCanBeDeleted(path);
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -70,7 +71,7 @@ public class CreateMediumIfNotAlreadyExistsLiveTest extends BaseVirtualBoxClient
|
||||||
HardDisk hardDisk = HardDisk.builder().diskpath(path).controllerPort(0).deviceSlot(0).build();
|
HardDisk hardDisk = HardDisk.builder().diskpath(path).controllerPort(0).deviceSlot(0).build();
|
||||||
new CreateMediumIfNotAlreadyExists(manager, machineUtils, true).apply(hardDisk);
|
new CreateMediumIfNotAlreadyExists(manager, machineUtils, true).apply(hardDisk);
|
||||||
IMedium iMedium = new CreateMediumIfNotAlreadyExists(manager, machineUtils, true).apply(hardDisk);
|
IMedium iMedium = new CreateMediumIfNotAlreadyExists(manager, machineUtils, true).apply(hardDisk);
|
||||||
manager.get().getVBox().findMedium(path, DeviceType.HardDisk);
|
manager.get().getVBox().openMedium(path, DeviceType.HardDisk, AccessMode.ReadWrite, true);
|
||||||
try {
|
try {
|
||||||
assertFileCanBeDeleted(path);
|
assertFileCanBeDeleted(path);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -22,7 +22,6 @@ package org.jclouds.virtualbox.functions;
|
||||||
import static org.easymock.EasyMock.anyLong;
|
import static org.easymock.EasyMock.anyLong;
|
||||||
import static org.easymock.EasyMock.createMock;
|
import static org.easymock.EasyMock.createMock;
|
||||||
import static org.easymock.EasyMock.createNiceMock;
|
import static org.easymock.EasyMock.createNiceMock;
|
||||||
import static org.easymock.EasyMock.eq;
|
|
||||||
import static org.easymock.EasyMock.expect;
|
import static org.easymock.EasyMock.expect;
|
||||||
import static org.easymock.EasyMock.replay;
|
import static org.easymock.EasyMock.replay;
|
||||||
import static org.easymock.EasyMock.verify;
|
import static org.easymock.EasyMock.verify;
|
||||||
|
@ -32,16 +31,17 @@ import org.jclouds.virtualbox.domain.HardDisk;
|
||||||
import org.jclouds.virtualbox.util.MachineUtils;
|
import org.jclouds.virtualbox.util.MachineUtils;
|
||||||
import org.testng.annotations.BeforeMethod;
|
import org.testng.annotations.BeforeMethod;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.DeviceType;
|
import org.virtualbox_4_2.AccessMode;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.DeviceType;
|
||||||
import org.virtualbox_4_1.IMedium;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.IMediumAttachment;
|
import org.virtualbox_4_2.IMedium;
|
||||||
import org.virtualbox_4_1.IProgress;
|
import org.virtualbox_4_2.IMediumAttachment;
|
||||||
import org.virtualbox_4_1.ISession;
|
import org.virtualbox_4_2.IProgress;
|
||||||
import org.virtualbox_4_1.IVirtualBox;
|
import org.virtualbox_4_2.ISession;
|
||||||
import org.virtualbox_4_1.LockType;
|
import org.virtualbox_4_2.IVirtualBox;
|
||||||
import org.virtualbox_4_1.VBoxException;
|
import org.virtualbox_4_2.LockType;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_2.VBoxException;
|
||||||
|
import org.virtualbox_4_2.VirtualBoxManager;
|
||||||
|
|
||||||
import com.google.common.base.Suppliers;
|
import com.google.common.base.Suppliers;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
@ -74,14 +74,14 @@ public class CreateMediumIfNotAlreadyExistsTest {
|
||||||
IProgress progress = createNiceMock(IProgress.class);
|
IProgress progress = createNiceMock(IProgress.class);
|
||||||
|
|
||||||
StringBuilder errorBuilder = new StringBuilder();
|
StringBuilder errorBuilder = new StringBuilder();
|
||||||
errorBuilder.append("org.virtualbox_4_1.VBoxException: VirtualBox error: ");
|
errorBuilder.append("org.virtualbox_4_2.VBoxException: VirtualBox error: ");
|
||||||
errorBuilder.append("Could not find an open hard disk with location ");
|
errorBuilder.append("Could not find file for the medium ");
|
||||||
errorBuilder.append("'/Users/johndoe/jclouds-virtualbox-test/testadmin.vdi' (0x80BB0001)");
|
errorBuilder.append("'/Users/johndoe/jclouds-virtualbox-test/testadmin.vdi' (0x80BB0001)");
|
||||||
String errorMessage = errorBuilder.toString();
|
String errorMessage = errorBuilder.toString();
|
||||||
expect(manager.getVBox()).andReturn(vBox).anyTimes();
|
expect(manager.getVBox()).andReturn(vBox).anyTimes();
|
||||||
|
|
||||||
VBoxException notFoundException = new VBoxException(createNiceMock(Throwable.class), errorMessage);
|
VBoxException notFoundException = new VBoxException(createNiceMock(Throwable.class), errorMessage);
|
||||||
expect(vBox.findMedium(eq(adminDiskPath), eq(DeviceType.HardDisk))).andThrow(notFoundException);
|
expect(vBox.openMedium(adminDiskPath, DeviceType.HardDisk, AccessMode.ReadWrite, false)).andThrow(notFoundException);
|
||||||
expect(vBox.createHardDisk(diskFormat, adminDiskPath)).andReturn(medium);
|
expect(vBox.createHardDisk(diskFormat, adminDiskPath)).andReturn(medium);
|
||||||
expect(medium.createBaseStorage(anyLong(), anyLong())).andReturn(progress);
|
expect(medium.createBaseStorage(anyLong(), anyLong())).andReturn(progress);
|
||||||
//expect(machineUtils.writeLockMachineAndApply(anyString(), new DetachDistroMediumFromMachine(anyString(), anyInt() , anyInt()))).andReturn().anyTimes();
|
//expect(machineUtils.writeLockMachineAndApply(anyString(), new DetachDistroMediumFromMachine(anyString(), anyInt() , anyInt()))).andReturn().anyTimes();
|
||||||
|
@ -108,7 +108,7 @@ public class CreateMediumIfNotAlreadyExistsTest {
|
||||||
IProgress progress = createNiceMock(IProgress.class);
|
IProgress progress = createNiceMock(IProgress.class);
|
||||||
|
|
||||||
expect(manager.getVBox()).andReturn(vBox).anyTimes();
|
expect(manager.getVBox()).andReturn(vBox).anyTimes();
|
||||||
expect(vBox.findMedium(adminDiskPath, DeviceType.HardDisk)).andReturn(medium);
|
expect(vBox.openMedium(adminDiskPath, DeviceType.HardDisk, AccessMode.ReadWrite, false)).andReturn(medium);
|
||||||
|
|
||||||
expect(medium.deleteStorage()).andReturn(progress);
|
expect(medium.deleteStorage()).andReturn(progress);
|
||||||
expect(vBox.createHardDisk(diskFormat, adminDiskPath)).andReturn(newHardDisk);
|
expect(vBox.createHardDisk(diskFormat, adminDiskPath)).andReturn(newHardDisk);
|
||||||
|
@ -140,7 +140,7 @@ public class CreateMediumIfNotAlreadyExistsTest {
|
||||||
IProgress progress = createNiceMock(IProgress.class);
|
IProgress progress = createNiceMock(IProgress.class);
|
||||||
|
|
||||||
expect(manager.getVBox()).andReturn(vBox).anyTimes();
|
expect(manager.getVBox()).andReturn(vBox).anyTimes();
|
||||||
expect(vBox.findMedium(adminDiskPath, DeviceType.HardDisk)).andReturn(medium);
|
expect(vBox.openMedium(adminDiskPath, DeviceType.HardDisk, AccessMode.ReadWrite, false)).andReturn(medium);
|
||||||
|
|
||||||
String oldMachineId = "a1e03931-29f3-4370-ada3-9547b1009212";
|
String oldMachineId = "a1e03931-29f3-4370-ada3-9547b1009212";
|
||||||
String oldMachineName = "oldMachine";
|
String oldMachineName = "oldMachine";
|
||||||
|
@ -154,7 +154,7 @@ public class CreateMediumIfNotAlreadyExistsTest {
|
||||||
ISession detachSession = createNiceMock(ISession.class);
|
ISession detachSession = createNiceMock(ISession.class);
|
||||||
|
|
||||||
StringBuilder errorBuilder = new StringBuilder();
|
StringBuilder errorBuilder = new StringBuilder();
|
||||||
errorBuilder.append("org.virtualbox_4_1.VBoxException: VirtualBox error: ");
|
errorBuilder.append("org.virtualbox_4_2.VBoxException: VirtualBox error: ");
|
||||||
errorBuilder.append("Cannot delete storage: medium '/Users/adriancole/jclouds-virtualbox-test/testadmin.vdi ");
|
errorBuilder.append("Cannot delete storage: medium '/Users/adriancole/jclouds-virtualbox-test/testadmin.vdi ");
|
||||||
errorBuilder.append("is still attached to the following 1 virtual machine(s): ");
|
errorBuilder.append("is still attached to the following 1 virtual machine(s): ");
|
||||||
errorBuilder.append(oldMachineId + " (0x80BB000C)");
|
errorBuilder.append(oldMachineId + " (0x80BB000C)");
|
||||||
|
@ -207,7 +207,7 @@ public class CreateMediumIfNotAlreadyExistsTest {
|
||||||
IProgress progress = createNiceMock(IProgress.class);
|
IProgress progress = createNiceMock(IProgress.class);
|
||||||
|
|
||||||
expect(manager.getVBox()).andReturn(vBox).anyTimes();
|
expect(manager.getVBox()).andReturn(vBox).anyTimes();
|
||||||
expect(vBox.findMedium(adminDiskPath, DeviceType.HardDisk)).andReturn(medium);
|
expect(vBox.openMedium(adminDiskPath, DeviceType.HardDisk, AccessMode.ReadWrite, false)).andReturn(medium);
|
||||||
|
|
||||||
replay(manager, machine, vBox, medium, newHardDisk, progress, machineUtils);
|
replay(manager, machine, vBox, medium, newHardDisk, progress, machineUtils);
|
||||||
|
|
||||||
|
@ -232,7 +232,7 @@ public class CreateMediumIfNotAlreadyExistsTest {
|
||||||
expect(manager.getVBox()).andReturn(vBox).anyTimes();
|
expect(manager.getVBox()).andReturn(vBox).anyTimes();
|
||||||
|
|
||||||
VBoxException notFoundException = new VBoxException(createNiceMock(Throwable.class), errorMessage);
|
VBoxException notFoundException = new VBoxException(createNiceMock(Throwable.class), errorMessage);
|
||||||
expect(vBox.findMedium(adminDiskPath, DeviceType.HardDisk)).andThrow(notFoundException);
|
expect(vBox.openMedium(adminDiskPath, DeviceType.HardDisk, AccessMode.ReadWrite, false)).andThrow(notFoundException);
|
||||||
expect(vBox.createHardDisk(diskFormat, adminDiskPath)).andReturn(medium);
|
expect(vBox.createHardDisk(diskFormat, adminDiskPath)).andReturn(medium);
|
||||||
expect(medium.createBaseStorage(anyLong(), anyLong())).andReturn(progress);
|
expect(medium.createBaseStorage(anyLong(), anyLong())).andReturn(progress);
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,8 @@ import static org.easymock.EasyMock.replay;
|
||||||
import static org.easymock.EasyMock.verify;
|
import static org.easymock.EasyMock.verify;
|
||||||
|
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.VBoxException;
|
import org.virtualbox_4_2.VBoxException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Andrea Turli
|
* @author Andrea Turli
|
||||||
|
|
|
@ -28,10 +28,10 @@ import static org.testng.Assert.assertEquals;
|
||||||
import org.jclouds.compute.domain.Hardware;
|
import org.jclouds.compute.domain.Hardware;
|
||||||
import org.jclouds.compute.predicates.ImagePredicates;
|
import org.jclouds.compute.predicates.ImagePredicates;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.IGuestOSType;
|
import org.virtualbox_4_2.IGuestOSType;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.IVirtualBox;
|
import org.virtualbox_4_2.IVirtualBox;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_2.VirtualBoxManager;
|
||||||
|
|
||||||
import com.google.common.base.Suppliers;
|
import com.google.common.base.Suppliers;
|
||||||
|
|
||||||
|
|
|
@ -37,11 +37,11 @@ import org.jclouds.json.config.GsonModule;
|
||||||
import org.jclouds.virtualbox.config.VirtualBoxComputeServiceContextModule;
|
import org.jclouds.virtualbox.config.VirtualBoxComputeServiceContextModule;
|
||||||
import org.jclouds.virtualbox.config.VirtualBoxConstants;
|
import org.jclouds.virtualbox.config.VirtualBoxConstants;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.IGuestOSType;
|
import org.virtualbox_4_2.IGuestOSType;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.IVirtualBox;
|
import org.virtualbox_4_2.IVirtualBox;
|
||||||
import org.virtualbox_4_1.MachineState;
|
import org.virtualbox_4_2.MachineState;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_2.VirtualBoxManager;
|
||||||
|
|
||||||
import com.google.common.base.Suppliers;
|
import com.google.common.base.Suppliers;
|
||||||
import com.google.inject.Guice;
|
import com.google.inject.Guice;
|
||||||
|
|
|
@ -28,48 +28,70 @@ import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_NODE_
|
||||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_NODE_PREFIX;
|
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_NODE_PREFIX;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.jclouds.compute.config.BaseComputeServiceContextModule;
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
import org.jclouds.compute.domain.NodeMetadata;
|
||||||
|
import org.jclouds.compute.domain.OsFamily;
|
||||||
|
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||||
|
import org.jclouds.json.Json;
|
||||||
|
import org.jclouds.json.config.GsonModule;
|
||||||
import org.jclouds.virtualbox.config.VirtualBoxComputeServiceContextModule;
|
import org.jclouds.virtualbox.config.VirtualBoxComputeServiceContextModule;
|
||||||
import org.jclouds.virtualbox.util.NetworkUtils;
|
import org.jclouds.virtualbox.util.NetworkUtils;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IGuest;
|
||||||
import org.virtualbox_4_1.INATEngine;
|
import org.virtualbox_4_2.IGuestOSType;
|
||||||
import org.virtualbox_4_1.INetworkAdapter;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.MachineState;
|
import org.virtualbox_4_2.INATEngine;
|
||||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
import org.virtualbox_4_2.INetworkAdapter;
|
||||||
|
import org.virtualbox_4_2.IVirtualBox;
|
||||||
|
import org.virtualbox_4_2.MachineState;
|
||||||
|
import org.virtualbox_4_2.NetworkAttachmentType;
|
||||||
|
import org.virtualbox_4_2.VirtualBoxManager;
|
||||||
|
|
||||||
|
import com.google.common.base.Suppliers;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
|
import com.google.inject.Guice;
|
||||||
|
|
||||||
public class IMachineToNodeMetadataTest {
|
public class IMachineToNodeMetadataTest {
|
||||||
|
|
||||||
private static final String MASTER_NAME = "mock-image-of-a-server";
|
private static final String MASTER_NAME = "mock-image-of-a-server";
|
||||||
|
Map<OsFamily, Map<String, String>> map = new BaseComputeServiceContextModule() {
|
||||||
|
}.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule())
|
||||||
|
.getInstance(Json.class));
|
||||||
|
|
||||||
@Test
|
@Test(enabled=false)
|
||||||
public void testCreateFromMaster() throws Exception {
|
public void testCreateFromMaster() throws Exception {
|
||||||
|
|
||||||
IMachine vm = createNiceMock(IMachine.class);
|
IMachine vm = createNiceMock(IMachine.class);
|
||||||
|
VirtualBoxManager vbm = createNiceMock(VirtualBoxManager.class);
|
||||||
expect(vm.getName()).andReturn(VIRTUALBOX_IMAGE_PREFIX + MASTER_NAME).anyTimes();
|
IVirtualBox vBox = createNiceMock(IVirtualBox.class);
|
||||||
expect(vm.getState()).andReturn(MachineState.PoweredOff).anyTimes();
|
IGuestOSType iGuestOSType = createNiceMock(IGuestOSType.class);
|
||||||
|
|
||||||
INetworkAdapter nat = createNiceMock(INetworkAdapter.class);
|
INetworkAdapter nat = createNiceMock(INetworkAdapter.class);
|
||||||
INATEngine natEng = createNiceMock(INATEngine.class);
|
INATEngine natEng = createNiceMock(INATEngine.class);
|
||||||
|
|
||||||
|
expect(vm.getName()).andReturn(VIRTUALBOX_IMAGE_PREFIX + MASTER_NAME).anyTimes();
|
||||||
|
expect(vm.getState()).andReturn(MachineState.PoweredOff).anyTimes();
|
||||||
expect(vm.getNetworkAdapter(eq(0l))).andReturn(nat).once();
|
expect(vm.getNetworkAdapter(eq(0l))).andReturn(nat).once();
|
||||||
expect(vm.getNetworkAdapter(eq(1l))).andReturn(null).once();
|
expect(vm.getNetworkAdapter(eq(1l))).andReturn(null).once();
|
||||||
expect(nat.getAttachmentType()).andReturn(NetworkAttachmentType.NAT).once();
|
expect(nat.getAttachmentType()).andReturn(NetworkAttachmentType.NAT).once();
|
||||||
expect(nat.getNatDriver()).andReturn(natEng).anyTimes();
|
expect(nat.getNATEngine()).andReturn(natEng).anyTimes();
|
||||||
expect(natEng.getHostIP()).andReturn("127.0.0.1").once();
|
expect(natEng.getHostIP()).andReturn("127.0.0.1").once();
|
||||||
expect(natEng.getRedirects()).andReturn(ImmutableList.of("0,1,127.0.0.1,2222,,22"));
|
expect(natEng.getRedirects()).andReturn(ImmutableList.of("0,1,127.0.0.1,2222,,22"));
|
||||||
|
|
||||||
|
expect(vbm.getVBox()).andReturn(vBox).anyTimes();
|
||||||
|
expect(vm.getOSTypeId()).andReturn("RedHat_64").anyTimes();
|
||||||
|
expect(vBox.getGuestOSType(vm.getOSTypeId())).andReturn(iGuestOSType);
|
||||||
|
|
||||||
INetworkAdapter hostOnly = createNiceMock(INetworkAdapter.class);
|
INetworkAdapter hostOnly = createNiceMock(INetworkAdapter.class);
|
||||||
NetworkUtils networkUtils = createNiceMock(NetworkUtils.class);
|
NetworkUtils networkUtils = createNiceMock(NetworkUtils.class);
|
||||||
|
|
||||||
replay(vm, nat, natEng, hostOnly, networkUtils);
|
replay(vm, vBox, iGuestOSType, nat, natEng, hostOnly, networkUtils);
|
||||||
|
|
||||||
NodeMetadata node = new IMachineToNodeMetadata(VirtualBoxComputeServiceContextModule.toPortableNodeStatus,
|
NodeMetadata node = new IMachineToNodeMetadata(Suppliers
|
||||||
networkUtils).apply(vm);
|
.ofInstance(vbm), VirtualBoxComputeServiceContextModule.toPortableNodeStatus,
|
||||||
|
networkUtils, map).apply(vm);
|
||||||
|
|
||||||
assertEquals(MASTER_NAME, node.getName());
|
assertEquals(MASTER_NAME, node.getName());
|
||||||
assertEquals(1, node.getPrivateAddresses().size());
|
assertEquals(1, node.getPrivateAddresses().size());
|
||||||
|
@ -79,11 +101,13 @@ public class IMachineToNodeMetadataTest {
|
||||||
assertEquals("", node.getGroup());
|
assertEquals("", node.getGroup());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(enabled=false)
|
||||||
public void testCreateFromNode() throws Exception {
|
public void testCreateFromNode() throws Exception {
|
||||||
|
|
||||||
IMachine vm = createNiceMock(IMachine.class);
|
IMachine vm = createNiceMock(IMachine.class);
|
||||||
|
VirtualBoxManager vbm = createNiceMock(VirtualBoxManager.class);
|
||||||
|
IVirtualBox vBox = createNiceMock(IVirtualBox.class);
|
||||||
|
expect(vbm.getVBox()).andReturn(vBox).anyTimes();
|
||||||
String group = "my-cluster-group";
|
String group = "my-cluster-group";
|
||||||
String name = "a-name-with-a-code-338";
|
String name = "a-name-with-a-code-338";
|
||||||
|
|
||||||
|
@ -97,18 +121,21 @@ public class IMachineToNodeMetadataTest {
|
||||||
|
|
||||||
INetworkAdapter hostOnly = createNiceMock(INetworkAdapter.class);
|
INetworkAdapter hostOnly = createNiceMock(INetworkAdapter.class);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
expect(vm.getNetworkAdapter(eq(0l))).andReturn(nat).once();
|
expect(vm.getNetworkAdapter(eq(0l))).andReturn(nat).once();
|
||||||
expect(vm.getNetworkAdapter(eq(1l))).andReturn(hostOnly).once();
|
expect(vm.getNetworkAdapter(eq(1l))).andReturn(hostOnly).once();
|
||||||
expect(nat.getAttachmentType()).andReturn(NetworkAttachmentType.NAT).once();
|
expect(nat.getAttachmentType()).andReturn(NetworkAttachmentType.NAT).once();
|
||||||
expect(nat.getNatDriver()).andReturn(natEng).anyTimes();
|
expect(nat.getNATEngine()).andReturn(natEng).anyTimes();
|
||||||
expect(natEng.getHostIP()).andReturn("127.0.0.1").once();
|
expect(natEng.getHostIP()).andReturn("127.0.0.1").once();
|
||||||
expect(natEng.getRedirects()).andReturn(ImmutableList.of("0,1,127.0.0.1,3000,,22"));
|
expect(natEng.getRedirects()).andReturn(ImmutableList.of("0,1,127.0.0.1,3000,,22"));
|
||||||
NetworkUtils networkUtils = createNiceMock(NetworkUtils.class);
|
NetworkUtils networkUtils = createNiceMock(NetworkUtils.class);
|
||||||
|
|
||||||
replay(vm, nat, natEng, hostOnly, networkUtils);
|
replay(vm, nat, natEng, hostOnly, networkUtils);
|
||||||
|
|
||||||
NodeMetadata node = new IMachineToNodeMetadata(VirtualBoxComputeServiceContextModule.toPortableNodeStatus,
|
NodeMetadata node = new IMachineToNodeMetadata(Suppliers
|
||||||
networkUtils).apply(vm);
|
.ofInstance(vbm), VirtualBoxComputeServiceContextModule.toPortableNodeStatus,
|
||||||
|
networkUtils, map).apply(vm);
|
||||||
|
|
||||||
assertEquals(name, node.getName());
|
assertEquals(name, node.getName());
|
||||||
assertEquals(group, node.getGroup());
|
assertEquals(group, node.getGroup());
|
||||||
|
|
|
@ -29,13 +29,13 @@ import org.jclouds.virtualbox.domain.IsoImage;
|
||||||
import org.jclouds.virtualbox.domain.StorageController;
|
import org.jclouds.virtualbox.domain.StorageController;
|
||||||
import org.jclouds.virtualbox.domain.VmSpec;
|
import org.jclouds.virtualbox.domain.VmSpec;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.DeviceType;
|
import org.virtualbox_4_2.DeviceType;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.IMedium;
|
import org.virtualbox_4_2.IMedium;
|
||||||
import org.virtualbox_4_1.IMediumAttachment;
|
import org.virtualbox_4_2.IMediumAttachment;
|
||||||
import org.virtualbox_4_1.IStorageController;
|
import org.virtualbox_4_2.IStorageController;
|
||||||
import org.virtualbox_4_1.StorageBus;
|
import org.virtualbox_4_2.StorageBus;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_2.VirtualBoxManager;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
|
|
@ -25,11 +25,11 @@ import static org.easymock.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_2.IMachine;
|
||||||
import org.virtualbox_4_1.IProgress;
|
import org.virtualbox_4_2.IProgress;
|
||||||
import org.virtualbox_4_1.ISession;
|
import org.virtualbox_4_2.ISession;
|
||||||
import org.virtualbox_4_1.SessionState;
|
import org.virtualbox_4_2.SessionState;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_2.VirtualBoxManager;
|
||||||
|
|
||||||
@Test(groups = "unit", testName = "LaunchMachineIfNotAlreadyRunningTest")
|
@Test(groups = "unit", testName = "LaunchMachineIfNotAlreadyRunningTest")
|
||||||
public class LaunchMachineIfNotAlreadyRunningTest {
|
public class LaunchMachineIfNotAlreadyRunningTest {
|
||||||
|
|
|
@ -26,14 +26,14 @@ import static org.easymock.EasyMock.verify;
|
||||||
|
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.IConsole;
|
import org.virtualbox_4_2.IConsole;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.IProgress;
|
import org.virtualbox_4_2.IProgress;
|
||||||
import org.virtualbox_4_1.ISession;
|
import org.virtualbox_4_2.ISession;
|
||||||
import org.virtualbox_4_1.ISnapshot;
|
import org.virtualbox_4_2.ISnapshot;
|
||||||
import org.virtualbox_4_1.IVirtualBox;
|
import org.virtualbox_4_2.IVirtualBox;
|
||||||
import org.virtualbox_4_1.MachineState;
|
import org.virtualbox_4_2.MachineState;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_2.VirtualBoxManager;
|
||||||
|
|
||||||
import com.google.common.base.Suppliers;
|
import com.google.common.base.Suppliers;
|
||||||
|
|
||||||
|
|
|
@ -60,4 +60,4 @@ public class ImageFromYamlStringTest {
|
||||||
public void testNodesParse() {
|
public void testNodesParse() {
|
||||||
assertEquals(Iterables.getFirst(images.keySet(), null), TEST1);
|
assertEquals(Iterables.getFirst(images.keySet(), null), TEST1);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -24,21 +24,18 @@ import static org.easymock.EasyMock.expect;
|
||||||
import static org.easymock.EasyMock.expectLastCall;
|
import static org.easymock.EasyMock.expectLastCall;
|
||||||
import static org.easymock.EasyMock.replay;
|
import static org.easymock.EasyMock.replay;
|
||||||
import static org.easymock.EasyMock.verify;
|
import static org.easymock.EasyMock.verify;
|
||||||
import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot;
|
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
import org.jclouds.compute.callables.RunScriptOnNode;
|
import org.jclouds.compute.callables.RunScriptOnNode;
|
||||||
import org.jclouds.compute.callables.RunScriptOnNode.Factory;
|
import org.jclouds.compute.callables.RunScriptOnNode.Factory;
|
||||||
import org.jclouds.compute.domain.ExecResponse;
|
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
import org.jclouds.compute.domain.NodeMetadata;
|
||||||
import org.jclouds.compute.domain.NodeMetadata.Status;
|
import org.jclouds.compute.domain.NodeMetadata.Status;
|
||||||
import org.jclouds.compute.domain.NodeMetadataBuilder;
|
import org.jclouds.compute.domain.NodeMetadataBuilder;
|
||||||
import org.jclouds.compute.domain.OperatingSystem;
|
import org.jclouds.virtualbox.functions.HardcodedHostToHostNodeMetadata;
|
||||||
import org.jclouds.scriptbuilder.domain.Statements;
|
|
||||||
import org.jclouds.virtualbox.predicates.RetryIfSocketNotYetOpen;
|
import org.jclouds.virtualbox.predicates.RetryIfSocketNotYetOpen;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_2.VirtualBoxManager;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Functions;
|
import com.google.common.base.Functions;
|
||||||
|
@ -53,57 +50,18 @@ public class StartVBoxIfNotAlreadyRunningLiveTest {
|
||||||
public void testStartVboxConnectsToManagerWhenPortAlreadyListening() throws Exception {
|
public void testStartVboxConnectsToManagerWhenPortAlreadyListening() throws Exception {
|
||||||
VirtualBoxManager manager = createMock(VirtualBoxManager.class);
|
VirtualBoxManager manager = createMock(VirtualBoxManager.class);
|
||||||
Factory runScriptOnNodeFactory = createMock(Factory.class);
|
Factory runScriptOnNodeFactory = createMock(Factory.class);
|
||||||
|
RunScriptOnNode runScriptOnNode = createMock(RunScriptOnNode.class);
|
||||||
RetryIfSocketNotYetOpen client = createMock(RetryIfSocketNotYetOpen.class);
|
RetryIfSocketNotYetOpen client = createMock(RetryIfSocketNotYetOpen.class);
|
||||||
|
HardcodedHostToHostNodeMetadata hardcodedHostToHostNodeMetadata = createMock(HardcodedHostToHostNodeMetadata.class);
|
||||||
NodeMetadata host = new NodeMetadataBuilder().id("host").status(Status.RUNNING).build();
|
NodeMetadata host = new NodeMetadataBuilder().id("host").status(Status.RUNNING).build();
|
||||||
URI provider = URI.create("http://localhost:18083/");
|
URI provider = URI.create("http://localhost:18083/");
|
||||||
expect(client.seconds(3)).andReturn(client);
|
expect(client.seconds(3)).andReturn(client);
|
||||||
expect(client.apply(HostAndPort.fromParts(provider.getHost(), provider.getPort()))).andReturn(true).anyTimes();
|
expect(client.apply(HostAndPort.fromParts(provider.getHost(), provider.getPort()))).andReturn(true).anyTimes();
|
||||||
manager.connect(provider.toASCIIString(), "", "");
|
manager.connect(provider.toASCIIString(), "", "");
|
||||||
expectLastCall().anyTimes();
|
expectLastCall().anyTimes();
|
||||||
|
|
||||||
replay(manager, runScriptOnNodeFactory, client);
|
|
||||||
|
|
||||||
new StartVBoxIfNotAlreadyRunning((Function) Functions.constant(manager), runScriptOnNodeFactory, client,
|
|
||||||
Suppliers.ofInstance(host), Suppliers.ofInstance(provider), null).start();
|
|
||||||
|
|
||||||
verify(manager, runScriptOnNodeFactory, client);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
|
||||||
@Test
|
|
||||||
public void testStartVboxDisablesPasswordAccessOnWebsrvauthlibraryStartsVboxwebsrvInBackgroundAndConnectsManagerWhenPortIsNotListening()
|
|
||||||
throws Exception {
|
|
||||||
VirtualBoxManager manager = createMock(VirtualBoxManager.class);
|
|
||||||
Factory runScriptOnNodeFactory = createMock(Factory.class);
|
|
||||||
RetryIfSocketNotYetOpen client = createMock(RetryIfSocketNotYetOpen.class);
|
|
||||||
RunScriptOnNode runScriptOnNode = createMock(RunScriptOnNode.class);
|
|
||||||
NodeMetadata host = new NodeMetadataBuilder().id("host").status(Status.RUNNING).operatingSystem(
|
|
||||||
OperatingSystem.builder().description("unix").build()).build();
|
|
||||||
URI provider = URI.create("http://localhost:18083/");
|
|
||||||
|
|
||||||
expect(client.seconds(3)).andReturn(client);
|
|
||||||
expect(client.apply(HostAndPort.fromParts(provider.getHost(), provider.getPort()))).andReturn(false).once().andReturn(true).once();
|
|
||||||
expect(runScriptOnNodeFactory.create(host,
|
|
||||||
Statements.exec("VBoxManage setproperty websrvauthlibrary null"),
|
|
||||||
runAsRoot(false).wrapInInitScript(false))).andReturn(runScriptOnNode);
|
|
||||||
expect(runScriptOnNode.init()).andReturn(runScriptOnNode);
|
|
||||||
expect(runScriptOnNode.call()).andReturn(new ExecResponse("", "", 0));
|
|
||||||
|
|
||||||
expect(runScriptOnNodeFactory.create(host,
|
|
||||||
Statements.exec("vboxwebsrv -t 10000 -v -b -H localhost"), runAsRoot(false)
|
|
||||||
.wrapInInitScript(false).blockOnComplete(false).nameTask("vboxwebsrv")))
|
|
||||||
.andReturn(runScriptOnNode);
|
|
||||||
|
|
||||||
expect(runScriptOnNode.init()).andReturn(runScriptOnNode);
|
|
||||||
expect(runScriptOnNode.call()).andReturn(new ExecResponse("", "", 0));
|
|
||||||
manager.connect(provider.toASCIIString(), "", "");
|
|
||||||
expectLastCall().anyTimes();
|
|
||||||
|
|
||||||
replay(manager, runScriptOnNodeFactory, runScriptOnNode, client);
|
replay(manager, runScriptOnNodeFactory, runScriptOnNode, client);
|
||||||
new StartVBoxIfNotAlreadyRunning((Function) Functions.constant(manager), runScriptOnNodeFactory, client,
|
new StartVBoxIfNotAlreadyRunning((Function) Functions.constant(manager), runScriptOnNodeFactory, client,
|
||||||
Suppliers.ofInstance(host), Suppliers.ofInstance(provider), null);
|
Suppliers.ofInstance(host), Suppliers.ofInstance(provider), hardcodedHostToHostNodeMetadata).start();
|
||||||
|
verify(manager, runScriptOnNodeFactory, client);
|
||||||
verify(manager, runScriptOnNodeFactory, runScriptOnNode, client);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,19 +27,19 @@ import static org.easymock.EasyMock.replay;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
|
|
||||||
import org.jclouds.virtualbox.domain.HardDisk;
|
import org.jclouds.virtualbox.domain.HardDisk;
|
||||||
import org.jclouds.virtualbox.domain.StorageController;
|
import org.jclouds.virtualbox.domain.StorageController;
|
||||||
import org.jclouds.virtualbox.domain.VmSpec;
|
import org.jclouds.virtualbox.domain.VmSpec;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.CleanupMode;
|
import org.virtualbox_4_2.CleanupMode;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.IMedium;
|
import org.virtualbox_4_2.IMedium;
|
||||||
import org.virtualbox_4_1.IProgress;
|
import org.virtualbox_4_2.IProgress;
|
||||||
import org.virtualbox_4_1.IVirtualBox;
|
import org.virtualbox_4_2.IVirtualBox;
|
||||||
import org.virtualbox_4_1.StorageBus;
|
import org.virtualbox_4_2.StorageBus;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_2.VirtualBoxManager;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
@Test(groups = "unit", testName = "UnregisterMachineIfExistsTest")
|
@Test(groups = "unit", testName = "UnregisterMachineIfExistsTest")
|
||||||
public class UnregisterMachineIfExistsAndDeleteItsMediaTest {
|
public class UnregisterMachineIfExistsAndDeleteItsMediaTest {
|
||||||
|
@ -58,22 +58,20 @@ public class UnregisterMachineIfExistsAndDeleteItsMediaTest {
|
||||||
IProgress progress = createNiceMock(IProgress.class);
|
IProgress progress = createNiceMock(IProgress.class);
|
||||||
List<IMedium> media = Lists.newArrayList();
|
List<IMedium> media = Lists.newArrayList();
|
||||||
List<IMedium> mediums = Collections.unmodifiableList(media);
|
List<IMedium> mediums = Collections.unmodifiableList(media);
|
||||||
|
|
||||||
StorageController ideController = StorageController.builder().name(ideControllerName).bus(StorageBus.IDE)
|
StorageController ideController = StorageController.builder().name(ideControllerName).bus(StorageBus.IDE)
|
||||||
.attachISO(0, 0, "/tmp/ubuntu-11.04-server-i386.iso")
|
.attachISO(0, 0, "/tmp/ubuntu-11.04-server-i386.iso")
|
||||||
.attachHardDisk(HardDisk.builder().diskpath("/tmp/testadmin.vdi").controllerPort(0).deviceSlot(1).build())
|
.attachHardDisk(HardDisk.builder().diskpath("/tmp/testadmin.vdi").controllerPort(0).deviceSlot(1).build())
|
||||||
.attachISO(1, 1, "/tmp/VBoxGuestAdditions_4.1.2.iso").build();
|
.attachISO(1, 1, "/tmp/VBoxGuestAdditions_4.1.2.iso").build();
|
||||||
VmSpec vmSpecification = VmSpec.builder().id(vmId).name(vmName).memoryMB(512).osTypeId(osTypeId)
|
VmSpec vmSpecification = VmSpec.builder().id(vmId).name(vmName).memoryMB(512).osTypeId(osTypeId)
|
||||||
.controller(ideController)
|
.controller(ideController).forceOverwrite(true).cleanUpMode(CleanupMode.Full).build();
|
||||||
.forceOverwrite(true)
|
|
||||||
.cleanUpMode(CleanupMode.Full).build();
|
|
||||||
|
|
||||||
expect(manager.getVBox()).andReturn(vBox).anyTimes();
|
expect(manager.getVBox()).andReturn(vBox).anyTimes();
|
||||||
expect(vBox.findMachine(vmName)).andReturn(registeredMachine);
|
expect(vBox.findMachine(vmName)).andReturn(registeredMachine);
|
||||||
|
|
||||||
expect(registeredMachine.unregister(mode)).andReturn(mediums);
|
expect(registeredMachine.unregister(mode)).andReturn(mediums);
|
||||||
expectLastCall().anyTimes();
|
expectLastCall().anyTimes();
|
||||||
|
|
||||||
expect(registeredMachine.delete(mediums)).andReturn(progress);
|
expect(registeredMachine.delete(mediums)).andReturn(progress);
|
||||||
expectLastCall().anyTimes();
|
expectLastCall().anyTimes();
|
||||||
|
|
||||||
|
|
|
@ -42,10 +42,10 @@ import org.jclouds.virtualbox.functions.IMachineToSshClient;
|
||||||
import org.jclouds.virtualbox.util.NetworkUtils;
|
import org.jclouds.virtualbox.util.NetworkUtils;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.CleanupMode;
|
import org.virtualbox_4_2.CleanupMode;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
import org.virtualbox_4_2.NetworkAttachmentType;
|
||||||
import org.virtualbox_4_1.StorageBus;
|
import org.virtualbox_4_2.StorageBus;
|
||||||
|
|
||||||
import com.google.common.base.CaseFormat;
|
import com.google.common.base.CaseFormat;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
@ -56,15 +56,15 @@ import com.google.inject.Injector;
|
||||||
/**
|
/**
|
||||||
* @author Andrea Turli
|
* @author Andrea Turli
|
||||||
*/
|
*/
|
||||||
@Test(groups = "live", singleThreaded = true, testName = "GuestAdditionsInstallerLiveTest", enabled=false)
|
@Test(groups = "live", singleThreaded = true, testName = "GuestAdditionsInstallerLiveTest")
|
||||||
public class GuestAdditionsInstallerLiveTest extends BaseVirtualBoxClientLiveTest {
|
public class GuestAdditionsInstallerLiveTest extends BaseVirtualBoxClientLiveTest {
|
||||||
|
|
||||||
private Injector injector;
|
private Injector injector;
|
||||||
private Function<IMachine, SshClient> sshClientForIMachine;
|
private Function<IMachine, SshClient> sshClientForIMachine;
|
||||||
private Predicate<SshClient> sshResponds;
|
private Predicate<SshClient> sshResponds;
|
||||||
|
private VmSpec instanceVmSpec;
|
||||||
private MasterSpec machineSpec;
|
private NetworkSpec instanceNetworkSpec;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@BeforeClass(groups = "live")
|
@BeforeClass(groups = "live")
|
||||||
public void setupContext() {
|
public void setupContext() {
|
||||||
|
@ -83,7 +83,7 @@ public class GuestAdditionsInstallerLiveTest extends BaseVirtualBoxClientLiveTes
|
||||||
HardDisk.builder().diskpath(adminDisk(instanceName)).controllerPort(0).deviceSlot(1)
|
HardDisk.builder().diskpath(adminDisk(instanceName)).controllerPort(0).deviceSlot(1)
|
||||||
.autoDelete(true).build()).attachISO(1, 1, guestAdditionsIso).build();
|
.autoDelete(true).build()).attachISO(1, 1, guestAdditionsIso).build();
|
||||||
|
|
||||||
VmSpec instanceVmSpec = VmSpec.builder().id(instanceName).name(instanceName).osTypeId("").memoryMB(512)
|
instanceVmSpec = VmSpec.builder().id(instanceName).name(instanceName).osTypeId("").memoryMB(512)
|
||||||
.cleanUpMode(CleanupMode.Full).controller(ideController).forceOverwrite(true).build();
|
.cleanUpMode(CleanupMode.Full).controller(ideController).forceOverwrite(true).build();
|
||||||
|
|
||||||
Function<String, String> configProperties = injector.getInstance(ValueOfConfigurationKeyOrNull.class);
|
Function<String, String> configProperties = injector.getInstance(ValueOfConfigurationKeyOrNull.class);
|
||||||
|
@ -94,13 +94,14 @@ public class GuestAdditionsInstallerLiveTest extends BaseVirtualBoxClientLiveTes
|
||||||
configProperties.apply(VIRTUALBOX_INSTALLATION_KEY_SEQUENCE).replace("HOSTNAME",
|
configProperties.apply(VIRTUALBOX_INSTALLATION_KEY_SEQUENCE).replace("HOSTNAME",
|
||||||
instanceVmSpec.getVmName())).build();
|
instanceVmSpec.getVmName())).build();
|
||||||
|
|
||||||
NetworkAdapter networkAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.NAT)
|
NetworkAdapter networkAdapter = NetworkAdapter.builder()
|
||||||
.tcpRedirectRule("127.0.0.1", 2222, "", 22).build();
|
.networkAttachmentType(NetworkAttachmentType.HostOnly)
|
||||||
|
.build();
|
||||||
NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(networkAdapter)
|
NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(networkAdapter)
|
||||||
.build();
|
.addHostInterfaceName("vboxnet0").slot(0L).build();
|
||||||
|
|
||||||
NetworkSpec networkSpec = NetworkSpec.builder().addNIC(networkInterfaceCard).build();
|
instanceNetworkSpec = NetworkSpec.builder().addNIC(networkInterfaceCard).build();
|
||||||
machineSpec = MasterSpec.builder().iso(isoSpec).vm(instanceVmSpec).network(networkSpec).build();
|
//cloneSpec = MasterSpec.builder().iso(isoSpec).vm(instanceVmSpec).network(networkSpec).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -119,23 +120,29 @@ public class GuestAdditionsInstallerLiveTest extends BaseVirtualBoxClientLiveTes
|
||||||
assertTrue(NetworkUtils.isIpv4(networkUtils.getIpAddressFromNicSlot(machine.getName(), 0l)));
|
assertTrue(NetworkUtils.isIpv4(networkUtils.getIpAddressFromNicSlot(machine.getName(), 0l)));
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
for (String vmNameOrId : ImmutableSet.of(machine.getName())) {
|
if(machine!=null) {
|
||||||
machineController.ensureMachineHasPowerDown(vmNameOrId);
|
for (String vmNameOrId : ImmutableSet.of(machine.getName())) {
|
||||||
undoVm(vmNameOrId);
|
machineController.ensureMachineHasPowerDown(vmNameOrId);
|
||||||
|
undoVm(vmNameOrId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IMachine cloneFromMaster() {
|
protected IMachine cloneFromMaster() {
|
||||||
IMachine source = getVmWithGuestAdditionsInstalled();
|
IMachine source = getVmWithGuestAdditionsInstalled();
|
||||||
CloneSpec cloneSpec = CloneSpec.builder().vm(machineSpec.getVmSpec()).network(machineSpec.getNetworkSpec())
|
CloneSpec cloneSpec = CloneSpec.builder()
|
||||||
.master(source).linked(true).build();
|
.vm(instanceVmSpec)
|
||||||
|
.network(instanceNetworkSpec)
|
||||||
|
.master(source)
|
||||||
|
.linked(true)
|
||||||
|
.build();
|
||||||
return new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(manager, workingDir, machineUtils)
|
return new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(manager, workingDir, machineUtils)
|
||||||
.apply(cloneSpec);
|
.apply(cloneSpec);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IMachine getVmWithGuestAdditionsInstalled() {
|
private IMachine getVmWithGuestAdditionsInstalled() {
|
||||||
MasterSpec masterSpecForTest = super.getMasterSpecForTest();
|
MasterSpec masterSpecForTest = getMasterSpecForTest();
|
||||||
try {
|
try {
|
||||||
Injector injector = view.utils().injector();
|
Injector injector = view.utils().injector();
|
||||||
return injector.getInstance(CreateAndInstallVm.class).apply(masterSpecForTest);
|
return injector.getInstance(CreateAndInstallVm.class).apply(masterSpecForTest);
|
||||||
|
@ -144,5 +151,4 @@ public class GuestAdditionsInstallerLiveTest extends BaseVirtualBoxClientLiveTes
|
||||||
return manager.get().getVBox().findMachine(masterSpecForTest.getVmSpec().getVmId());
|
return manager.get().getVBox().findMachine(masterSpecForTest.getVmSpec().getVmId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,10 +40,10 @@ import org.jclouds.virtualbox.functions.CreateAndInstallVm;
|
||||||
import org.testng.annotations.AfterGroups;
|
import org.testng.annotations.AfterGroups;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.CleanupMode;
|
import org.virtualbox_4_2.CleanupMode;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_2.IMachine;
|
||||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
import org.virtualbox_4_2.NetworkAttachmentType;
|
||||||
import org.virtualbox_4_1.StorageBus;
|
import org.virtualbox_4_2.StorageBus;
|
||||||
|
|
||||||
import com.google.common.base.CaseFormat;
|
import com.google.common.base.CaseFormat;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
|
|
@ -26,8 +26,8 @@ import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
|
||||||
import org.jclouds.virtualbox.domain.StorageController;
|
import org.jclouds.virtualbox.domain.StorageController;
|
||||||
import org.jclouds.virtualbox.domain.VmSpec;
|
import org.jclouds.virtualbox.domain.VmSpec;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.CleanupMode;
|
import org.virtualbox_4_2.CleanupMode;
|
||||||
import org.virtualbox_4_1.StorageBus;
|
import org.virtualbox_4_2.StorageBus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Andrea Turli, David Alves
|
* @author Andrea Turli, David Alves
|
||||||
|
@ -44,8 +44,8 @@ public class InstallGuestAdditionsLiveTest extends BaseVirtualBoxClientLiveTest
|
||||||
|
|
||||||
InstallGuestAdditions installer = new InstallGuestAdditions(vmSpecification, "4.1.8");
|
InstallGuestAdditions installer = new InstallGuestAdditions(vmSpecification, "4.1.8");
|
||||||
String scripts = installer.render(OsFamily.UNIX);
|
String scripts = installer.render(OsFamily.UNIX);
|
||||||
assertEquals("installModuleAssistantIfNeeded || return 1\n" + "mount -t iso9660 /dev/sr1 /mnt\n"
|
assertEquals(scripts, "installModuleAssistantIfNeeded || return 1\n" + "mount -t iso9660 /dev/cdrom1 /mnt\n"
|
||||||
+ "/mnt/VBoxLinuxAdditions.run --nox11\n", scripts);
|
+ "/mnt/VBoxLinuxAdditions.run --nox11\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testIsoNotPresent() {
|
public void testIsoNotPresent() {
|
||||||
|
@ -56,12 +56,11 @@ public class InstallGuestAdditionsLiveTest extends BaseVirtualBoxClientLiveTest
|
||||||
|
|
||||||
InstallGuestAdditions installer = new InstallGuestAdditions(vmSpecification, "4.1.8");
|
InstallGuestAdditions installer = new InstallGuestAdditions(vmSpecification, "4.1.8");
|
||||||
String scripts = installer.render(OsFamily.UNIX);
|
String scripts = installer.render(OsFamily.UNIX);
|
||||||
assertEquals(
|
assertEquals(scripts,
|
||||||
"installModuleAssistantIfNeeded || return 1\n"
|
"installModuleAssistantIfNeeded || return 1\n"
|
||||||
+ "setupPublicCurl || return 1\n"
|
+ "setupPublicCurl || return 1\n"
|
||||||
+ "(mkdir -p /tmp/ && cd /tmp/ && [ ! -f VBoxGuestAdditions_4.1.8.iso ] && curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -C - -X GET http://download.virtualbox.org/virtualbox/4.1.8/VBoxGuestAdditions_4.1.8.iso >VBoxGuestAdditions_4.1.8.iso)\n"
|
+ "(mkdir -p /tmp/ && cd /tmp/ && [ ! -f VBoxGuestAdditions_4.1.8.iso ] && curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -C - -X GET http://download.virtualbox.org/virtualbox/4.1.8/VBoxGuestAdditions_4.1.8.iso >VBoxGuestAdditions_4.1.8.iso)\n"
|
||||||
+ "mount -o loop /tmp/VBoxGuestAdditions_4.1.8.iso /mnt\n"
|
+ "mount -o loop /tmp/VBoxGuestAdditions_4.1.8.iso /mnt\n"
|
||||||
+ "/mnt/VBoxLinuxAdditions.run --nox11\n", scripts);
|
+ "/mnt/VBoxLinuxAdditions.run --nox11\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,79 @@
|
||||||
|
/**
|
||||||
|
* 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.statements;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
import org.jclouds.scriptbuilder.domain.OsFamily;
|
||||||
|
import org.jclouds.virtualbox.domain.StorageController;
|
||||||
|
import org.jclouds.virtualbox.domain.VmSpec;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
import org.virtualbox_4_2.CleanupMode;
|
||||||
|
import org.virtualbox_4_2.StorageBus;
|
||||||
|
|
||||||
|
public class InstallGuestAdditionsTest {
|
||||||
|
|
||||||
|
private final static String VBOX_VERISION = "4.2.0";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInstallGAWhenIsoIsPresent() {
|
||||||
|
StorageController ideController = StorageController.builder()
|
||||||
|
.name("IDE Controller")
|
||||||
|
.bus(StorageBus.IDE)
|
||||||
|
.attachISO(1, 0, "VBoxGuestAdditions_")
|
||||||
|
.build();
|
||||||
|
VmSpec vmSpec = VmSpec.builder()
|
||||||
|
.id("").name("")
|
||||||
|
.memoryMB(512)
|
||||||
|
.osTypeId("")
|
||||||
|
.controller(ideController)
|
||||||
|
.forceOverwrite(true)
|
||||||
|
.cleanUpMode(CleanupMode.Full)
|
||||||
|
.build();
|
||||||
|
InstallGuestAdditions installGuestAdditions = new InstallGuestAdditions(vmSpec , VBOX_VERISION);
|
||||||
|
assertEquals(installGuestAdditions.render(OsFamily.UNIX),
|
||||||
|
"installModuleAssistantIfNeeded || return 1\n" +
|
||||||
|
"mount -t iso9660 /dev/cdrom1 /mnt\n" +
|
||||||
|
"/mnt/VBoxLinuxAdditions.run --nox11\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInstallGAWhenIsoIsNotPresent() {
|
||||||
|
StorageController ideController = StorageController.builder()
|
||||||
|
.name("IDE Controller")
|
||||||
|
.bus(StorageBus.IDE)
|
||||||
|
.build();
|
||||||
|
VmSpec vmSpec = VmSpec.builder()
|
||||||
|
.id("").name("")
|
||||||
|
.memoryMB(512)
|
||||||
|
.osTypeId("")
|
||||||
|
.controller(ideController)
|
||||||
|
.forceOverwrite(true)
|
||||||
|
.cleanUpMode(CleanupMode.Full)
|
||||||
|
.build();
|
||||||
|
InstallGuestAdditions installGuestAdditions = new InstallGuestAdditions(vmSpec , VBOX_VERISION);
|
||||||
|
assertEquals(installGuestAdditions.render(OsFamily.UNIX),
|
||||||
|
"installModuleAssistantIfNeeded || return 1\n" +
|
||||||
|
"setupPublicCurl || return 1\n" +
|
||||||
|
"(mkdir -p /tmp/ && cd /tmp/ && [ ! -f VBoxGuestAdditions_4.2.0.iso ] && curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -C - -X GET http://download.virtualbox.org/virtualbox/4.2.0/VBoxGuestAdditions_4.2.0.iso >VBoxGuestAdditions_4.2.0.iso)\n" +
|
||||||
|
"mount -o loop /tmp/VBoxGuestAdditions_4.2.0.iso /mnt\n" +
|
||||||
|
"/mnt/VBoxLinuxAdditions.run --nox11\n");
|
||||||
|
}
|
||||||
|
}
|
|
@ -25,7 +25,7 @@ import org.jclouds.scriptbuilder.domain.OsFamily;
|
||||||
import org.jclouds.virtualbox.domain.NetworkAdapter;
|
import org.jclouds.virtualbox.domain.NetworkAdapter;
|
||||||
import org.jclouds.virtualbox.domain.NetworkInterfaceCard;
|
import org.jclouds.virtualbox.domain.NetworkInterfaceCard;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
import org.virtualbox_4_2.NetworkAttachmentType;
|
||||||
|
|
||||||
public class SetIpAddressTest {
|
public class SetIpAddressTest {
|
||||||
|
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue