mirror of https://github.com/apache/jclouds.git
First step on IsoSpec/NetworkSpec/IMachineSpec. Also reverted ubuntu version to 11.04.
This commit is contained in:
parent
f1427fbb74
commit
ef0b689113
|
@ -64,7 +64,8 @@ public class VirtualBoxPropertiesBuilder extends PropertiesBuilder {
|
||||||
properties.put(VIRTUALBOX_ISO_URL, "http://releases.ubuntu.com/11.04/ubuntu-11.04-server-i386.iso");
|
properties.put(VIRTUALBOX_ISO_URL, "http://releases.ubuntu.com/11.04/ubuntu-11.04-server-i386.iso");
|
||||||
properties.put(VIRTUALBOX_INSTALLATION_KEY_SEQUENCE, "<Esc><Esc><Enter> "
|
properties.put(VIRTUALBOX_INSTALLATION_KEY_SEQUENCE, "<Esc><Esc><Enter> "
|
||||||
+ "/install/vmlinuz noapic preseed/url=PRECONFIGURATION_URL "
|
+ "/install/vmlinuz noapic preseed/url=PRECONFIGURATION_URL "
|
||||||
+ "debian-installer=en_US auto locale=en_US kbd-chooser/method=us " + "hostname=" + "HOSTNAME "
|
+ "debian-installer=en_US auto locale=en_US kbd-chooser/method=us "
|
||||||
|
+ "hostname=" + "HOSTNAME "
|
||||||
+ "fb=false debconf/frontend=noninteractive "
|
+ "fb=false debconf/frontend=noninteractive "
|
||||||
+ "keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false "
|
+ "keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false "
|
||||||
+ "initrd=/install/initrd.gz -- <Enter>");
|
+ "initrd=/install/initrd.gz -- <Enter>");
|
||||||
|
|
|
@ -0,0 +1,113 @@
|
||||||
|
/*
|
||||||
|
* 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.domain;
|
||||||
|
|
||||||
|
import com.google.common.base.Objects;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A complete specification of a "master" node, including the ISO, networking setup
|
||||||
|
* and the physical machine specification.
|
||||||
|
*/
|
||||||
|
public class IMachineSpec {
|
||||||
|
|
||||||
|
private VmSpec vmSpec;
|
||||||
|
private IsoSpec isoSpec;
|
||||||
|
private NetworkSpec networkSpec;
|
||||||
|
|
||||||
|
public static Builder builder() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
|
||||||
|
private VmSpec vmSpec;
|
||||||
|
private IsoSpec isoSpec;
|
||||||
|
private NetworkSpec networkSpec;
|
||||||
|
|
||||||
|
public Builder vm(VmSpec vmSpec) {
|
||||||
|
this.vmSpec = vmSpec;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder network(NetworkSpec networkSpec) {
|
||||||
|
this.networkSpec = networkSpec;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder iso(IsoSpec isoSpec) {
|
||||||
|
this.isoSpec = isoSpec;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IMachineSpec build() {
|
||||||
|
return new IMachineSpec(vmSpec, isoSpec, networkSpec);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public IMachineSpec(VmSpec vmSpec, IsoSpec isoSpec, NetworkSpec networkSpec) {
|
||||||
|
checkNotNull(vmSpec, "vmSpec");
|
||||||
|
checkNotNull(isoSpec, "isoSpec");
|
||||||
|
checkNotNull(networkSpec, "networkSpec");
|
||||||
|
this.vmSpec = vmSpec;
|
||||||
|
this.isoSpec = isoSpec;
|
||||||
|
this.networkSpec = networkSpec;
|
||||||
|
}
|
||||||
|
|
||||||
|
public VmSpec getVmSpec() {
|
||||||
|
return vmSpec;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IsoSpec getIsoSpec() {
|
||||||
|
return isoSpec;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NetworkSpec getNetworkSpec() {
|
||||||
|
return networkSpec;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o instanceof VmSpec) {
|
||||||
|
IMachineSpec other = (IMachineSpec) o;
|
||||||
|
return Objects.equal(vmSpec, other.vmSpec) &&
|
||||||
|
Objects.equal(isoSpec, other.isoSpec) &&
|
||||||
|
Objects.equal(networkSpec, other.networkSpec);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hashCode(vmSpec,isoSpec,networkSpec);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "IMachineSpec{" +
|
||||||
|
"vmSpec=" + vmSpec +
|
||||||
|
", isoSpec=" + isoSpec +
|
||||||
|
", networkSpec=" + networkSpec +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,116 @@
|
||||||
|
/*
|
||||||
|
* 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.domain;
|
||||||
|
|
||||||
|
import com.google.common.base.Objects;
|
||||||
|
import com.google.common.base.Supplier;
|
||||||
|
import org.jclouds.virtualbox.Preconfiguration;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The information needed to create a machine from a .iso file.
|
||||||
|
*/
|
||||||
|
public class IsoSpec {
|
||||||
|
|
||||||
|
private final String installationKeySequence;
|
||||||
|
private final String sourcePath;
|
||||||
|
private final Supplier<URI> preConfigurationUri;
|
||||||
|
|
||||||
|
public IsoSpec(String sourcePath, String installationKeySequence, @Preconfiguration Supplier<URI> preConfigurationUri) {
|
||||||
|
checkNotNull(sourcePath, "sourcePath");
|
||||||
|
checkNotNull(installationKeySequence, "installationKeySequence");
|
||||||
|
checkNotNull(preConfigurationUri, "preConfigurationUri");
|
||||||
|
this.sourcePath = sourcePath;
|
||||||
|
this.installationKeySequence = installationKeySequence;
|
||||||
|
this.preConfigurationUri = preConfigurationUri;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Builder builder() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
|
||||||
|
private String installationSequence;
|
||||||
|
private Supplier<URI> preConfigurationUri;
|
||||||
|
private String sourcePath;
|
||||||
|
|
||||||
|
public Builder installationScript(String installationSequence) {
|
||||||
|
this.installationSequence = installationSequence;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder preConfiguration(Supplier<URI> preConfigurationUri) {
|
||||||
|
this.preConfigurationUri = preConfigurationUri;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder sourcePath(String sourcePath) {
|
||||||
|
this.sourcePath = sourcePath;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public IsoSpec build() {
|
||||||
|
return new IsoSpec(sourcePath, installationSequence, preConfigurationUri);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getInstallationKeySequence() {
|
||||||
|
return installationKeySequence;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Supplier<URI> getPreConfigurationUri() {
|
||||||
|
return preConfigurationUri;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSourcePath() {
|
||||||
|
return sourcePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o instanceof VmSpec) {
|
||||||
|
IsoSpec other = (IsoSpec) o;
|
||||||
|
return Objects.equal(sourcePath, other.sourcePath) &&
|
||||||
|
Objects.equal(installationKeySequence, other.installationKeySequence) &&
|
||||||
|
Objects.equal(preConfigurationUri, other.preConfigurationUri);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hashCode(sourcePath, installationKeySequence, preConfigurationUri);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "IsoSpec{" +
|
||||||
|
"sourcePath='" + sourcePath + '\'' +
|
||||||
|
"installationKeySequence='" + installationKeySequence + '\'' +
|
||||||
|
", preConfigurationUri=" + preConfigurationUri +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,87 @@
|
||||||
|
/*
|
||||||
|
* 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.domain;
|
||||||
|
|
||||||
|
import com.google.common.base.Objects;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Describes the network configuration for a VirtualBox machine.
|
||||||
|
*/
|
||||||
|
public class NetworkSpec {
|
||||||
|
|
||||||
|
private final Map<Long, NatAdapter> natNetworkAdapters;
|
||||||
|
|
||||||
|
public NetworkSpec(final Map<Long, NatAdapter> natNetworkAdapters) {
|
||||||
|
checkNotNull(natNetworkAdapters, "natNetworkAdapters");
|
||||||
|
this.natNetworkAdapters = natNetworkAdapters;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Builder builder() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
|
||||||
|
private Map<Long, NatAdapter> natNetworkAdapters = new HashMap<Long, NatAdapter>();
|
||||||
|
|
||||||
|
public Builder natNetworkAdapter(int slot, NatAdapter adapter) {
|
||||||
|
this.natNetworkAdapters.put((long) slot, adapter);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NetworkSpec build() {
|
||||||
|
return new NetworkSpec(natNetworkAdapters);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Map<Long, NatAdapter> getNatNetworkAdapters() {
|
||||||
|
return Collections.unmodifiableMap(natNetworkAdapters);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o instanceof VmSpec) {
|
||||||
|
NetworkSpec other = (NetworkSpec) o;
|
||||||
|
return Objects.equal(natNetworkAdapters, other.natNetworkAdapters);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hashCode(natNetworkAdapters);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "NetworkSpec{" +
|
||||||
|
"natNetworkAdapters=" + natNetworkAdapters +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,18 +18,13 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.virtualbox.domain;
|
package org.jclouds.virtualbox.domain;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
import com.google.common.base.Objects;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.virtualbox_4_1.CleanupMode;
|
import org.virtualbox_4_1.CleanupMode;
|
||||||
|
|
||||||
import com.google.common.base.Objects;
|
import java.util.*;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A description of a Virtual Machine in VirtualBox.
|
* A description of a Virtual Machine in VirtualBox.
|
||||||
|
@ -41,16 +36,14 @@ public class VmSpec {
|
||||||
private final String vmId;
|
private final String vmId;
|
||||||
private final long memory;
|
private final long memory;
|
||||||
private final boolean forceOverwrite;
|
private final boolean forceOverwrite;
|
||||||
private final Map<Long, NatAdapter> natNetworkAdapters;
|
|
||||||
private final Set<StorageController> controllers;
|
private final Set<StorageController> controllers;
|
||||||
private final CleanupMode cleanupMode;
|
private final CleanupMode cleanupMode;
|
||||||
|
|
||||||
public VmSpec(String vmId, String vmName, String osTypeId, long memory, boolean forceOverwrite, Set<StorageController> controllers, Map<Long, NatAdapter> natNetworkAdapters, CleanupMode cleanupMode) {
|
public VmSpec(String vmId, String vmName, String osTypeId, long memory, boolean forceOverwrite, Set<StorageController> controllers, CleanupMode cleanupMode) {
|
||||||
checkNotNull(vmId, "vmId");
|
checkNotNull(vmId, "vmId");
|
||||||
checkNotNull(vmName, "vmName");
|
checkNotNull(vmName, "vmName");
|
||||||
checkArgument(memory > 0, "memory must be > 0");
|
checkArgument(memory > 0, "memory must be > 0");
|
||||||
checkNotNull(controllers, "controllers");
|
checkNotNull(controllers, "controllers");
|
||||||
checkNotNull(natNetworkAdapters, "natNetworkAdapters");
|
|
||||||
checkNotNull(cleanupMode, "cleanupMode");
|
checkNotNull(cleanupMode, "cleanupMode");
|
||||||
this.vmId = vmId;
|
this.vmId = vmId;
|
||||||
this.vmName = vmName;
|
this.vmName = vmName;
|
||||||
|
@ -58,7 +51,6 @@ public class VmSpec {
|
||||||
this.memory = memory;
|
this.memory = memory;
|
||||||
this.controllers = controllers;
|
this.controllers = controllers;
|
||||||
this.forceOverwrite = forceOverwrite;
|
this.forceOverwrite = forceOverwrite;
|
||||||
this.natNetworkAdapters = natNetworkAdapters;
|
|
||||||
this.cleanupMode = cleanupMode;
|
this.cleanupMode = cleanupMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,10 +66,9 @@ public class VmSpec {
|
||||||
private String id;
|
private String id;
|
||||||
private String osTypeId = "";
|
private String osTypeId = "";
|
||||||
private boolean forceOverwrite;
|
private boolean forceOverwrite;
|
||||||
private Map<Long, NatAdapter> natNetworkAdapters = new HashMap<Long, NatAdapter>();
|
|
||||||
private long memory;
|
private long memory;
|
||||||
private CleanupMode cleanUpMode;
|
private CleanupMode cleanUpMode;
|
||||||
|
|
||||||
public Builder controller(StorageController controller) {
|
public Builder controller(StorageController controller) {
|
||||||
controllers.add(controller);
|
controllers.add(controller);
|
||||||
return this;
|
return this;
|
||||||
|
@ -103,30 +94,24 @@ public class VmSpec {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder natNetworkAdapter(int slot, NatAdapter adapter) {
|
|
||||||
this.natNetworkAdapters.put((long) slot, adapter);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder memoryMB(int memorySize) {
|
public Builder memoryMB(int memorySize) {
|
||||||
this.memory = (long) memorySize;
|
this.memory = (long) memorySize;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder cleanUpMode(CleanupMode cleanupMode) {
|
public Builder cleanUpMode(CleanupMode cleanupMode) {
|
||||||
this.cleanUpMode = cleanupMode;
|
this.cleanUpMode = cleanupMode;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public VmSpec build() {
|
public VmSpec build() {
|
||||||
checkNotNull(name, "name");
|
checkNotNull(name, "name");
|
||||||
checkNotNull(id, "id");
|
checkNotNull(id, "id");
|
||||||
checkArgument(memory > 0, "Memory must be set");
|
checkArgument(memory > 0, "Memory must be set");
|
||||||
return new VmSpec(id, name, osTypeId, memory, forceOverwrite, controllers, natNetworkAdapters, cleanUpMode);
|
return new VmSpec(id, name, osTypeId, memory, forceOverwrite, controllers, cleanUpMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getVmId() {
|
public String getVmId() {
|
||||||
return vmId;
|
return vmId;
|
||||||
}
|
}
|
||||||
|
@ -151,10 +136,6 @@ public class VmSpec {
|
||||||
return Collections.unmodifiableSet(controllers);
|
return Collections.unmodifiableSet(controllers);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Long, NatAdapter> getNatNetworkAdapters() {
|
|
||||||
return Collections.unmodifiableMap(natNetworkAdapters);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CleanupMode getCleanupMode() {
|
public CleanupMode getCleanupMode() {
|
||||||
return cleanupMode;
|
return cleanupMode;
|
||||||
}
|
}
|
||||||
|
@ -169,7 +150,6 @@ public class VmSpec {
|
||||||
Objects.equal(osTypeId, other.osTypeId) &&
|
Objects.equal(osTypeId, other.osTypeId) &&
|
||||||
Objects.equal(memory, other.memory) &&
|
Objects.equal(memory, other.memory) &&
|
||||||
Objects.equal(forceOverwrite, other.forceOverwrite) &&
|
Objects.equal(forceOverwrite, other.forceOverwrite) &&
|
||||||
Objects.equal(natNetworkAdapters, other.natNetworkAdapters) &&
|
|
||||||
Objects.equal(controllers, other.controllers) &&
|
Objects.equal(controllers, other.controllers) &&
|
||||||
Objects.equal(cleanupMode, other.cleanupMode);
|
Objects.equal(cleanupMode, other.cleanupMode);
|
||||||
}
|
}
|
||||||
|
@ -178,7 +158,7 @@ public class VmSpec {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hashCode(vmId, vmName, osTypeId, memory, forceOverwrite, natNetworkAdapters, controllers);
|
return Objects.hashCode(vmId, vmName, osTypeId, memory, forceOverwrite, controllers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -189,7 +169,6 @@ public class VmSpec {
|
||||||
", memory='" + memory + '\'' +
|
", memory='" + memory + '\'' +
|
||||||
", vmId='" + vmId + '\'' +
|
", vmId='" + vmId + '\'' +
|
||||||
", forceOverwrite=" + forceOverwrite +
|
", forceOverwrite=" + forceOverwrite +
|
||||||
", natNetworkAdapters=" + natNetworkAdapters +
|
|
||||||
", controllers=" + controllers +
|
", controllers=" + controllers +
|
||||||
", cleanupMode=" + cleanupMode +
|
", cleanupMode=" + cleanupMode +
|
||||||
'}';
|
'}';
|
||||||
|
|
|
@ -18,30 +18,20 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.virtualbox.functions;
|
package org.jclouds.virtualbox.functions;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
import com.google.common.base.Function;
|
||||||
import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot;
|
import com.google.common.base.Predicate;
|
||||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE;
|
import com.google.common.base.Supplier;
|
||||||
import static org.jclouds.virtualbox.util.MachineUtils.applyForMachine;
|
import com.google.inject.Inject;
|
||||||
import static org.jclouds.virtualbox.util.MachineUtils.lockSessionOnMachineAndApply;
|
|
||||||
import static org.virtualbox_4_1.LockType.Shared;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import javax.inject.Named;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import org.jclouds.compute.callables.RunScriptOnNode;
|
import org.jclouds.compute.callables.RunScriptOnNode;
|
||||||
import org.jclouds.compute.callables.RunScriptOnNode.Factory;
|
import org.jclouds.compute.callables.RunScriptOnNode.Factory;
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
import org.jclouds.compute.domain.NodeMetadata;
|
||||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||||
import org.jclouds.config.ValueOfConfigurationKeyOrNull;
|
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.scriptbuilder.domain.Statements;
|
import org.jclouds.scriptbuilder.domain.Statements;
|
||||||
import org.jclouds.ssh.SshClient;
|
import org.jclouds.ssh.SshClient;
|
||||||
import org.jclouds.virtualbox.Preconfiguration;
|
|
||||||
import org.jclouds.virtualbox.domain.ExecutionType;
|
import org.jclouds.virtualbox.domain.ExecutionType;
|
||||||
|
import org.jclouds.virtualbox.domain.IMachineSpec;
|
||||||
|
import org.jclouds.virtualbox.domain.IsoSpec;
|
||||||
import org.jclouds.virtualbox.domain.VmSpec;
|
import org.jclouds.virtualbox.domain.VmSpec;
|
||||||
import org.jclouds.virtualbox.settings.KeyboardScancodes;
|
import org.jclouds.virtualbox.settings.KeyboardScancodes;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_1.IMachine;
|
||||||
|
@ -49,16 +39,19 @@ import org.virtualbox_4_1.IProgress;
|
||||||
import org.virtualbox_4_1.ISession;
|
import org.virtualbox_4_1.ISession;
|
||||||
import org.virtualbox_4_1.VirtualBoxManager;
|
import org.virtualbox_4_1.VirtualBoxManager;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import javax.annotation.Resource;
|
||||||
import com.google.common.base.Predicate;
|
import javax.inject.Named;
|
||||||
import com.google.common.base.Splitter;
|
import javax.inject.Singleton;
|
||||||
import com.google.common.base.Supplier;
|
import java.net.URI;
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
import com.google.common.collect.Lists;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
import com.google.inject.Inject;
|
import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot;
|
||||||
|
import static org.jclouds.virtualbox.util.MachineUtils.applyForMachine;
|
||||||
|
import static org.jclouds.virtualbox.util.MachineUtils.lockSessionOnMachineAndApply;
|
||||||
|
import static org.virtualbox_4_1.LockType.Shared;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public class CreateAndInstallVm implements Function<VmSpec, IMachine> {
|
public class CreateAndInstallVm implements Function<IMachineSpec, IMachine> {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||||
|
@ -66,9 +59,7 @@ public class CreateAndInstallVm implements Function<VmSpec, IMachine> {
|
||||||
|
|
||||||
private final Supplier<VirtualBoxManager> manager;
|
private final Supplier<VirtualBoxManager> manager;
|
||||||
private final CreateAndRegisterMachineFromIsoIfNotAlreadyExists createAndRegisterMachineFromIsoIfNotAlreadyExists;
|
private final CreateAndRegisterMachineFromIsoIfNotAlreadyExists createAndRegisterMachineFromIsoIfNotAlreadyExists;
|
||||||
private final ValueOfConfigurationKeyOrNull valueOfConfigurationKeyOrNull;
|
|
||||||
|
|
||||||
private final Supplier<URI> preconfiguration;
|
|
||||||
private final Predicate<SshClient> sshResponds;
|
private final Predicate<SshClient> sshResponds;
|
||||||
private final ExecutionType executionType;
|
private final ExecutionType executionType;
|
||||||
|
|
||||||
|
@ -78,66 +69,53 @@ public class CreateAndInstallVm implements Function<VmSpec, IMachine> {
|
||||||
private final Function<IMachine, SshClient> sshClientForIMachine;
|
private final Function<IMachine, SshClient> sshClientForIMachine;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public CreateAndInstallVm(
|
public CreateAndInstallVm(Supplier<VirtualBoxManager> manager,
|
||||||
Supplier<VirtualBoxManager> manager,
|
CreateAndRegisterMachineFromIsoIfNotAlreadyExists CreateAndRegisterMachineFromIsoIfNotAlreadyExists,
|
||||||
CreateAndRegisterMachineFromIsoIfNotAlreadyExists CreateAndRegisterMachineFromIsoIfNotAlreadyExists,
|
Predicate<SshClient> sshResponds, Function<IMachine, SshClient> sshClientForIMachine,
|
||||||
ValueOfConfigurationKeyOrNull valueOfConfigurationKeyOrNull,
|
Supplier<NodeMetadata> host, RunScriptOnNode.Factory scriptRunner, ExecutionType executionType) {
|
||||||
Predicate<SshClient> sshResponds,
|
|
||||||
Function<IMachine, SshClient> sshClientForIMachine,
|
|
||||||
Supplier<NodeMetadata> host, RunScriptOnNode.Factory scriptRunner,
|
|
||||||
@Preconfiguration Supplier<URI> preconfiguration,
|
|
||||||
ExecutionType executionType) {
|
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
this.createAndRegisterMachineFromIsoIfNotAlreadyExists = CreateAndRegisterMachineFromIsoIfNotAlreadyExists;
|
this.createAndRegisterMachineFromIsoIfNotAlreadyExists = CreateAndRegisterMachineFromIsoIfNotAlreadyExists;
|
||||||
this.valueOfConfigurationKeyOrNull = valueOfConfigurationKeyOrNull;
|
|
||||||
this.sshResponds = sshResponds;
|
this.sshResponds = sshResponds;
|
||||||
this.sshClientForIMachine = sshClientForIMachine;
|
this.sshClientForIMachine = sshClientForIMachine;
|
||||||
this.scriptRunner = scriptRunner;
|
this.scriptRunner = scriptRunner;
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.preconfiguration = preconfiguration;
|
|
||||||
this.executionType = executionType;
|
this.executionType = executionType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IMachine apply(VmSpec vmSpec) {
|
public IMachine apply(IMachineSpec machineSpec) {
|
||||||
|
|
||||||
|
VmSpec vmSpec = machineSpec.getVmSpec();
|
||||||
|
IsoSpec isoSpec = machineSpec.getIsoSpec();
|
||||||
|
|
||||||
String vmName = vmSpec.getVmName();
|
String vmName = vmSpec.getVmName();
|
||||||
|
|
||||||
// note this may not be reachable, as this likely uses the 10.2.2 address
|
final IMachine vm = createAndRegisterMachineFromIsoIfNotAlreadyExists.apply(machineSpec);
|
||||||
URI preconfigurationUri = preconfiguration.get();
|
|
||||||
String keySequence = valueOfConfigurationKeyOrNull
|
|
||||||
.apply(VIRTUALBOX_INSTALLATION_KEY_SEQUENCE)
|
|
||||||
.replace("PRECONFIGURATION_URL",
|
|
||||||
preconfigurationUri.toASCIIString())
|
|
||||||
.replace("HOSTNAME", vmName);
|
|
||||||
|
|
||||||
final IMachine vm = createAndRegisterMachineFromIsoIfNotAlreadyExists
|
|
||||||
.apply(vmSpec);
|
|
||||||
|
|
||||||
// Launch machine and wait for it to come online
|
// Launch machine and wait for it to come online
|
||||||
ensureMachineIsLaunched(vmName);
|
ensureMachineIsLaunched(vmName);
|
||||||
|
|
||||||
sendKeyboardSequence(keySequence, vmName);
|
URI uri = isoSpec.getPreConfigurationUri().get();
|
||||||
|
String installationKeySequence = isoSpec.getInstallationKeySequence()
|
||||||
|
.replace("PRECONFIGURATION_URL", uri.toASCIIString());
|
||||||
|
sendKeyboardSequence(installationKeySequence, vmName);
|
||||||
|
|
||||||
SshClient client = sshClientForIMachine.apply(vm);
|
SshClient client = sshClientForIMachine.apply(vm);
|
||||||
|
|
||||||
logger.debug(">> awaiting installation to finish node(%s)", vmName);
|
logger.debug(">> awaiting installation to finish node(%s)", vmName);
|
||||||
checkState(sshResponds.apply(client),
|
checkState(sshResponds.apply(client), "timed out waiting for guest %s to be accessible via ssh", vmName);
|
||||||
"timed out waiting for guest %s to be accessible via ssh", vmName);
|
|
||||||
|
|
||||||
logger.debug("<< installation of image complete. Powering down node(%s)",
|
logger.debug("<< installation of image complete. Powering down node(%s)", vmName);
|
||||||
vmName);
|
lockSessionOnMachineAndApply(manager.get(), Shared, vmName, new Function<ISession, Void>() {
|
||||||
lockSessionOnMachineAndApply(manager.get(), Shared, vmName,
|
|
||||||
new Function<ISession, Void>() {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Void apply(ISession session) {
|
public Void apply(ISession session) {
|
||||||
IProgress powerDownProgress = session.getConsole()
|
IProgress powerDownProgress = session.getConsole().powerDown();
|
||||||
.powerDown();
|
powerDownProgress.waitForCompletion(-1);
|
||||||
powerDownProgress.waitForCompletion(-1);
|
return null;
|
||||||
return null;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
return vm;
|
return vm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,12 +36,7 @@ import javax.inject.Singleton;
|
||||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.virtualbox.config.VirtualBoxConstants;
|
import org.jclouds.virtualbox.config.VirtualBoxConstants;
|
||||||
import org.jclouds.virtualbox.domain.DeviceDetails;
|
import org.jclouds.virtualbox.domain.*;
|
||||||
import org.jclouds.virtualbox.domain.HardDisk;
|
|
||||||
import org.jclouds.virtualbox.domain.IsoImage;
|
|
||||||
import org.jclouds.virtualbox.domain.NatAdapter;
|
|
||||||
import org.jclouds.virtualbox.domain.StorageController;
|
|
||||||
import org.jclouds.virtualbox.domain.VmSpec;
|
|
||||||
import org.virtualbox_4_1.AccessMode;
|
import org.virtualbox_4_1.AccessMode;
|
||||||
import org.virtualbox_4_1.DeviceType;
|
import org.virtualbox_4_1.DeviceType;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_1.IMachine;
|
||||||
|
@ -57,7 +52,7 @@ import com.google.common.base.Supplier;
|
||||||
* @author Mattias Holmqvist
|
* @author Mattias Holmqvist
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class CreateAndRegisterMachineFromIsoIfNotAlreadyExists implements Function<VmSpec, IMachine> {
|
public class CreateAndRegisterMachineFromIsoIfNotAlreadyExists implements Function<IMachineSpec, IMachine> {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||||
|
@ -74,9 +69,9 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExists implements Functi
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IMachine apply(@Nullable VmSpec launchSpecification) {
|
public IMachine apply(@Nullable IMachineSpec launchSpecification) {
|
||||||
final IVirtualBox vBox = manager.get().getVBox();
|
final IVirtualBox vBox = manager.get().getVBox();
|
||||||
String vmName = launchSpecification.getVmName();
|
String vmName = launchSpecification.getVmSpec().getVmName();
|
||||||
try {
|
try {
|
||||||
vBox.findMachine(vmName);
|
vBox.findMachine(vmName);
|
||||||
throw new IllegalStateException("Machine " + vmName + " is already registered.");
|
throw new IllegalStateException("Machine " + vmName + " is already registered.");
|
||||||
|
@ -92,17 +87,20 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExists implements Functi
|
||||||
return e.getMessage().contains("VirtualBox error: Could not find a registered machine named ");
|
return e.getMessage().contains("VirtualBox error: Could not find a registered machine named ");
|
||||||
}
|
}
|
||||||
|
|
||||||
private IMachine createMachine(IVirtualBox vBox, VmSpec vmSpec) {
|
private IMachine createMachine(IVirtualBox vBox, IMachineSpec machineSpec) {
|
||||||
|
VmSpec vmSpec = machineSpec.getVmSpec();
|
||||||
String settingsFile = vBox.composeMachineFilename(vmSpec.getVmName(), workingDir);
|
String settingsFile = vBox.composeMachineFilename(vmSpec.getVmName(), workingDir);
|
||||||
|
|
||||||
IMachine newMachine = vBox.createMachine(settingsFile, vmSpec.getVmName(), vmSpec.getOsTypeId(),
|
IMachine newMachine = vBox.createMachine(settingsFile, vmSpec.getVmName(), vmSpec.getOsTypeId(),
|
||||||
vmSpec.getVmId(), vmSpec.isForceOverwrite());
|
vmSpec.getVmId(), vmSpec.isForceOverwrite());
|
||||||
manager.get().getVBox().registerMachine(newMachine);
|
manager.get().getVBox().registerMachine(newMachine);
|
||||||
ensureConfiguration(vmSpec);
|
ensureConfiguration(machineSpec);
|
||||||
return newMachine;
|
return newMachine;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ensureConfiguration(VmSpec vmSpec) {
|
private void ensureConfiguration(IMachineSpec machineSpec) {
|
||||||
|
VmSpec vmSpec = machineSpec.getVmSpec();
|
||||||
|
NetworkSpec networkSpec = machineSpec.getNetworkSpec();
|
||||||
String vmName = vmSpec.getVmName();
|
String vmName = vmSpec.getVmName();
|
||||||
|
|
||||||
// Change RAM
|
// Change RAM
|
||||||
|
@ -118,7 +116,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExists implements Functi
|
||||||
setupDvdsForController(vmSpec, vmName, controller);
|
setupDvdsForController(vmSpec, vmName, controller);
|
||||||
|
|
||||||
// NAT
|
// NAT
|
||||||
Map<Long, NatAdapter> natNetworkAdapters = vmSpec.getNatNetworkAdapters();
|
Map<Long, NatAdapter> natNetworkAdapters = networkSpec.getNatNetworkAdapters();
|
||||||
for (Map.Entry<Long, NatAdapter> natAdapterAndSlot : natNetworkAdapters.entrySet()) {
|
for (Map.Entry<Long, NatAdapter> natAdapterAndSlot : natNetworkAdapters.entrySet()) {
|
||||||
long slotId = natAdapterAndSlot.getKey();
|
long slotId = natAdapterAndSlot.getKey();
|
||||||
NatAdapter natAdapter = natAdapterAndSlot.getValue();
|
NatAdapter natAdapter = natAdapterAndSlot.getValue();
|
||||||
|
|
|
@ -70,9 +70,6 @@ public class VmSpecTest {
|
||||||
.osTypeId("Ubuntu")
|
.osTypeId("Ubuntu")
|
||||||
.memoryMB(1024)
|
.memoryMB(1024)
|
||||||
.cleanUpMode(CleanupMode.Full)
|
.cleanUpMode(CleanupMode.Full)
|
||||||
.natNetworkAdapter(
|
|
||||||
0,
|
|
||||||
NatAdapter.builder().tcpRedirectRule("localhost", 2222, "", 22).build())
|
|
||||||
.forceOverwrite(true)
|
.forceOverwrite(true)
|
||||||
.controller(
|
.controller(
|
||||||
StorageController.builder().name("Controller")
|
StorageController.builder().name("Controller")
|
||||||
|
|
|
@ -22,10 +22,9 @@ package org.jclouds.virtualbox.functions;
|
||||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX;
|
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
import com.google.inject.Injector;
|
||||||
import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
|
import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
|
||||||
import org.jclouds.virtualbox.domain.HardDisk;
|
import org.jclouds.virtualbox.domain.*;
|
||||||
import org.jclouds.virtualbox.domain.StorageController;
|
|
||||||
import org.jclouds.virtualbox.domain.VmSpec;
|
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.CleanupMode;
|
import org.virtualbox_4_1.CleanupMode;
|
||||||
|
@ -45,7 +44,8 @@ public class CloneAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends Ba
|
||||||
private static final boolean IS_LINKED_CLONE = true;
|
private static final boolean IS_LINKED_CLONE = true;
|
||||||
|
|
||||||
private VmSpec clonedVmSpec;
|
private VmSpec clonedVmSpec;
|
||||||
private VmSpec sourceVmSpec;
|
private IMachineSpec sourceMachineSpec;
|
||||||
|
|
||||||
|
|
||||||
private CleanupMode mode = CleanupMode.Full;
|
private CleanupMode mode = CleanupMode.Full;
|
||||||
|
|
||||||
|
@ -53,22 +53,25 @@ public class CloneAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends Ba
|
||||||
@BeforeClass(groups = "live")
|
@BeforeClass(groups = "live")
|
||||||
public void setupClient() {
|
public void setupClient() {
|
||||||
super.setupClient();
|
super.setupClient();
|
||||||
String sourceName = VIRTUALBOX_IMAGE_PREFIX
|
String sourceName = VIRTUALBOX_IMAGE_PREFIX
|
||||||
+ CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, getClass().getSimpleName());
|
+ CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, getClass().getSimpleName());
|
||||||
String cloneName = VIRTUALBOX_IMAGE_PREFIX
|
String cloneName = VIRTUALBOX_IMAGE_PREFIX
|
||||||
+ "Clone#" + CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, getClass().getSimpleName()
|
+ "Clone#" + CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, getClass().getSimpleName()
|
||||||
);
|
);
|
||||||
|
|
||||||
StorageController ideController = StorageController.builder().name("IDE Controller").bus(StorageBus.IDE)
|
StorageController ideController = StorageController.builder().name("IDE Controller").bus(StorageBus.IDE)
|
||||||
.attachISO(0, 0, operatingSystemIso).attachHardDisk(
|
.attachISO(0, 0, operatingSystemIso).attachHardDisk(
|
||||||
HardDisk.builder().diskpath(adminDisk).controllerPort(0).deviceSlot(1).autoDelete(true).build()).attachISO(1, 1,
|
HardDisk.builder().diskpath(adminDisk).controllerPort(0).deviceSlot(1).autoDelete(true).build()).attachISO(1, 1,
|
||||||
guestAdditionsIso).build();
|
guestAdditionsIso).build();
|
||||||
|
|
||||||
sourceVmSpec = VmSpec.builder().id(sourceName).name(sourceName).osTypeId("").memoryMB(512).cleanUpMode(
|
VmSpec sourceVmSpec = VmSpec.builder().id(sourceName).name(sourceName).osTypeId("").memoryMB(512).cleanUpMode(
|
||||||
CleanupMode.Full).controller(ideController).forceOverwrite(true).build();
|
CleanupMode.Full).controller(ideController).forceOverwrite(true).build();
|
||||||
|
IsoSpec isoSpec = IsoSpec.builder().build();
|
||||||
|
NetworkSpec networkSpec = NetworkSpec.builder().build();
|
||||||
|
sourceMachineSpec = IMachineSpec.builder().iso(isoSpec).vm(sourceVmSpec).network(networkSpec).build();
|
||||||
|
|
||||||
clonedVmSpec = VmSpec.builder().id(cloneName).name(cloneName).memoryMB(512).cleanUpMode(mode)
|
clonedVmSpec = VmSpec.builder().id(cloneName).name(cloneName).memoryMB(512).cleanUpMode(mode)
|
||||||
.forceOverwrite(true).build();
|
.forceOverwrite(true).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -83,10 +86,10 @@ public class CloneAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends Ba
|
||||||
}
|
}
|
||||||
|
|
||||||
IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(manager, workingDir, clonedVmSpec,
|
IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(manager, workingDir, clonedVmSpec,
|
||||||
IS_LINKED_CLONE).apply(source);
|
IS_LINKED_CLONE).apply(source);
|
||||||
assertEquals(clone.getName(), clonedVmSpec.getVmName());
|
assertEquals(clone.getName(), clonedVmSpec.getVmName());
|
||||||
} finally {
|
} finally {
|
||||||
for (VmSpec spec : ImmutableSet.of(clonedVmSpec, sourceVmSpec))
|
for (VmSpec spec : ImmutableSet.of(clonedVmSpec, sourceMachineSpec.getVmSpec()))
|
||||||
undoVm(spec);
|
undoVm(spec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,11 +97,12 @@ public class CloneAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends Ba
|
||||||
|
|
||||||
private IMachine getSourceNode() {
|
private IMachine getSourceNode() {
|
||||||
try {
|
try {
|
||||||
return context.utils().injector().getInstance(CreateAndRegisterMachineFromIsoIfNotAlreadyExists.class).apply(
|
Injector injector = context.utils().injector();
|
||||||
sourceVmSpec);
|
return injector.getInstance(CreateAndRegisterMachineFromIsoIfNotAlreadyExists.class).apply(
|
||||||
|
sourceMachineSpec);
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
// already created
|
// already created
|
||||||
return manager.get().getVBox().findMachine(sourceVmSpec.getVmId());
|
return manager.get().getVBox().findMachine(sourceMachineSpec.getVmSpec().getVmId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -19,28 +19,19 @@
|
||||||
|
|
||||||
package org.jclouds.virtualbox.functions;
|
package org.jclouds.virtualbox.functions;
|
||||||
|
|
||||||
import static com.google.common.base.Predicates.equalTo;
|
import com.google.common.base.CaseFormat;
|
||||||
import static com.google.common.collect.Iterables.any;
|
import com.google.common.base.Function;
|
||||||
import static com.google.common.collect.Iterables.transform;
|
import com.google.inject.Guice;
|
||||||
import static org.testng.Assert.assertTrue;
|
import com.google.inject.Injector;
|
||||||
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
import org.jclouds.compute.config.BaseComputeServiceContextModule;
|
import org.jclouds.compute.config.BaseComputeServiceContextModule;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
import org.jclouds.compute.domain.OsFamily;
|
import org.jclouds.compute.domain.OsFamily;
|
||||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||||
|
import org.jclouds.config.ValueOfConfigurationKeyOrNull;
|
||||||
import org.jclouds.json.Json;
|
import org.jclouds.json.Json;
|
||||||
import org.jclouds.json.config.GsonModule;
|
import org.jclouds.json.config.GsonModule;
|
||||||
import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
|
import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
|
||||||
import org.jclouds.virtualbox.domain.HardDisk;
|
import org.jclouds.virtualbox.domain.*;
|
||||||
import org.jclouds.virtualbox.domain.NatAdapter;
|
|
||||||
import org.jclouds.virtualbox.domain.StorageController;
|
|
||||||
import org.jclouds.virtualbox.domain.VmSpec;
|
|
||||||
import org.testng.annotations.AfterClass;
|
import org.testng.annotations.AfterClass;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
@ -48,9 +39,16 @@ import org.virtualbox_4_1.CleanupMode;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_1.IMachine;
|
||||||
import org.virtualbox_4_1.StorageBus;
|
import org.virtualbox_4_1.StorageBus;
|
||||||
|
|
||||||
import com.google.common.base.CaseFormat;
|
import javax.annotation.Nullable;
|
||||||
import com.google.common.base.Function;
|
import java.util.Map;
|
||||||
import com.google.inject.Guice;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static com.google.common.base.Predicates.equalTo;
|
||||||
|
import static com.google.common.collect.Iterables.any;
|
||||||
|
import static com.google.common.collect.Iterables.transform;
|
||||||
|
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.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Andrea Turli, Mattias Holmqvist
|
* @author Andrea Turli, Mattias Holmqvist
|
||||||
|
@ -68,11 +66,11 @@ public class CreateAndInstallVmLiveTest extends BaseVirtualBoxClientLiveTest {
|
||||||
@BeforeClass(groups = "live")
|
@BeforeClass(groups = "live")
|
||||||
public void setupClient() {
|
public void setupClient() {
|
||||||
super.setupClient();
|
super.setupClient();
|
||||||
String vmName = VIRTUALBOX_IMAGE_PREFIX
|
String vmName = VIRTUALBOX_IMAGE_PREFIX
|
||||||
+ CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, getClass().getSimpleName());
|
+ CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, getClass().getSimpleName());
|
||||||
|
|
||||||
HardDisk hardDisk = HardDisk.builder().diskpath(adminDisk).autoDelete(true)
|
HardDisk hardDisk = HardDisk.builder().diskpath(adminDisk).autoDelete(true)
|
||||||
.controllerPort(0).deviceSlot(1).build();
|
.controllerPort(0).deviceSlot(1).build();
|
||||||
StorageController ideController = StorageController.builder().name("IDE Controller").bus(StorageBus.IDE)
|
StorageController ideController = StorageController.builder().name("IDE Controller").bus(StorageBus.IDE)
|
||||||
.attachISO(0, 0, operatingSystemIso)
|
.attachISO(0, 0, operatingSystemIso)
|
||||||
.attachHardDisk(hardDisk)
|
.attachHardDisk(hardDisk)
|
||||||
|
@ -80,14 +78,26 @@ public class CreateAndInstallVmLiveTest extends BaseVirtualBoxClientLiveTest {
|
||||||
vmSpecification = VmSpec.builder().id("jclouds-image-iso-1").name(vmName).memoryMB(512).osTypeId("")
|
vmSpecification = VmSpec.builder().id("jclouds-image-iso-1").name(vmName).memoryMB(512).osTypeId("")
|
||||||
.controller(ideController)
|
.controller(ideController)
|
||||||
.forceOverwrite(true)
|
.forceOverwrite(true)
|
||||||
.cleanUpMode(CleanupMode.Full)
|
.cleanUpMode(CleanupMode.Full).build();
|
||||||
.natNetworkAdapter(0, NatAdapter.builder().tcpRedirectRule("127.0.0.1", 2222, "", 22).build()).build();
|
|
||||||
undoVm(vmSpecification);
|
undoVm(vmSpecification);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCreateImageMachineFromIso() throws Exception {
|
public void testCreateImageMachineFromIso() throws Exception {
|
||||||
|
Injector injector = context.utils().injector();
|
||||||
|
Function<String, String> configProperties = injector.getInstance(ValueOfConfigurationKeyOrNull.class);
|
||||||
|
|
||||||
IMachine imageMachine = context.utils().injector().getInstance(CreateAndInstallVm.class).apply(vmSpecification);
|
IMachineSpec machineSpec = IMachineSpec.builder().vm(vmSpecification)
|
||||||
|
.iso(IsoSpec.builder()
|
||||||
|
.sourcePath(operatingSystemIso)
|
||||||
|
.installationScript(configProperties
|
||||||
|
.apply(VIRTUALBOX_INSTALLATION_KEY_SEQUENCE)
|
||||||
|
.replace("HOSTNAME", vmSpecification.getVmName()))
|
||||||
|
.preConfiguration(preconfigurationUri)
|
||||||
|
.build())
|
||||||
|
.network(NetworkSpec.builder()
|
||||||
|
.natNetworkAdapter(0, NatAdapter.builder().tcpRedirectRule("127.0.0.1", 2222, "", 22).build())
|
||||||
|
.build()).build();
|
||||||
|
IMachine imageMachine = injector.getInstance(CreateAndInstallVm.class).apply(machineSpec);
|
||||||
|
|
||||||
IMachineToImage iMachineToImage = new IMachineToImage(manager, map);
|
IMachineToImage iMachineToImage = new IMachineToImage(manager, map);
|
||||||
Image newImage = iMachineToImage.apply(imageMachine);
|
Image newImage = iMachineToImage.apply(imageMachine);
|
||||||
|
@ -107,6 +117,7 @@ public class CreateAndInstallVmLiveTest extends BaseVirtualBoxClientLiveTest {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@AfterClass(groups = "live")
|
@AfterClass(groups = "live")
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
|
|
|
@ -21,11 +21,9 @@ package org.jclouds.virtualbox.functions;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
import static org.testng.Assert.fail;
|
import static org.testng.Assert.fail;
|
||||||
|
|
||||||
|
import com.google.inject.Injector;
|
||||||
import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
|
import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
|
||||||
import org.jclouds.virtualbox.domain.ErrorCode;
|
import org.jclouds.virtualbox.domain.*;
|
||||||
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.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.CleanupMode;
|
import org.virtualbox_4_1.CleanupMode;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_1.IMachine;
|
||||||
|
@ -47,38 +45,62 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends B
|
||||||
super.setupClient();
|
super.setupClient();
|
||||||
ideControllerName = "IDE Controller";
|
ideControllerName = "IDE Controller";
|
||||||
mode = CleanupMode.Full;
|
mode = CleanupMode.Full;
|
||||||
ideController = StorageController.builder().name(ideControllerName).bus(StorageBus.IDE).attachISO(0, 0,
|
ideController = StorageController.builder().name(ideControllerName).bus(StorageBus.IDE)
|
||||||
operatingSystemIso).attachHardDisk(
|
.attachISO(0, 0, operatingSystemIso)
|
||||||
HardDisk.builder().diskpath(adminDisk).controllerPort(0).deviceSlot(1).build()).attachISO(1, 1,
|
.attachHardDisk(HardDisk.builder().diskpath(adminDisk).controllerPort(0).deviceSlot(1).build()).attachISO(1, 1,
|
||||||
guestAdditionsIso).build();
|
guestAdditionsIso).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateNewMachine() throws Exception {
|
public void testCreateNewMachine() throws Exception {
|
||||||
String vmName = "jclouds-test-create-1-node";
|
String vmName = "jclouds-test-create-1-node";
|
||||||
VmSpec launchSpecification = VmSpec.builder().id(vmName).name(vmName).memoryMB(512).controller(ideController)
|
VmSpec vmSpec = VmSpec.builder()
|
||||||
.cleanUpMode(mode).osTypeId("Debian").forceOverwrite(true).build();
|
.id(vmName)
|
||||||
undoVm(launchSpecification);
|
.name(vmName)
|
||||||
|
.memoryMB(512)
|
||||||
|
.controller(ideController)
|
||||||
|
.cleanUpMode(mode)
|
||||||
|
.osTypeId("Debian")
|
||||||
|
.forceOverwrite(true).build();
|
||||||
|
IMachineSpec machineSpec = IMachineSpec.builder()
|
||||||
|
.iso(IsoSpec.builder()
|
||||||
|
.sourcePath(operatingSystemIso)
|
||||||
|
.installationScript("")
|
||||||
|
.preConfiguration(preconfigurationUri)
|
||||||
|
.build())
|
||||||
|
.vm(vmSpec)
|
||||||
|
.network(NetworkSpec.builder().build()).build();
|
||||||
|
undoVm(vmSpec);
|
||||||
try {
|
try {
|
||||||
IMachine debianNode = context.utils().injector().getInstance(
|
IMachine debianNode = context.utils().injector().getInstance(
|
||||||
CreateAndRegisterMachineFromIsoIfNotAlreadyExists.class).apply(launchSpecification);
|
CreateAndRegisterMachineFromIsoIfNotAlreadyExists.class).apply(machineSpec);
|
||||||
IMachine machine = manager.get().getVBox().findMachine(vmName);
|
IMachine machine = manager.get().getVBox().findMachine(vmName);
|
||||||
assertEquals(debianNode.getName(), machine.getName());
|
assertEquals(debianNode.getName(), machine.getName());
|
||||||
} finally {
|
} finally {
|
||||||
undoVm(launchSpecification);
|
undoVm(vmSpec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateNewMachineWithBadOsType() throws Exception {
|
public void testCreateNewMachineWithBadOsType() throws Exception {
|
||||||
String vmName = "jclouds-test-create-2-node";
|
String vmName = "jclouds-test-create-2-node";
|
||||||
VmSpec launchSpecification = VmSpec.builder().id(vmName).name(vmName).memoryMB(512).controller(ideController)
|
VmSpec vmSpec = VmSpec.builder().id(vmName).name(vmName).memoryMB(512).controller(ideController)
|
||||||
.cleanUpMode(mode).osTypeId("SomeWeirdUnknownOs").forceOverwrite(true).build();
|
.cleanUpMode(mode).osTypeId("SomeWeirdUnknownOs").forceOverwrite(true).build();
|
||||||
|
IsoSpec isoSpec = IsoSpec.builder()
|
||||||
undoVm(launchSpecification);
|
.sourcePath(operatingSystemIso)
|
||||||
|
.installationScript("")
|
||||||
|
.preConfiguration(preconfigurationUri)
|
||||||
|
.build();
|
||||||
|
NetworkSpec networkSpec = NetworkSpec.builder().build();
|
||||||
|
IMachineSpec machineSpec = IMachineSpec.builder()
|
||||||
|
.iso(isoSpec)
|
||||||
|
.vm(vmSpec)
|
||||||
|
.network(networkSpec).build();
|
||||||
|
undoVm(vmSpec);
|
||||||
try {
|
try {
|
||||||
context.utils().injector().getInstance(CreateAndRegisterMachineFromIsoIfNotAlreadyExists.class).apply(
|
Injector injector = context.utils().injector();
|
||||||
launchSpecification);
|
injector.getInstance(CreateAndRegisterMachineFromIsoIfNotAlreadyExists.class)
|
||||||
|
.apply(machineSpec);
|
||||||
fail();
|
fail();
|
||||||
} catch (VBoxException e) {
|
} catch (VBoxException e) {
|
||||||
ErrorCode errorCode = ErrorCode.valueOf(e);
|
ErrorCode errorCode = ErrorCode.valueOf(e);
|
||||||
|
@ -86,7 +108,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends B
|
||||||
// if osTypeId is not found.
|
// if osTypeId is not found.
|
||||||
assertEquals(errorCode, ErrorCode.VBOX_E_OBJECT_NOT_FOUND);
|
assertEquals(errorCode, ErrorCode.VBOX_E_OBJECT_NOT_FOUND);
|
||||||
} finally {
|
} finally {
|
||||||
undoVm(launchSpecification);
|
undoVm(vmSpec);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,14 @@ import static org.easymock.classextension.EasyMock.createNiceMock;
|
||||||
import static org.easymock.classextension.EasyMock.replay;
|
import static org.easymock.classextension.EasyMock.replay;
|
||||||
import static org.easymock.classextension.EasyMock.verify;
|
import static org.easymock.classextension.EasyMock.verify;
|
||||||
|
|
||||||
|
import com.google.common.base.Supplier;
|
||||||
|
import com.google.inject.Key;
|
||||||
|
import com.google.inject.TypeLiteral;
|
||||||
import org.easymock.EasyMock;
|
import org.easymock.EasyMock;
|
||||||
|
import org.jclouds.virtualbox.Preconfiguration;
|
||||||
|
import org.jclouds.virtualbox.domain.IMachineSpec;
|
||||||
|
import org.jclouds.virtualbox.domain.IsoSpec;
|
||||||
|
import org.jclouds.virtualbox.domain.NetworkSpec;
|
||||||
import org.jclouds.virtualbox.domain.VmSpec;
|
import org.jclouds.virtualbox.domain.VmSpec;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.CleanupMode;
|
import org.virtualbox_4_1.CleanupMode;
|
||||||
|
@ -40,6 +47,8 @@ import org.virtualbox_4_1.VirtualBoxManager;
|
||||||
|
|
||||||
import com.google.common.base.Suppliers;
|
import com.google.common.base.Suppliers;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mattias Holmqvist
|
* @author Mattias Holmqvist
|
||||||
*/
|
*/
|
||||||
|
@ -51,11 +60,14 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
||||||
|
|
||||||
VirtualBoxManager manager = createMock(VirtualBoxManager.class);
|
VirtualBoxManager manager = createMock(VirtualBoxManager.class);
|
||||||
IVirtualBox vBox = createMock(IVirtualBox.class);
|
IVirtualBox vBox = createMock(IVirtualBox.class);
|
||||||
|
Supplier<URI> preconfiguration = createNiceMock(Supplier.class);
|
||||||
String vmName = "jclouds-image-my-ubuntu-image";
|
String vmName = "jclouds-image-my-ubuntu-image";
|
||||||
|
VmSpec vmSpec = VmSpec.builder().id(vmName).name(vmName).osTypeId("").memoryMB(1024).cleanUpMode(
|
||||||
VmSpec launchSpecification = VmSpec.builder().id(vmName).name(vmName).osTypeId("").memoryMB(1024).cleanUpMode(
|
CleanupMode.Full).build();
|
||||||
CleanupMode.Full).build();
|
IMachineSpec machineSpec = IMachineSpec.builder()
|
||||||
|
.iso(IsoSpec.builder().sourcePath("some.iso").installationScript("").preConfiguration(preconfiguration).build())
|
||||||
|
.vm(vmSpec)
|
||||||
|
.network(NetworkSpec.builder().build()).build();
|
||||||
IMachine createdMachine = createMock(IMachine.class);
|
IMachine createdMachine = createMock(IMachine.class);
|
||||||
ISession session = createMock(ISession.class);
|
ISession session = createMock(ISession.class);
|
||||||
|
|
||||||
|
@ -71,9 +83,9 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
||||||
expect(vBox.findMachine(vmName)).andThrow(vBoxException);
|
expect(vBox.findMachine(vmName)).andThrow(vBoxException);
|
||||||
|
|
||||||
expect(vBox.createMachine(anyString(), eq(vmName), anyString(), anyString(), anyBoolean())).andReturn(
|
expect(vBox.createMachine(anyString(), eq(vmName), anyString(), anyString(), anyBoolean())).andReturn(
|
||||||
createdMachine).anyTimes();
|
createdMachine).anyTimes();
|
||||||
vBox.registerMachine(createdMachine);
|
vBox.registerMachine(createdMachine);
|
||||||
|
|
||||||
expect(vBox.findMachine(vmName)).andReturn(createdMachine).anyTimes();
|
expect(vBox.findMachine(vmName)).andReturn(createdMachine).anyTimes();
|
||||||
expect(manager.getSessionObject()).andReturn(session);
|
expect(manager.getSessionObject()).andReturn(session);
|
||||||
expect(session.getMachine()).andReturn(createdMachine);
|
expect(session.getMachine()).andReturn(createdMachine);
|
||||||
|
@ -81,13 +93,13 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
||||||
createdMachine.setMemorySize(1024l);
|
createdMachine.setMemorySize(1024l);
|
||||||
createdMachine.saveSettings();
|
createdMachine.saveSettings();
|
||||||
session.unlockMachine();
|
session.unlockMachine();
|
||||||
|
|
||||||
|
|
||||||
//TODO: this mock test is not finished.
|
//TODO: this mock test is not finished.
|
||||||
|
|
||||||
replay(manager, createdMachine, vBox, session);
|
replay(manager, createdMachine, vBox, session);
|
||||||
|
|
||||||
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(Suppliers.ofInstance(manager), "/tmp/workingDir").apply(launchSpecification);
|
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(Suppliers.ofInstance(manager), "/tmp/workingDir").apply(machineSpec);
|
||||||
|
|
||||||
verify(manager, createdMachine, vBox, session);
|
verify(manager, createdMachine, vBox, session);
|
||||||
}
|
}
|
||||||
|
@ -97,6 +109,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
||||||
|
|
||||||
VirtualBoxManager manager = createNiceMock(VirtualBoxManager.class);
|
VirtualBoxManager manager = createNiceMock(VirtualBoxManager.class);
|
||||||
IVirtualBox vBox = createNiceMock(IVirtualBox.class);
|
IVirtualBox vBox = createNiceMock(IVirtualBox.class);
|
||||||
|
Supplier<URI> preconfiguration = createNiceMock(Supplier.class);
|
||||||
String vmName = "jclouds-image-my-ubuntu-image";
|
String vmName = "jclouds-image-my-ubuntu-image";
|
||||||
|
|
||||||
IMachine registeredMachine = createMock(IMachine.class);
|
IMachine registeredMachine = createMock(IMachine.class);
|
||||||
|
@ -107,8 +120,16 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
||||||
replay(manager, vBox);
|
replay(manager, vBox);
|
||||||
|
|
||||||
VmSpec launchSpecification = VmSpec.builder().id("").name(vmName).osTypeId("").memoryMB(1024).cleanUpMode(
|
VmSpec launchSpecification = VmSpec.builder().id("").name(vmName).osTypeId("").memoryMB(1024).cleanUpMode(
|
||||||
CleanupMode.Full).build();
|
CleanupMode.Full).build();
|
||||||
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(Suppliers.ofInstance(manager), "/tmp/workingDir").apply(launchSpecification);
|
|
||||||
|
IMachineSpec machineSpec = IMachineSpec.builder()
|
||||||
|
.iso(IsoSpec.builder()
|
||||||
|
.sourcePath("some.iso")
|
||||||
|
.installationScript("dostuff")
|
||||||
|
.preConfiguration(preconfiguration).build())
|
||||||
|
.vm(launchSpecification)
|
||||||
|
.network(NetworkSpec.builder().build()).build();
|
||||||
|
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(Suppliers.ofInstance(manager), "/tmp/workingDir").apply(machineSpec);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = VBoxException.class)
|
@Test(expectedExceptions = VBoxException.class)
|
||||||
|
@ -116,6 +137,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
||||||
|
|
||||||
VirtualBoxManager manager = createNiceMock(VirtualBoxManager.class);
|
VirtualBoxManager manager = createNiceMock(VirtualBoxManager.class);
|
||||||
IVirtualBox vBox = createNiceMock(IVirtualBox.class);
|
IVirtualBox vBox = createNiceMock(IVirtualBox.class);
|
||||||
|
Supplier<URI> preconfiguration = createNiceMock(Supplier.class);
|
||||||
String vmName = "jclouds-image-my-ubuntu-image";
|
String vmName = "jclouds-image-my-ubuntu-image";
|
||||||
|
|
||||||
String errorMessage = "VirtualBox error: Soem other VBox error";
|
String errorMessage = "VirtualBox error: Soem other VBox error";
|
||||||
|
@ -129,12 +151,20 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
||||||
replay(manager, vBox);
|
replay(manager, vBox);
|
||||||
|
|
||||||
VmSpec launchSpecification = VmSpec.builder().id("").name(vmName).osTypeId("").cleanUpMode(CleanupMode.Full)
|
VmSpec launchSpecification = VmSpec.builder().id("").name(vmName).osTypeId("").cleanUpMode(CleanupMode.Full)
|
||||||
.memoryMB(1024).build();
|
.memoryMB(1024).build();
|
||||||
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(Suppliers.ofInstance(manager), "/tmp/workingDir").apply(launchSpecification);
|
IMachineSpec machineSpec = IMachineSpec.builder()
|
||||||
|
.iso(IsoSpec.builder()
|
||||||
|
.sourcePath("some.iso")
|
||||||
|
.installationScript("dostuff")
|
||||||
|
.preConfiguration(preconfiguration).build())
|
||||||
|
.vm(launchSpecification)
|
||||||
|
.network(NetworkSpec.builder().build()).build();
|
||||||
|
|
||||||
|
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(Suppliers.ofInstance(manager), "/tmp/workingDir").apply(machineSpec);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String anyString() {
|
private String anyString() {
|
||||||
return EasyMock.<String> anyObject();
|
return EasyMock.<String>anyObject();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,10 +28,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.jclouds.virtualbox.domain.HardDisk;
|
import org.jclouds.virtualbox.domain.*;
|
||||||
import org.jclouds.virtualbox.domain.NatAdapter;
|
|
||||||
import org.jclouds.virtualbox.domain.StorageController;
|
|
||||||
import org.jclouds.virtualbox.domain.VmSpec;
|
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.virtualbox_4_1.CleanupMode;
|
import org.virtualbox_4_1.CleanupMode;
|
||||||
import org.virtualbox_4_1.IMachine;
|
import org.virtualbox_4_1.IMachine;
|
||||||
|
@ -66,8 +63,7 @@ public class UnregisterMachineIfExistsAndDeleteItsMediaTest {
|
||||||
VmSpec vmSpecification = VmSpec.builder().id(vmId).name(vmName).memoryMB(512).osTypeId(osTypeId)
|
VmSpec vmSpecification = VmSpec.builder().id(vmId).name(vmName).memoryMB(512).osTypeId(osTypeId)
|
||||||
.controller(ideController)
|
.controller(ideController)
|
||||||
.forceOverwrite(true)
|
.forceOverwrite(true)
|
||||||
.cleanUpMode(CleanupMode.Full)
|
.cleanUpMode(CleanupMode.Full).build();
|
||||||
.natNetworkAdapter(0, NatAdapter.builder().tcpRedirectRule("127.0.0.1", 2222, "", 22).build()).build();
|
|
||||||
|
|
||||||
expect(manager.getVBox()).andReturn(vBox).anyTimes();
|
expect(manager.getVBox()).andReturn(vBox).anyTimes();
|
||||||
expect(vBox.findMachine(vmName)).andReturn(registeredMachine);
|
expect(vBox.findMachine(vmName)).andReturn(registeredMachine);
|
||||||
|
|
|
@ -22,10 +22,9 @@ import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE
|
||||||
import static org.testng.Assert.assertFalse;
|
import static org.testng.Assert.assertFalse;
|
||||||
import static org.testng.Assert.assertTrue;
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
|
import com.google.inject.Injector;
|
||||||
import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
|
import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest;
|
||||||
import org.jclouds.virtualbox.domain.HardDisk;
|
import org.jclouds.virtualbox.domain.*;
|
||||||
import org.jclouds.virtualbox.domain.StorageController;
|
|
||||||
import org.jclouds.virtualbox.domain.VmSpec;
|
|
||||||
import org.jclouds.virtualbox.functions.CloneAndRegisterMachineFromIMachineIfNotAlreadyExists;
|
import org.jclouds.virtualbox.functions.CloneAndRegisterMachineFromIMachineIfNotAlreadyExists;
|
||||||
import org.jclouds.virtualbox.functions.CreateAndRegisterMachineFromIsoIfNotAlreadyExists;
|
import org.jclouds.virtualbox.functions.CreateAndRegisterMachineFromIsoIfNotAlreadyExists;
|
||||||
import org.testng.annotations.AfterMethod;
|
import org.testng.annotations.AfterMethod;
|
||||||
|
@ -53,7 +52,7 @@ public class IsLinkedClonesLiveTest extends BaseVirtualBoxClientLiveTest {
|
||||||
private String cloneName;
|
private String cloneName;
|
||||||
private String vmName;
|
private String vmName;
|
||||||
private StorageController masterStorageController;
|
private StorageController masterStorageController;
|
||||||
private VmSpec masterSpec;
|
private IMachineSpec masterMachineSpec;
|
||||||
private VmSpec cloneSpec;
|
private VmSpec cloneSpec;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -70,8 +69,15 @@ public class IsLinkedClonesLiveTest extends BaseVirtualBoxClientLiveTest {
|
||||||
.build();
|
.build();
|
||||||
masterStorageController = StorageController.builder().name(ideControllerName).bus(StorageBus.IDE).attachISO(0, 0,
|
masterStorageController = StorageController.builder().name(ideControllerName).bus(StorageBus.IDE).attachISO(0, 0,
|
||||||
operatingSystemIso).attachHardDisk(hardDisk).attachISO(1, 1, guestAdditionsIso).build();
|
operatingSystemIso).attachHardDisk(hardDisk).attachISO(1, 1, guestAdditionsIso).build();
|
||||||
masterSpec = VmSpec.builder().id(vmId).name(vmName).memoryMB(512).osTypeId(osTypeId).controller(
|
VmSpec masterSpec = VmSpec.builder().id(vmId).name(vmName).memoryMB(512).osTypeId(osTypeId).controller(
|
||||||
masterStorageController).forceOverwrite(true).cleanUpMode(CleanupMode.Full).build();
|
masterStorageController).forceOverwrite(true).cleanUpMode(CleanupMode.Full).build();
|
||||||
|
masterMachineSpec = IMachineSpec.builder()
|
||||||
|
.iso(IsoSpec.builder()
|
||||||
|
.sourcePath(operatingSystemIso)
|
||||||
|
.preConfiguration(preconfigurationUri)
|
||||||
|
.installationScript("").build())
|
||||||
|
.vm(masterSpec)
|
||||||
|
.network(NetworkSpec.builder().build()).build();
|
||||||
|
|
||||||
cloneSpec = VmSpec.builder().id(cloneName).name(cloneName).memoryMB(512).cleanUpMode(CleanupMode.Full)
|
cloneSpec = VmSpec.builder().id(cloneName).name(cloneName).memoryMB(512).cleanUpMode(CleanupMode.Full)
|
||||||
.forceOverwrite(true).build();
|
.forceOverwrite(true).build();
|
||||||
|
@ -80,8 +86,9 @@ public class IsLinkedClonesLiveTest extends BaseVirtualBoxClientLiveTest {
|
||||||
@Test
|
@Test
|
||||||
public void testLinkedClone() {
|
public void testLinkedClone() {
|
||||||
|
|
||||||
IMachine master = context.utils().injector().getInstance(CreateAndRegisterMachineFromIsoIfNotAlreadyExists.class)
|
Injector injector = context.utils().injector();
|
||||||
.apply(masterSpec);
|
IMachine master = injector.getInstance(CreateAndRegisterMachineFromIsoIfNotAlreadyExists.class)
|
||||||
|
.apply(masterMachineSpec);
|
||||||
IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(manager, workingDir, cloneSpec,
|
IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(manager, workingDir, cloneSpec,
|
||||||
IS_LINKED_CLONE).apply(master);
|
IS_LINKED_CLONE).apply(master);
|
||||||
|
|
||||||
|
@ -102,7 +109,7 @@ public class IsLinkedClonesLiveTest extends BaseVirtualBoxClientLiveTest {
|
||||||
@BeforeMethod
|
@BeforeMethod
|
||||||
@AfterMethod
|
@AfterMethod
|
||||||
void cleanUpVms() {
|
void cleanUpVms() {
|
||||||
for (VmSpec spec : ImmutableSet.of(cloneSpec, masterSpec))
|
for (VmSpec spec : ImmutableSet.of(cloneSpec, masterMachineSpec.getVmSpec()))
|
||||||
this.undoVm(spec);
|
this.undoVm(spec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue