mirror of https://github.com/apache/jclouds.git
Added support for memory to VmSpec.
This commit is contained in:
parent
91e5351ef3
commit
6d435742e1
|
@ -23,6 +23,7 @@ import com.google.common.base.Objects;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,14 +34,16 @@ public class VmSpec {
|
||||||
private final String vmName;
|
private final String vmName;
|
||||||
private final String osTypeId;
|
private final String osTypeId;
|
||||||
private final String vmId;
|
private final String vmId;
|
||||||
|
private final long memory;
|
||||||
private final boolean forceOverwrite;
|
private final boolean forceOverwrite;
|
||||||
private final Map<Long, NatAdapter> natNetworkAdapters;
|
private final Map<Long, NatAdapter> natNetworkAdapters;
|
||||||
private final Set<StorageController> controllers;
|
private final Set<StorageController> controllers;
|
||||||
|
|
||||||
public VmSpec(String vmId, String vmName, String osTypeId, boolean forceOverwrite, Set<StorageController> controllers, Map<Long, NatAdapter> natNetworkAdapters) {
|
public VmSpec(String vmId, String vmName, String osTypeId, long memory, boolean forceOverwrite, Set<StorageController> controllers, Map<Long, NatAdapter> natNetworkAdapters) {
|
||||||
this.vmId = vmId;
|
this.vmId = vmId;
|
||||||
this.vmName = vmName;
|
this.vmName = vmName;
|
||||||
this.osTypeId = osTypeId;
|
this.osTypeId = osTypeId;
|
||||||
|
this.memory = memory;
|
||||||
this.controllers = controllers;
|
this.controllers = controllers;
|
||||||
this.forceOverwrite = forceOverwrite;
|
this.forceOverwrite = forceOverwrite;
|
||||||
this.natNetworkAdapters = natNetworkAdapters;
|
this.natNetworkAdapters = natNetworkAdapters;
|
||||||
|
@ -53,12 +56,13 @@ public class VmSpec {
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
|
|
||||||
private Set<StorageController> controllers = new HashSet<StorageController>();
|
private Set<StorageController> controllers = new HashSet<StorageController>();
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
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 Map<Long, NatAdapter> natNetworkAdapters = new HashMap<Long, NatAdapter>();
|
||||||
|
private long memory;
|
||||||
public Builder controller(StorageController controller) {
|
public Builder controller(StorageController controller) {
|
||||||
controllers.add(controller);
|
controllers.add(controller);
|
||||||
return this;
|
return this;
|
||||||
|
@ -89,12 +93,22 @@ public class VmSpec {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Builder memoryMB(int memorySize) {
|
||||||
|
this.memory = (long) memorySize;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public VmSpec build() {
|
public VmSpec build() {
|
||||||
checkNotNull(name, "name");
|
checkNotNull(name, "name");
|
||||||
checkNotNull(id, "id");
|
checkNotNull(id, "id");
|
||||||
return new VmSpec(id, name, osTypeId, forceOverwrite, controllers, natNetworkAdapters);
|
checkArgument(memory > 0, "Memory must be set");
|
||||||
|
return new VmSpec(id, name, osTypeId, memory, forceOverwrite, controllers, natNetworkAdapters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
public String getVmId() {
|
||||||
|
return vmId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getVmName() {
|
public String getVmName() {
|
||||||
|
@ -105,8 +119,8 @@ public class VmSpec {
|
||||||
return osTypeId;
|
return osTypeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getVmId() {
|
public long getMemory() {
|
||||||
return vmId;
|
return memory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isForceOverwrite() {
|
public boolean isForceOverwrite() {
|
||||||
|
@ -129,6 +143,7 @@ public class VmSpec {
|
||||||
return Objects.equal(vmId, other.vmId) &&
|
return Objects.equal(vmId, other.vmId) &&
|
||||||
Objects.equal(vmName, other.vmName) &&
|
Objects.equal(vmName, other.vmName) &&
|
||||||
Objects.equal(osTypeId, other.osTypeId) &&
|
Objects.equal(osTypeId, other.osTypeId) &&
|
||||||
|
Objects.equal(memory, other.memory) &&
|
||||||
Objects.equal(forceOverwrite, other.forceOverwrite) &&
|
Objects.equal(forceOverwrite, other.forceOverwrite) &&
|
||||||
Objects.equal(natNetworkAdapters, other.natNetworkAdapters) &&
|
Objects.equal(natNetworkAdapters, other.natNetworkAdapters) &&
|
||||||
Objects.equal(controllers, other.controllers);
|
Objects.equal(controllers, other.controllers);
|
||||||
|
@ -138,7 +153,7 @@ public class VmSpec {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hashCode(vmId, vmName, osTypeId, forceOverwrite, natNetworkAdapters, controllers);
|
return Objects.hashCode(vmId, vmName, osTypeId, memory, forceOverwrite, natNetworkAdapters, controllers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -146,6 +161,7 @@ public class VmSpec {
|
||||||
return "VmSpecification{" +
|
return "VmSpecification{" +
|
||||||
"vmName='" + vmName + '\'' +
|
"vmName='" + vmName + '\'' +
|
||||||
", osTypeId='" + osTypeId + '\'' +
|
", osTypeId='" + osTypeId + '\'' +
|
||||||
|
", memory='" + memory + '\'' +
|
||||||
", vmId='" + vmId + '\'' +
|
", vmId='" + vmId + '\'' +
|
||||||
", forceOverwrite=" + forceOverwrite +
|
", forceOverwrite=" + forceOverwrite +
|
||||||
", natNetworkAdapters=" + natNetworkAdapters +
|
", natNetworkAdapters=" + natNetworkAdapters +
|
||||||
|
|
|
@ -77,28 +77,28 @@ public class CreateAndInstallVm implements Function<VmSpec, IMachine> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IMachine apply(VmSpec vmSpecification) {
|
public IMachine apply(VmSpec vmSpec) {
|
||||||
|
|
||||||
ensureWebServerIsRunning();
|
ensureWebServerIsRunning();
|
||||||
|
|
||||||
final IMachine vm = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager).apply(vmSpecification);
|
final IMachine vm = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager).apply(vmSpec);
|
||||||
|
|
||||||
String vmName = vmSpecification.getVmName();
|
String vmName = vmSpec.getVmName();
|
||||||
|
|
||||||
// Change RAM
|
// Change RAM
|
||||||
ensureMachineHasMemory(vmName, 1024l);
|
ensureMachineHasMemory(vmName, vmSpec.getMemory());
|
||||||
|
|
||||||
Set<StorageController> controllers = vmSpecification.getControllers();
|
Set<StorageController> controllers = vmSpec.getControllers();
|
||||||
if (controllers.isEmpty()) {
|
if (controllers.isEmpty()) {
|
||||||
throw new IllegalStateException(missingIDEControllersMessage(vmSpecification));
|
throw new IllegalStateException(missingIDEControllersMessage(vmSpec));
|
||||||
}
|
}
|
||||||
StorageController controller = controllers.iterator().next();
|
StorageController controller = controllers.iterator().next();
|
||||||
ensureMachineHasIDEControllerNamed(vmName, controller);
|
ensureMachineHasIDEControllerNamed(vmName, controller);
|
||||||
setupHardDisksForController(vmName, controller);
|
setupHardDisksForController(vmName, controller);
|
||||||
setupDvdsForController(vmSpecification, vmName, controller);
|
setupDvdsForController(vmSpec, vmName, controller);
|
||||||
|
|
||||||
// NAT
|
// NAT
|
||||||
Map<Long, NatAdapter> natNetworkAdapters = vmSpecification.getNatNetworkAdapters();
|
Map<Long, NatAdapter> natNetworkAdapters = vmSpec.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();
|
||||||
|
|
|
@ -67,6 +67,7 @@ public class VmSpecTest {
|
||||||
.id("MyVmId")
|
.id("MyVmId")
|
||||||
.name("My VM")
|
.name("My VM")
|
||||||
.osTypeId("Ubuntu")
|
.osTypeId("Ubuntu")
|
||||||
|
.memoryMB(1024)
|
||||||
.natNetworkAdapter(
|
.natNetworkAdapter(
|
||||||
0,
|
0,
|
||||||
NatAdapter.builder().tcpRedirectRule("localhost", 2222, "", 22).build())
|
NatAdapter.builder().tcpRedirectRule("localhost", 2222, "", 22).build())
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/**
|
/*
|
||||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
* contributor license agreements. See the NOTICE file
|
* contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -49,7 +49,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
||||||
IVirtualBox vBox = createMock(IVirtualBox.class);
|
IVirtualBox vBox = createMock(IVirtualBox.class);
|
||||||
String vmName = "jclouds-image-my-ubuntu-image";
|
String vmName = "jclouds-image-my-ubuntu-image";
|
||||||
|
|
||||||
VmSpec launchSpecification = VmSpec.builder().id(vmName).name(vmName).osTypeId("").build();
|
VmSpec launchSpecification = VmSpec.builder().id(vmName).name(vmName).osTypeId("").memoryMB(1024).build();
|
||||||
|
|
||||||
IMachine createdMachine = createMock(IMachine.class);
|
IMachine createdMachine = createMock(IMachine.class);
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
||||||
|
|
||||||
replay(manager, vBox);
|
replay(manager, vBox);
|
||||||
|
|
||||||
VmSpec launchSpecification = VmSpec.builder().id("").name(vmName).osTypeId("").build();
|
VmSpec launchSpecification = VmSpec.builder().id("").name(vmName).osTypeId("").memoryMB(1024).build();
|
||||||
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager).apply(launchSpecification);
|
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager).apply(launchSpecification);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
||||||
|
|
||||||
replay(manager, vBox);
|
replay(manager, vBox);
|
||||||
|
|
||||||
VmSpec launchSpecification = VmSpec.builder().id("").name(vmName).osTypeId("").build();
|
VmSpec launchSpecification = VmSpec.builder().id("").name(vmName).osTypeId("").memoryMB(1024).build();
|
||||||
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager).apply(launchSpecification);
|
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager).apply(launchSpecification);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue