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
|
||||
.metadata/
|
||||
atlassian-ide-plugin.xml
|
||||
.DS_Store
|
||||
|
|
|
@ -56,6 +56,12 @@
|
|||
</properties>
|
||||
|
||||
<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>
|
||||
<groupId>org.jclouds</groupId>
|
||||
<artifactId>jclouds-compute</artifactId>
|
||||
|
|
Binary file not shown.
|
@ -35,9 +35,10 @@
|
|||
<packaging>bundle</packaging>
|
||||
|
||||
<properties>
|
||||
<virtualbox.version>4.2.6</virtualbox.version>
|
||||
<test.virtualbox.endpoint>http://localhost:18083/</test.virtualbox.endpoint>
|
||||
<test.virtualbox.api-version>4.1.4</test.virtualbox.api-version>
|
||||
<test.virtualbox.build-version>4.1.20r80170</test.virtualbox.build-version>
|
||||
<test.virtualbox.api-version>4.2.6</test.virtualbox.api-version>
|
||||
<test.virtualbox.build-version>${virtualbox.version}</test.virtualbox.build-version>
|
||||
<test.virtualbox.identity>${user.name}</test.virtualbox.identity>
|
||||
<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>
|
||||
|
@ -59,7 +60,7 @@
|
|||
<dependency>
|
||||
<groupId>org.virtualbox</groupId>
|
||||
<artifactId>vboxjws</artifactId>
|
||||
<version>${test.virtualbox.api-version}</version>
|
||||
<version>${virtualbox.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jclouds.api</groupId>
|
||||
|
@ -86,6 +87,11 @@
|
|||
<artifactId>jclouds-slf4j</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jclouds</groupId>
|
||||
<artifactId>jclouds-core</artifactId>
|
||||
|
@ -100,11 +106,6 @@
|
|||
<type>test-jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
<artifactId>testng</artifactId>
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
package org.jclouds.virtualbox;
|
||||
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
import org.virtualbox_4_2.VirtualBoxManager;
|
||||
|
||||
public class VirtualBox {
|
||||
|
||||
|
|
|
@ -20,12 +20,11 @@ package org.jclouds.virtualbox;
|
|||
|
||||
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_GUEST_MEMORY;
|
||||
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_PRECONFIGURATION_URL;
|
||||
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.net.URI;
|
||||
|
@ -65,15 +64,16 @@ public class VirtualBoxApiMetadata extends BaseApiMetadata {
|
|||
|
||||
properties.put(VIRTUALBOX_INSTALLATION_KEY_SEQUENCE, "<Esc><Esc><Enter> "
|
||||
+ "/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 "
|
||||
+ "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>");
|
||||
|
||||
String workingDir = System.getProperty("test.virtualbox.workingDir", VIRTUALBOX_DEFAULT_DIR);
|
||||
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);
|
||||
|
||||
String yamlDescriptor = System.getProperty("test.virtualbox.image.descriptor.yaml", VIRTUALBOX_WORKINGDIR
|
||||
|
@ -96,10 +96,9 @@ public class VirtualBoxApiMetadata extends BaseApiMetadata {
|
|||
.defaultIdentity(System.getProperty("user.name"))
|
||||
.defaultCredential("CHANGE_ME")
|
||||
.defaultEndpoint("http://localhost:18083/")
|
||||
.documentation(URI.create("https://github.com/jclouds/jclouds/tree/master/apis/byon"))
|
||||
// later version not in maven, yet
|
||||
.version("4.1.4")
|
||||
.buildVersion("4.1.8r75467")
|
||||
.documentation(URI.create("https://github.com/jclouds/jclouds/tree/master/labs/virtualbox"))
|
||||
.version("4.2.4")
|
||||
.buildVersion("4.2.4")
|
||||
.defaultProperties(VirtualBoxApiMetadata.defaultProperties())
|
||||
.view(ComputeServiceContext.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.compute.domain.OsFamily;
|
||||
import org.virtualbox_4_1.IGuestOSType;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
import org.virtualbox_4_2.IGuestOSType;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.VirtualBoxManager;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
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.functions.admin.UnregisterMachineIfExistsAndForceDeleteItsMedia;
|
||||
import org.jclouds.virtualbox.util.MachineController;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IProgress;
|
||||
import org.virtualbox_4_1.ISession;
|
||||
import org.virtualbox_4_1.MachineState;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.IProgress;
|
||||
import org.virtualbox_4_2.ISession;
|
||||
import org.virtualbox_4_2.MachineState;
|
||||
import org.virtualbox_4_2.VBoxException;
|
||||
import org.virtualbox_4_2.VirtualBoxManager;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
|
@ -90,7 +90,7 @@ public class VirtualBoxComputeServiceAdapter implements ComputeServiceAdapter<IM
|
|||
Function<NodeSpec, NodeAndInitialCredentials<IMachine>> cloneCreator,
|
||||
Function<IMachine, Image> imachineToImage,
|
||||
MachineController machineController) {
|
||||
this.manager = checkNotNull(manager, "manager");
|
||||
this.manager = checkNotNull(manager, "virtualbox manager can't be null");
|
||||
this.imagesToYamlImages = imagesMapper.get();
|
||||
this.mastersLoader = mastersLoader;
|
||||
this.cloneCreator = cloneCreator;
|
||||
|
@ -254,10 +254,10 @@ public class VirtualBoxComputeServiceAdapter implements ComputeServiceAdapter<IM
|
|||
logger.debug("vm was already powered down: ", machine.getId());
|
||||
return;
|
||||
}
|
||||
logger.debug("powering down vm: %s", machine.getName());
|
||||
logger.debug("<< powering down vm(%s)", machine.getName());
|
||||
machineController.ensureMachineHasPowerDown(machine.getName());
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,17 +47,18 @@ import org.jclouds.virtualbox.functions.IMachineToVmSpec;
|
|||
import org.jclouds.virtualbox.functions.TakeSnapshotIfNotAlreadyAttached;
|
||||
import org.jclouds.virtualbox.functions.admin.UnregisterMachineIfExistsAndDeleteItsMedia;
|
||||
import org.jclouds.virtualbox.util.MachineUtils;
|
||||
import org.virtualbox_4_1.CloneMode;
|
||||
import org.virtualbox_4_1.CloneOptions;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IProgress;
|
||||
import org.virtualbox_4_1.ISnapshot;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
import org.virtualbox_4_2.CloneMode;
|
||||
import org.virtualbox_4_2.CloneOptions;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.IProgress;
|
||||
import org.virtualbox_4_2.ISnapshot;
|
||||
import org.virtualbox_4_2.VirtualBoxManager;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
|
@ -118,9 +119,12 @@ public class VirtualBoxImageExtension implements ImageExtension {
|
|||
|
||||
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()
|
||||
.createMachine(settingsFile, template.getName(), source.getOSTypeId(), template.getName(), true);
|
||||
.createMachine(settingsFile, template.getName(), groups, source.getOSTypeId(), flags);
|
||||
|
||||
List<CloneOptions> options = Lists.newArrayList();
|
||||
if (isLinkedClone)
|
||||
|
@ -136,7 +140,7 @@ public class VirtualBoxImageExtension implements ImageExtension {
|
|||
IProgress progress = currentSnapshot.getMachine().cloneTo(clonedMachine, CloneMode.MachineState, options);
|
||||
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
|
||||
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.StartVBoxIfNotAlreadyRunning;
|
||||
import org.jclouds.virtualbox.predicates.SshResponds;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.LockType;
|
||||
import org.virtualbox_4_1.MachineState;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.LockType;
|
||||
import org.virtualbox_4_2.MachineState;
|
||||
import org.virtualbox_4_2.VirtualBoxManager;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Function;
|
||||
|
@ -104,15 +104,15 @@ public class VirtualBoxComputeServiceContextModule extends
|
|||
bind(new TypeLiteral<Function<IMachine, Image>>() {
|
||||
}).to(IMachineToImage.class);
|
||||
bind(new TypeLiteral<CacheLoader<IsoSpec, URI>>() {
|
||||
}).to((Class) PreseedCfgServer.class);
|
||||
}).to(Class.class.cast(PreseedCfgServer.class));
|
||||
bind(new TypeLiteral<Function<URI, File>>() {
|
||||
}).to((Class) FileDownloadFromURI.class);
|
||||
}).to(Class.class.cast(FileDownloadFromURI.class));
|
||||
|
||||
bind(new TypeLiteral<Supplier<VirtualBoxManager>>() {
|
||||
}).to((Class) StartVBoxIfNotAlreadyRunning.class);
|
||||
}).to(Class.class.cast(StartVBoxIfNotAlreadyRunning.class));
|
||||
// the yaml config to image mapper
|
||||
bind(new TypeLiteral<Supplier<Map<Image, YamlImage>>>() {
|
||||
}).to((Class) ImagesToYamlImagesFromYamlDescriptor.class);
|
||||
}).to(Class.class.cast(ImagesToYamlImagesFromYamlDescriptor.class));
|
||||
// the yaml config provider
|
||||
bind(YamlImagesFromFileConfig.class);
|
||||
|
||||
|
@ -126,15 +126,15 @@ public class VirtualBoxComputeServiceContextModule extends
|
|||
|
||||
// the master creating function
|
||||
bind(new TypeLiteral<Function<MasterSpec, IMachine>>() {
|
||||
}).to((Class) CreateAndInstallVm.class);
|
||||
}).to(Class.class.cast(CreateAndInstallVm.class));
|
||||
// the machine cloning function
|
||||
bind(new TypeLiteral<Function<NodeSpec, NodeAndInitialCredentials<IMachine>>>() {
|
||||
}).to((Class) NodeCreator.class);
|
||||
}).to(Class.class.cast(NodeCreator.class));
|
||||
bind(new TypeLiteral<Function<CloneSpec, IMachine>>() {
|
||||
}).to((Class) CloneAndRegisterMachineFromIMachineIfNotAlreadyExists.class);
|
||||
}).to(Class.class.cast(CloneAndRegisterMachineFromIMachineIfNotAlreadyExists.class));
|
||||
// the jetty server provider
|
||||
bind(new TypeLiteral<Server>() {
|
||||
}).to((Class) PreseedCfgServer.class).asEagerSingleton();
|
||||
}).to(Class.class.cast(PreseedCfgServer.class)).asEagerSingleton();
|
||||
|
||||
bind(new TypeLiteral<Function<IMachine, SshClient>>() {
|
||||
}).to(IMachineToSshClient.class);
|
||||
|
|
|
@ -115,15 +115,15 @@ public class BridgedIf {
|
|||
public BridgedIf(String name, String guid, String dhcp, String ipAddress,
|
||||
String networkMask, String ipv6Address, String iv6NetworkMask,
|
||||
String mediumType, String status) {
|
||||
this.name = checkNotNull(name, "bridgedIf name");
|
||||
this.name = checkNotNull(name, "bridgedIf name can't be null");
|
||||
this.guid = guid;
|
||||
this.dhcp = dhcp;
|
||||
this.ipAddress = checkNotNull(ipAddress, "bridgedIf ipAddress");
|
||||
this.ipAddress = checkNotNull(ipAddress, "bridgedIf ipAddress can't be null");
|
||||
this.networkMask = networkMask;
|
||||
this.ipv6Address = ipv6Address;
|
||||
this.ipv6NetworkMask = iv6NetworkMask;
|
||||
this.mediumType = mediumType;
|
||||
this.status = checkNotNull(status, "bridgedIf status");
|
||||
this.status = checkNotNull(status, "bridgedIf status can't be null");
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.jclouds.virtualbox.domain;
|
|||
|
||||
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;
|
||||
|
||||
|
@ -74,12 +74,9 @@ public class CloneSpec {
|
|||
}
|
||||
|
||||
public CloneSpec(VmSpec vmSpec, NetworkSpec networkSpec, IMachine master, boolean isLinked) {
|
||||
checkNotNull(vmSpec, "vmSpec");
|
||||
checkNotNull(networkSpec, "networkSpec");
|
||||
checkNotNull(master, "master");
|
||||
this.vmSpec = vmSpec;
|
||||
this.networkSpec = networkSpec;
|
||||
this.master = master;
|
||||
this.vmSpec = checkNotNull(vmSpec, "vmSpec can't be null");
|
||||
this.networkSpec = checkNotNull(networkSpec, "networkSpec can't be null");
|
||||
this.master = checkNotNull(master, "master can't be null");
|
||||
this.isLinked = isLinked;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.jclouds.virtualbox.domain;
|
|||
|
||||
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;
|
||||
|
||||
|
@ -43,10 +43,9 @@ public class DeviceDetails {
|
|||
private final DeviceType deviceType;
|
||||
|
||||
public DeviceDetails(int port, int deviceSlot, DeviceType deviceType) {
|
||||
checkNotNull(deviceType, "deviceType");
|
||||
this.port = port;
|
||||
this.deviceSlot = deviceSlot;
|
||||
this.deviceType = deviceType;
|
||||
this.deviceType = checkNotNull(deviceType, "deviceType can't be null");
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
|
@ -87,7 +86,7 @@ public class DeviceDetails {
|
|||
}
|
||||
|
||||
public DeviceDetails build() {
|
||||
checkNotNull(deviceType, "deviceType");
|
||||
checkNotNull(deviceType, "deviceType can't be null");
|
||||
return new DeviceDetails(port, deviceSlot, deviceType);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,8 +21,8 @@ package org.jclouds.virtualbox.domain;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
import org.virtualbox_4_1.jaxws.RuntimeFaultMsg;
|
||||
import org.virtualbox_4_2.VBoxException;
|
||||
import org.virtualbox_4_2.jaxws.RuntimeFaultMsg;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
|
@ -76,7 +76,7 @@ public enum ErrorCode {
|
|||
this.code = code;
|
||||
}
|
||||
|
||||
private static final Map<Long, ErrorCode> TABLE;
|
||||
private final static Map<Long, ErrorCode> TABLE;
|
||||
static {
|
||||
ImmutableMap.Builder<Long, ErrorCode> builder = ImmutableMap.builder();
|
||||
for (ErrorCode errorCode : ErrorCode.values()) {
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.jclouds.virtualbox.domain;
|
|||
|
||||
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;
|
||||
|
||||
|
@ -46,12 +46,9 @@ public class HardDisk {
|
|||
private final boolean autoDelete;
|
||||
|
||||
public HardDisk(DeviceDetails deviceDetails, String diskPath, String diskFormat, boolean autoDelete) {
|
||||
checkNotNull(deviceDetails, "deviceDetails");
|
||||
checkNotNull(diskPath, "diskPath");
|
||||
checkNotNull(diskFormat, "diskFormat");
|
||||
this.diskPath = diskPath;
|
||||
this.diskFormat = diskFormat;
|
||||
this.deviceDetails = deviceDetails;
|
||||
this.diskPath = checkNotNull(diskPath, "diskPath can't be null");
|
||||
this.diskFormat = checkNotNull(diskFormat, "diskFormat can't be null");
|
||||
this.deviceDetails = checkNotNull(deviceDetails, "deviceDetails can't be null");
|
||||
this.name = diskPath.substring(diskPath.lastIndexOf("/") + 1);
|
||||
this.autoDelete = autoDelete;
|
||||
}
|
||||
|
|
|
@ -33,10 +33,8 @@ public class IsoImage {
|
|||
private String sourcePath;
|
||||
|
||||
public IsoImage(DeviceDetails deviceDetails, String sourcePath) {
|
||||
checkNotNull(deviceDetails, "deviceDetails");
|
||||
checkNotNull(sourcePath, "sourcePath");
|
||||
this.deviceDetails = deviceDetails;
|
||||
this.sourcePath = sourcePath;
|
||||
this.deviceDetails = checkNotNull(deviceDetails, "deviceDetails can't be null");
|
||||
this.sourcePath = checkNotNull(sourcePath, "sourcePath can't be null");
|
||||
}
|
||||
|
||||
public DeviceDetails getDeviceDetails() {
|
||||
|
|
|
@ -32,8 +32,8 @@ public class IsoSpec {
|
|||
private final String sourcePath;
|
||||
|
||||
public IsoSpec(String sourcePath, String installationKeySequence) {
|
||||
this.sourcePath = checkNotNull(sourcePath, "sourcePath");
|
||||
this.installationKeySequence = checkNotNull(installationKeySequence, "installationKeySequence");
|
||||
this.sourcePath = checkNotNull(sourcePath, "sourcePath can't be null");
|
||||
this.installationKeySequence = checkNotNull(installationKeySequence, "installationKeySequence can't be null");
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
package org.jclouds.virtualbox.domain;
|
||||
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
|
||||
public class Master {
|
||||
|
||||
|
|
|
@ -74,12 +74,9 @@ public class MasterSpec {
|
|||
}
|
||||
|
||||
private MasterSpec(VmSpec vmSpec, IsoSpec isoSpec, NetworkSpec networkSpec, LoginCredentials loginCredentials) {
|
||||
checkNotNull(vmSpec, "vmSpec");
|
||||
checkNotNull(isoSpec, "isoSpec");
|
||||
checkNotNull(networkSpec, "networkSpec");
|
||||
this.vmSpec = vmSpec;
|
||||
this.isoSpec = isoSpec;
|
||||
this.networkSpec = networkSpec;
|
||||
this.vmSpec = checkNotNull(vmSpec, "vmSpec can't be null");
|
||||
this.isoSpec = checkNotNull(isoSpec, "isoSpec can't be null");
|
||||
this.networkSpec = checkNotNull(networkSpec, "networkSpec can't be null");
|
||||
this.loginCredentials = loginCredentials;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
import java.util.Collections;
|
||||
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.collect.Sets;
|
||||
|
|
|
@ -25,8 +25,8 @@ import java.util.Collections;
|
|||
import java.util.Set;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.virtualbox_4_1.NATProtocol;
|
||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
||||
import org.virtualbox_4_2.NATProtocol;
|
||||
import org.virtualbox_4_2.NetworkAttachmentType;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
@ -48,7 +48,7 @@ public class NetworkAdapter {
|
|||
String macAddress, Set<RedirectRule> redirectRules,
|
||||
String staticIp) {
|
||||
this.networkAttachmentType = checkNotNull(networkAttachmentType,
|
||||
"networkAttachmentType");
|
||||
"networkAttachmentType can't be null");
|
||||
this.macAddress = macAddress;
|
||||
this.redirectRules = ImmutableSet.<RedirectRule>copyOf(redirectRules);
|
||||
this.staticIp = staticIp;
|
||||
|
|
|
@ -31,8 +31,8 @@ public class NetworkInterfaceCard {
|
|||
private final boolean enabled;
|
||||
|
||||
public NetworkInterfaceCard(long slot, NetworkAdapter networkAdapter, String hostInterfaceName, boolean enabled) {
|
||||
this.slot = checkNotNull(slot, "slot");
|
||||
this.networkAdapter = checkNotNull(networkAdapter, "networkAdapter");
|
||||
this.slot = checkNotNull(slot, "slot can't be null");
|
||||
this.networkAdapter = checkNotNull(networkAdapter, "networkAdapter can't be null");
|
||||
this.hostInterfaceName = hostInterfaceName;
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ public class NetworkSpec {
|
|||
private 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() {
|
||||
|
|
|
@ -20,7 +20,7 @@ package org.jclouds.virtualbox.domain;
|
|||
|
||||
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;
|
||||
|
||||
|
|
|
@ -24,8 +24,8 @@ import static com.google.common.collect.Iterables.filter;
|
|||
import java.util.Set;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.virtualbox_4_1.DeviceType;
|
||||
import org.virtualbox_4_1.StorageBus;
|
||||
import org.virtualbox_4_2.DeviceType;
|
||||
import org.virtualbox_4_2.StorageBus;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Predicate;
|
||||
|
@ -49,14 +49,10 @@ public class StorageController {
|
|||
private Set<IsoImage> isoImages;
|
||||
|
||||
public StorageController(String name, StorageBus bus, Set<HardDisk> hardDisks, Set<IsoImage> isoImages) {
|
||||
checkNotNull(name, "name");
|
||||
checkNotNull(bus, "bus");
|
||||
checkNotNull(hardDisks, "hardDisks");
|
||||
checkNotNull(isoImages, "isoImages");
|
||||
this.name = name;
|
||||
this.bus = bus;
|
||||
this.hardDisks = hardDisks;
|
||||
this.isoImages = isoImages;
|
||||
this.name = checkNotNull(name, "storage name can't be null");
|
||||
this.bus = checkNotNull(bus, "bus can't be null");
|
||||
this.hardDisks = checkNotNull(hardDisks, "hardDisks can't be null");
|
||||
this.isoImages = checkNotNull(isoImages, "isoImages can't be null");
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
|
|
@ -24,7 +24,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
import java.util.Collections;
|
||||
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.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,
|
||||
Set<StorageController> controllers, CleanupMode cleanupMode) {
|
||||
this.vmId = checkNotNull(vmId, "vmId");
|
||||
this.vmName = checkNotNull(vmName, "vmName");
|
||||
this.osTypeId = checkNotNull(osTypeId, "osTypeId");
|
||||
this.vmId = checkNotNull(vmId, "vmId can't be null");
|
||||
this.vmName = checkNotNull(vmName, "vmName can't be null");
|
||||
this.osTypeId = checkNotNull(osTypeId, "osTypeId can't be null");
|
||||
checkArgument(memory > 0, "memory must be > 0");
|
||||
this.memory = memory;
|
||||
this.controllers = checkNotNull(controllers, "controllers");
|
||||
this.cleanupMode = checkNotNull(cleanupMode, "cleanupMode");
|
||||
this.controllers = checkNotNull(controllers, "controllers can't be null");
|
||||
this.cleanupMode = checkNotNull(cleanupMode, "cleanupMode can't be null");
|
||||
this.forceOverwrite = forceOverwrite;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,8 +21,8 @@ package org.jclouds.virtualbox.functions;
|
|||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import org.jclouds.virtualbox.domain.StorageController;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.VBoxException;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
|
@ -35,7 +35,7 @@ public class AddIDEControllerIfNotExists implements Function<IMachine, Void> {
|
|||
private final StorageController storageController;
|
||||
|
||||
public AddIDEControllerIfNotExists(StorageController storageController) {
|
||||
this.storageController = checkNotNull(storageController, "storageController");
|
||||
this.storageController = checkNotNull(storageController, "storageController can't be null");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
package org.jclouds.virtualbox.functions;
|
||||
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
|
|
|
@ -18,12 +18,12 @@
|
|||
*/
|
||||
package org.jclouds.virtualbox.functions;
|
||||
|
||||
import static org.virtualbox_4_1.NetworkAdapterType.Am79C973;
|
||||
import static org.virtualbox_4_1.NetworkAttachmentType.Bridged;
|
||||
import static org.virtualbox_4_2.NetworkAdapterType.Am79C973;
|
||||
import static org.virtualbox_4_2.NetworkAttachmentType.Bridged;
|
||||
|
||||
import org.jclouds.virtualbox.domain.NetworkInterfaceCard;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.INetworkAdapter;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.INetworkAdapter;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
|
@ -43,7 +43,6 @@ public class AttachBridgedAdapterToMachine implements Function<IMachine, Void> {
|
|||
public Void apply(IMachine machine) {
|
||||
INetworkAdapter iNetworkAdapter = machine.getNetworkAdapter(networkInterfaceCard.getSlot());
|
||||
iNetworkAdapter.setAttachmentType(Bridged);
|
||||
iNetworkAdapter.setAdapterType(Am79C973);
|
||||
iNetworkAdapter.setMACAddress(networkInterfaceCard.getNetworkAdapter().getMacAddress());
|
||||
iNetworkAdapter.setBridgedInterface(networkInterfaceCard.getHostInterfaceName());
|
||||
iNetworkAdapter.setEnabled(networkInterfaceCard.isEnabled());
|
||||
|
|
|
@ -18,12 +18,11 @@
|
|||
*/
|
||||
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.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.INetworkAdapter;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.INetworkAdapter;
|
||||
import org.virtualbox_4_2.NetworkAdapterType;
|
||||
import org.virtualbox_4_2.NetworkAttachmentType;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
|
@ -41,8 +40,7 @@ public class AttachHostOnlyAdapter implements Function<IMachine, Void> {
|
|||
@Override
|
||||
public Void apply(IMachine machine) {
|
||||
INetworkAdapter iNetworkAdapter = machine.getNetworkAdapter(networkInterfaceCard.getSlot());
|
||||
iNetworkAdapter.setAttachmentType(HostOnly);
|
||||
iNetworkAdapter.setAdapterType(Am79C973);
|
||||
iNetworkAdapter.setAttachmentType(NetworkAttachmentType.HostOnly);
|
||||
iNetworkAdapter.setMACAddress(networkInterfaceCard.getNetworkAdapter().getMacAddress());
|
||||
iNetworkAdapter.setHostOnlyInterface(networkInterfaceCard.getHostInterfaceName());
|
||||
iNetworkAdapter.setEnabled(networkInterfaceCard.isEnabled());
|
||||
|
|
|
@ -20,9 +20,9 @@
|
|||
package org.jclouds.virtualbox.functions;
|
||||
|
||||
import org.jclouds.virtualbox.domain.DeviceDetails;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IMedium;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.IMedium;
|
||||
import org.virtualbox_4_2.VBoxException;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
|
@ -54,6 +54,7 @@ public class AttachMediumToMachineIfNotAlreadyAttached implements Function<IMach
|
|||
}
|
||||
|
||||
private boolean alreadyAttached(VBoxException e) {
|
||||
System.out.println(medium.getName() + " " + e.getMessage());
|
||||
return e.getMessage().contains("is already attached to port");
|
||||
}
|
||||
|
||||
|
|
|
@ -19,15 +19,18 @@
|
|||
|
||||
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.RedirectRule;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.INetworkAdapter;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.INetworkAdapter;
|
||||
import org.virtualbox_4_2.NetworkAdapterType;
|
||||
import org.virtualbox_4_2.VBoxException;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* @author Mattias Holmqvist, Andrea Turli
|
||||
|
@ -43,12 +46,19 @@ public class AttachNATAdapterToMachineIfNotAlreadyExists implements Function<IMa
|
|||
@Override
|
||||
public Void apply(IMachine machine) {
|
||||
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);
|
||||
for (RedirectRule rule : networkInterfaceCard.getNetworkAdapter().getRedirectRules()) {
|
||||
try {
|
||||
String ruleName = String.format("%s@%s:%s->%s:%s",rule.getProtocol(), rule.getHost(), rule.getHostPort(),
|
||||
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());
|
||||
} catch (VBoxException e) {
|
||||
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.util.MachineUtils;
|
||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
||||
import org.virtualbox_4_2.NetworkAttachmentType;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
|
@ -35,8 +35,8 @@ public class AttachNicToMachine implements Function<NetworkInterfaceCard, Void>
|
|||
private final MachineUtils machineUtils;
|
||||
|
||||
public AttachNicToMachine(String vmName, MachineUtils machineUtils) {
|
||||
this.vmName = checkNotNull(vmName, "vmName");
|
||||
this.machineUtils = checkNotNull(machineUtils, "machineUtils");
|
||||
this.vmName = checkNotNull(vmName, "vmName can't be null");
|
||||
this.machineUtils = checkNotNull(machineUtils, "machineUtils can't be null");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -48,7 +48,7 @@ public class BridgedIfStringToBridgedIf implements Function<String, BridgedIf> {
|
|||
|
||||
@Override
|
||||
public BridgedIf apply(String rawBridgedIf) {
|
||||
checkNotNull(rawBridgedIf, "rawBridgedIf");
|
||||
checkNotNull(rawBridgedIf, "bridged interface can't be null");
|
||||
|
||||
String transformedBridgedIf = transformRawBridgedIf(rawBridgedIf);
|
||||
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.VmSpec;
|
||||
import org.jclouds.virtualbox.util.MachineUtils;
|
||||
import org.virtualbox_4_1.CloneMode;
|
||||
import org.virtualbox_4_1.CloneOptions;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IProgress;
|
||||
import org.virtualbox_4_1.ISnapshot;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
import org.virtualbox_4_2.CloneMode;
|
||||
import org.virtualbox_4_2.CloneOptions;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.IProgress;
|
||||
import org.virtualbox_4_2.ISnapshot;
|
||||
import org.virtualbox_4_2.VBoxException;
|
||||
import org.virtualbox_4_2.VirtualBoxManager;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
|
@ -96,13 +97,14 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExists implements Fu
|
|||
NetworkSpec networkSpec = cloneSpec.getNetworkSpec();
|
||||
boolean isLinkedClone = cloneSpec.isLinked();
|
||||
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
|
||||
.get()
|
||||
.getVBox()
|
||||
.createMachine(settingsFile, vmSpec.getVmName(), vmSpec.getOsTypeId(), vmSpec.getVmId(),
|
||||
vmSpec.isForceOverwrite());
|
||||
|
||||
.createMachine(settingsFile, vmSpec.getVmName(), groups, vmSpec.getOsTypeId(), flags);
|
||||
List<CloneOptions> options = Lists.newArrayList();
|
||||
if (isLinkedClone)
|
||||
options.add(CloneOptions.Link);
|
||||
|
@ -112,8 +114,6 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExists implements Fu
|
|||
IProgress progress = currentSnapshot.getMachine().cloneTo(clonedMachine,
|
||||
CloneMode.MachineState, options);
|
||||
progress.waitForCompletion(-1);
|
||||
logger.debug(String.format("Machine %s is cloned correctly",
|
||||
clonedMachine.getName()));
|
||||
|
||||
// memory may not be the same as the master vm
|
||||
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
|
||||
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 masterPassword = master.getExtraData(GUEST_OS_PASSWORD);
|
||||
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.util.MachineController;
|
||||
import org.jclouds.virtualbox.util.MachineUtils;
|
||||
import org.virtualbox_4_1.DeviceType;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IMediumAttachment;
|
||||
import org.virtualbox_4_2.DeviceType;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.IMediumAttachment;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.base.Stopwatch;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.common.util.concurrent.Uninterruptibles;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
@Singleton
|
||||
|
@ -87,7 +87,7 @@ public class CreateAndInstallVm implements Function<MasterSpec, IMachine> {
|
|||
this.machineUtils = machineUtils;
|
||||
this.imachineToNodeMetadata = imachineToNodeMetadata;
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -104,28 +104,29 @@ public class CreateAndInstallVm implements Function<MasterSpec, IMachine> {
|
|||
|
||||
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_PASSWORD, masterSpec.getLoginCredentials().getPassword());
|
||||
|
||||
SshClient client = sshClientForIMachine.apply(masterMachine);
|
||||
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);
|
||||
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);
|
||||
|
||||
logger.debug(">> awaiting post-installation actions on vm: %s", masterName);
|
||||
ListenableFuture<ExecResponse> execCleanup = machineUtils.runScriptOnNode(nodeMetadata,
|
||||
call("cleanupUdevIfNeeded"), RunScriptOptions.NONE);
|
||||
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);
|
||||
ListenableFuture<ExecResponse> execInstallGA = machineUtils.runScriptOnNode(nodeMetadata,
|
||||
new InstallGuestAdditions(vmSpec, version), RunScriptOptions.NONE);
|
||||
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);
|
||||
|
||||
|
@ -140,9 +141,9 @@ public class CreateAndInstallVm implements Function<MasterSpec, IMachine> {
|
|||
}
|
||||
});
|
||||
for (IMediumAttachment iMediumAttachment : mediumAttachments) {
|
||||
logger.debug("Detach %s from (%s)", iMediumAttachment.getMedium()
|
||||
logger.debug("<< iMedium(%s) detached from (%s)", iMediumAttachment.getMedium()
|
||||
.getName(), masterMachine.getName());
|
||||
machineUtils.writeLockMachineAndApply(
|
||||
machineUtils.sharedLockMachineAndApply(
|
||||
masterMachine.getName(),
|
||||
new DetachDistroMediumFromMachine(iMediumAttachment
|
||||
.getController(), iMediumAttachment.getPort(),
|
||||
|
|
|
@ -23,7 +23,9 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
import static org.jclouds.virtualbox.util.MachineUtils.machineNotFoundException;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
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.VmSpec;
|
||||
import org.jclouds.virtualbox.util.MachineUtils;
|
||||
import org.virtualbox_4_1.AccessMode;
|
||||
import org.virtualbox_4_1.DeviceType;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IMedium;
|
||||
import org.virtualbox_4_1.IVirtualBox;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
import org.virtualbox_4_2.AccessMode;
|
||||
import org.virtualbox_4_2.DeviceType;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.IMedium;
|
||||
import org.virtualbox_4_2.IVirtualBox;
|
||||
import org.virtualbox_4_2.VBoxException;
|
||||
import org.virtualbox_4_2.VirtualBoxManager;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.util.concurrent.Uninterruptibles;
|
||||
|
||||
/**
|
||||
* @author Mattias Holmqvist
|
||||
|
@ -95,10 +99,12 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExists implements Functi
|
|||
|
||||
private IMachine createMachine(IVirtualBox vBox, MasterSpec masterSpec) {
|
||||
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(),
|
||||
vmSpec.getVmId(), vmSpec.isForceOverwrite());
|
||||
IMachine newMachine = vBox.createMachine(settingsFile, vmSpec.getVmName(), groups, vmSpec.getOsTypeId(), flags);
|
||||
|
||||
manager.get().getVBox().registerMachine(newMachine);
|
||||
ensureConfiguration(masterSpec);
|
||||
|
@ -171,6 +177,6 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExists implements Functi
|
|||
|
||||
public void ensureMachineHasStorageControllerNamed(String vmName, StorageController storageController) {
|
||||
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.util.MachineUtils;
|
||||
import org.virtualbox_4_1.DeviceType;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IMedium;
|
||||
import org.virtualbox_4_1.IMediumAttachment;
|
||||
import org.virtualbox_4_1.IProgress;
|
||||
import org.virtualbox_4_1.IVirtualBox;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
import org.virtualbox_4_2.AccessMode;
|
||||
import org.virtualbox_4_2.DeviceType;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.IMedium;
|
||||
import org.virtualbox_4_2.IMediumAttachment;
|
||||
import org.virtualbox_4_2.IProgress;
|
||||
import org.virtualbox_4_2.IVirtualBox;
|
||||
import org.virtualbox_4_2.VBoxException;
|
||||
import org.virtualbox_4_2.VirtualBoxManager;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
|
@ -65,7 +66,7 @@ public class CreateMediumIfNotAlreadyExists implements Function<HardDisk, IMediu
|
|||
IVirtualBox vBox = manager.get().getVBox();
|
||||
try {
|
||||
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) {
|
||||
try {
|
||||
deleteMediumAndBlockUntilComplete(medium);
|
||||
|
@ -114,14 +115,14 @@ public class CreateMediumIfNotAlreadyExists implements Function<HardDisk, IMediu
|
|||
}
|
||||
|
||||
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) {
|
||||
try {
|
||||
long size = 4L * 1024L * 1024L * 1024L - 4L;
|
||||
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);
|
||||
} catch (VBoxException e) {
|
||||
if (fileNotFoundException(e)) {
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
*/
|
||||
package org.jclouds.virtualbox.functions;
|
||||
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.VBoxException;
|
||||
|
||||
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.javax.annotation.Nullable;
|
||||
import org.jclouds.virtualbox.config.VirtualBoxConstants;
|
||||
import org.virtualbox_4_1.IGuestOSType;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
import org.virtualbox_4_2.IGuestOSType;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.VirtualBoxManager;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
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.javax.annotation.Nullable;
|
||||
import org.jclouds.virtualbox.config.VirtualBoxConstants;
|
||||
import org.virtualbox_4_1.IGuestOSType;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.MachineState;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
import org.virtualbox_4_2.IGuestOSType;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.MachineState;
|
||||
import org.virtualbox_4_2.VirtualBoxManager;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
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.options.RunScriptOptions;
|
||||
import org.jclouds.virtualbox.config.VirtualBoxConstants;
|
||||
import org.virtualbox_4_1.IGuestOSType;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
import org.virtualbox_4_2.IGuestOSType;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.VirtualBoxManager;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
|
@ -50,8 +50,7 @@ public class IMachineToIpAddress implements Function<IMachine, String> {
|
|||
public String apply(IMachine machine) {
|
||||
|
||||
String macAddress = machine.getNetworkAdapter(0l).getMACAddress();
|
||||
int offset = 0;
|
||||
int step = 2;
|
||||
int offset = 0, step = 2;
|
||||
for (int j = 1; j <= 5; j++) {
|
||||
macAddress = new StringBuilder(macAddress).insert(j * step + offset, ":").toString().toLowerCase();
|
||||
offset++;
|
||||
|
|
|
@ -19,6 +19,9 @@
|
|||
|
||||
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_USER;
|
||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_NODE_NAME_SEPARATOR;
|
||||
|
@ -31,6 +34,8 @@ import javax.annotation.Resource;
|
|||
import javax.inject.Named;
|
||||
|
||||
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.NodeMetadataBuilder;
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
|
@ -40,13 +45,16 @@ import org.jclouds.domain.LoginCredentials;
|
|||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.virtualbox.util.NetworkUtils;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.INetworkAdapter;
|
||||
import org.virtualbox_4_1.MachineState;
|
||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
||||
import org.virtualbox_4_2.IGuestOSType;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.INetworkAdapter;
|
||||
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.Splitter;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.inject.Inject;
|
||||
|
@ -59,14 +67,18 @@ public class IMachineToNodeMetadata implements Function<IMachine, NodeMetadata>
|
|||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
private final Supplier<VirtualBoxManager> virtualboxManager;
|
||||
private final Map<MachineState, Status> toPortableNodeStatus;
|
||||
private final NetworkUtils networkUtils;
|
||||
private final Map<OsFamily, Map<String, String>> osVersionMap;
|
||||
|
||||
@Inject
|
||||
public IMachineToNodeMetadata(Map<MachineState, NodeMetadata.Status> toPortableNodeStatus,
|
||||
NetworkUtils networkUtils) {
|
||||
this.toPortableNodeStatus = toPortableNodeStatus;
|
||||
this.networkUtils = networkUtils;
|
||||
public IMachineToNodeMetadata(Supplier<VirtualBoxManager> virtualboxManager, Map<MachineState, NodeMetadata.Status> toPortableNodeStatus,
|
||||
NetworkUtils networkUtils, Map<OsFamily, Map<String, String>> osVersionMap) {
|
||||
this.virtualboxManager = checkNotNull(virtualboxManager, "virtualboxManager");
|
||||
this.toPortableNodeStatus = checkNotNull(toPortableNodeStatus, "toPortableNodeStatus");
|
||||
this.networkUtils = checkNotNull(networkUtils, "networkUtils");
|
||||
this.osVersionMap = checkNotNull(osVersionMap, "osVersionMap");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -99,6 +111,13 @@ public class IMachineToNodeMetadata implements Function<IMachine, NodeMetadata>
|
|||
nodeMetadataBuilder.status(nodeState);
|
||||
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 guestOsPassword = vm.getExtraData(GUEST_OS_PASSWORD);
|
||||
LoginCredentials loginCredentials = new LoginCredentials(guestOsUser, guestOsPassword, null, true);
|
||||
|
@ -114,11 +133,11 @@ public class IMachineToNodeMetadata implements Function<IMachine, NodeMetadata>
|
|||
INetworkAdapter adapter = vm.getNetworkAdapter(slot);
|
||||
if(adapter != null) {
|
||||
if (adapter.getAttachmentType() == NetworkAttachmentType.NAT) {
|
||||
String hostIP = adapter.getNatDriver().getHostIP();
|
||||
String hostIP = adapter.getNATEngine().getHostIP();
|
||||
if(!hostIP.isEmpty())
|
||||
publicIpAddresses.add(hostIP);
|
||||
for (String nameProtocolnumberAddressInboundportGuestTargetport : adapter.getNatDriver().getRedirects()) {
|
||||
Iterable<String> stuff = Splitter.on(',').split(nameProtocolnumberAddressInboundportGuestTargetport);
|
||||
for (String nameProtocolnumberAddressInboudportGuestTargetport : adapter.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);
|
||||
|
@ -130,13 +149,11 @@ public class IMachineToNodeMetadata implements Function<IMachine, NodeMetadata>
|
|||
}
|
||||
}
|
||||
} else if (adapter.getAttachmentType() == NetworkAttachmentType.Bridged) {
|
||||
// TODO quick test first
|
||||
String clientIpAddress = networkUtils.getIpAddressFromNicSlot(vm.getName(), adapter.getSlot());
|
||||
privateIpAddresses.add(clientIpAddress);
|
||||
|
||||
} else if (adapter.getAttachmentType() == NetworkAttachmentType.HostOnly) {
|
||||
// TODO quick test first
|
||||
String clientIpAddress = networkUtils.getIpAddressFromNicSlot(vm.getName(), adapter.getSlot());
|
||||
String clientIpAddress = networkUtils.getValidHostOnlyIpFromVm(vm.getName());
|
||||
publicIpAddresses.add(clientIpAddress);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
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_USER;
|
||||
|
||||
|
@ -31,12 +30,13 @@ import org.jclouds.domain.LoginCredentials;
|
|||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.ssh.SshClient;
|
||||
import org.jclouds.virtualbox.util.NetworkUtils;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.INetworkAdapter;
|
||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.INetworkAdapter;
|
||||
import org.virtualbox_4_2.NetworkAttachmentType;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.net.HostAndPort;
|
||||
import com.google.inject.Inject;
|
||||
|
@ -52,34 +52,29 @@ public class IMachineToSshClient implements Function<IMachine, SshClient> {
|
|||
private final NetworkUtils networkUtils;
|
||||
|
||||
@Inject
|
||||
public IMachineToSshClient(SshClient.Factory sshClientFactory,
|
||||
NetworkUtils networkUtils) {
|
||||
public IMachineToSshClient(SshClient.Factory sshClientFactory, NetworkUtils networkUtils) {
|
||||
this.sshClientFactory = sshClientFactory;
|
||||
this.networkUtils = networkUtils;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SshClient apply(final IMachine vm) {
|
||||
INetworkAdapter networkAdapter = vm.getNetworkAdapter(0L);
|
||||
|
||||
SshClient client = null;
|
||||
checkNotNull(networkAdapter);
|
||||
|
||||
String clientIpAddress = null;
|
||||
String sshPort = "22";
|
||||
String guestIdentity = vm.getExtraData(GUEST_OS_USER);
|
||||
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();
|
||||
|
||||
if (networkAdapter.getAttachmentType()
|
||||
.equals(NetworkAttachmentType.NAT)) {
|
||||
for (String nameProtocolnumberAddressInboundPortGuestTargetport : networkAdapter
|
||||
.getNatDriver().getRedirects()) {
|
||||
Iterable<String> stuff = Splitter.on(',').split(
|
||||
nameProtocolnumberAddressInboundPortGuestTargetport);
|
||||
String clientIpAddress = null;
|
||||
|
||||
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);
|
||||
|
@ -89,20 +84,15 @@ public class IMachineToSshClient implements Function<IMachine, SshClient> {
|
|||
sshPort = inboundPort;
|
||||
}
|
||||
}
|
||||
} else if (networkAdapter.getAttachmentType().equals(
|
||||
NetworkAttachmentType.Bridged)) {
|
||||
clientIpAddress = networkUtils.getIpAddressFromNicSlot(vm.getName(), networkAdapter.getSlot());
|
||||
} else if (networkAdapter.getAttachmentType().equals(
|
||||
NetworkAttachmentType.HostOnly)) {
|
||||
} 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());
|
||||
}
|
||||
|
||||
checkNotNull(clientIpAddress, "clientIpAddress");
|
||||
client = sshClientFactory.create(
|
||||
HostAndPort.fromParts(clientIpAddress, Integer.parseInt(sshPort)),
|
||||
nicSlot++;
|
||||
}
|
||||
return sshClientFactory.create(HostAndPort.fromParts(clientIpAddress, Integer.parseInt(sshPort)),
|
||||
loginCredentials);
|
||||
checkNotNull(client);
|
||||
return client;
|
||||
}
|
||||
|
||||
}
|
|
@ -30,12 +30,12 @@ import org.jclouds.virtualbox.domain.HardDisk;
|
|||
import org.jclouds.virtualbox.domain.StorageController;
|
||||
import org.jclouds.virtualbox.domain.StorageController.Builder;
|
||||
import org.jclouds.virtualbox.domain.VmSpec;
|
||||
import org.virtualbox_4_1.CleanupMode;
|
||||
import org.virtualbox_4_1.DeviceType;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IMedium;
|
||||
import org.virtualbox_4_1.IMediumAttachment;
|
||||
import org.virtualbox_4_1.IStorageController;
|
||||
import org.virtualbox_4_2.CleanupMode;
|
||||
import org.virtualbox_4_2.DeviceType;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.IMedium;
|
||||
import org.virtualbox_4_2.IMediumAttachment;
|
||||
import org.virtualbox_4_2.IStorageController;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
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.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
|
@ -33,14 +32,13 @@ import javax.inject.Singleton;
|
|||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.virtualbox.util.MachineNameOrIdAndNicSlot;
|
||||
import org.jclouds.virtualbox.util.NetworkUtils;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
import org.virtualbox_4_2.VirtualBoxManager;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.cache.AbstractLoadingCache;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
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
|
||||
|
@ -71,19 +69,12 @@ public class IpAddressesLoadingCache extends
|
|||
return masters.get(machineNameOrIdAndNicPort);
|
||||
}
|
||||
String query = String.format("/VirtualBox/GuestInfo/Net/%s/V4/IP", machineNameOrIdAndNicPort.getSlotText());
|
||||
String currentIp = "";
|
||||
while (!NetworkUtils.isIpv4(currentIp)) {
|
||||
currentIp = manager.get().getVBox().findMachine(machineNameOrIdAndNicPort.getMachineNameOrId())
|
||||
.getGuestPropertyValue(query);
|
||||
if(!Strings.nullToEmpty(currentIp).isEmpty())
|
||||
logger.debug("Found IP address %s for '%s' at slot %s", currentIp,
|
||||
machineNameOrIdAndNicPort.getMachineNameOrId(),
|
||||
machineNameOrIdAndNicPort.getSlotText());
|
||||
Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
masters.put(machineNameOrIdAndNicPort, currentIp);
|
||||
return currentIp;
|
||||
String ipAddress = Strings.nullToEmpty(manager.get().getVBox()
|
||||
.findMachine(machineNameOrIdAndNicPort.getMachineNameOrId()).getGuestPropertyValue(query));
|
||||
logger.debug("<< vm(%s) has IP address(%s) at slot(%s)", machineNameOrIdAndNicPort.getMachineNameOrId(),
|
||||
ipAddress, machineNameOrIdAndNicPort.getSlotText());
|
||||
masters.put(machineNameOrIdAndNicPort, ipAddress);
|
||||
return ipAddress;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -27,12 +27,12 @@ import org.jclouds.compute.reference.ComputeServiceConstants;
|
|||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.virtualbox.domain.ErrorCode;
|
||||
import org.jclouds.virtualbox.domain.ExecutionType;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IProgress;
|
||||
import org.virtualbox_4_1.ISession;
|
||||
import org.virtualbox_4_1.SessionState;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.IProgress;
|
||||
import org.virtualbox_4_2.ISession;
|
||||
import org.virtualbox_4_2.SessionState;
|
||||
import org.virtualbox_4_2.VBoxException;
|
||||
import org.virtualbox_4_2.VirtualBoxManager;
|
||||
|
||||
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.functions.admin.PreseedCfgServer;
|
||||
import org.jclouds.virtualbox.predicates.RetryIfSocketNotYetOpen;
|
||||
import org.jclouds.virtualbox.statements.Md5;
|
||||
import org.jclouds.virtualbox.util.NetworkUtils;
|
||||
import org.virtualbox_4_1.CleanupMode;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
||||
import org.virtualbox_4_1.StorageBus;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
import org.virtualbox_4_2.CleanupMode;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.NetworkAttachmentType;
|
||||
import org.virtualbox_4_2.StorageBus;
|
||||
import org.virtualbox_4_2.VBoxException;
|
||||
import org.virtualbox_4_2.VirtualBoxManager;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.base.Supplier;
|
||||
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.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
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
|
||||
|
@ -121,41 +125,30 @@ public class MastersLoadingCache extends AbstractLoadingCache<Image, Master> {
|
|||
private final HardcodedHostToHostNodeMetadata hardcodedHostToHostNodeMetadata;
|
||||
|
||||
@Inject
|
||||
public MastersLoadingCache(
|
||||
@BuildVersion String version,
|
||||
public MastersLoadingCache(@BuildVersion String version,
|
||||
@Named(VIRTUALBOX_INSTALLATION_KEY_SEQUENCE) String installationKeySequence,
|
||||
@Named(VIRTUALBOX_PRECONFIGURATION_URL) String preconfigurationUrl,
|
||||
@Named(VIRTUALBOX_WORKINGDIR) String workingDir,
|
||||
Function<MasterSpec, IMachine> masterLoader,
|
||||
Supplier<Map<Image, YamlImage>> yamlMapper,
|
||||
Supplier<VirtualBoxManager> manager,
|
||||
Factory runScriptOnNodeFactory,
|
||||
RetryIfSocketNotYetOpen socketTester, Supplier<NodeMetadata> host,
|
||||
@Provider Supplier<URI> providerSupplier,
|
||||
HardcodedHostToHostNodeMetadata hardcodedHostToHostNodeMetadata) {
|
||||
checkNotNull(version, "version");
|
||||
checkNotNull(installationKeySequence, "installationKeySequence");
|
||||
checkNotNull(manager, "vboxmanager");
|
||||
this.manager = manager;
|
||||
@Named(VIRTUALBOX_WORKINGDIR) String workingDir, Function<MasterSpec, IMachine> masterLoader,
|
||||
Supplier<Map<Image, YamlImage>> yamlMapper, Supplier<VirtualBoxManager> manager,
|
||||
Factory runScriptOnNodeFactory, RetryIfSocketNotYetOpen socketTester, Supplier<NodeMetadata> host,
|
||||
@Provider Supplier<URI> providerSupplier, HardcodedHostToHostNodeMetadata hardcodedHostToHostNodeMetadata) {
|
||||
this.manager = checkNotNull(manager, "vboxmanager can't be null");
|
||||
this.masterCreatorAndInstaller = masterLoader;
|
||||
this.installationKeySequence = installationKeySequence;
|
||||
this.workingDir = workingDir == null ? VIRTUALBOX_DEFAULT_DIR
|
||||
: workingDir;
|
||||
this.installationKeySequence = checkNotNull(installationKeySequence, "installationKeySequence can't be null");
|
||||
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.version = Iterables.get(Splitter.on('r').split(checkNotNull(version, "version")), 0);
|
||||
this.preconfigurationUrl = preconfigurationUrl;
|
||||
|
||||
this.runScriptOnNodeFactory = checkNotNull(runScriptOnNodeFactory,
|
||||
"runScriptOnNodeFactory");
|
||||
this.runScriptOnNodeFactory = checkNotNull(runScriptOnNodeFactory, "runScriptOnNodeFactory");
|
||||
this.socketTester = checkNotNull(socketTester, "socketTester");
|
||||
this.socketTester.seconds(3L);
|
||||
this.host = checkNotNull(host, "host");
|
||||
this.providerSupplier = checkNotNull(providerSupplier,
|
||||
"endpoint to virtualbox websrvd is needed");
|
||||
this.providerSupplier = checkNotNull(providerSupplier, "endpoint to virtualbox websrvd is needed");
|
||||
this.hardcodedHostToHostNodeMetadata = hardcodedHostToHostNodeMetadata;
|
||||
}
|
||||
|
||||
|
@ -172,8 +165,7 @@ public class MastersLoadingCache extends AbstractLoadingCache<Image, Master> {
|
|||
if (masters.containsKey(key.getId())) {
|
||||
return masters.get(key.getId());
|
||||
}
|
||||
checkState(!key.getId().contains(VIRTUALBOX_NODE_NAME_SEPARATOR),
|
||||
"master image names cannot contain \""
|
||||
checkState(!key.getId().contains(VIRTUALBOX_NODE_NAME_SEPARATOR), "master image names cannot contain \""
|
||||
+ VIRTUALBOX_NODE_NAME_SEPARATOR + "\"");
|
||||
String vmName = VIRTUALBOX_IMAGE_PREFIX + key.getId();
|
||||
IMachine masterMachine;
|
||||
|
@ -191,8 +183,7 @@ public class MastersLoadingCache extends AbstractLoadingCache<Image, Master> {
|
|||
URI preseedServer;
|
||||
try {
|
||||
preseedServer = new URI(preconfigurationUrl);
|
||||
if (!socketTester.apply(HostAndPort.fromParts(preseedServer.getHost(),
|
||||
preseedServer.getPort()))) {
|
||||
if (!socketTester.apply(HostAndPort.fromParts(preseedServer.getHost(), preseedServer.getPort()))) {
|
||||
server.start(preconfigurationUrl, currentImage.preseed_cfg);
|
||||
}
|
||||
} catch (URISyntaxException e1) {
|
||||
|
@ -200,11 +191,9 @@ public class MastersLoadingCache extends AbstractLoadingCache<Image, Master> {
|
|||
throw e;
|
||||
}
|
||||
|
||||
MasterSpec masterSpec = buildMasterSpecFromYaml(currentImage,
|
||||
vmName);
|
||||
MasterSpec masterSpec = buildMasterSpecFromYaml(currentImage, vmName);
|
||||
masterMachine = masterCreatorAndInstaller.apply(masterSpec);
|
||||
master = Master.builder().machine(masterMachine)
|
||||
.spec(masterSpec).build();
|
||||
master = Master.builder().machine(masterMachine).spec(masterSpec).build();
|
||||
} else {
|
||||
logger.error("Problem during master creation", e);
|
||||
throw e;
|
||||
|
@ -217,64 +206,47 @@ public class MastersLoadingCache extends AbstractLoadingCache<Image, Master> {
|
|||
return master;
|
||||
}
|
||||
|
||||
private MasterSpec buildMasterSpecFromYaml(YamlImage currentImage,
|
||||
String vmName) throws ExecutionException {
|
||||
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;
|
||||
private MasterSpec buildMasterSpecFromYaml(YamlImage currentImage, String vmName) throws ExecutionException {
|
||||
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();
|
||||
HardDisk hardDisk = HardDisk.builder().diskpath(adminDisk).autoDelete(true).controllerPort(0).deviceSlot(1)
|
||||
.build();
|
||||
|
||||
StorageController ideController = StorageController.builder()
|
||||
.name("IDE Controller").bus(StorageBus.IDE)
|
||||
.attachISO(0, 0, localIsoUrl).attachHardDisk(hardDisk)
|
||||
.attachISO(1, 0, guestAdditionsIso).build();
|
||||
StorageController ideController = StorageController.builder().name("IDE Controller").bus(StorageBus.IDE)
|
||||
.attachISO(0, 0, localIsoUrl).attachHardDisk(hardDisk).build();
|
||||
|
||||
VmSpec vmSpecification = VmSpec.builder().id(currentImage.id)
|
||||
.name(vmName).memoryMB(512).osTypeId(getOsTypeId(currentImage.os_family, currentImage.os_64bit))
|
||||
.controller(ideController).forceOverwrite(true)
|
||||
.guestUser(currentImage.username).guestPassword(currentImage.credential)
|
||||
VmSpec vmSpecification = VmSpec.builder().id(currentImage.id).name(vmName).memoryMB(512)
|
||||
.osTypeId(getOsTypeId(currentImage.os_family, currentImage.os_64bit)).controller(ideController)
|
||||
.forceOverwrite(true).guestUser(currentImage.username).guestPassword(currentImage.credential)
|
||||
.cleanUpMode(CleanupMode.Full).build();
|
||||
|
||||
NetworkAdapter networkAdapter = NetworkAdapter
|
||||
.builder()
|
||||
.networkAttachmentType(NetworkAttachmentType.NAT)
|
||||
.tcpRedirectRule(providerSupplier.get().getHost(), NetworkUtils.MASTER_PORT,
|
||||
"", 22).build();
|
||||
NetworkAdapter networkAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.NAT)
|
||||
.tcpRedirectRule(providerSupplier.get().getHost(), NetworkUtils.MASTER_PORT, "", 22).build();
|
||||
|
||||
NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard
|
||||
.builder().addNetworkAdapter(networkAdapter).slot(0L).build();
|
||||
NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(networkAdapter)
|
||||
.slot(0L).build();
|
||||
|
||||
NetworkSpec networkSpec = NetworkSpec.builder()
|
||||
.addNIC(networkInterfaceCard).build();
|
||||
NetworkSpec networkSpec = NetworkSpec.builder().addNIC(networkInterfaceCard).build();
|
||||
|
||||
return MasterSpec
|
||||
.builder()
|
||||
.vm(vmSpecification)
|
||||
.iso(IsoSpec
|
||||
.builder()
|
||||
.sourcePath(localIsoUrl)
|
||||
.installationScript(
|
||||
installationKeySequence.replace("HOSTNAME",
|
||||
vmSpecification.getVmName())).build())
|
||||
.iso(IsoSpec.builder().sourcePath(localIsoUrl)
|
||||
.installationScript(installationKeySequence.replace("HOSTNAME", vmSpecification.getVmName())).build())
|
||||
.network(networkSpec)
|
||||
.credentials(new LoginCredentials(currentImage.username, currentImage.credential, null, true))
|
||||
.build();
|
||||
.credentials(new LoginCredentials(currentImage.username, currentImage.credential, null, true)).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Master getIfPresent(Object key) {
|
||||
checkArgument(key instanceof Image,
|
||||
"this cache is for entries who's keys are Images");
|
||||
checkArgument(key instanceof Image, "this cache is for entries who's keys are Images");
|
||||
Image image = Image.class.cast(key);
|
||||
if (masters.containsKey(image.getId())) {
|
||||
return masters.get(image.getId());
|
||||
|
@ -282,36 +254,31 @@ public class MastersLoadingCache extends AbstractLoadingCache<Image, Master> {
|
|||
return null;
|
||||
}
|
||||
|
||||
private String getFilePathOrDownload(String httpUrl, String md5)
|
||||
throws ExecutionException {
|
||||
String fileName = httpUrl.substring(httpUrl.lastIndexOf('/') + 1,
|
||||
httpUrl.length());
|
||||
private String getFilePathOrDownload(String httpUrl, String expectedMd5) throws ExecutionException {
|
||||
String fileName = httpUrl.substring(httpUrl.lastIndexOf('/') + 1, httpUrl.length());
|
||||
URI provider = providerSupplier.get();
|
||||
if (!socketTester.apply(HostAndPort.fromParts(provider.getHost(),
|
||||
provider.getPort()))) {
|
||||
if (!socketTester.apply(HostAndPort.fromParts(provider.getHost(), provider.getPort()))) {
|
||||
throw new RuntimeException("could not connect to virtualbox");
|
||||
}
|
||||
File file = new File(isosDir, fileName);
|
||||
List<Statement> statements = Lists.newArrayList();
|
||||
statements.add(Statements.saveHttpResponseTo(URI.create(httpUrl),
|
||||
isosDir, fileName));
|
||||
List<Statement> statements = new ImmutableList.Builder<Statement>().add(
|
||||
Statements.saveHttpResponseTo(URI.create(httpUrl), isosDir, fileName)).build();
|
||||
StatementList statementList = new StatementList(statements);
|
||||
NodeMetadata hostNodeMetadata = hardcodedHostToHostNodeMetadata
|
||||
.apply(host.get());
|
||||
runScriptOnNodeFactory
|
||||
.create(hostNodeMetadata, statementList, runAsRoot(false)).init()
|
||||
.call();
|
||||
NodeMetadata hostNodeMetadata = hardcodedHostToHostNodeMetadata.apply(host.get());
|
||||
ListenableFuture<ExecResponse> future = runScriptOnNodeFactory.submit(hostNodeMetadata, statementList,
|
||||
runAsRoot(false));
|
||||
Futures.getUnchecked(future);
|
||||
|
||||
ExecResponse response = runScriptOnNodeFactory
|
||||
.create(
|
||||
hostNodeMetadata,
|
||||
Statements.exec("md5 " + isosDir + File.separator + fileName),
|
||||
runAsRoot(false)).init().call();
|
||||
if (md5 != null) {
|
||||
if (!Iterables.get(
|
||||
Splitter.on("=").trimResults().split(response.getOutput()), 1)
|
||||
.equals(md5))
|
||||
return null;
|
||||
if (expectedMd5 != null) {
|
||||
String filePath = isosDir + File.separator + fileName;
|
||||
ListenableFuture<ExecResponse> md5future = runScriptOnNodeFactory.submit(hostNodeMetadata, new Md5(filePath),
|
||||
runAsRoot(false));
|
||||
|
||||
ExecResponse responseMd5 = Futures.getUnchecked(md5future);
|
||||
assert responseMd5.getExitStatus() == 0 : hostNodeMetadata.getId() + ": " + responseMd5;
|
||||
checkNotNull(responseMd5.getOutput(), "iso_md5 missing");
|
||||
String actualMd5 = responseMd5.getOutput().trim();
|
||||
checkState(actualMd5.equals(expectedMd5), "md5 of %s is %s but expected %s", filePath, actualMd5, expectedMd5);
|
||||
}
|
||||
return file.getAbsolutePath();
|
||||
}
|
||||
|
|
|
@ -52,13 +52,13 @@ import org.jclouds.virtualbox.statements.DeleteGShadowLock;
|
|||
import org.jclouds.virtualbox.util.MachineController;
|
||||
import org.jclouds.virtualbox.util.MachineUtils;
|
||||
import org.jclouds.virtualbox.util.NetworkUtils;
|
||||
import org.virtualbox_4_1.CleanupMode;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IProgress;
|
||||
import org.virtualbox_4_1.ISession;
|
||||
import org.virtualbox_4_1.LockType;
|
||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
import org.virtualbox_4_2.CleanupMode;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.IProgress;
|
||||
import org.virtualbox_4_2.ISession;
|
||||
import org.virtualbox_4_2.LockType;
|
||||
import org.virtualbox_4_2.NetworkAttachmentType;
|
||||
import org.virtualbox_4_2.VirtualBoxManager;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Optional;
|
||||
|
@ -118,7 +118,7 @@ public class NodeCreator implements Function<NodeSpec, NodeAndInitialCredentials
|
|||
} catch (Exception 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 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)
|
||||
.vm(cloneVmSpec).build();
|
||||
|
||||
logger.debug("Cloning a new guest an existing snapshot from %s ...", master.getMachine().getName());
|
||||
IMachine cloned = cloner.apply(cloneSpec);
|
||||
logger.debug("<< cloned a vm(%s) from master(%s)", cloneName, master.getMachine().getName());
|
||||
machineController.ensureMachineIsLaunched(cloneVmSpec.getVmName());
|
||||
|
||||
// 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())
|
||||
checkState(networkUtils.enableNetworkInterface(partialNodeMetadata, optionalNatIfaceCard.get()),
|
||||
"cannot enable Nat Interface");
|
||||
"cannot enable NAT Interface on vm(%s)", cloneName);
|
||||
|
||||
LoginCredentials credentials = partialNodeMetadata.getCredentials();
|
||||
return new NodeAndInitialCredentials<IMachine>(cloned,
|
||||
|
@ -185,8 +185,10 @@ public class NodeCreator implements Function<NodeSpec, NodeAndInitialCredentials
|
|||
long slot = -1;
|
||||
long i = 0;
|
||||
while (slot == -1 && i < 4) {
|
||||
if(clone.getNetworkAdapter(i).getAttachmentType().equals(networkAttachmentType))
|
||||
if(clone.getNetworkAdapter(i).getAttachmentType().equals(networkAttachmentType)) {
|
||||
slot = i;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
checkState(slot!=-1);
|
||||
|
|
|
@ -31,7 +31,7 @@ import javax.annotation.Resource;
|
|||
import javax.inject.Named;
|
||||
|
||||
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.util.concurrent.Uninterruptibles;
|
||||
|
@ -57,9 +57,10 @@ class SendScancodes implements Function<ISession, Void> {
|
|||
logger.debug("List of scancodes sent: ", maxOrLess);
|
||||
assert codesSent == maxOrLess.size();
|
||||
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 {
|
||||
Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
|
||||
Uninterruptibles.sleepUninterruptibly(250, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -66,5 +66,4 @@ public class StringToKeyCode implements Function<String, List<Integer>> {
|
|||
private boolean containsSpecialCharacter(String s) {
|
||||
return s.startsWith("<");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,12 +22,12 @@ package org.jclouds.virtualbox.functions;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IProgress;
|
||||
import org.virtualbox_4_1.ISession;
|
||||
import org.virtualbox_4_1.ISnapshot;
|
||||
import org.virtualbox_4_1.MachineState;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.IProgress;
|
||||
import org.virtualbox_4_2.ISession;
|
||||
import org.virtualbox_4_2.ISnapshot;
|
||||
import org.virtualbox_4_2.MachineState;
|
||||
import org.virtualbox_4_2.VirtualBoxManager;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
|
@ -61,8 +61,6 @@ public class TakeSnapshotIfNotAlreadyAttached implements Function<IMachine, ISna
|
|||
if (snap == null) {
|
||||
try {
|
||||
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;
|
||||
while (true) {
|
||||
try {
|
||||
|
@ -83,7 +81,7 @@ public class TakeSnapshotIfNotAlreadyAttached implements Function<IMachine, ISna
|
|||
}
|
||||
|
||||
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());
|
||||
break;
|
||||
} 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.checkState;
|
||||
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.util.List;
|
||||
|
@ -40,16 +43,16 @@ import org.jclouds.location.Provider;
|
|||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.scriptbuilder.domain.Statement;
|
||||
import org.jclouds.scriptbuilder.domain.StatementList;
|
||||
import org.jclouds.scriptbuilder.domain.Statements;
|
||||
import org.jclouds.virtualbox.functions.HardcodedHostToHostNodeMetadata;
|
||||
import org.jclouds.virtualbox.predicates.RetryIfSocketNotYetOpen;
|
||||
import org.virtualbox_4_1.SessionState;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
import org.virtualbox_4_2.SessionState;
|
||||
import org.virtualbox_4_2.VirtualBoxManager;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
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.util.concurrent.UncheckedTimeoutException;
|
||||
|
||||
@Singleton
|
||||
public class StartVBoxIfNotAlreadyRunning implements Supplier<VirtualBoxManager> {
|
||||
|
@ -70,8 +73,7 @@ public class StartVBoxIfNotAlreadyRunning implements Supplier<VirtualBoxManager>
|
|||
@Inject
|
||||
public StartVBoxIfNotAlreadyRunning(Function<Supplier<NodeMetadata>, VirtualBoxManager> managerForNode,
|
||||
Factory runScriptOnNodeFactory, RetryIfSocketNotYetOpen socketTester, Supplier<NodeMetadata> host,
|
||||
@Provider Supplier<URI> providerSupplier,
|
||||
HardcodedHostToHostNodeMetadata hardcodedHostToHostNodeMetadata) {
|
||||
@Provider Supplier<URI> providerSupplier, HardcodedHostToHostNodeMetadata hardcodedHostToHostNodeMetadata) {
|
||||
this.runScriptOnNodeFactory = checkNotNull(runScriptOnNodeFactory, "runScriptOnNodeFactory");
|
||||
this.socketTester = checkNotNull(socketTester, "socketTester");
|
||||
this.socketTester.seconds(3L);
|
||||
|
@ -82,63 +84,57 @@ public class StartVBoxIfNotAlreadyRunning implements Supplier<VirtualBoxManager>
|
|||
}
|
||||
|
||||
@PostConstruct
|
||||
public synchronized void start() {
|
||||
public void start() {
|
||||
URI provider = providerSupplier.get();
|
||||
NodeMetadata hostNodeMetadata = hardcodedHostToHostNodeMetadata.apply(host.get());
|
||||
cleanUpHost(provider, hostNodeMetadata);
|
||||
|
||||
if (!socketTester.apply(HostAndPort.fromParts(provider.getHost(), provider.getPort()))) {
|
||||
logger.debug("disabling password access");
|
||||
runScriptOnNodeFactory
|
||||
.create(
|
||||
hostNodeMetadata,
|
||||
Statements
|
||||
.exec("VBoxManage setproperty websrvauthlibrary null"),
|
||||
.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();
|
||||
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()
|
||||
.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 RuntimeException("could not connect to virtualbox");
|
||||
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.connect(provider.toASCIIString(), "", "");
|
||||
if (logger.isDebugEnabled())
|
||||
if (manager.getSessionObject().getState() != SessionState.Unlocked)
|
||||
logger.warn("manager is not in unlocked state "
|
||||
+ manager.getSessionObject().getState());
|
||||
logger.warn("manager is not in unlocked state " + manager.getSessionObject().getState());
|
||||
|
||||
}
|
||||
|
||||
private void cleanUpHost(URI provider, NodeMetadata hostNodeMetadata) {
|
||||
public void cleanUpHost() {
|
||||
// kill previously started vboxwebsrv (possibly dirty session)
|
||||
List<Statement> statements = Lists.newArrayList();
|
||||
statements.add(Statements.findPid("vboxwebsrv"));
|
||||
statements.add(Statements.kill());
|
||||
URI provider = providerSupplier.get();
|
||||
NodeMetadata hostNodeMetadata = hardcodedHostToHostNodeMetadata.apply(host.get());
|
||||
List<Statement> statements = new ImmutableList.Builder<Statement>()
|
||||
.add(findPid("vboxwebsrv"))
|
||||
.add(kill()).build();
|
||||
StatementList statementList = new StatementList(statements);
|
||||
|
||||
if (socketTester.apply(HostAndPort.fromParts(provider.getHost(),
|
||||
provider.getPort()))) {
|
||||
if (socketTester.apply(HostAndPort.fromParts(provider.getHost(), provider.getPort()))) {
|
||||
logger.debug(String.format("shutting down previously started vboxwewbsrv at %s", provider));
|
||||
ExecResponse execResponse = runScriptOnNodeFactory
|
||||
.create(hostNodeMetadata, statementList, runAsRoot(false))
|
||||
ExecResponse execResponse = runScriptOnNodeFactory.create(hostNodeMetadata, statementList, runAsRoot(false))
|
||||
.init().call();
|
||||
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
|
||||
public VirtualBoxManager get() {
|
||||
checkState(manager != null, "start not called");
|
||||
checkState(manager != null, "VirtualBoxManager is not initialised");
|
||||
return manager;
|
||||
}
|
||||
|
||||
|
|
|
@ -52,11 +52,11 @@ import org.jclouds.logging.Logger;
|
|||
import org.jclouds.virtualbox.domain.ErrorCode;
|
||||
import org.jclouds.virtualbox.domain.StorageController;
|
||||
import org.jclouds.virtualbox.domain.VmSpec;
|
||||
import org.virtualbox_4_1.DeviceType;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IMedium;
|
||||
import org.virtualbox_4_1.IProgress;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
import org.virtualbox_4_2.DeviceType;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.IMedium;
|
||||
import org.virtualbox_4_2.IProgress;
|
||||
import org.virtualbox_4_2.VBoxException;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
|
|
|
@ -49,12 +49,12 @@ import javax.inject.Singleton;
|
|||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.virtualbox.domain.ErrorCode;
|
||||
import org.virtualbox_4_1.CleanupMode;
|
||||
import org.virtualbox_4_1.DeviceType;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IMedium;
|
||||
import org.virtualbox_4_1.IProgress;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
import org.virtualbox_4_2.CleanupMode;
|
||||
import org.virtualbox_4_2.DeviceType;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.IMedium;
|
||||
import org.virtualbox_4_2.IProgress;
|
||||
import org.virtualbox_4_2.VBoxException;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
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.machineIdsContain;
|
||||
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_1.IMedium;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.IMedium;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
|
@ -58,11 +58,9 @@ public class IMachinePredicates {
|
|||
public String toString() {
|
||||
return "isLinkedClone()";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Predicate<IMachine> isLinkedClone() {
|
||||
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.collect.Iterables.any;
|
||||
|
||||
import org.virtualbox_4_1.DeviceType;
|
||||
import org.virtualbox_4_1.IMedium;
|
||||
import org.virtualbox_4_2.DeviceType;
|
||||
import org.virtualbox_4_2.IMedium;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
|
|
|
@ -82,5 +82,4 @@ public class EnableNetworkInterface implements Statement {
|
|||
throw new UnsupportedOperationException("windows not yet implemented");
|
||||
return statements.render(family);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ public class InstallGuestAdditions implements Statement {
|
|||
return false;
|
||||
}
|
||||
}).isPresent()) {
|
||||
statements.add(exec("mount -t iso9660 /dev/sr1 " + mountPoint));
|
||||
statements.add(exec("mount -t iso9660 /dev/cdrom1 " + mountPoint));
|
||||
} else {
|
||||
String vboxGuestAdditionsIso = "VBoxGuestAdditions_" + vboxVersion + ".iso";
|
||||
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(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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
import org.virtualbox_4_1.IMedium;
|
||||
import org.virtualbox_4_1.IMediumAttachment;
|
||||
import org.virtualbox_4_2.IMedium;
|
||||
import org.virtualbox_4_2.IMediumAttachment;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.jclouds.virtualbox.util;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -29,19 +30,20 @@ import javax.inject.Singleton;
|
|||
|
||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.predicates.RetryableNumTimesPredicate;
|
||||
import org.jclouds.virtualbox.domain.ExecutionType;
|
||||
import org.jclouds.virtualbox.functions.LaunchMachineIfNotAlreadyRunning;
|
||||
import org.virtualbox_4_1.AdditionsFacilityStatus;
|
||||
import org.virtualbox_4_1.AdditionsFacilityType;
|
||||
import org.virtualbox_4_1.AdditionsRunLevelType;
|
||||
import org.virtualbox_4_1.IAdditionsFacility;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IProgress;
|
||||
import org.virtualbox_4_1.ISession;
|
||||
import org.virtualbox_4_1.LockType;
|
||||
import org.virtualbox_4_1.MachineState;
|
||||
import org.virtualbox_4_1.SessionState;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
import org.virtualbox_4_2.AdditionsFacilityStatus;
|
||||
import org.virtualbox_4_2.AdditionsFacilityType;
|
||||
import org.virtualbox_4_2.AdditionsRunLevelType;
|
||||
import org.virtualbox_4_2.IAdditionsFacility;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.IProgress;
|
||||
import org.virtualbox_4_2.ISession;
|
||||
import org.virtualbox_4_2.IVirtualBox;
|
||||
import org.virtualbox_4_2.LockType;
|
||||
import org.virtualbox_4_2.MachineState;
|
||||
import org.virtualbox_4_2.VirtualBoxManager;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
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.Supplier;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.util.concurrent.Uninterruptibles;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
|
@ -81,66 +82,11 @@ public class MachineController {
|
|||
IMachine machine = manager.get().getVBox().findMachine(vmName);
|
||||
while (!machine.getState().equals(MachineState.Running)) {
|
||||
try {
|
||||
session = machineUtils.applyForMachine(vmName,
|
||||
new LaunchMachineIfNotAlreadyRunning(manager.get(),
|
||||
session = machineUtils.applyForMachine(vmName, new LaunchMachineIfNotAlreadyRunning(manager.get(),
|
||||
executionType, ""));
|
||||
} catch (RuntimeException e) {
|
||||
if (e.getMessage()
|
||||
.contains(
|
||||
"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")) {
|
||||
if (e.getMessage().contains(
|
||||
"org.virtualbox_4_2.VBoxException: VirtualBox error: The given session is busy (0x80BB0007)")) {
|
||||
throw e;
|
||||
} else if (e.getMessage().contains("VirtualBox error: The object is not ready")) {
|
||||
continue;
|
||||
|
@ -149,7 +95,36 @@ 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");
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
|
@ -158,21 +133,20 @@ public class MachineController {
|
|||
* http://askubuntu.com/questions/82015/shutting-down-ubuntu-server-running-in-headless-virtualbox
|
||||
*/
|
||||
public ISession ensureMachineIsShutdown(String vmName) {
|
||||
IMachine machine = manager.get().getVBox().findMachine(vmName);
|
||||
ISession session = machineUtils.lockSessionOnMachineAndApply(vmName, LockType.Shared,
|
||||
new Function<ISession, ISession>() {
|
||||
ISession session = machineUtils.sharedLockMachineAndApplyToSession(vmName, new Function<ISession, ISession>() {
|
||||
@Override
|
||||
public ISession apply(ISession session) {
|
||||
session.getConsole().powerButton();
|
||||
return session;
|
||||
}
|
||||
});
|
||||
safeCheckMachineIsUnlocked(machine);
|
||||
checkState(new RetryableNumTimesPredicate<MachineState>(
|
||||
new MachineStatePredicate(manager.get().getVBox(), vmName), 5,
|
||||
3L, TimeUnit.SECONDS).apply(MachineState.PoweredOff), "vm(%s) is not shutdown correctly", vmName);
|
||||
return checkNotNull(session, "session");
|
||||
}
|
||||
|
||||
public void ensureMachineIsPaused(String vmName) {
|
||||
IMachine machine = manager.get().getVBox().findMachine(vmName);
|
||||
while (!manager.get().getVBox().findMachine(vmName).getState().equals(MachineState.Paused)) {
|
||||
try {
|
||||
machineUtils.lockSessionOnMachineAndApply(vmName, LockType.Shared, new Function<ISession, Void>() {
|
||||
|
@ -195,11 +169,9 @@ public class MachineController {
|
|||
}
|
||||
}
|
||||
}
|
||||
safeCheckMachineIsUnlocked(machine);
|
||||
}
|
||||
|
||||
public void ensureMachineIsResumed(String vmName) {
|
||||
IMachine machine = manager.get().getVBox().findMachine(vmName);
|
||||
while (!manager.get().getVBox().findMachine(vmName).getState().equals(MachineState.Running)) {
|
||||
try {
|
||||
machineUtils.lockSessionOnMachineAndApply(vmName, LockType.Shared, new Function<ISession, Void>() {
|
||||
|
@ -211,8 +183,7 @@ public class MachineController {
|
|||
});
|
||||
} catch (RuntimeException e) {
|
||||
// sometimes the machine might be powered of between the while
|
||||
// test and the call to
|
||||
// lockSessionOnMachineAndApply
|
||||
// test and the call to lockSessionOnMachineAndApply
|
||||
if (e.getMessage().contains("Invalid machine state: Resumed")) {
|
||||
return;
|
||||
} 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) {
|
||||
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) {
|
||||
private void waitVBoxServiceIsActive(final String vmName) {
|
||||
machineUtils.sharedLockMachineAndApplyToSession(vmName, new Function<ISession, Void>() {
|
||||
|
||||
@Override
|
||||
public Void apply(ISession session) {
|
||||
session.getConsole().getGuest().setStatisticsUpdateInterval(1l);
|
||||
while (!session.getConsole().getGuest().getAdditionsStatus(AdditionsRunLevelType.Userland)) {
|
||||
Uninterruptibles.sleepUninterruptibly(200, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
checkState(new RetryableNumTimesPredicate<AdditionsRunLevelType>(new AdditionsStatusPredicate(session),
|
||||
5, 2L, TimeUnit.SECONDS).apply(AdditionsRunLevelType.Userland), "timed out waiting for additionsRunLevelType to be %s", AdditionsRunLevelType.Userland);
|
||||
checkState(new RetryableNumTimesPredicate<Integer>(new FacilitiesPredicate(session),
|
||||
5, 3L, TimeUnit.SECONDS).apply(4), "timed out waiting for 4 running facilities");
|
||||
Optional<IAdditionsFacility> vboxServiceFacility = Optional.absent();
|
||||
while (!vboxServiceFacility.isPresent()) {
|
||||
vboxServiceFacility = Iterables.tryFind(session.getConsole().getGuest().getFacilities(),
|
||||
new Predicate<IAdditionsFacility>() {
|
||||
List<IAdditionsFacility> facilities = session.getConsole().getGuest().getFacilities();
|
||||
vboxServiceFacility = Iterables.tryFind(facilities, new Predicate<IAdditionsFacility>() {
|
||||
@Override
|
||||
public boolean apply(IAdditionsFacility additionsFacility) {
|
||||
return additionsFacility.getType().equals(AdditionsFacilityType.VBoxService);
|
||||
};
|
||||
return additionsFacility.getType().equals(AdditionsFacilityType.VBoxService)
|
||||
&& additionsFacility.getStatus().equals(AdditionsFacilityStatus.Active);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
while(!vboxServiceFacility.get().getStatus().equals(AdditionsFacilityStatus.Active)) {
|
||||
Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
|
||||
}
|
||||
Uninterruptibles.sleepUninterruptibly(3, TimeUnit.SECONDS);
|
||||
logger.debug("<< virtualbox service ready on vm(%s)", vmName);
|
||||
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.Splitter;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
|
||||
|
@ -61,32 +62,19 @@ public final class MachineNameOrIdAndNicSlot {
|
|||
return new MachineNameOrIdAndNicSlot(checkNotNull(machineNameOrId, "machineNameOrId"), slot);
|
||||
}
|
||||
|
||||
public static MachineNameOrIdAndNicSlot fromString(
|
||||
String machineNameOrIdAndNicSlotString) {
|
||||
checkNotNull(machineNameOrIdAndNicSlotString);
|
||||
String machineNameOrId = null;
|
||||
String nicSlotString = null;
|
||||
|
||||
Iterable<String> splittedString = Splitter.on(SEPARATOR).split(
|
||||
machineNameOrIdAndNicSlotString);
|
||||
public static MachineNameOrIdAndNicSlot fromString(String machineNameOrIdAndNicSlotString) {
|
||||
Iterable<String> splittedString = Splitter.on(SEPARATOR).split(machineNameOrIdAndNicSlotString);
|
||||
checkState(Iterables.size(splittedString) == 2);
|
||||
machineNameOrId = Iterables.get(splittedString, 0);
|
||||
nicSlotString = Iterables.get(splittedString, 1);
|
||||
|
||||
long slot = -1;
|
||||
if (nicSlotString != null) {
|
||||
checkArgument(!nicSlotString.startsWith("+"),
|
||||
"Unparseable slot number: %s", nicSlotString);
|
||||
String machineNameOrId = Strings.nullToEmpty(Iterables.get(splittedString, 0));
|
||||
String nicSlotString = Strings.nullToEmpty(Iterables.get(splittedString, 1));
|
||||
checkArgument(!nicSlotString.startsWith("+"), "Unparseable slot number: %s", nicSlotString);
|
||||
try {
|
||||
slot = Long.parseLong(nicSlotString);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new IllegalArgumentException("Unparseable slot number: "
|
||||
+ nicSlotString);
|
||||
}
|
||||
checkArgument(isValidSlot(slot), "Slot number out of range: %s",
|
||||
nicSlotString);
|
||||
}
|
||||
long slot = Long.parseLong(nicSlotString);
|
||||
checkArgument(isValidSlot(slot), "Slot number out of range: %s", nicSlotString);
|
||||
return new MachineNameOrIdAndNicSlot(machineNameOrId, slot);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new IllegalArgumentException("Unparseable slot number: " + nicSlotString);
|
||||
}
|
||||
}
|
||||
|
||||
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.reference.ComputeServiceConstants;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.predicates.RetryableNumTimesPredicate;
|
||||
import org.jclouds.scriptbuilder.domain.Statement;
|
||||
import org.jclouds.util.Throwables2;
|
||||
import org.jclouds.virtualbox.functions.IpAddressesLoadingCache;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.ISession;
|
||||
import org.virtualbox_4_1.LockType;
|
||||
import org.virtualbox_4_1.SessionState;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.ISession;
|
||||
import org.virtualbox_4_2.LockType;
|
||||
import org.virtualbox_4_2.SessionState;
|
||||
import org.virtualbox_4_2.VBoxException;
|
||||
import org.virtualbox_4_2.VirtualBoxManager;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
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,
|
||||
type, e.getMessage()), e);
|
||||
} finally {
|
||||
if (session.getState().equals(SessionState.Locked)) {
|
||||
session.unlockMachine();
|
||||
while (!session.getState().equals(SessionState.Unlocked)) {
|
||||
logger.debug("Session not unlocked - wait ...");
|
||||
// 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)) {
|
||||
session.unlockMachine();
|
||||
}
|
||||
if(!session.getState().equals(SessionState.Unlocked)) {
|
||||
checkSessionIsUnlocked(session, 5, 3L, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -216,7 +221,6 @@ public class MachineUtils {
|
|||
int count = 0;
|
||||
IMachine immutableMachine = manager.get().getVBox().findMachine(machineId);
|
||||
ISession session = null;
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
session = manager.get().getSessionObject();
|
||||
|
@ -240,12 +244,6 @@ public class MachineUtils {
|
|||
return checkNotNull(session, "session");
|
||||
}
|
||||
|
||||
void print() {
|
||||
for (StackTraceElement element : Thread.currentThread().getStackTrace()){
|
||||
System.err.println(element.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param machineId
|
||||
* @param function
|
||||
|
@ -271,4 +269,23 @@ public class MachineUtils {
|
|||
|| 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.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
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.GetIPAddressFromMAC;
|
||||
import org.jclouds.virtualbox.statements.ScanNetworkWithPing;
|
||||
import org.virtualbox_4_1.HostNetworkInterfaceType;
|
||||
import org.virtualbox_4_1.IDHCPServer;
|
||||
import org.virtualbox_4_1.IHostNetworkInterface;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.INetworkAdapter;
|
||||
import org.virtualbox_4_1.ISession;
|
||||
import org.virtualbox_4_1.LockType;
|
||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
import org.virtualbox_4_2.HostNetworkInterfaceType;
|
||||
import org.virtualbox_4_2.IDHCPServer;
|
||||
import org.virtualbox_4_2.IHostNetworkInterface;
|
||||
import org.virtualbox_4_2.INetworkAdapter;
|
||||
import org.virtualbox_4_2.NetworkAttachmentType;
|
||||
import org.virtualbox_4_2.VirtualBoxManager;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
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;
|
||||
|
||||
/**
|
||||
|
@ -97,62 +94,53 @@ public class NetworkUtils {
|
|||
|
||||
@Inject
|
||||
public NetworkUtils(Supplier<VirtualBoxManager> manager, MachineUtils machineUtils,
|
||||
MachineController machineController,
|
||||
Supplier<NodeMetadata> host,
|
||||
@Provider Supplier<URI> providerSupplier,
|
||||
IpAddressesLoadingCache ipAddressesLoadingCache,
|
||||
Supplier<NodeMetadata> hostSupplier,
|
||||
MachineController machineController, Supplier<NodeMetadata> host, @Provider Supplier<URI> providerSupplier,
|
||||
IpAddressesLoadingCache ipAddressesLoadingCache, Supplier<NodeMetadata> hostSupplier,
|
||||
RunScriptOnNode.Factory scriptRunnerFactory) {
|
||||
this.manager = manager;
|
||||
this.machineUtils = machineUtils;
|
||||
this.host = checkNotNull(host, "host");
|
||||
this.providerSupplier = checkNotNull(providerSupplier,
|
||||
"endpoint to virtualbox websrvd is needed");
|
||||
this.host = checkNotNull(host, "host can't be null");
|
||||
this.providerSupplier = checkNotNull(providerSupplier, "endpoint to virtualbox web server can't be null");
|
||||
this.ipAddressesLoadingCache = ipAddressesLoadingCache;
|
||||
this.scriptRunnerFactory = scriptRunnerFactory;
|
||||
this.hostSupplier = hostSupplier;
|
||||
}
|
||||
|
||||
public NetworkSpec createNetworkSpecWhenVboxIsLocalhost() {
|
||||
NetworkAdapter natAdapter = NetworkAdapter.builder()
|
||||
.networkAttachmentType(NetworkAttachmentType.NAT)
|
||||
.build();
|
||||
NetworkAdapter natAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.NAT).build();
|
||||
|
||||
NetworkInterfaceCard natIfaceCard = NetworkInterfaceCard.builder()
|
||||
.addNetworkAdapter(natAdapter)
|
||||
.slot(1L)
|
||||
NetworkInterfaceCard natIfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(natAdapter).slot(1L).build();
|
||||
NetworkAdapter hostOnlyAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.HostOnly)
|
||||
.build();
|
||||
NetworkAdapter hostOnlyAdapter = NetworkAdapter.builder()
|
||||
.networkAttachmentType(NetworkAttachmentType.HostOnly)
|
||||
.build();
|
||||
// create new hostOnly interface if needed, otherwise use the one already there with dhcp enabled ...
|
||||
// create new hostOnly interface if needed, otherwise use the one already
|
||||
// there with dhcp enabled ...
|
||||
String hostOnlyIfName = getHostOnlyIfOrCreate();
|
||||
NetworkInterfaceCard hostOnlyIfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(hostOnlyAdapter)
|
||||
.addHostInterfaceName(hostOnlyIfName).slot(0L).build();
|
||||
return createNetworkSpecForHostOnlyNATNICs(natIfaceCard, hostOnlyIfaceCard);
|
||||
}
|
||||
|
||||
public boolean enableNetworkInterface(NodeMetadata nodeMetadata, NetworkInterfaceCard networkInterfaceCard) {
|
||||
ExecResponse execResponse = null;
|
||||
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());
|
||||
public NetworkInterfaceCard createHostOnlyNIC(long port) {
|
||||
NetworkAdapter hostOnlyAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.HostOnly)
|
||||
.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();
|
||||
}
|
||||
if(execResponse == null)
|
||||
return false;
|
||||
return execResponse.getExitStatus() == 0;
|
||||
|
||||
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();
|
||||
return NetworkSpec.builder().addNIC(hostOnlyIfaceCard).addNIC(natIfaceCard).build();
|
||||
}
|
||||
|
||||
public String getHostOnlyIfOrCreate() {
|
||||
|
@ -168,10 +156,10 @@ public class NetworkUtils {
|
|||
}
|
||||
|
||||
private void assignDHCPtoHostOnlyInterface(final String hostOnlyIfName) {
|
||||
List<IHostNetworkInterface> availableNetworkInterfaces = manager.get().getVBox().getHost()
|
||||
.getNetworkInterfaces();
|
||||
List<IHostNetworkInterface> availableNetworkInterfaces = manager.get().getVBox().getHost().getNetworkInterfaces();
|
||||
|
||||
IHostNetworkInterface iHostNetworkInterfaceWithHostOnlyIfName = Iterables.getOnlyElement(Iterables.filter(availableNetworkInterfaces, new Predicate<IHostNetworkInterface>() {
|
||||
IHostNetworkInterface iHostNetworkInterfaceWithHostOnlyIfName = Iterables.getOnlyElement(Iterables.filter(
|
||||
availableNetworkInterfaces, new Predicate<IHostNetworkInterface>() {
|
||||
|
||||
@Override
|
||||
public boolean apply(IHostNetworkInterface iHostNetworkInterface) {
|
||||
|
@ -187,38 +175,37 @@ public class NetworkUtils {
|
|||
NodeMetadata hostNodeMetadata = getHostNodeMetadata();
|
||||
|
||||
ExecResponse response = scriptRunnerFactory
|
||||
.create(hostNodeMetadata,
|
||||
.create(
|
||||
hostNodeMetadata,
|
||||
Statements.exec(String
|
||||
.format("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();
|
||||
.format(
|
||||
"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() {
|
||||
final String hostOnlyIfName;
|
||||
NodeMetadata hostNodeMetadata = getHostNodeMetadata();
|
||||
ExecResponse createHostOnlyResponse = scriptRunnerFactory
|
||||
.create(hostNodeMetadata, Statements.exec("VBoxManage hostonlyif create"),
|
||||
runAsRoot(false).wrapInInitScript(false)).init().call();
|
||||
String output = createHostOnlyResponse.getOutput();
|
||||
checkState(createHostOnlyResponse.getExitStatus()==0);
|
||||
checkState(output.contains("'"), "cannot create hostonlyif");
|
||||
hostOnlyIfName = output.substring(output.indexOf("'") + 1, output.lastIndexOf("'"));
|
||||
return hostOnlyIfName;
|
||||
checkState(createHostOnlyResponse.getExitStatus() == 0, "cannot create hostonly interface ");
|
||||
checkState(output.contains("'"), "cannot create hostonly interface");
|
||||
return output.substring(output.indexOf("'") + 1, output.lastIndexOf("'"));
|
||||
}
|
||||
|
||||
private NodeMetadata getHostNodeMetadata() {
|
||||
NodeMetadata hostNodeMetadata = NodeMetadataBuilder
|
||||
.fromNodeMetadata(host.get())
|
||||
.publicAddresses(
|
||||
ImmutableList.of(providerSupplier.get().getHost()))
|
||||
.build();
|
||||
return hostNodeMetadata;
|
||||
return NodeMetadataBuilder.fromNodeMetadata(host.get())
|
||||
.publicAddresses(ImmutableList.of(providerSupplier.get().getHost())).build();
|
||||
}
|
||||
|
||||
private IHostNetworkInterface returnExistingHostNetworkInterfaceWithDHCPenabledOrNull(Iterable<IHostNetworkInterface> availableNetworkInterfaces) {
|
||||
private IHostNetworkInterface returnExistingHostNetworkInterfaceWithDHCPenabledOrNull(
|
||||
Iterable<IHostNetworkInterface> availableNetworkInterfaces) {
|
||||
checkNotNull(availableNetworkInterfaces);
|
||||
return Iterables.getFirst(filterAvailableNetworkInterfaceByHostOnlyAndDHCPenabled(availableNetworkInterfaces), null);
|
||||
return Iterables.getFirst(filterAvailableNetworkInterfaceByHostOnlyAndDHCPenabled(availableNetworkInterfaces),
|
||||
null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -226,113 +213,97 @@ public class NetworkUtils {
|
|||
* @param hostOnlyIfIpAddress
|
||||
* @return
|
||||
*/
|
||||
private Iterable<IHostNetworkInterface> filterAvailableNetworkInterfaceByHostOnlyAndDHCPenabled(Iterable<IHostNetworkInterface> availableNetworkInterfaces) {
|
||||
Iterable<IHostNetworkInterface> filteredNetworkInterfaces = Iterables.filter(availableNetworkInterfaces, new Predicate<IHostNetworkInterface>() {
|
||||
private Iterable<IHostNetworkInterface> filterAvailableNetworkInterfaceByHostOnlyAndDHCPenabled(
|
||||
Iterable<IHostNetworkInterface> availableNetworkInterfaces) {
|
||||
Iterable<IHostNetworkInterface> filteredNetworkInterfaces = Iterables.filter(availableNetworkInterfaces,
|
||||
new Predicate<IHostNetworkInterface>() {
|
||||
@Override
|
||||
public boolean apply(IHostNetworkInterface iHostNetworkInterface) {
|
||||
// this is an horrible workaround cause iHostNetworkInterface.getDhcpEnabled is working only for windows host
|
||||
// this is an horrible workaround cause
|
||||
// iHostNetworkInterface.getDhcpEnabled is working only for
|
||||
// windows host
|
||||
boolean match = false;
|
||||
List<IDHCPServer> availableDHCPservers = manager.get().getVBox().getDHCPServers();
|
||||
for (IDHCPServer idhcpServer : availableDHCPservers) {
|
||||
if(idhcpServer.getEnabled() && idhcpServer.getNetworkName().equals(iHostNetworkInterface.getNetworkName()))
|
||||
if (idhcpServer.getEnabled()
|
||||
&& idhcpServer.getNetworkName().equals(iHostNetworkInterface.getNetworkName()))
|
||||
match = true;
|
||||
}
|
||||
return iHostNetworkInterface.getInterfaceType().equals(HostNetworkInterfaceType.HostOnly) &&
|
||||
match;
|
||||
return iHostNetworkInterface.getInterfaceType().equals(HostNetworkInterfaceType.HostOnly) && match;
|
||||
}
|
||||
});
|
||||
return filteredNetworkInterfaces;
|
||||
}
|
||||
|
||||
public String getValidHostOnlyIpFromVm(String machineNameOrId) {
|
||||
long nicSlot = 0;
|
||||
String ipAddress = "";
|
||||
while (nicSlot < 4 && ipAddress.isEmpty()) {
|
||||
MachineNameOrIdAndNicSlot machineNameOrIdAndNicSlot = MachineNameOrIdAndNicSlot.fromParts(machineNameOrId,
|
||||
nicSlot);
|
||||
ipAddress = getIpAddressFromNicSlot(machineNameOrIdAndNicSlot);
|
||||
if (!isValidIpForHostOnly(machineNameOrIdAndNicSlot, ipAddress)) {
|
||||
ipAddressesLoadingCache.invalidate(machineNameOrIdAndNicSlot);
|
||||
ipAddress = "";
|
||||
}
|
||||
nicSlot++;
|
||||
}
|
||||
return checkNotNull(Strings.emptyToNull(ipAddress),
|
||||
String.format("Cannot find a valid IP address for the %s's HostOnly NIC", machineNameOrId));
|
||||
}
|
||||
|
||||
public String getIpAddressFromNicSlot(String machineNameOrId, long nicSlot) {
|
||||
MachineNameOrIdAndNicSlot machineNameOrIdAndNicSlot =
|
||||
MachineNameOrIdAndNicSlot.fromParts(machineNameOrId, nicSlot);
|
||||
logger.debug("Looking for an available IP address for %s at slot %s ...",
|
||||
machineNameOrIdAndNicSlot.getMachineNameOrId(),
|
||||
machineNameOrIdAndNicSlot.getSlotText());
|
||||
try {
|
||||
String ipAddress = ipAddressesLoadingCache.get(machineNameOrIdAndNicSlot);
|
||||
while(!isValidIpForHostOnly(machineNameOrIdAndNicSlot, ipAddress)) {
|
||||
ipAddressesLoadingCache.invalidate(machineNameOrIdAndNicSlot);
|
||||
ipAddress = ipAddressesLoadingCache.get(machineNameOrIdAndNicSlot);
|
||||
MachineNameOrIdAndNicSlot machineNameOrIdAndNicSlot = MachineNameOrIdAndNicSlot.fromParts(machineNameOrId,
|
||||
nicSlot);
|
||||
return getIpAddressFromNicSlot(machineNameOrIdAndNicSlot);
|
||||
}
|
||||
logger.debug("Found an available IP address %s for guest: %s at slot: %s",
|
||||
ipAddress,
|
||||
machineNameOrIdAndNicSlot.getMachineNameOrId(),
|
||||
machineNameOrIdAndNicSlot.getSlotText());
|
||||
return ipAddress;
|
||||
|
||||
public String getIpAddressFromNicSlot(MachineNameOrIdAndNicSlot machineNameOrIdAndNicSlot) {
|
||||
try {
|
||||
return ipAddressesLoadingCache.get(machineNameOrIdAndNicSlot);
|
||||
} catch (ExecutionException e) {
|
||||
logger.error("Problem in using the ipAddressCache", e.getCause());
|
||||
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) {
|
||||
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])$";
|
||||
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])$";
|
||||
Pattern pattern = Pattern.compile(IP_V4_ADDRESS_PATTERN);
|
||||
Matcher matcher = pattern.matcher(s);
|
||||
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,
|
||||
IMachine machine) {
|
||||
boolean result = isIpv4(ip) && machine.getNetworkAdapter(slot).getAttachmentType().equals(NetworkAttachmentType.HostOnly)
|
||||
&& !ipBelongsToNatRange(ip);
|
||||
return result;
|
||||
private static boolean ipEqualsToNatGateway(String ip) {
|
||||
return ip.equals(VIRTUALBOX_HOST_GATEWAY);
|
||||
}
|
||||
|
||||
private static boolean ipBelongsToNatRange(String ip) {
|
||||
return ip.startsWith("10.0.3");
|
||||
}
|
||||
|
||||
protected String getIpAddressFromBridgedNIC(INetworkAdapter networkAdapter,
|
||||
String network) {
|
||||
protected String getIpAddressFromBridgedNIC(INetworkAdapter networkAdapter, String network) {
|
||||
// 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");
|
||||
network = activeBridgedIf.getIpAddress();
|
||||
|
||||
// scan ip
|
||||
RunScriptOnNode ipScanRunScript = scriptRunnerFactory.create(
|
||||
hostSupplier.get(), new ScanNetworkWithPing(network),
|
||||
RunScriptOptions.NONE);
|
||||
RunScriptOnNode ipScanRunScript = scriptRunnerFactory.create(hostSupplier.get(),
|
||||
new ScanNetworkWithPing(network), RunScriptOptions.NONE);
|
||||
ExecResponse execResponse = ipScanRunScript.init().call();
|
||||
checkState(execResponse.getExitStatus() == 0);
|
||||
|
||||
// retrieve ip from mac
|
||||
RunScriptOnNode getIpFromMACAddressRunScript = scriptRunnerFactory
|
||||
.create(hostSupplier.get(), new GetIPAddressFromMAC(
|
||||
networkAdapter.getMACAddress()),
|
||||
RunScriptOptions.NONE);
|
||||
ExecResponse ipExecResponse = getIpFromMACAddressRunScript.init()
|
||||
.call();
|
||||
RunScriptOnNode getIpFromMACAddressRunScript = scriptRunnerFactory.create(hostSupplier.get(),
|
||||
new GetIPAddressFromMAC(networkAdapter.getMACAddress()), RunScriptOptions.NONE);
|
||||
ExecResponse ipExecResponse = getIpFromMACAddressRunScript.init().call();
|
||||
checkState(ipExecResponse.getExitStatus() == 0);
|
||||
return checkNotNull(ipExecResponse.getOutput(), "ipAddress");
|
||||
}
|
||||
|
|
|
@ -276,24 +276,20 @@ images:
|
|||
os_description: ubuntu
|
||||
os_version: 12.04.1
|
||||
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
|
||||
username: toor
|
||||
credential: password
|
||||
keystroke_sequence: |
|
||||
<Esc><Esc><Enter>
|
||||
/install/vmlinuz noapic preseed/url=http://10.0.2.2:8080/src/test/resources/preseed.cfg
|
||||
debian-installer=en_US auto locale=en_US kbd-chooser/method=us
|
||||
hostname=vmName
|
||||
fb=false debconf/frontend=noninteractive
|
||||
keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false
|
||||
console-setup/ask_detect=false keyboard-configuration/layoutcode=us
|
||||
initrd=/install/initrd.gz -- <Enter>
|
||||
preseed_cfg: |
|
||||
## Options to set on the command line
|
||||
d-i debian-installer/locale string en_US.utf8
|
||||
d-i console-setup/ask_detect boolean false
|
||||
d-i console-setup/layout string USA
|
||||
#d-i netcfg/get_hostname string dummy
|
||||
d-i netcfg/get_hostname string unassigned-hostname
|
||||
d-i netcfg/get_domain string unassigned-domain
|
||||
# Continue without a default route
|
||||
|
|
|
@ -2,8 +2,5 @@ function cleanupUdevIfNeeded {
|
|||
if [ -f '/etc/udev/rules.d/70-persistent-net.rules' ]
|
||||
then
|
||||
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
|
||||
}
|
|
@ -20,16 +20,23 @@
|
|||
package org.jclouds.virtualbox;
|
||||
|
||||
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_INSTALLATION_KEY_SEQUENCE;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.inject.Inject;
|
||||
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.NodeMetadata;
|
||||
import org.jclouds.compute.domain.Template;
|
||||
|
@ -39,6 +46,8 @@ import org.jclouds.concurrent.MoreExecutors;
|
|||
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
||||
import org.jclouds.config.ValueOfConfigurationKeyOrNull;
|
||||
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.virtualbox.config.VirtualBoxConstants;
|
||||
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.StorageController;
|
||||
import org.jclouds.virtualbox.domain.VmSpec;
|
||||
import org.jclouds.virtualbox.functions.HardcodedHostToHostNodeMetadata;
|
||||
import org.jclouds.virtualbox.functions.IMachineToVmSpec;
|
||||
import org.jclouds.virtualbox.functions.admin.UnregisterMachineIfExistsAndDeleteItsMedia;
|
||||
import org.jclouds.virtualbox.predicates.RetryIfSocketNotYetOpen;
|
||||
import org.jclouds.virtualbox.util.MachineController;
|
||||
import org.jclouds.virtualbox.util.MachineUtils;
|
||||
import org.jclouds.virtualbox.util.NetworkUtils;
|
||||
import org.testng.annotations.AfterSuite;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.CleanupMode;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
||||
import org.virtualbox_4_1.SessionState;
|
||||
import org.virtualbox_4_1.StorageBus;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
import org.virtualbox_4_2.CleanupMode;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.NetworkAttachmentType;
|
||||
import org.virtualbox_4_2.SessionState;
|
||||
import org.virtualbox_4_2.StorageBus;
|
||||
import org.virtualbox_4_2.VBoxException;
|
||||
import org.virtualbox_4_2.VirtualBoxManager;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.net.HostAndPort;
|
||||
import com.google.common.util.concurrent.Uninterruptibles;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
|
@ -116,8 +129,10 @@ public class BaseVirtualBoxClientLiveTest extends BaseComputeServiceContextLiveT
|
|||
@Named(VirtualBoxConstants.VIRTUALBOX_WORKINGDIR)
|
||||
protected String workingDir;
|
||||
protected String isosDir;
|
||||
@Inject
|
||||
protected Supplier<NodeMetadata> host;
|
||||
@Inject protected Supplier<NodeMetadata> host;
|
||||
@Inject protected Factory runScriptOnNodeFactory;
|
||||
@Inject protected RetryIfSocketNotYetOpen socketTester;
|
||||
@Inject protected HardcodedHostToHostNodeMetadata hardcodedHostToHostNodeMetadata;
|
||||
@Inject
|
||||
protected PrioritizeCredentialsFromTemplate prioritizeCredentialsFromTemplate;
|
||||
@Inject
|
||||
|
@ -126,7 +141,6 @@ public class BaseVirtualBoxClientLiveTest extends BaseComputeServiceContextLiveT
|
|||
private final ExecutorService singleThreadExec = MoreExecutors.sameThreadExecutor();
|
||||
private String masterName;
|
||||
|
||||
|
||||
@Override
|
||||
protected Iterable<Module> setupModules() {
|
||||
return ImmutableSet.<Module> of(getLoggingModule(), credentialStoreModule, getSshModule(), new ExecutorServiceModule(
|
||||
|
@ -147,7 +161,7 @@ public class BaseVirtualBoxClientLiveTest extends BaseComputeServiceContextLiveT
|
|||
masterName = VIRTUALBOX_IMAGE_PREFIX + template.getImage().getId();
|
||||
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());
|
||||
guestAdditionsIso = String.format("%s/VBoxGuestAdditions_%s.iso", isosDir, hostVersion);
|
||||
}
|
||||
|
@ -217,5 +231,4 @@ public class BaseVirtualBoxClientLiveTest extends BaseComputeServiceContextLiveT
|
|||
undoVm(masterName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@ import com.google.common.collect.Iterables;
|
|||
@Test(groups = "live", singleThreaded = true, testName = "PreseedCfgServerTest")
|
||||
public class PreseedCfgServerTest {
|
||||
private static final String lineSeparator = System.getProperty("line.separator");
|
||||
|
||||
@Test
|
||||
public void testJettyServerServesPreseedFile() throws Exception {
|
||||
Properties props = VirtualBoxApiMetadata.defaultProperties();
|
||||
|
|
|
@ -37,7 +37,7 @@ import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
|
|||
import org.jclouds.virtualbox.functions.IMachineToSshClient;
|
||||
import org.testng.annotations.AfterGroups;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ import static org.easymock.EasyMock.expect;
|
|||
import static org.easymock.EasyMock.replay;
|
||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -37,14 +38,14 @@ import org.jclouds.json.config.GsonModule;
|
|||
import org.jclouds.virtualbox.config.VirtualBoxComputeServiceContextModule;
|
||||
import org.jclouds.virtualbox.functions.IMachineToImage;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.IGuestOSType;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IVirtualBox;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
import org.virtualbox_4_2.IGuestOSType;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.IVirtualBox;
|
||||
import org.virtualbox_4_2.VirtualBoxManager;
|
||||
|
||||
import com.beust.jcommander.internal.Lists;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.inject.Guice;
|
||||
|
||||
@Test(groups = "unit")
|
||||
|
@ -82,25 +83,6 @@ public class VirtualBoxComputeServiceAdapterTest {
|
|||
|
||||
Function<IMachine, Image> iMachineToImage = new IMachineToImage(
|
||||
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;
|
||||
final String clusterName = "test-launch-cluster";
|
||||
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");
|
||||
for (NodeMetadata node : nodes) {
|
||||
assertEquals("test-launch-cluster", node.getGroup());
|
||||
assertTrue(node.getGroup().equals("test-launch-cluster"));
|
||||
logger.debug("Created Node: %s", node);
|
||||
SshClient client = context.utils().sshForNode().apply(node);
|
||||
client.connect();
|
||||
|
|
|
@ -20,12 +20,11 @@
|
|||
package org.jclouds.virtualbox.domain;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertNotEquals;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.CleanupMode;
|
||||
import org.virtualbox_4_1.StorageBus;
|
||||
import org.virtualbox_4_2.CleanupMode;
|
||||
import org.virtualbox_4_2.StorageBus;
|
||||
|
||||
public class VmSpecTest {
|
||||
|
||||
|
|
|
@ -27,10 +27,10 @@ import static org.easymock.EasyMock.verify;
|
|||
|
||||
import org.jclouds.virtualbox.domain.StorageController;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IStorageController;
|
||||
import org.virtualbox_4_1.StorageBus;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.IStorageController;
|
||||
import org.virtualbox_4_2.StorageBus;
|
||||
import org.virtualbox_4_2.VBoxException;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
|
|
|
@ -26,8 +26,8 @@ import static org.easymock.EasyMock.replay;
|
|||
import static org.easymock.EasyMock.verify;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.VBoxException;
|
||||
|
||||
/**
|
||||
* @author Mattias Holmqvist
|
||||
|
|
|
@ -22,15 +22,14 @@ import static org.easymock.EasyMock.createMock;
|
|||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.EasyMock.replay;
|
||||
import static org.easymock.EasyMock.verify;
|
||||
import static org.virtualbox_4_1.NetworkAdapterType.Am79C973;
|
||||
import static org.virtualbox_4_1.NetworkAttachmentType.Bridged;
|
||||
import static org.virtualbox_4_2.NetworkAttachmentType.Bridged;
|
||||
|
||||
import org.jclouds.virtualbox.domain.NetworkAdapter;
|
||||
import org.jclouds.virtualbox.domain.NetworkInterfaceCard;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.INetworkAdapter;
|
||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.INetworkAdapter;
|
||||
import org.virtualbox_4_2.NetworkAttachmentType;
|
||||
|
||||
/**
|
||||
* @author Andrea Turli
|
||||
|
@ -49,7 +48,6 @@ public class AttachBridgedAdapterToMachineTest {
|
|||
|
||||
expect(machine.getNetworkAdapter(adapterId)).andReturn(iNetworkAdapter);
|
||||
iNetworkAdapter.setAttachmentType(Bridged);
|
||||
iNetworkAdapter.setAdapterType(Am79C973);
|
||||
iNetworkAdapter.setMACAddress(macAddress);
|
||||
iNetworkAdapter.setBridgedInterface(hostInterface);
|
||||
iNetworkAdapter.setEnabled(true);
|
||||
|
|
|
@ -32,14 +32,14 @@ import org.jclouds.virtualbox.domain.DeviceDetails;
|
|||
import org.jclouds.virtualbox.domain.HardDisk;
|
||||
import org.jclouds.virtualbox.domain.StorageController;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.DeviceType;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IMedium;
|
||||
import org.virtualbox_4_1.IProgress;
|
||||
import org.virtualbox_4_1.IVirtualBox;
|
||||
import org.virtualbox_4_1.StorageBus;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
import org.virtualbox_4_2.DeviceType;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.IMedium;
|
||||
import org.virtualbox_4_2.IProgress;
|
||||
import org.virtualbox_4_2.IVirtualBox;
|
||||
import org.virtualbox_4_2.StorageBus;
|
||||
import org.virtualbox_4_2.VBoxException;
|
||||
import org.virtualbox_4_2.VirtualBoxManager;
|
||||
|
||||
/**
|
||||
* @author Mattias Holmqvist
|
||||
|
|
|
@ -25,17 +25,20 @@ import static org.easymock.EasyMock.expect;
|
|||
import static org.easymock.EasyMock.expectLastCall;
|
||||
import static org.easymock.EasyMock.replay;
|
||||
import static org.easymock.EasyMock.verify;
|
||||
import static org.virtualbox_4_1.NATProtocol.TCP;
|
||||
import static org.virtualbox_4_1.NetworkAttachmentType.NAT;
|
||||
import static org.virtualbox_4_2.NATProtocol.TCP;
|
||||
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.NetworkInterfaceCard;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.INATEngine;
|
||||
import org.virtualbox_4_1.INetworkAdapter;
|
||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.INATEngine;
|
||||
import org.virtualbox_4_2.INetworkAdapter;
|
||||
import org.virtualbox_4_2.NetworkAttachmentType;
|
||||
import org.virtualbox_4_2.VBoxException;
|
||||
|
||||
/**
|
||||
* @author Mattias Holmqvist, Andrea Turli
|
||||
|
@ -52,8 +55,10 @@ public class AttachNATAdapterToMachineIfNotAlreadyExistsTest {
|
|||
|
||||
expect(machine.getNetworkAdapter(slotId)).andReturn(iNetworkAdapter);
|
||||
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",
|
||||
2222, "", 22);
|
||||
iNetworkAdapter.setEnabled(true);
|
||||
|
@ -81,7 +86,10 @@ public class AttachNATAdapterToMachineIfNotAlreadyExistsTest {
|
|||
|
||||
expect(machine.getNetworkAdapter(slotId)).andReturn(iNetworkAdapter);
|
||||
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",
|
||||
2222, "", 22);
|
||||
|
|
|
@ -37,10 +37,10 @@ import org.jclouds.virtualbox.domain.VmSpec;
|
|||
import org.testng.annotations.AfterGroups;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.CleanupMode;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
||||
import org.virtualbox_4_1.StorageBus;
|
||||
import org.virtualbox_4_2.CleanupMode;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.NetworkAttachmentType;
|
||||
import org.virtualbox_4_2.StorageBus;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
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 org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX;
|
||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
@ -52,10 +51,10 @@ import org.jclouds.virtualbox.predicates.SshResponds;
|
|||
import org.testng.annotations.AfterGroups;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.CleanupMode;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
||||
import org.virtualbox_4_1.StorageBus;
|
||||
import org.virtualbox_4_2.CleanupMode;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.NetworkAttachmentType;
|
||||
import org.virtualbox_4_2.StorageBus;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
import com.google.common.base.Function;
|
||||
|
@ -137,8 +136,7 @@ public class CreateAndInstallVmLiveTest extends BaseVirtualBoxClientLiveTest {
|
|||
|
||||
String version = machine.getGuestPropertyValue("/VirtualBox/GuestAdd/Version");
|
||||
|
||||
assertNotNull(version);
|
||||
assertFalse(version.isEmpty());
|
||||
assertTrue(version != null && !version.isEmpty());
|
||||
} finally {
|
||||
for (VmSpec spec : ImmutableSet.of(machineSpec.getVmSpec())) {
|
||||
machineController.ensureMachineIsShutdown(spec.getVmName());
|
||||
|
|
|
@ -35,11 +35,11 @@ import org.jclouds.virtualbox.domain.StorageController;
|
|||
import org.jclouds.virtualbox.domain.VmSpec;
|
||||
import org.testng.annotations.AfterGroups;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.CleanupMode;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
||||
import org.virtualbox_4_1.StorageBus;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
import org.virtualbox_4_2.CleanupMode;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.NetworkAttachmentType;
|
||||
import org.virtualbox_4_2.StorageBus;
|
||||
import org.virtualbox_4_2.VBoxException;
|
||||
|
||||
import com.google.inject.Injector;
|
||||
|
||||
|
@ -83,11 +83,11 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends B
|
|||
MasterSpec machineSpec = MasterSpec.builder()
|
||||
.iso(IsoSpec.builder().sourcePath(operatingSystemIso).installationScript("").build()).vm(vmSpec)
|
||||
.network(networkSpec).build();
|
||||
// undoVm(vmSpec);
|
||||
IMachine debianNode = view.utils().injector()
|
||||
.getInstance(CreateAndRegisterMachineFromIsoIfNotAlreadyExists.class).apply(machineSpec);
|
||||
IMachine machine = manager.get().getVBox().findMachine(vmName);
|
||||
assertEquals(debianNode.getName(), machine.getName());
|
||||
undoVm(vmName);
|
||||
|
||||
}
|
||||
|
||||
|
@ -116,12 +116,12 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends B
|
|||
// if osTypeId is not found.
|
||||
assertEquals(errorCode, ErrorCode.VBOX_E_OBJECT_NOT_FOUND);
|
||||
}
|
||||
undoVm(vmName);
|
||||
}
|
||||
|
||||
@AfterGroups(groups = "live")
|
||||
@Override
|
||||
protected void tearDownContext() {
|
||||
undoVm(vmName);
|
||||
super.tearDownContext();
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.virtualbox.functions;
|
||||
|
||||
import static org.easymock.EasyMock.anyBoolean;
|
||||
import static org.easymock.EasyMock.createMock;
|
||||
import static org.easymock.EasyMock.createNiceMock;
|
||||
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.verify;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.easymock.EasyMock;
|
||||
import org.jclouds.virtualbox.domain.IsoSpec;
|
||||
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.util.MachineUtils;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.CleanupMode;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.ISession;
|
||||
import org.virtualbox_4_1.IVirtualBox;
|
||||
import org.virtualbox_4_1.LockType;
|
||||
import org.virtualbox_4_1.StorageBus;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
import org.virtualbox_4_2.CleanupMode;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.ISession;
|
||||
import org.virtualbox_4_2.IVirtualBox;
|
||||
import org.virtualbox_4_2.LockType;
|
||||
import org.virtualbox_4_2.StorageBus;
|
||||
import org.virtualbox_4_2.VBoxException;
|
||||
import org.virtualbox_4_2.VirtualBoxManager;
|
||||
|
||||
import com.beust.jcommander.internal.Lists;
|
||||
import com.google.common.base.Suppliers;
|
||||
|
||||
/**
|
||||
|
@ -60,17 +62,19 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
|||
IVirtualBox vBox = createMock(IVirtualBox.class);
|
||||
String vmName = "jclouds-image-my-ubuntu-image";
|
||||
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(
|
||||
CleanupMode.Full).build();
|
||||
VmSpec vmSpec = VmSpec.builder().id(vmName).name(vmName).osTypeId("").memoryMB(1024).controller(ideController)
|
||||
.cleanUpMode(CleanupMode.Full).build();
|
||||
MasterSpec machineSpec = MasterSpec.builder()
|
||||
.iso(IsoSpec.builder().sourcePath("some.iso").installationScript("").build())
|
||||
.vm(vmSpec)
|
||||
.iso(IsoSpec.builder().sourcePath("some.iso").installationScript("").build()).vm(vmSpec)
|
||||
.network(NetworkSpec.builder().build()).build();
|
||||
IMachine createdMachine = createMock(IMachine.class);
|
||||
ISession session = createMock(ISession.class);
|
||||
|
||||
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();
|
||||
errorMessageBuilder.append("VirtualBox error: Could not find a registered machine with UUID {");
|
||||
|
@ -80,8 +84,8 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
|||
|
||||
expect(vBox.findMachine(vmName)).andThrow(vBoxException);
|
||||
|
||||
expect(vBox.createMachine(anyString(), eq(vmName), anyString(), anyString(), anyBoolean())).andReturn(
|
||||
createdMachine).anyTimes();
|
||||
expect(vBox.createMachine(anyString(), eq(vmName), groups, anyString(), anyString())).andReturn(createdMachine)
|
||||
.anyTimes();
|
||||
vBox.registerMachine(createdMachine);
|
||||
|
||||
expect(vBox.findMachine(vmName)).andReturn(createdMachine).anyTimes();
|
||||
|
@ -92,11 +96,11 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
|||
createdMachine.saveSettings();
|
||||
session.unlockMachine();
|
||||
|
||||
|
||||
// TODO: this mock test is not finished.
|
||||
replay(manager, createdMachine, vBox, session);
|
||||
|
||||
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(Suppliers.ofInstance(manager), machineUtils, "/tmp/workingDir").apply(machineSpec);
|
||||
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(Suppliers.ofInstance(manager), machineUtils,
|
||||
"/tmp/workingDir").apply(machineSpec);
|
||||
|
||||
verify(manager, createdMachine, vBox, session);
|
||||
}
|
||||
|
@ -117,16 +121,14 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
|||
|
||||
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(CleanupMode.Full).build();
|
||||
|
||||
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);
|
||||
.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);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = VBoxException.class)
|
||||
|
@ -151,13 +153,11 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
|||
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();
|
||||
.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);
|
||||
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(Suppliers.ofInstance(manager), machineUtils,
|
||||
"/tmp/workingDir").apply(machineSpec);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -28,10 +28,11 @@ import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
|
|||
import org.jclouds.virtualbox.domain.ErrorCode;
|
||||
import org.jclouds.virtualbox.domain.HardDisk;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.DeviceType;
|
||||
import org.virtualbox_4_1.IMedium;
|
||||
import org.virtualbox_4_1.IProgress;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
import org.virtualbox_4_2.AccessMode;
|
||||
import org.virtualbox_4_2.DeviceType;
|
||||
import org.virtualbox_4_2.IMedium;
|
||||
import org.virtualbox_4_2.IProgress;
|
||||
import org.virtualbox_4_2.VBoxException;
|
||||
|
||||
/**
|
||||
* @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";
|
||||
HardDisk hardDisk = HardDisk.builder().diskpath(path).controllerPort(0).deviceSlot(0).build();
|
||||
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 {
|
||||
assertFileCanBeDeleted(path);
|
||||
} finally {
|
||||
|
@ -70,7 +71,7 @@ public class CreateMediumIfNotAlreadyExistsLiveTest extends BaseVirtualBoxClient
|
|||
HardDisk hardDisk = HardDisk.builder().diskpath(path).controllerPort(0).deviceSlot(0).build();
|
||||
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 {
|
||||
assertFileCanBeDeleted(path);
|
||||
} finally {
|
||||
|
|
|
@ -22,7 +22,6 @@ package org.jclouds.virtualbox.functions;
|
|||
import static org.easymock.EasyMock.anyLong;
|
||||
import static org.easymock.EasyMock.createMock;
|
||||
import static org.easymock.EasyMock.createNiceMock;
|
||||
import static org.easymock.EasyMock.eq;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.EasyMock.replay;
|
||||
import static org.easymock.EasyMock.verify;
|
||||
|
@ -32,16 +31,17 @@ import org.jclouds.virtualbox.domain.HardDisk;
|
|||
import org.jclouds.virtualbox.util.MachineUtils;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.DeviceType;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IMedium;
|
||||
import org.virtualbox_4_1.IMediumAttachment;
|
||||
import org.virtualbox_4_1.IProgress;
|
||||
import org.virtualbox_4_1.ISession;
|
||||
import org.virtualbox_4_1.IVirtualBox;
|
||||
import org.virtualbox_4_1.LockType;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
import org.virtualbox_4_2.AccessMode;
|
||||
import org.virtualbox_4_2.DeviceType;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.IMedium;
|
||||
import org.virtualbox_4_2.IMediumAttachment;
|
||||
import org.virtualbox_4_2.IProgress;
|
||||
import org.virtualbox_4_2.ISession;
|
||||
import org.virtualbox_4_2.IVirtualBox;
|
||||
import org.virtualbox_4_2.LockType;
|
||||
import org.virtualbox_4_2.VBoxException;
|
||||
import org.virtualbox_4_2.VirtualBoxManager;
|
||||
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
@ -74,14 +74,14 @@ public class CreateMediumIfNotAlreadyExistsTest {
|
|||
IProgress progress = createNiceMock(IProgress.class);
|
||||
|
||||
StringBuilder errorBuilder = new StringBuilder();
|
||||
errorBuilder.append("org.virtualbox_4_1.VBoxException: VirtualBox error: ");
|
||||
errorBuilder.append("Could not find an open hard disk with location ");
|
||||
errorBuilder.append("org.virtualbox_4_2.VBoxException: VirtualBox error: ");
|
||||
errorBuilder.append("Could not find file for the medium ");
|
||||
errorBuilder.append("'/Users/johndoe/jclouds-virtualbox-test/testadmin.vdi' (0x80BB0001)");
|
||||
String errorMessage = errorBuilder.toString();
|
||||
expect(manager.getVBox()).andReturn(vBox).anyTimes();
|
||||
|
||||
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(medium.createBaseStorage(anyLong(), anyLong())).andReturn(progress);
|
||||
//expect(machineUtils.writeLockMachineAndApply(anyString(), new DetachDistroMediumFromMachine(anyString(), anyInt() , anyInt()))).andReturn().anyTimes();
|
||||
|
@ -108,7 +108,7 @@ public class CreateMediumIfNotAlreadyExistsTest {
|
|||
IProgress progress = createNiceMock(IProgress.class);
|
||||
|
||||
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(vBox.createHardDisk(diskFormat, adminDiskPath)).andReturn(newHardDisk);
|
||||
|
@ -140,7 +140,7 @@ public class CreateMediumIfNotAlreadyExistsTest {
|
|||
IProgress progress = createNiceMock(IProgress.class);
|
||||
|
||||
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 oldMachineName = "oldMachine";
|
||||
|
@ -154,7 +154,7 @@ public class CreateMediumIfNotAlreadyExistsTest {
|
|||
ISession detachSession = createNiceMock(ISession.class);
|
||||
|
||||
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("is still attached to the following 1 virtual machine(s): ");
|
||||
errorBuilder.append(oldMachineId + " (0x80BB000C)");
|
||||
|
@ -207,7 +207,7 @@ public class CreateMediumIfNotAlreadyExistsTest {
|
|||
IProgress progress = createNiceMock(IProgress.class);
|
||||
|
||||
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);
|
||||
|
||||
|
@ -232,7 +232,7 @@ public class CreateMediumIfNotAlreadyExistsTest {
|
|||
expect(manager.getVBox()).andReturn(vBox).anyTimes();
|
||||
|
||||
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(medium.createBaseStorage(anyLong(), anyLong())).andReturn(progress);
|
||||
|
||||
|
|
|
@ -25,8 +25,8 @@ import static org.easymock.EasyMock.replay;
|
|||
import static org.easymock.EasyMock.verify;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.VBoxException;
|
||||
|
||||
/**
|
||||
* @author Andrea Turli
|
||||
|
|
|
@ -28,10 +28,10 @@ import static org.testng.Assert.assertEquals;
|
|||
import org.jclouds.compute.domain.Hardware;
|
||||
import org.jclouds.compute.predicates.ImagePredicates;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.IGuestOSType;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IVirtualBox;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
import org.virtualbox_4_2.IGuestOSType;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.IVirtualBox;
|
||||
import org.virtualbox_4_2.VirtualBoxManager;
|
||||
|
||||
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.VirtualBoxConstants;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.IGuestOSType;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IVirtualBox;
|
||||
import org.virtualbox_4_1.MachineState;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
import org.virtualbox_4_2.IGuestOSType;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.IVirtualBox;
|
||||
import org.virtualbox_4_2.MachineState;
|
||||
import org.virtualbox_4_2.VirtualBoxManager;
|
||||
|
||||
import com.google.common.base.Suppliers;
|
||||
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.testng.Assert.assertEquals;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.compute.config.BaseComputeServiceContextModule;
|
||||
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.util.NetworkUtils;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.INATEngine;
|
||||
import org.virtualbox_4_1.INetworkAdapter;
|
||||
import org.virtualbox_4_1.MachineState;
|
||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
||||
import org.virtualbox_4_2.IGuest;
|
||||
import org.virtualbox_4_2.IGuestOSType;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.INATEngine;
|
||||
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.Iterables;
|
||||
import com.google.inject.Guice;
|
||||
|
||||
public class IMachineToNodeMetadataTest {
|
||||
|
||||
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 {
|
||||
|
||||
IMachine vm = createNiceMock(IMachine.class);
|
||||
|
||||
expect(vm.getName()).andReturn(VIRTUALBOX_IMAGE_PREFIX + MASTER_NAME).anyTimes();
|
||||
expect(vm.getState()).andReturn(MachineState.PoweredOff).anyTimes();
|
||||
|
||||
VirtualBoxManager vbm = createNiceMock(VirtualBoxManager.class);
|
||||
IVirtualBox vBox = createNiceMock(IVirtualBox.class);
|
||||
IGuestOSType iGuestOSType = createNiceMock(IGuestOSType.class);
|
||||
INetworkAdapter nat = createNiceMock(INetworkAdapter.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(1l))).andReturn(null).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.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);
|
||||
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,
|
||||
networkUtils).apply(vm);
|
||||
NodeMetadata node = new IMachineToNodeMetadata(Suppliers
|
||||
.ofInstance(vbm), VirtualBoxComputeServiceContextModule.toPortableNodeStatus,
|
||||
networkUtils, map).apply(vm);
|
||||
|
||||
assertEquals(MASTER_NAME, node.getName());
|
||||
assertEquals(1, node.getPrivateAddresses().size());
|
||||
|
@ -79,11 +101,13 @@ public class IMachineToNodeMetadataTest {
|
|||
assertEquals("", node.getGroup());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(enabled=false)
|
||||
public void testCreateFromNode() throws Exception {
|
||||
|
||||
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 name = "a-name-with-a-code-338";
|
||||
|
||||
|
@ -97,18 +121,21 @@ public class IMachineToNodeMetadataTest {
|
|||
|
||||
INetworkAdapter hostOnly = createNiceMock(INetworkAdapter.class);
|
||||
|
||||
|
||||
|
||||
expect(vm.getNetworkAdapter(eq(0l))).andReturn(nat).once();
|
||||
expect(vm.getNetworkAdapter(eq(1l))).andReturn(hostOnly).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.getRedirects()).andReturn(ImmutableList.of("0,1,127.0.0.1,3000,,22"));
|
||||
NetworkUtils networkUtils = createNiceMock(NetworkUtils.class);
|
||||
|
||||
replay(vm, nat, natEng, hostOnly, networkUtils);
|
||||
|
||||
NodeMetadata node = new IMachineToNodeMetadata(VirtualBoxComputeServiceContextModule.toPortableNodeStatus,
|
||||
networkUtils).apply(vm);
|
||||
NodeMetadata node = new IMachineToNodeMetadata(Suppliers
|
||||
.ofInstance(vbm), VirtualBoxComputeServiceContextModule.toPortableNodeStatus,
|
||||
networkUtils, map).apply(vm);
|
||||
|
||||
assertEquals(name, node.getName());
|
||||
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.VmSpec;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.DeviceType;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IMedium;
|
||||
import org.virtualbox_4_1.IMediumAttachment;
|
||||
import org.virtualbox_4_1.IStorageController;
|
||||
import org.virtualbox_4_1.StorageBus;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
import org.virtualbox_4_2.DeviceType;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.IMedium;
|
||||
import org.virtualbox_4_2.IMediumAttachment;
|
||||
import org.virtualbox_4_2.IStorageController;
|
||||
import org.virtualbox_4_2.StorageBus;
|
||||
import org.virtualbox_4_2.VirtualBoxManager;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
|
|
|
@ -25,11 +25,11 @@ import static org.easymock.EasyMock.verify;
|
|||
|
||||
import org.jclouds.virtualbox.domain.ExecutionType;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IProgress;
|
||||
import org.virtualbox_4_1.ISession;
|
||||
import org.virtualbox_4_1.SessionState;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.IProgress;
|
||||
import org.virtualbox_4_2.ISession;
|
||||
import org.virtualbox_4_2.SessionState;
|
||||
import org.virtualbox_4_2.VirtualBoxManager;
|
||||
|
||||
@Test(groups = "unit", testName = "LaunchMachineIfNotAlreadyRunningTest")
|
||||
public class LaunchMachineIfNotAlreadyRunningTest {
|
||||
|
|
|
@ -26,14 +26,14 @@ import static org.easymock.EasyMock.verify;
|
|||
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.IConsole;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IProgress;
|
||||
import org.virtualbox_4_1.ISession;
|
||||
import org.virtualbox_4_1.ISnapshot;
|
||||
import org.virtualbox_4_1.IVirtualBox;
|
||||
import org.virtualbox_4_1.MachineState;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
import org.virtualbox_4_2.IConsole;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.IProgress;
|
||||
import org.virtualbox_4_2.ISession;
|
||||
import org.virtualbox_4_2.ISnapshot;
|
||||
import org.virtualbox_4_2.IVirtualBox;
|
||||
import org.virtualbox_4_2.MachineState;
|
||||
import org.virtualbox_4_2.VirtualBoxManager;
|
||||
|
||||
import com.google.common.base.Suppliers;
|
||||
|
||||
|
|
|
@ -24,21 +24,18 @@ import static org.easymock.EasyMock.expect;
|
|||
import static org.easymock.EasyMock.expectLastCall;
|
||||
import static org.easymock.EasyMock.replay;
|
||||
import static org.easymock.EasyMock.verify;
|
||||
import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.jclouds.compute.callables.RunScriptOnNode;
|
||||
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.Status;
|
||||
import org.jclouds.compute.domain.NodeMetadataBuilder;
|
||||
import org.jclouds.compute.domain.OperatingSystem;
|
||||
import org.jclouds.scriptbuilder.domain.Statements;
|
||||
import org.jclouds.virtualbox.functions.HardcodedHostToHostNodeMetadata;
|
||||
import org.jclouds.virtualbox.predicates.RetryIfSocketNotYetOpen;
|
||||
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.Functions;
|
||||
|
@ -53,57 +50,18 @@ public class StartVBoxIfNotAlreadyRunningLiveTest {
|
|||
public void testStartVboxConnectsToManagerWhenPortAlreadyListening() throws Exception {
|
||||
VirtualBoxManager manager = createMock(VirtualBoxManager.class);
|
||||
Factory runScriptOnNodeFactory = createMock(Factory.class);
|
||||
RunScriptOnNode runScriptOnNode = createMock(RunScriptOnNode.class);
|
||||
RetryIfSocketNotYetOpen client = createMock(RetryIfSocketNotYetOpen.class);
|
||||
HardcodedHostToHostNodeMetadata hardcodedHostToHostNodeMetadata = createMock(HardcodedHostToHostNodeMetadata.class);
|
||||
NodeMetadata host = new NodeMetadataBuilder().id("host").status(Status.RUNNING).build();
|
||||
URI provider = URI.create("http://localhost:18083/");
|
||||
expect(client.seconds(3)).andReturn(client);
|
||||
expect(client.apply(HostAndPort.fromParts(provider.getHost(), provider.getPort()))).andReturn(true).anyTimes();
|
||||
manager.connect(provider.toASCIIString(), "", "");
|
||||
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);
|
||||
new StartVBoxIfNotAlreadyRunning((Function) Functions.constant(manager), runScriptOnNodeFactory, client,
|
||||
Suppliers.ofInstance(host), Suppliers.ofInstance(provider), null);
|
||||
|
||||
verify(manager, runScriptOnNodeFactory, runScriptOnNode, client);
|
||||
Suppliers.ofInstance(host), Suppliers.ofInstance(provider), hardcodedHostToHostNodeMetadata).start();
|
||||
verify(manager, runScriptOnNodeFactory, client);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,19 +27,19 @@ import static org.easymock.EasyMock.replay;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import org.jclouds.virtualbox.domain.HardDisk;
|
||||
import org.jclouds.virtualbox.domain.StorageController;
|
||||
import org.jclouds.virtualbox.domain.VmSpec;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.CleanupMode;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IMedium;
|
||||
import org.virtualbox_4_1.IProgress;
|
||||
import org.virtualbox_4_1.IVirtualBox;
|
||||
import org.virtualbox_4_1.StorageBus;
|
||||
import org.virtualbox_4_1.VirtualBoxManager;
|
||||
import org.virtualbox_4_2.CleanupMode;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.IMedium;
|
||||
import org.virtualbox_4_2.IProgress;
|
||||
import org.virtualbox_4_2.IVirtualBox;
|
||||
import org.virtualbox_4_2.StorageBus;
|
||||
import org.virtualbox_4_2.VirtualBoxManager;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
@Test(groups = "unit", testName = "UnregisterMachineIfExistsTest")
|
||||
public class UnregisterMachineIfExistsAndDeleteItsMediaTest {
|
||||
|
@ -64,9 +64,7 @@ public class UnregisterMachineIfExistsAndDeleteItsMediaTest {
|
|||
.attachHardDisk(HardDisk.builder().diskpath("/tmp/testadmin.vdi").controllerPort(0).deviceSlot(1).build())
|
||||
.attachISO(1, 1, "/tmp/VBoxGuestAdditions_4.1.2.iso").build();
|
||||
VmSpec vmSpecification = VmSpec.builder().id(vmId).name(vmName).memoryMB(512).osTypeId(osTypeId)
|
||||
.controller(ideController)
|
||||
.forceOverwrite(true)
|
||||
.cleanUpMode(CleanupMode.Full).build();
|
||||
.controller(ideController).forceOverwrite(true).cleanUpMode(CleanupMode.Full).build();
|
||||
|
||||
expect(manager.getVBox()).andReturn(vBox).anyTimes();
|
||||
expect(vBox.findMachine(vmName)).andReturn(registeredMachine);
|
||||
|
|
|
@ -42,10 +42,10 @@ import org.jclouds.virtualbox.functions.IMachineToSshClient;
|
|||
import org.jclouds.virtualbox.util.NetworkUtils;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.CleanupMode;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
||||
import org.virtualbox_4_1.StorageBus;
|
||||
import org.virtualbox_4_2.CleanupMode;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.NetworkAttachmentType;
|
||||
import org.virtualbox_4_2.StorageBus;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
import com.google.common.base.Function;
|
||||
|
@ -56,14 +56,14 @@ import com.google.inject.Injector;
|
|||
/**
|
||||
* @author Andrea Turli
|
||||
*/
|
||||
@Test(groups = "live", singleThreaded = true, testName = "GuestAdditionsInstallerLiveTest", enabled=false)
|
||||
@Test(groups = "live", singleThreaded = true, testName = "GuestAdditionsInstallerLiveTest")
|
||||
public class GuestAdditionsInstallerLiveTest extends BaseVirtualBoxClientLiveTest {
|
||||
|
||||
private Injector injector;
|
||||
private Function<IMachine, SshClient> sshClientForIMachine;
|
||||
private Predicate<SshClient> sshResponds;
|
||||
|
||||
private MasterSpec machineSpec;
|
||||
private VmSpec instanceVmSpec;
|
||||
private NetworkSpec instanceNetworkSpec;
|
||||
|
||||
@Override
|
||||
@BeforeClass(groups = "live")
|
||||
|
@ -83,7 +83,7 @@ public class GuestAdditionsInstallerLiveTest extends BaseVirtualBoxClientLiveTes
|
|||
HardDisk.builder().diskpath(adminDisk(instanceName)).controllerPort(0).deviceSlot(1)
|
||||
.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();
|
||||
|
||||
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",
|
||||
instanceVmSpec.getVmName())).build();
|
||||
|
||||
NetworkAdapter networkAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.NAT)
|
||||
.tcpRedirectRule("127.0.0.1", 2222, "", 22).build();
|
||||
NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(networkAdapter)
|
||||
NetworkAdapter networkAdapter = NetworkAdapter.builder()
|
||||
.networkAttachmentType(NetworkAttachmentType.HostOnly)
|
||||
.build();
|
||||
NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(networkAdapter)
|
||||
.addHostInterfaceName("vboxnet0").slot(0L).build();
|
||||
|
||||
NetworkSpec networkSpec = NetworkSpec.builder().addNIC(networkInterfaceCard).build();
|
||||
machineSpec = MasterSpec.builder().iso(isoSpec).vm(instanceVmSpec).network(networkSpec).build();
|
||||
instanceNetworkSpec = NetworkSpec.builder().addNIC(networkInterfaceCard).build();
|
||||
//cloneSpec = MasterSpec.builder().iso(isoSpec).vm(instanceVmSpec).network(networkSpec).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -119,23 +120,29 @@ public class GuestAdditionsInstallerLiveTest extends BaseVirtualBoxClientLiveTes
|
|||
assertTrue(NetworkUtils.isIpv4(networkUtils.getIpAddressFromNicSlot(machine.getName(), 0l)));
|
||||
|
||||
} finally {
|
||||
if(machine!=null) {
|
||||
for (String vmNameOrId : ImmutableSet.of(machine.getName())) {
|
||||
machineController.ensureMachineHasPowerDown(vmNameOrId);
|
||||
undoVm(vmNameOrId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IMachine cloneFromMaster() {
|
||||
protected IMachine cloneFromMaster() {
|
||||
IMachine source = getVmWithGuestAdditionsInstalled();
|
||||
CloneSpec cloneSpec = CloneSpec.builder().vm(machineSpec.getVmSpec()).network(machineSpec.getNetworkSpec())
|
||||
.master(source).linked(true).build();
|
||||
CloneSpec cloneSpec = CloneSpec.builder()
|
||||
.vm(instanceVmSpec)
|
||||
.network(instanceNetworkSpec)
|
||||
.master(source)
|
||||
.linked(true)
|
||||
.build();
|
||||
return new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(manager, workingDir, machineUtils)
|
||||
.apply(cloneSpec);
|
||||
}
|
||||
|
||||
private IMachine getVmWithGuestAdditionsInstalled() {
|
||||
MasterSpec masterSpecForTest = super.getMasterSpecForTest();
|
||||
MasterSpec masterSpecForTest = getMasterSpecForTest();
|
||||
try {
|
||||
Injector injector = view.utils().injector();
|
||||
return injector.getInstance(CreateAndInstallVm.class).apply(masterSpecForTest);
|
||||
|
@ -144,5 +151,4 @@ public class GuestAdditionsInstallerLiveTest extends BaseVirtualBoxClientLiveTes
|
|||
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.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.CleanupMode;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
||||
import org.virtualbox_4_1.StorageBus;
|
||||
import org.virtualbox_4_2.CleanupMode;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.NetworkAttachmentType;
|
||||
import org.virtualbox_4_2.StorageBus;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
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.VmSpec;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.CleanupMode;
|
||||
import org.virtualbox_4_1.StorageBus;
|
||||
import org.virtualbox_4_2.CleanupMode;
|
||||
import org.virtualbox_4_2.StorageBus;
|
||||
|
||||
/**
|
||||
* @author Andrea Turli, David Alves
|
||||
|
@ -44,8 +44,8 @@ public class InstallGuestAdditionsLiveTest extends BaseVirtualBoxClientLiveTest
|
|||
|
||||
InstallGuestAdditions installer = new InstallGuestAdditions(vmSpecification, "4.1.8");
|
||||
String scripts = installer.render(OsFamily.UNIX);
|
||||
assertEquals("installModuleAssistantIfNeeded || return 1\n" + "mount -t iso9660 /dev/sr1 /mnt\n"
|
||||
+ "/mnt/VBoxLinuxAdditions.run --nox11\n", scripts);
|
||||
assertEquals(scripts, "installModuleAssistantIfNeeded || return 1\n" + "mount -t iso9660 /dev/cdrom1 /mnt\n"
|
||||
+ "/mnt/VBoxLinuxAdditions.run --nox11\n");
|
||||
}
|
||||
|
||||
public void testIsoNotPresent() {
|
||||
|
@ -56,12 +56,11 @@ public class InstallGuestAdditionsLiveTest extends BaseVirtualBoxClientLiveTest
|
|||
|
||||
InstallGuestAdditions installer = new InstallGuestAdditions(vmSpecification, "4.1.8");
|
||||
String scripts = installer.render(OsFamily.UNIX);
|
||||
assertEquals(
|
||||
assertEquals(scripts,
|
||||
"installModuleAssistantIfNeeded || 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"
|
||||
+ "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.NetworkInterfaceCard;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
||||
import org.virtualbox_4_2.NetworkAttachmentType;
|
||||
|
||||
public class SetIpAddressTest {
|
||||
|
||||
|
|
|
@ -21,8 +21,8 @@ package org.jclouds.virtualbox.util;
|
|||
|
||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX;
|
||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE;
|
||||
import static org.testng.AssertJUnit.assertTrue;
|
||||
import static org.testng.AssertJUnit.assertEquals;
|
||||
import static org.testng.AssertJUnit.assertSame;
|
||||
|
||||
import org.jclouds.config.ValueOfConfigurationKeyOrNull;
|
||||
import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
|
||||
|
@ -40,12 +40,12 @@ import org.jclouds.virtualbox.functions.CreateAndInstallVm;
|
|||
import org.testng.annotations.AfterGroups;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.CleanupMode;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.ISession;
|
||||
import org.virtualbox_4_1.NetworkAttachmentType;
|
||||
import org.virtualbox_4_1.SessionState;
|
||||
import org.virtualbox_4_1.StorageBus;
|
||||
import org.virtualbox_4_2.CleanupMode;
|
||||
import org.virtualbox_4_2.IMachine;
|
||||
import org.virtualbox_4_2.ISession;
|
||||
import org.virtualbox_4_2.NetworkAttachmentType;
|
||||
import org.virtualbox_4_2.SessionState;
|
||||
import org.virtualbox_4_2.StorageBus;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
import com.google.common.base.Function;
|
||||
|
@ -55,8 +55,9 @@ import com.google.inject.Injector;
|
|||
@Test(groups = "live", testName = "MachineControllerLiveTest")
|
||||
public class MachineControllerLiveTest extends BaseVirtualBoxClientLiveTest {
|
||||
|
||||
private MasterSpec machineSpec;
|
||||
private MasterSpec masterSpec;
|
||||
private String instanceName;
|
||||
private IMachine clonedMachine;
|
||||
|
||||
@Override
|
||||
@BeforeClass(groups = "live")
|
||||
|
@ -71,53 +72,42 @@ public class MachineControllerLiveTest extends BaseVirtualBoxClientLiveTest {
|
|||
.bus(StorageBus.IDE)
|
||||
.attachISO(0, 0, operatingSystemIso)
|
||||
.attachHardDisk(
|
||||
HardDisk.builder().diskpath(adminDisk(instanceName)).controllerPort(0).deviceSlot(1)
|
||||
.autoDelete(true).build()).attachISO(1, 1, guestAdditionsIso).build();
|
||||
HardDisk.builder().diskpath(adminDisk(instanceName)).controllerPort(0).deviceSlot(1).autoDelete(true)
|
||||
.build()).attachISO(1, 1, guestAdditionsIso).build();
|
||||
|
||||
VmSpec instanceVmSpec = VmSpec.builder().id(instanceName).name(instanceName).osTypeId("").memoryMB(512)
|
||||
.cleanUpMode(CleanupMode.Full).controller(ideController).forceOverwrite(true).build();
|
||||
|
||||
Injector injector = view.utils().injector();
|
||||
Function<String, String> configProperties = injector
|
||||
.getInstance(ValueOfConfigurationKeyOrNull.class);
|
||||
Function<String, String> configProperties = injector.getInstance(ValueOfConfigurationKeyOrNull.class);
|
||||
IsoSpec isoSpec = IsoSpec
|
||||
.builder()
|
||||
.sourcePath(operatingSystemIso)
|
||||
.installationScript(
|
||||
configProperties.apply(VIRTUALBOX_INSTALLATION_KEY_SEQUENCE)
|
||||
.replace("HOSTNAME", instanceVmSpec.getVmName()))
|
||||
.build();
|
||||
configProperties.apply(VIRTUALBOX_INSTALLATION_KEY_SEQUENCE).replace("HOSTNAME",
|
||||
instanceVmSpec.getVmName())).build();
|
||||
|
||||
NetworkAdapter networkAdapter = NetworkAdapter.builder()
|
||||
.networkAttachmentType(NetworkAttachmentType.HostOnly).build();
|
||||
NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard
|
||||
.builder().addNetworkAdapter(networkAdapter)
|
||||
NetworkAdapter networkAdapter = NetworkAdapter.builder().networkAttachmentType(NetworkAttachmentType.HostOnly)
|
||||
.build();
|
||||
NetworkInterfaceCard networkInterfaceCard = NetworkInterfaceCard.builder().addNetworkAdapter(networkAdapter)
|
||||
.addHostInterfaceName("vboxnet0").slot(0L).build();
|
||||
NetworkSpec networkSpec = NetworkSpec.builder()
|
||||
.addNIC(networkInterfaceCard).build();
|
||||
machineSpec = MasterSpec.builder().iso(isoSpec).vm(instanceVmSpec)
|
||||
.network(networkSpec).build();
|
||||
NetworkSpec networkSpec = NetworkSpec.builder().addNIC(networkInterfaceCard).build();
|
||||
masterSpec = MasterSpec.builder().iso(isoSpec).vm(instanceVmSpec).network(networkSpec).build();
|
||||
clonedMachine = cloneFromMaster();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnsureMachineisLaunchedAndSessionIsUnlocked() {
|
||||
cloneFromMaster();
|
||||
ISession cloneMachineSession = machineController.ensureMachineIsLaunched(instanceName);
|
||||
assertSame(cloneMachineSession.getState(), SessionState.Unlocked);
|
||||
cloneMachineSession = machineController.ensureMachineHasPowerDown(instanceName);
|
||||
assertSame(cloneMachineSession.getState(), SessionState.Unlocked);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods="testEnsureMachineisLaunchedAndSessionIsUnlocked")
|
||||
public void testEnsureMachineCanBePoweredOffMoreThanOneTimeAndSessionIsUnlocked() {
|
||||
ISession cloneMachineSession = machineController.ensureMachineHasPowerDown(instanceName);
|
||||
ISession cloneMachineSession = machineController.ensureMachineIsLaunched(clonedMachine.getName());
|
||||
assertTrue(cloneMachineSession.getState() == SessionState.Unlocked);
|
||||
cloneMachineSession = machineController.ensureMachineHasPowerDown(clonedMachine.getName());
|
||||
SessionState state = cloneMachineSession.getState();
|
||||
assertEquals(SessionState.Unlocked, state);
|
||||
}
|
||||
|
||||
private IMachine cloneFromMaster() {
|
||||
IMachine source = getVmWithGuestAdditionsInstalled();
|
||||
CloneSpec cloneSpec = CloneSpec.builder().vm(machineSpec.getVmSpec()).network(machineSpec.getNetworkSpec())
|
||||
CloneSpec cloneSpec = CloneSpec.builder().vm(masterSpec.getVmSpec()).network(masterSpec.getNetworkSpec())
|
||||
.master(source).linked(true).build();
|
||||
return new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(manager, workingDir, machineUtils)
|
||||
.apply(cloneSpec);
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue