mirror of https://github.com/apache/jclouds.git
Updates to InstanceApi. 100% coverage
This commit is contained in:
parent
fd27ab1a9a
commit
94d42c3c6c
|
@ -153,6 +153,7 @@ public final class GoogleComputeEngineServiceAdapter
|
||||||
// We need to see the created instance so that we can access the newly created disk.
|
// We need to see the created instance so that we can access the newly created disk.
|
||||||
AtomicReference<Instance> instance = Atomics.newReference(Instance.create( //
|
AtomicReference<Instance> instance = Atomics.newReference(Instance.create( //
|
||||||
"0000000000000000000", // id can't be null, but isn't available until provisioning is done.
|
"0000000000000000000", // id can't be null, but isn't available until provisioning is done.
|
||||||
|
null, // creationTimestamp
|
||||||
create.targetLink(), // selfLink
|
create.targetLink(), // selfLink
|
||||||
newInstance.name(), // name
|
newInstance.name(), // name
|
||||||
newInstance.description(), // description
|
newInstance.description(), // description
|
||||||
|
@ -161,6 +162,7 @@ public final class GoogleComputeEngineServiceAdapter
|
||||||
Instance.Status.PROVISIONING, // status
|
Instance.Status.PROVISIONING, // status
|
||||||
null, // statusMessage
|
null, // statusMessage
|
||||||
create.zone(), // zone
|
create.zone(), // zone
|
||||||
|
null, // canIpForward
|
||||||
null, // networkInterfaces
|
null, // networkInterfaces
|
||||||
null, // disks
|
null, // disks
|
||||||
newInstance.metadata(), // metadata
|
newInstance.metadata(), // metadata
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package org.jclouds.googlecomputeengine.domain;
|
package org.jclouds.googlecomputeengine.domain;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.jclouds.javax.annotation.Nullable;
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
import org.jclouds.json.SerializedNames;
|
import org.jclouds.json.SerializedNames;
|
||||||
|
@ -26,7 +27,7 @@ import com.google.auto.value.AutoValue;
|
||||||
@AutoValue
|
@AutoValue
|
||||||
public abstract class AttachDisk {
|
public abstract class AttachDisk {
|
||||||
@AutoValue
|
@AutoValue
|
||||||
abstract static class InitializeParams {
|
public abstract static class InitializeParams {
|
||||||
/** Override the default naming convention. */
|
/** Override the default naming convention. */
|
||||||
@Nullable public abstract String diskName();
|
@Nullable public abstract String diskName();
|
||||||
|
|
||||||
|
@ -36,13 +37,15 @@ public abstract class AttachDisk {
|
||||||
/** The {@link org.jclouds.googlecomputeengine.domain.Image#selfLink() source image}. */
|
/** The {@link org.jclouds.googlecomputeengine.domain.Image#selfLink() source image}. */
|
||||||
public abstract URI sourceImage();
|
public abstract URI sourceImage();
|
||||||
|
|
||||||
|
@Nullable public abstract String diskType();
|
||||||
|
|
||||||
static InitializeParams create(URI sourceImage) {
|
static InitializeParams create(URI sourceImage) {
|
||||||
return create(null, null, sourceImage);
|
return create(null, null, sourceImage, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SerializedNames({ "diskName", "diskSizeGb", "sourceImage" })
|
@SerializedNames({ "diskName", "diskSizeGb", "sourceImage", "diskType" })
|
||||||
static InitializeParams create(String diskName, Long diskSizeGb, URI sourceImage) {
|
public static InitializeParams create(String diskName, Long diskSizeGb, URI sourceImage, String diskType) {
|
||||||
return new AutoValue_AttachDisk_InitializeParams(diskName, diskSizeGb, sourceImage);
|
return new AutoValue_AttachDisk_InitializeParams(diskName, diskSizeGb, sourceImage, diskType);
|
||||||
}
|
}
|
||||||
|
|
||||||
InitializeParams() {
|
InitializeParams() {
|
||||||
|
@ -59,6 +62,11 @@ public abstract class AttachDisk {
|
||||||
READ_ONLY;
|
READ_ONLY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum DiskInterface {
|
||||||
|
NVME,
|
||||||
|
SCSI;
|
||||||
|
}
|
||||||
|
|
||||||
public abstract Type type();
|
public abstract Type type();
|
||||||
|
|
||||||
@Nullable public abstract Mode mode();
|
@Nullable public abstract Mode mode();
|
||||||
|
@ -82,6 +90,11 @@ public abstract class AttachDisk {
|
||||||
/** True if this disk will be deleted when the instance is delete. */
|
/** True if this disk will be deleted when the instance is delete. */
|
||||||
public abstract boolean autoDelete();
|
public abstract boolean autoDelete();
|
||||||
|
|
||||||
|
@Nullable public abstract List<String> licenses();
|
||||||
|
|
||||||
|
// Note: this is disks[].interface in the api docs but interface is a Java keyword.
|
||||||
|
@Nullable public abstract DiskInterface diskInterface();
|
||||||
|
|
||||||
public static AttachDisk existingBootDisk(URI existingBootDisk) {
|
public static AttachDisk existingBootDisk(URI existingBootDisk) {
|
||||||
return create(Type.PERSISTENT, existingBootDisk, null, true, false);
|
return create(Type.PERSISTENT, existingBootDisk, null, true, false);
|
||||||
}
|
}
|
||||||
|
@ -96,13 +109,13 @@ public abstract class AttachDisk {
|
||||||
|
|
||||||
static AttachDisk create(Type type, URI source, InitializeParams initializeParams, boolean boot,
|
static AttachDisk create(Type type, URI source, InitializeParams initializeParams, boolean boot,
|
||||||
boolean autoDelete) {
|
boolean autoDelete) {
|
||||||
return create(type, null, source, null, boot, initializeParams, autoDelete);
|
return create(type, null, source, null, boot, initializeParams, autoDelete, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SerializedNames({"type", "mode", "source", "deviceName", "boot", "initializeParams", "autoDelete" })
|
@SerializedNames({"type", "mode", "source", "deviceName", "boot", "initializeParams", "autoDelete", "licenses", "interface" })
|
||||||
public static AttachDisk create(Type type, Mode mode, URI source, String deviceName, boolean boot, InitializeParams initializeParams,
|
public static AttachDisk create(Type type, Mode mode, URI source, String deviceName, boolean boot, InitializeParams initializeParams,
|
||||||
boolean autoDelete) {
|
boolean autoDelete, List<String> licenses, DiskInterface diskInterface) {
|
||||||
return new AutoValue_AttachDisk(type, mode, source, deviceName, boot, initializeParams, autoDelete);
|
return new AutoValue_AttachDisk(type, mode, source, deviceName, boot, initializeParams, autoDelete, licenses, diskInterface);
|
||||||
}
|
}
|
||||||
|
|
||||||
AttachDisk() {
|
AttachDisk() {
|
||||||
|
|
|
@ -19,8 +19,11 @@ package org.jclouds.googlecomputeengine.domain;
|
||||||
import static org.jclouds.googlecloud.internal.NullSafeCopies.copyOf;
|
import static org.jclouds.googlecloud.internal.NullSafeCopies.copyOf;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.jclouds.googlecomputeengine.domain.AttachDisk.DiskInterface;
|
||||||
|
import org.jclouds.googlecomputeengine.domain.AttachDisk.InitializeParams;
|
||||||
import org.jclouds.javax.annotation.Nullable;
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
import org.jclouds.json.SerializedNames;
|
import org.jclouds.json.SerializedNames;
|
||||||
|
|
||||||
|
@ -63,10 +66,20 @@ public abstract class Instance {
|
||||||
|
|
||||||
public abstract boolean boot();
|
public abstract boolean boot();
|
||||||
|
|
||||||
@SerializedNames({ "index", "type", "mode", "source", "deviceName", "autoDelete", "boot" })
|
@Nullable public abstract InitializeParams initializeParams();
|
||||||
|
|
||||||
|
@Nullable public abstract List<String> licenses();
|
||||||
|
|
||||||
|
// Note: this is disks[].interface in the api docs but interface is a Java keyword.
|
||||||
|
@Nullable public abstract DiskInterface diskInterface();
|
||||||
|
|
||||||
|
@SerializedNames({ "index", "type", "mode", "source", "deviceName", "autoDelete", "boot",
|
||||||
|
"initializeParams", "licenses", "interface" })
|
||||||
public static AttachedDisk create(int index, Type type, Mode mode, URI source, String deviceName,
|
public static AttachedDisk create(int index, Type type, Mode mode, URI source, String deviceName,
|
||||||
boolean autoDelete, boolean boot) {
|
boolean autoDelete, boolean boot, InitializeParams initializeParams,
|
||||||
return new AutoValue_Instance_AttachedDisk(index, type, mode, source, deviceName, autoDelete, boot);
|
List<String> licenses, DiskInterface diskInterface) {
|
||||||
|
return new AutoValue_Instance_AttachedDisk(index, type, mode, source, deviceName, autoDelete,
|
||||||
|
boot, initializeParams, licenses, diskInterface);
|
||||||
}
|
}
|
||||||
|
|
||||||
AttachedDisk() {
|
AttachedDisk() {
|
||||||
|
@ -124,7 +137,7 @@ public abstract class Instance {
|
||||||
@AutoValue
|
@AutoValue
|
||||||
public abstract static class SerialPortOutput {
|
public abstract static class SerialPortOutput {
|
||||||
|
|
||||||
@Nullable public abstract URI selfLink(); // TODO: is this really nullable?!
|
public abstract URI selfLink();
|
||||||
|
|
||||||
/** The contents of the console output. */
|
/** The contents of the console output. */
|
||||||
public abstract String contents();
|
public abstract String contents();
|
||||||
|
@ -200,6 +213,8 @@ public abstract class Instance {
|
||||||
|
|
||||||
public abstract String id();
|
public abstract String id();
|
||||||
|
|
||||||
|
@Nullable public abstract Date creationTimestamp();
|
||||||
|
|
||||||
public abstract URI selfLink();
|
public abstract URI selfLink();
|
||||||
|
|
||||||
public abstract String name();
|
public abstract String name();
|
||||||
|
@ -221,6 +236,8 @@ public abstract class Instance {
|
||||||
*/
|
*/
|
||||||
public abstract URI zone();
|
public abstract URI zone();
|
||||||
|
|
||||||
|
@Nullable public abstract Boolean canIpForward();
|
||||||
|
|
||||||
public abstract List<NetworkInterface> networkInterfaces();
|
public abstract List<NetworkInterface> networkInterfaces();
|
||||||
|
|
||||||
public abstract List<AttachedDisk> disks();
|
public abstract List<AttachedDisk> disks();
|
||||||
|
@ -231,13 +248,13 @@ public abstract class Instance {
|
||||||
|
|
||||||
public abstract Scheduling scheduling();
|
public abstract Scheduling scheduling();
|
||||||
|
|
||||||
@SerializedNames({ "id", "selfLink", "name", "description", "tags", "machineType", "status", "statusMessage", "zone",
|
@SerializedNames({ "id", "creationTimestamp", "selfLink", "name", "description", "tags", "machineType", "status", "statusMessage", "zone",
|
||||||
"networkInterfaces", "disks", "metadata", "serviceAccounts", "scheduling"})
|
"canIpForward", "networkInterfaces", "disks", "metadata", "serviceAccounts", "scheduling"})
|
||||||
public static Instance create(String id, URI selfLink, String name, String description, Tags tags, URI machineType,
|
public static Instance create(String id, Date creationTimestamp, URI selfLink, String name, String description, Tags tags, URI machineType,
|
||||||
Status status, String statusMessage, URI zone, List<NetworkInterface> networkInterfaces,
|
Status status, String statusMessage, URI zone, Boolean canIpForward, List<NetworkInterface> networkInterfaces,
|
||||||
List<AttachedDisk> disks, Metadata metadata, List<ServiceAccount> serviceAccounts, Scheduling scheduling) {
|
List<AttachedDisk> disks, Metadata metadata, List<ServiceAccount> serviceAccounts, Scheduling scheduling) {
|
||||||
return new AutoValue_Instance(id, selfLink, name, description, tags, machineType, status, statusMessage, zone,
|
return new AutoValue_Instance(id, creationTimestamp, selfLink, name, description, tags, machineType, status, statusMessage, zone,
|
||||||
copyOf(networkInterfaces), copyOf(disks), metadata, copyOf(serviceAccounts), scheduling);
|
canIpForward, copyOf(networkInterfaces), copyOf(disks), metadata, copyOf(serviceAccounts), scheduling);
|
||||||
}
|
}
|
||||||
|
|
||||||
Instance() {
|
Instance() {
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.util.List;
|
||||||
|
|
||||||
import org.jclouds.googlecomputeengine.domain.Instance.NetworkInterface.AccessConfig;
|
import org.jclouds.googlecomputeengine.domain.Instance.NetworkInterface.AccessConfig;
|
||||||
import org.jclouds.googlecomputeengine.domain.Instance.Scheduling;
|
import org.jclouds.googlecomputeengine.domain.Instance.Scheduling;
|
||||||
|
import org.jclouds.googlecomputeengine.domain.Instance.ServiceAccount;
|
||||||
import org.jclouds.javax.annotation.Nullable;
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
import org.jclouds.json.SerializedNames;
|
import org.jclouds.json.SerializedNames;
|
||||||
|
|
||||||
|
@ -56,6 +57,8 @@ public abstract class NewInstance {
|
||||||
|
|
||||||
public abstract URI machineType();
|
public abstract URI machineType();
|
||||||
|
|
||||||
|
@Nullable public abstract Boolean canIpForward();
|
||||||
|
|
||||||
public abstract List<NetworkInterface> networkInterfaces();
|
public abstract List<NetworkInterface> networkInterfaces();
|
||||||
|
|
||||||
public abstract List<AttachDisk> disks();
|
public abstract List<AttachDisk> disks();
|
||||||
|
@ -67,6 +70,8 @@ public abstract class NewInstance {
|
||||||
/** Add metadata via {@link Metadata#items()}. */
|
/** Add metadata via {@link Metadata#items()}. */
|
||||||
public abstract Metadata metadata();
|
public abstract Metadata metadata();
|
||||||
|
|
||||||
|
@Nullable public abstract List<ServiceAccount> serviceAccounts();
|
||||||
|
|
||||||
@Nullable public abstract Scheduling scheduling();
|
@Nullable public abstract Scheduling scheduling();
|
||||||
|
|
||||||
/** Convenience for creating a new instance with only a boot disk and minimal parameters. */
|
/** Convenience for creating a new instance with only a boot disk and minimal parameters. */
|
||||||
|
@ -83,14 +88,15 @@ public abstract class NewInstance {
|
||||||
foundBoot = true;
|
foundBoot = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return create(name, machineType, ImmutableList.of(NetworkInterface.create(network)), ImmutableList.copyOf(disks),
|
return create(name, machineType, null, ImmutableList.of(NetworkInterface.create(network)), ImmutableList.copyOf(disks),
|
||||||
description, Tags.create(), Metadata.create(), null);
|
description, Tags.create(), Metadata.create(), null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SerializedNames({ "name", "machineType", "networkInterfaces", "disks", "description", "tags", "metadata", "scheduling" })
|
@SerializedNames({ "name", "machineType", "canIpForward", "networkInterfaces", "disks", "description", "tags", "metadata",
|
||||||
static NewInstance create(String name, URI machineType, List<NetworkInterface> networkInterfaces,
|
"serviceAccounts", "scheduling" })
|
||||||
List<AttachDisk> disks, String description, Tags tags, Metadata metadata, Scheduling scheduling) {
|
static NewInstance create(String name, URI machineType, Boolean canIpForward, List<NetworkInterface> networkInterfaces,
|
||||||
return new AutoValue_NewInstance(name, machineType, networkInterfaces, disks, description, tags, metadata, scheduling);
|
List<AttachDisk> disks, String description, Tags tags, Metadata metadata, List<ServiceAccount> serviceAccounts, Scheduling scheduling) {
|
||||||
|
return new AutoValue_NewInstance(name, machineType, canIpForward, networkInterfaces, disks, description, tags, metadata, serviceAccounts, scheduling);
|
||||||
}
|
}
|
||||||
|
|
||||||
NewInstance() {
|
NewInstance() {
|
||||||
|
|
|
@ -107,7 +107,7 @@ public interface InstanceApi {
|
||||||
Operation addAccessConfigToNic(@PathParam("instance") String instance,
|
Operation addAccessConfigToNic(@PathParam("instance") String instance,
|
||||||
@BinderParam(BindToJsonPayload.class)
|
@BinderParam(BindToJsonPayload.class)
|
||||||
AccessConfig accessConfig,
|
AccessConfig accessConfig,
|
||||||
@QueryParam("network_interface") String networkInterfaceName);
|
@QueryParam("networkInterface") String networkInterfaceName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes an access config from an instance's network interface.
|
* Deletes an access config from an instance's network interface.
|
||||||
|
@ -122,8 +122,8 @@ public interface InstanceApi {
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("/{instance}/deleteAccessConfig")
|
@Path("/{instance}/deleteAccessConfig")
|
||||||
Operation deleteAccessConfigFromNic(@PathParam("instance") String instance,
|
Operation deleteAccessConfigFromNic(@PathParam("instance") String instance,
|
||||||
@QueryParam("access_config") String accessConfigName,
|
@QueryParam("accessConfig") String accessConfigName,
|
||||||
@QueryParam("network_interface") String networkInterfaceName);
|
@QueryParam("networkInterface") String networkInterfaceName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the specified instance's serial port output.
|
* Returns the specified instance's serial port output.
|
||||||
|
@ -131,7 +131,7 @@ public interface InstanceApi {
|
||||||
* @param instance the instance name.
|
* @param instance the instance name.
|
||||||
* @return if successful, this method returns a SerialPortOutput containing the instance's serial output.
|
* @return if successful, this method returns a SerialPortOutput containing the instance's serial output.
|
||||||
*/
|
*/
|
||||||
@Named("Instances:serialPort")
|
@Named("Instances:getSerialPortOutput")
|
||||||
@GET
|
@GET
|
||||||
@Path("/{instance}/serialPort")
|
@Path("/{instance}/serialPort")
|
||||||
SerialPortOutput getSerialPortOutput(@PathParam("instance") String instance);
|
SerialPortOutput getSerialPortOutput(@PathParam("instance") String instance);
|
||||||
|
|
|
@ -33,6 +33,7 @@ import org.jclouds.googlecomputeengine.domain.Image;
|
||||||
import org.jclouds.googlecomputeengine.domain.Instance;
|
import org.jclouds.googlecomputeengine.domain.Instance;
|
||||||
import org.jclouds.googlecomputeengine.domain.Instance.AttachedDisk;
|
import org.jclouds.googlecomputeengine.domain.Instance.AttachedDisk;
|
||||||
import org.jclouds.googlecomputeengine.domain.Instance.Scheduling;
|
import org.jclouds.googlecomputeengine.domain.Instance.Scheduling;
|
||||||
|
import org.jclouds.googlecomputeengine.domain.Instance.SerialPortOutput;
|
||||||
import org.jclouds.googlecomputeengine.domain.Metadata;
|
import org.jclouds.googlecomputeengine.domain.Metadata;
|
||||||
import org.jclouds.googlecomputeengine.domain.NewInstance;
|
import org.jclouds.googlecomputeengine.domain.NewInstance;
|
||||||
import org.jclouds.googlecomputeengine.domain.AttachDisk;
|
import org.jclouds.googlecomputeengine.domain.AttachDisk;
|
||||||
|
@ -121,6 +122,14 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
|
||||||
assertInstanceEquals(instance, this.instance);
|
assertInstanceEquals(instance, this.instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(groups = "live", dependsOnMethods = "testInsertInstance")
|
||||||
|
public void testGetSerialPortOutput() {
|
||||||
|
SerialPortOutput output = api().getSerialPortOutput(INSTANCE_NAME);
|
||||||
|
assertNotNull(output);
|
||||||
|
assertNotNull(output.selfLink());
|
||||||
|
assertNotNull(output.contents());
|
||||||
|
}
|
||||||
|
|
||||||
@Test(groups = "live", dependsOnMethods = "testInsertInstance")
|
@Test(groups = "live", dependsOnMethods = "testInsertInstance")
|
||||||
public void testSetDiskAutoDelete() {
|
public void testSetDiskAutoDelete() {
|
||||||
|
|
||||||
|
@ -196,13 +205,16 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
|
||||||
|
|
||||||
Instance originalInstance = api().get(INSTANCE_NAME);
|
Instance originalInstance = api().get(INSTANCE_NAME);
|
||||||
assertOperationDoneSuccessfully(api().attachDisk(INSTANCE_NAME,
|
assertOperationDoneSuccessfully(api().attachDisk(INSTANCE_NAME,
|
||||||
AttachDisk.create(AttachDisk.Type.PERSISTENT,
|
AttachDisk.create(AttachDisk.Type.PERSISTENT, // type
|
||||||
AttachDisk.Mode.READ_ONLY,
|
AttachDisk.Mode.READ_ONLY, // mode
|
||||||
getDiskUrl(ATTACH_DISK_NAME),
|
getDiskUrl(ATTACH_DISK_NAME), // source
|
||||||
ATTACH_DISK_DEVICE_NAME,
|
ATTACH_DISK_DEVICE_NAME, // deviceName
|
||||||
false,
|
false, // boot
|
||||||
null,
|
null, // initializeParams
|
||||||
false)));
|
false, // autoDelete
|
||||||
|
null, // licenses
|
||||||
|
null // interface
|
||||||
|
)));
|
||||||
|
|
||||||
Instance modifiedInstance = api().get(INSTANCE_NAME);
|
Instance modifiedInstance = api().get(INSTANCE_NAME);
|
||||||
|
|
||||||
|
@ -246,7 +258,7 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
|
||||||
assertOperationDoneSuccessfully(api().reset(INSTANCE_NAME));
|
assertOperationDoneSuccessfully(api().reset(INSTANCE_NAME));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(groups = "live", dependsOnMethods = {"testSetDiskAutoDelete", "testResetInstance", "testSetScheduling"}, alwaysRun = true)
|
@Test(groups = "live", dependsOnMethods = {"testSetDiskAutoDelete", "testResetInstance", "testSetScheduling", "testGetInstance", "testGetSerialPortOutput"}, alwaysRun = true)
|
||||||
public void testDeleteInstance() {
|
public void testDeleteInstance() {
|
||||||
assertOperationDoneSuccessfully(api().delete(INSTANCE_NAME));
|
assertOperationDoneSuccessfully(api().delete(INSTANCE_NAME));
|
||||||
assertOperationDoneSuccessfully(diskApi().delete(DISK_NAME));
|
assertOperationDoneSuccessfully(diskApi().delete(DISK_NAME));
|
||||||
|
|
|
@ -24,6 +24,9 @@ import java.net.URI;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.jclouds.googlecomputeengine.domain.AttachDisk;
|
import org.jclouds.googlecomputeengine.domain.AttachDisk;
|
||||||
|
import org.jclouds.googlecomputeengine.domain.AttachDisk.DiskInterface;
|
||||||
|
import org.jclouds.googlecomputeengine.domain.Instance.NetworkInterface.AccessConfig;
|
||||||
|
import org.jclouds.googlecomputeengine.domain.Instance.NetworkInterface.AccessConfig.Type;
|
||||||
import org.jclouds.googlecomputeengine.domain.Metadata;
|
import org.jclouds.googlecomputeengine.domain.Metadata;
|
||||||
import org.jclouds.googlecomputeengine.domain.NewInstance;
|
import org.jclouds.googlecomputeengine.domain.NewInstance;
|
||||||
import org.jclouds.googlecomputeengine.domain.Instance.Scheduling.OnHostMaintenance;
|
import org.jclouds.googlecomputeengine.domain.Instance.Scheduling.OnHostMaintenance;
|
||||||
|
@ -42,8 +45,8 @@ public class InstanceApiMockTest extends BaseGoogleComputeEngineApiMockTest {
|
||||||
public void get() throws Exception {
|
public void get() throws Exception {
|
||||||
server.enqueue(jsonResponse("/instance_get.json"));
|
server.enqueue(jsonResponse("/instance_get.json"));
|
||||||
|
|
||||||
assertEquals(instanceApi().get("test-1"), new ParseInstanceTest().expected(url("/projects")));
|
assertEquals(instanceApi().get("test-instance"), new ParseInstanceTest().expected(url("/projects")));
|
||||||
assertSent(server, "GET", "/projects/party/zones/us-central1-a/instances/test-1");
|
assertSent(server, "GET", "/projects/party/zones/us-central1-a/instances/test-instance");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void get_4xx() throws Exception {
|
public void get_4xx() throws Exception {
|
||||||
|
@ -57,7 +60,7 @@ public class InstanceApiMockTest extends BaseGoogleComputeEngineApiMockTest {
|
||||||
server.enqueue(jsonResponse("/instance_serial_port.json"));
|
server.enqueue(jsonResponse("/instance_serial_port.json"));
|
||||||
|
|
||||||
assertEquals(instanceApi().getSerialPortOutput("test-1"),
|
assertEquals(instanceApi().getSerialPortOutput("test-1"),
|
||||||
new ParseInstanceSerialOutputTest().expected());
|
new ParseInstanceSerialOutputTest().expected(url("/projects")));
|
||||||
|
|
||||||
assertSent(server, "GET", "/projects/party/zones/us-central1-a/instances/test-1/serialPort");
|
assertSent(server, "GET", "/projects/party/zones/us-central1-a/instances/test-1/serialPort");
|
||||||
}
|
}
|
||||||
|
@ -94,6 +97,32 @@ public class InstanceApiMockTest extends BaseGoogleComputeEngineApiMockTest {
|
||||||
stringFromResource("/instance_insert.json"));
|
stringFromResource("/instance_insert.json"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addAccessConfig() throws Exception {
|
||||||
|
server.enqueue(jsonResponse("/zone_operation.json"));
|
||||||
|
|
||||||
|
AccessConfig config = AccessConfig.create("test-access", Type.ONE_TO_ONE_NAT, "1.1.1.1");
|
||||||
|
assertEquals(instanceApi().addAccessConfigToNic("test-instance", config, "test-network"),
|
||||||
|
new ParseZoneOperationTest().expected(url("/projects")));
|
||||||
|
|
||||||
|
assertSent(server, "POST", "/projects/party/zones/us-central1-a/instances/test-instance/"
|
||||||
|
+ "addAccessConfig?networkInterface=test-network",
|
||||||
|
"{" +
|
||||||
|
" \"type\": \"ONE_TO_ONE_NAT\"," +
|
||||||
|
" \"name\": \"test-access\"," +
|
||||||
|
" \"natIP\": \"1.1.1.1\"" +
|
||||||
|
"}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteAccessConfig() throws Exception {
|
||||||
|
server.enqueue(jsonResponse("/zone_operation.json"));
|
||||||
|
|
||||||
|
assertEquals(instanceApi().deleteAccessConfigFromNic("test-instance", "test-access", "test-network"),
|
||||||
|
new ParseZoneOperationTest().expected(url("/projects")));
|
||||||
|
|
||||||
|
assertSent(server, "DELETE", "/projects/party/zones/us-central1-a/instances/test-instance/"
|
||||||
|
+ "deleteAccessConfig?accessConfig=test-access&networkInterface=test-network");
|
||||||
|
}
|
||||||
|
|
||||||
public void delete() throws Exception {
|
public void delete() throws Exception {
|
||||||
server.enqueue(jsonResponse("/zone_operation.json"));
|
server.enqueue(jsonResponse("/zone_operation.json"));
|
||||||
|
|
||||||
|
@ -154,10 +183,21 @@ public class InstanceApiMockTest extends BaseGoogleComputeEngineApiMockTest {
|
||||||
server.enqueue(jsonResponse("/zone_operation.json"));
|
server.enqueue(jsonResponse("/zone_operation.json"));
|
||||||
|
|
||||||
assertEquals(instanceApi().attachDisk("test-1",
|
assertEquals(instanceApi().attachDisk("test-1",
|
||||||
AttachDisk.create(AttachDisk.Type.PERSISTENT,
|
AttachDisk.create(AttachDisk.Type.PERSISTENT, // type
|
||||||
AttachDisk.Mode.READ_ONLY,
|
AttachDisk.Mode.READ_WRITE, // mode
|
||||||
URI.create(url("/projects/party/zones/us-central1-a/disks/testimage1")),
|
URI.create(url("/projects/party/zones/us-central1-a/disks/test")), // source
|
||||||
null, false, null, true)),
|
"test", // deviceName
|
||||||
|
true, // boot
|
||||||
|
AttachDisk.InitializeParams.create(
|
||||||
|
"test", // diskName
|
||||||
|
Long.parseLong("100", 10), // diskSizeGb
|
||||||
|
URI.create(url("/projects/party/global/images/test")), // sourceImage
|
||||||
|
"pd-standard" // diskType
|
||||||
|
), // initializeParams
|
||||||
|
true, // autoDelete
|
||||||
|
ImmutableList.of(url("/projects/suse-cloud/global/licenses/sles-12")), // licenses
|
||||||
|
DiskInterface.NVME // interface
|
||||||
|
)),
|
||||||
new ParseZoneOperationTest().expected(url("/projects")));
|
new ParseZoneOperationTest().expected(url("/projects")));
|
||||||
assertSent(server, "POST", "/projects/party/zones/us-central1-a/instances/test-1/attachDisk",
|
assertSent(server, "POST", "/projects/party/zones/us-central1-a/instances/test-1/attachDisk",
|
||||||
stringFromResource("/instance_attach_disk.json"));
|
stringFromResource("/instance_attach_disk.json"));
|
||||||
|
|
|
@ -19,6 +19,8 @@ package org.jclouds.googlecomputeengine.parse;
|
||||||
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
|
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
|
||||||
import static org.jclouds.googlecomputeengine.domain.Instance.SerialPortOutput;
|
import static org.jclouds.googlecomputeengine.domain.Instance.SerialPortOutput;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
|
|
||||||
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
|
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
|
||||||
|
@ -34,6 +36,13 @@ public class ParseInstanceSerialOutputTest extends BaseGoogleComputeEngineParseT
|
||||||
|
|
||||||
@Override @Consumes(APPLICATION_JSON)
|
@Override @Consumes(APPLICATION_JSON)
|
||||||
public SerialPortOutput expected() {
|
public SerialPortOutput expected() {
|
||||||
return SerialPortOutput.create(null, "console output");
|
return expected(BASE_URL);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Consumes(APPLICATION_JSON)
|
||||||
|
public SerialPortOutput expected(String baseUrl) {
|
||||||
|
return SerialPortOutput.create(
|
||||||
|
URI.create(baseUrl + "/party/zones/us-central1-a/instances/test-instance/serialPort"),
|
||||||
|
"console output");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,8 @@ import java.net.URI;
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
|
|
||||||
|
import org.jclouds.googlecomputeengine.domain.AttachDisk;
|
||||||
|
import org.jclouds.googlecomputeengine.domain.AttachDisk.DiskInterface;
|
||||||
import org.jclouds.googlecomputeengine.domain.Instance;
|
import org.jclouds.googlecomputeengine.domain.Instance;
|
||||||
import org.jclouds.googlecomputeengine.domain.Instance.AttachedDisk;
|
import org.jclouds.googlecomputeengine.domain.Instance.AttachedDisk;
|
||||||
import org.jclouds.googlecomputeengine.domain.Instance.NetworkInterface;
|
import org.jclouds.googlecomputeengine.domain.Instance.NetworkInterface;
|
||||||
|
@ -51,6 +53,7 @@ public class ParseInstanceTest extends BaseGoogleComputeEngineParseTest<Instance
|
||||||
public Instance expected(String baseUrl) {
|
public Instance expected(String baseUrl) {
|
||||||
return Instance.create( //
|
return Instance.create( //
|
||||||
"13051190678907570425", // id
|
"13051190678907570425", // id
|
||||||
|
parse("2012-11-25T23:48:20.758"), // creationTimestamp
|
||||||
URI.create(baseUrl + "/party/zones/us-central1-a/instances/test-0"), // selfLink
|
URI.create(baseUrl + "/party/zones/us-central1-a/instances/test-0"), // selfLink
|
||||||
"test-0", // name
|
"test-0", // name
|
||||||
"desc", // description
|
"desc", // description
|
||||||
|
@ -59,6 +62,7 @@ public class ParseInstanceTest extends BaseGoogleComputeEngineParseTest<Instance
|
||||||
Instance.Status.RUNNING, // status
|
Instance.Status.RUNNING, // status
|
||||||
null, // statusMessage
|
null, // statusMessage
|
||||||
URI.create(baseUrl + "/party/zones/us-central1-a"), // zone
|
URI.create(baseUrl + "/party/zones/us-central1-a"), // zone
|
||||||
|
true, // canIpForward
|
||||||
ImmutableList.of(NetworkInterface.create( //
|
ImmutableList.of(NetworkInterface.create( //
|
||||||
"nic0", // name
|
"nic0", // name
|
||||||
URI.create(baseUrl + "/party/global/networks/default"), // network
|
URI.create(baseUrl + "/party/global/networks/default"), // network
|
||||||
|
@ -72,7 +76,15 @@ public class ParseInstanceTest extends BaseGoogleComputeEngineParseTest<Instance
|
||||||
URI.create(baseUrl + "/party/zones/us-central1-a/disks/test"), // source
|
URI.create(baseUrl + "/party/zones/us-central1-a/disks/test"), // source
|
||||||
"test", // deviceName
|
"test", // deviceName
|
||||||
false, // autoDelete
|
false, // autoDelete
|
||||||
true// boot
|
true, // boot
|
||||||
|
AttachDisk.InitializeParams.create(
|
||||||
|
"test", // diskName
|
||||||
|
Long.parseLong("100", 10), // diskSizeGb
|
||||||
|
URI.create(baseUrl + "/party/global/images/test"), // sourceImage
|
||||||
|
"pd-standard" // diskType
|
||||||
|
), // initializeParams
|
||||||
|
ImmutableList.of(baseUrl + "/suse-cloud/global/licenses/sles-12"), // licenses
|
||||||
|
DiskInterface.NVME // interface
|
||||||
)), // disks
|
)), // disks
|
||||||
Metadata.create("efgh")
|
Metadata.create("efgh")
|
||||||
.put("aKey", "aValue")
|
.put("aKey", "aValue")
|
||||||
|
|
|
@ -1,7 +1,18 @@
|
||||||
{
|
{
|
||||||
"type": "PERSISTENT",
|
"type": "PERSISTENT",
|
||||||
"mode": "READ_ONLY",
|
"mode": "READ_WRITE",
|
||||||
"source": "https://www.googleapis.com/compute/v1/projects/party/zones/us-central1-a/disks/testimage1",
|
"deviceName": "test",
|
||||||
"boot": false,
|
"source": "https://www.googleapis.com/compute/v1/projects/party/zones/us-central1-a/disks/test",
|
||||||
"autoDelete": true
|
"boot": true,
|
||||||
|
"autoDelete": true,
|
||||||
|
"initializeParams": {
|
||||||
|
"diskName": "test",
|
||||||
|
"sourceImage": "https://www.googleapis.com/compute/v1/projects/party/global/images/test",
|
||||||
|
"diskSizeGb": 100,
|
||||||
|
"diskType": "pd-standard"
|
||||||
|
},
|
||||||
|
"licenses": [
|
||||||
|
"https://www.googleapis.com/compute/v1/projects/suse-cloud/global/licenses/sles-12"
|
||||||
|
],
|
||||||
|
"interface": "NVME"
|
||||||
}
|
}
|
|
@ -7,6 +7,7 @@
|
||||||
"name": "test-0",
|
"name": "test-0",
|
||||||
"machineType": "https://www.googleapis.com/compute/v1/projects/party/zones/us-central1-a/machineTypes/n1-standard-1",
|
"machineType": "https://www.googleapis.com/compute/v1/projects/party/zones/us-central1-a/machineTypes/n1-standard-1",
|
||||||
"status": "RUNNING",
|
"status": "RUNNING",
|
||||||
|
"canIpForward": true,
|
||||||
"zone": "https://www.googleapis.com/compute/v1/projects/party/zones/us-central1-a",
|
"zone": "https://www.googleapis.com/compute/v1/projects/party/zones/us-central1-a",
|
||||||
"networkInterfaces": [
|
"networkInterfaces": [
|
||||||
{
|
{
|
||||||
|
@ -24,7 +25,17 @@
|
||||||
"deviceName": "test",
|
"deviceName": "test",
|
||||||
"source": "https://www.googleapis.com/compute/v1/projects/party/zones/us-central1-a/disks/test",
|
"source": "https://www.googleapis.com/compute/v1/projects/party/zones/us-central1-a/disks/test",
|
||||||
"index": 0,
|
"index": 0,
|
||||||
"boot": true
|
"boot": true,
|
||||||
|
"initializeParams": {
|
||||||
|
"diskName": "test",
|
||||||
|
"sourceImage": "https://www.googleapis.com/compute/v1/projects/party/global/images/test",
|
||||||
|
"diskSizeGb": "100",
|
||||||
|
"diskType": "pd-standard"
|
||||||
|
},
|
||||||
|
"licenses": [
|
||||||
|
"https://www.googleapis.com/compute/v1/projects/suse-cloud/global/licenses/sles-12"
|
||||||
|
],
|
||||||
|
"interface": "NVME"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"serviceAccounts": [
|
"serviceAccounts": [
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
"name": "test-0",
|
"name": "test-0",
|
||||||
"machineType": "https://www.googleapis.com/compute/v1/projects/party/zones/us-central1-a/machineTypes/n1-standard-1",
|
"machineType": "https://www.googleapis.com/compute/v1/projects/party/zones/us-central1-a/machineTypes/n1-standard-1",
|
||||||
"status": "RUNNING",
|
"status": "RUNNING",
|
||||||
|
"canIpForward": true,
|
||||||
"zone": "https://www.googleapis.com/compute/v1/projects/party/zones/us-central1-a",
|
"zone": "https://www.googleapis.com/compute/v1/projects/party/zones/us-central1-a",
|
||||||
"networkInterfaces": [
|
"networkInterfaces": [
|
||||||
{
|
{
|
||||||
|
@ -29,7 +30,17 @@
|
||||||
"deviceName": "test",
|
"deviceName": "test",
|
||||||
"source": "https://www.googleapis.com/compute/v1/projects/party/zones/us-central1-a/disks/test",
|
"source": "https://www.googleapis.com/compute/v1/projects/party/zones/us-central1-a/disks/test",
|
||||||
"index": 0,
|
"index": 0,
|
||||||
"boot": true
|
"boot": true,
|
||||||
|
"initializeParams": {
|
||||||
|
"diskName": "test",
|
||||||
|
"sourceImage": "https://www.googleapis.com/compute/v1/projects/party/global/images/test",
|
||||||
|
"diskSizeGb": "100",
|
||||||
|
"diskType": "pd-standard"
|
||||||
|
},
|
||||||
|
"licenses": [
|
||||||
|
"https://www.googleapis.com/compute/v1/projects/suse-cloud/global/licenses/sles-12"
|
||||||
|
],
|
||||||
|
"interface": "NVME"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"serviceAccounts": [
|
"serviceAccounts": [
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
{
|
{
|
||||||
"kind": "compute#serialPortOutput",
|
"kind": "compute#serialPortOutput",
|
||||||
"contents": "console output"
|
"contents": "console output",
|
||||||
|
"selfLink": "https://www.googleapis.com/compute/v1/projects/party/zones/us-central1-a/instances/test-instance/serialPort"
|
||||||
}
|
}
|
Loading…
Reference in New Issue