You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by ad...@apache.org on 2014/11/15 02:53:55 UTC

jclouds-labs-google git commit: Add setDiskAutoDelete to InstanceApi, Refactor AttachDisk.

Repository: jclouds-labs-google
Updated Branches:
  refs/heads/master f191c8fb0 -> 4e5581f8c


Add setDiskAutoDelete to InstanceApi, Refactor AttachDisk.


Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/commit/4e5581f8
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/tree/4e5581f8
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/diff/4e5581f8

Branch: refs/heads/master
Commit: 4e5581f8c6b4b577c50e99434bf6f537738e2a8f
Parents: f191c8f
Author: Daniel Broudy <br...@google.com>
Authored: Mon Nov 10 14:43:00 2014 -0800
Committer: Adrian Cole <ac...@twitter.com>
Committed: Fri Nov 14 17:52:25 2014 -0800

----------------------------------------------------------------------
 .../GoogleComputeEngineServiceAdapter.java      |   8 +-
 .../googlecomputeengine/domain/AttachDisk.java  | 111 +++++++++++++++++++
 .../googlecomputeengine/domain/NewInstance.java |  72 +-----------
 .../features/InstanceApi.java                   |  21 +++-
 .../options/AttachDiskOptions.java              | 106 ------------------
 .../features/InstanceApiExpectTest.java         |  49 +++++---
 .../features/InstanceApiLiveTest.java           |  57 ++++++++--
 .../features/InstanceApiMockTest.java           |  42 +++++++
 .../parse/ParseZoneOperationTest.java           |  11 +-
 .../test/resources/instance_attach_disk.json    |   3 +-
 10 files changed, 269 insertions(+), 211 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/4e5581f8/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceAdapter.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceAdapter.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceAdapter.java
index bad4249..22315f3 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceAdapter.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceAdapter.java
@@ -23,7 +23,6 @@ import static com.google.common.collect.Lists.newArrayList;
 import static java.lang.String.format;
 import static org.jclouds.googlecloud.internal.ListPages.concat;
 import static org.jclouds.googlecomputeengine.config.GoogleComputeEngineProperties.IMAGE_PROJECTS;
-import static org.jclouds.googlecomputeengine.domain.NewInstance.Disk;
 
 import java.net.URI;
 import java.util.List;
@@ -45,6 +44,7 @@ import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
 import org.jclouds.googlecomputeengine.compute.functions.FirewallTagNamingConvention;
 import org.jclouds.googlecomputeengine.compute.functions.Resources;
 import org.jclouds.googlecomputeengine.compute.options.GoogleComputeEngineTemplateOptions;
+import org.jclouds.googlecomputeengine.domain.AttachDisk;
 import org.jclouds.googlecomputeengine.domain.Image;
 import org.jclouds.googlecomputeengine.domain.Instance;
 import org.jclouds.googlecomputeengine.domain.MachineType;
@@ -116,10 +116,10 @@ public final class GoogleComputeEngineServiceAdapter
       checkNotNull(hardware.getUri(), "hardware must have a URI");
       checkNotNull(template.getImage().getUri(), "image URI is null");
 
-      List<Disk> disks = Lists.newArrayList();
-      disks.add(Disk.newBootDisk(template.getImage().getUri()));
+      List<AttachDisk> disks = Lists.newArrayList();
+      disks.add(AttachDisk.newBootDisk(template.getImage().getUri()));
       for (URI existingDisk : options.additionalDisks()) {
-         disks.add(Disk.existingDisk(existingDisk));
+         disks.add(AttachDisk.existingDisk(existingDisk));
       }
 
       NewInstance newInstance = NewInstance.create(

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/4e5581f8/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/AttachDisk.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/AttachDisk.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/AttachDisk.java
new file mode 100644
index 0000000..22db29b
--- /dev/null
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/AttachDisk.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.googlecomputeengine.domain;
+
+import java.net.URI;
+
+import org.jclouds.javax.annotation.Nullable;
+import org.jclouds.json.SerializedNames;
+
+import com.google.auto.value.AutoValue;
+
+@AutoValue
+public abstract class AttachDisk {
+   @AutoValue
+   abstract static class InitializeParams {
+      /** Override the default naming convention. */
+      @Nullable public abstract String diskName();
+
+      /** Set to use a size larger than the {@link #sourceImage()}. You need to repartition when set. */
+      @Nullable public abstract Long diskSizeGb();
+
+      /** The {@link org.jclouds.googlecomputeengine.domain.Image#selfLink() source image}. */
+      public abstract URI sourceImage();
+
+      static InitializeParams create(URI sourceImage) {
+         return create(null, null, sourceImage);
+      }
+
+      @SerializedNames({ "diskName", "diskSizeGb", "sourceImage" })
+      static InitializeParams create(String diskName, Long diskSizeGb, URI sourceImage) {
+         return new AutoValue_AttachDisk_InitializeParams(diskName, diskSizeGb, sourceImage);
+      }
+
+      InitializeParams() {
+      }
+   }
+
+   public enum Type {
+      PERSISTENT,
+      SCRATCH;
+   }
+
+   public enum Mode {
+      READ_WRITE,
+      READ_ONLY;
+   }
+
+   public abstract Type type();
+
+   @Nullable public abstract Mode mode();
+
+   /** Use an existingBootDisk {@link org.jclouds.googlecomputeengine.domain.Disk#selfLink() boot disk}. */
+   @Nullable public abstract URI source();
+
+   /**
+    * Must be unique within the instance when specified. This represents a unique
+    * device name that is reflected into the /dev/ tree of a Linux operating system running within the
+    * instance. If not specified, a default will be chosen by the system.
+    */
+   @Nullable public abstract String deviceName();
+
+   /** True if this is a boot disk. VM will use the first partition of the disk for its root filesystem. */
+   public abstract boolean boot();
+
+   /** Set to automatically create a boot disk */
+   @Nullable public abstract InitializeParams initializeParams();
+
+   /** True if this disk will be deleted when the instance is delete. */
+   public abstract boolean autoDelete();
+
+   public static AttachDisk existingBootDisk(URI existingBootDisk) {
+      return create(Type.PERSISTENT, existingBootDisk, null, true, false);
+   }
+
+   public static AttachDisk newBootDisk(URI sourceImage) {
+      return create(Type.PERSISTENT, null, InitializeParams.create(sourceImage), true, true);
+   }
+
+   public static AttachDisk existingDisk(URI existingDisk) {
+      return create(Type.PERSISTENT, existingDisk, null, false, false);
+   }
+
+   static AttachDisk create(Type type, URI source, InitializeParams initializeParams, boolean boot,
+            boolean autoDelete) {
+         return create(type, null, source, null, boot, initializeParams, autoDelete);
+      }
+
+   @SerializedNames({"type", "mode", "source", "deviceName", "boot", "initializeParams", "autoDelete" })
+   public static AttachDisk create(Type type, Mode mode, URI source, String deviceName, boolean boot, InitializeParams initializeParams,
+         boolean autoDelete) {
+      return new AutoValue_AttachDisk(type, mode, source, deviceName, boot, initializeParams, autoDelete);
+   }
+
+   AttachDisk() {
+   }
+}
+

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/4e5581f8/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/NewInstance.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/NewInstance.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/NewInstance.java
index c7ccf75..6f59b85 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/NewInstance.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/NewInstance.java
@@ -17,13 +17,11 @@
 package org.jclouds.googlecomputeengine.domain;
 
 import static com.google.common.base.Preconditions.checkArgument;
-import static org.jclouds.googlecomputeengine.domain.Instance.AttachedDisk.Type.PERSISTENT;
 
 import java.net.URI;
 import java.util.Arrays;
 import java.util.List;
 
-import org.jclouds.googlecomputeengine.domain.Instance.AttachedDisk;
 import org.jclouds.googlecomputeengine.domain.Instance.NetworkInterface.AccessConfig;
 import org.jclouds.javax.annotation.Nullable;
 import org.jclouds.json.SerializedNames;
@@ -53,73 +51,13 @@ public abstract class NewInstance {
       }
    }
 
-   @AutoValue
-   public abstract static class Disk {
-      @AutoValue
-      abstract static class InitializeParams {
-         /** Override the default naming convention. */
-         @Nullable public abstract String diskName();
-
-         /** Set to use a size larger than the {@link #sourceImage()}. You need to repartition when set. */
-         @Nullable public abstract Long diskSizeGb();
-
-         /** The {@link org.jclouds.googlecomputeengine.domain.Image#selfLink() source image}. */
-         public abstract URI sourceImage();
-
-         static InitializeParams create(URI sourceImage) {
-            return create(null, null, sourceImage);
-         }
-
-         @SerializedNames({ "diskName", "diskSizeGb", "sourceImage" })
-         static InitializeParams create(String diskName, Long diskSizeGb, URI sourceImage) {
-            return new AutoValue_NewInstance_Disk_InitializeParams(diskName, diskSizeGb, sourceImage);
-         }
-
-         InitializeParams() {
-         }
-      }
-
-      public abstract AttachedDisk.Type type();
-
-      /** Use an existingBootDisk {@link org.jclouds.googlecomputeengine.domain.Disk#selfLink() boot disk}. */
-      @Nullable public abstract URI source();
-
-      /** Set to automatically create a boot disk */
-      @Nullable public abstract InitializeParams initializeParams();
-
-      public abstract boolean boot();
-
-      public abstract boolean autoDelete();
-
-      public static Disk existingBootDisk(URI existingBootDisk) {
-         return create(PERSISTENT, existingBootDisk, null, true, false);
-      }
-
-      public static Disk newBootDisk(URI sourceImage) {
-         return create(PERSISTENT, null, InitializeParams.create(sourceImage), true, true);
-      }
-
-      public static Disk existingDisk(URI existingDisk) {
-         return create(PERSISTENT, existingDisk, null, false, false);
-      }
-
-      @SerializedNames({ "type", "source", "initializeParams", "boot", "autoDelete" })
-      static Disk create(AttachedDisk.Type type, URI source, InitializeParams initializeParams, boolean boot,
-            boolean autoDelete) {
-         return new AutoValue_NewInstance_Disk(type, source, initializeParams, boot, autoDelete);
-      }
-
-      Disk() {
-      }
-   }
-
    public abstract String name();
 
    public abstract URI machineType();
 
    public abstract List<NetworkInterface> networkInterfaces();
 
-   public abstract List<Disk> disks();
+   public abstract List<AttachDisk> disks();
 
    @Nullable public abstract String description();
 
@@ -130,13 +68,13 @@ public abstract class NewInstance {
 
    /** Convenience for creating a new instance with only a boot disk and minimal parameters. */
    public static NewInstance create(String name, URI machineType, URI network, URI sourceImage) {
-      return create(name, machineType, network, Arrays.asList(Disk.newBootDisk(sourceImage)), null);
+      return create(name, machineType, network, Arrays.asList(AttachDisk.newBootDisk(sourceImage)), null);
    }
 
-   public static NewInstance create(String name, URI machineType, URI network, List<Disk> disks, String description) {
+   public static NewInstance create(String name, URI machineType, URI network, List<AttachDisk> disks, String description) {
       checkArgument(disks.get(0).boot(), "disk 0 must be a boot disk! %s", disks);
       boolean foundBoot = false;
-      for (Disk disk : disks) {
+      for (AttachDisk disk : disks) {
          if (disk.boot()) {
             checkArgument(!foundBoot, "There must be only one boot disk! %s", disks);
             foundBoot = true;
@@ -148,7 +86,7 @@ public abstract class NewInstance {
 
    @SerializedNames({ "name", "machineType", "networkInterfaces", "disks", "description", "tags", "metadata" })
    static NewInstance create(String name, URI machineType, List<NetworkInterface> networkInterfaces,
-         List<Disk> disks, String description, Tags tags, Metadata metadata) {
+         List<AttachDisk> disks, String description, Tags tags, Metadata metadata) {
       return new AutoValue_NewInstance(name, machineType, networkInterfaces, disks, description, tags, metadata);
    }
 

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/4e5581f8/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/InstanceApi.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/InstanceApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/InstanceApi.java
index 09ffcdf..6599de9 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/InstanceApi.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/InstanceApi.java
@@ -36,12 +36,12 @@ import javax.ws.rs.QueryParam;
 import org.jclouds.Fallbacks.NullOnNotFoundOr404;
 import org.jclouds.googlecloud.domain.ListPage;
 import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
+import org.jclouds.googlecomputeengine.domain.AttachDisk;
 import org.jclouds.googlecomputeengine.domain.Instance;
 import org.jclouds.googlecomputeengine.domain.Metadata;
 import org.jclouds.googlecomputeengine.domain.NewInstance;
 import org.jclouds.googlecomputeengine.domain.Operation;
 import org.jclouds.googlecomputeengine.internal.BaseCallerArg0ToIteratorOfListPage;
-import org.jclouds.googlecomputeengine.options.AttachDiskOptions;
 import org.jclouds.googlecomputeengine.options.ListOptions;
 import org.jclouds.javax.annotation.Nullable;
 import org.jclouds.oauth.v2.filters.OAuthAuthenticationFilter;
@@ -107,7 +107,7 @@ public interface InstanceApi {
                                   @BinderParam(BindToJsonPayload.class)
                                   AccessConfig accessConfig,
                                   @QueryParam("network_interface") String networkInterfaceName);
-  
+
    /**
     * Deletes an access config from an instance's network interface.
     *
@@ -161,7 +161,7 @@ public interface InstanceApi {
    @Produces(APPLICATION_JSON)
    @Path("/{instance}/attachDisk")
    Operation attachDisk(@PathParam("instance") String instance,
-                        @BinderParam(BindToJsonPayload.class) AttachDiskOptions attachDiskOptions);
+                        @BinderParam(BindToJsonPayload.class) AttachDisk attachDiskOptions);
 
    /**
     * Detaches an attached disk from an instance
@@ -219,6 +219,20 @@ public interface InstanceApi {
                      @PayloadParam("fingerprint") String fingerprint);
 
    /**
+    * Sets the auto-delete flag for a disk attached to an instance
+    *
+    * @param instanceName The name of the instance
+    * @param deviceName Disk device name to modify.
+    * @param autoDelete Whether to auto-delete the disk when the instance is deleted
+    */
+   @Named("Instances:setDiskAutoDelete")
+   @POST
+   @Path("/{instance}/setDiskAutoDelete")
+   Operation setDiskAutoDelete(@PathParam("instance") String instanceName,
+                               @QueryParam("deviceName") String deviceName,
+                               @QueryParam("autoDelete") boolean autoDelete);
+
+   /**
     * Retrieves the list of instance resources available to the specified project.
     * By default the list as a maximum size of 100, if no options are provided or ListOptions#getMaxResults() has not
     * been set.
@@ -260,5 +274,6 @@ public interface InstanceApi {
          };
       }
    }
+
 }
 

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/4e5581f8/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/AttachDiskOptions.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/AttachDiskOptions.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/AttachDiskOptions.java
deleted file mode 100644
index 4f85702..0000000
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/AttachDiskOptions.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF 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.googlecomputeengine.options;
-
-import java.net.URI;
-
-/**
- * Options for attaching disks to instances.
- *
- * @see <a href="https://developers.google.com/compute/docs/reference/latest/instances/attachDisk"/>
- */
-public final class AttachDiskOptions {
-
-   public enum DiskType {
-      SCRATCH,
-      PERSISTENT
-   }
-
-   public enum DiskMode {
-      READ_WRITE,
-      READ_ONLY
-   }
-
-   private DiskType type;
-   private DiskMode mode;
-   private URI source;
-   private String deviceName;
-   private boolean boot;
-
-   public DiskType type() {
-      return type;
-   }
-
-   public DiskMode mode() {
-      return mode;
-   }
-
-   /** The URI of the source disk - optional, if DiskType.SCRATCH is used. */
-   public URI source() {
-      return source;
-   }
-
-   /** The device name on the instance - optional. */
-   public String deviceName() {
-      return deviceName;
-   }
-
-   /** True if this is a boot disk. VM will use the first partition of the disk for its root filesystem. */
-   public boolean boot() {
-      return boot;
-   }
-
-   /**
-    * @see AttachDiskOptions#type()
-    */
-   public AttachDiskOptions type(DiskType type) {
-      this.type = type;
-      return this;
-   }
-
-   /**
-    * @see AttachDiskOptions#mode()
-    */
-   public AttachDiskOptions mode(DiskMode mode) {
-      this.mode = mode;
-      return this;
-   }
-
-   /**
-    * @see AttachDiskOptions#source()
-    */
-   public AttachDiskOptions source(URI source) {
-      this.source = source;
-      return this;
-   }
-
-   /**
-    * @see AttachDiskOptions#deviceName()
-    */
-   public AttachDiskOptions deviceName(String deviceName) {
-      this.deviceName = deviceName;
-      return this;
-   }
-
-   /**
-    * @see AttachDiskOptions#boot()
-    */
-   public AttachDiskOptions boot(boolean boot) {
-      this.boot = boot;
-      return this;
-   }
-}

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/4e5581f8/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiExpectTest.java
index ce353e3..1896892 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiExpectTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiExpectTest.java
@@ -30,11 +30,8 @@ import javax.ws.rs.core.MediaType;
 import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
 import org.jclouds.googlecomputeengine.domain.Metadata;
 import org.jclouds.googlecomputeengine.domain.NewInstance;
-import org.jclouds.googlecomputeengine.domain.NewInstance.Disk;
+import org.jclouds.googlecomputeengine.domain.AttachDisk;
 import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineExpectTest;
-import org.jclouds.googlecomputeengine.options.AttachDiskOptions;
-import org.jclouds.googlecomputeengine.options.AttachDiskOptions.DiskMode;
-import org.jclouds.googlecomputeengine.options.AttachDiskOptions.DiskType;
 import org.jclouds.googlecomputeengine.parse.ParseInstanceListTest;
 import org.jclouds.googlecomputeengine.parse.ParseInstanceSerialOutputTest;
 import org.jclouds.googlecomputeengine.parse.ParseInstanceTest;
@@ -158,7 +155,7 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineExpectTest<Goo
             "test-1", // name
             URI.create(BASE_URL + "/party/zones/us-central1-a/machineTypes/n1-standard-1"), // machineType
             URI.create(BASE_URL + "/party/global/networks/default"), // network
-            Arrays.asList(Disk.existingBootDisk(URI.create(BASE_URL + "/party/zones/us-central1-a/disks/test"))),
+            Arrays.asList(AttachDisk.existingBootDisk(URI.create(BASE_URL + "/party/zones/us-central1-a/disks/test"))),
             "desc" // description
       );
 
@@ -348,10 +345,13 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineExpectTest<Goo
               TOKEN_RESPONSE, attach, attachResponse).instancesInZone("us-central1-a");
 
       assertEquals(api.attachDisk("test-1",
-              new AttachDiskOptions()
-                      .mode(DiskMode.READ_ONLY)
-                      .source(URI.create(BASE_URL + "/party/zones/us-central1-a/disks/testimage1"))
-                      .type(DiskType.PERSISTENT)),
+              AttachDisk.create(AttachDisk.Type.PERSISTENT,
+                                       AttachDisk.Mode.READ_ONLY,
+                                       URI.create(BASE_URL + "/party/zones/us-central1-a/disks/testimage1"),
+                                       null,
+                                       false,
+                                       null,
+                                       true)),
               new ParseZoneOperationTest().expected());
    }
 
@@ -371,12 +371,9 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineExpectTest<Goo
       InstanceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
               TOKEN_RESPONSE, attach, attachResponse).instancesInZone("us-central1-a");
 
-      api.attachDisk("test-1",
-              new AttachDiskOptions()
-                      .mode(DiskMode.READ_ONLY)
-                      .source(URI.create(BASE_URL + "/party/zones/us-central1-a/disks/testimage1"))
-                      .type(DiskType.PERSISTENT));
-
+      api.attachDisk("test-1", AttachDisk.create(AttachDisk.Type.PERSISTENT, AttachDisk.Mode.READ_ONLY,
+                                                        URI.create(BASE_URL + "/party/zones/us-central1-a/disks/testimage1"),
+                                                        null, false, null, true));
    }
 
    public void testDetachDiskResponseIs2xx() {
@@ -416,4 +413,26 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineExpectTest<Goo
       api.detachDisk("test-1", "test-disk-1");
    }
 
+   @Test(expectedExceptions = ResourceNotFoundException.class)
+   public void testSetDiskAutoDeleteResponseIs4xx() {
+      HttpRequest setTrue = HttpRequest
+            .builder()
+            .method("POST")
+            .endpoint("https://www.googleapis" +
+                    ".com/compute/v1/projects/party/zones/us-central1-a/instances/test-1/setDiskAutoDelete" +
+                    "?deviceName=test-disk-1&autoDelete=true")
+            .addHeader("Accept", "application/json")
+            .addHeader("Authorization", "Bearer " + TOKEN)
+            .build();
+
+      HttpResponse setTrueResponse = HttpResponse.builder().statusCode(404).build();
+
+      InstanceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
+              TOKEN_RESPONSE, setTrue, setTrueResponse).instancesInZone("us-central1-a");
+
+      api.setDiskAutoDelete("test-1", "test-disk-1", true);
+   }
+
 }
+
+

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/4e5581f8/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java
index 2c3e832..fe671d6 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java
@@ -34,12 +34,9 @@ import org.jclouds.googlecomputeengine.domain.Instance;
 import org.jclouds.googlecomputeengine.domain.Instance.AttachedDisk;
 import org.jclouds.googlecomputeengine.domain.Metadata;
 import org.jclouds.googlecomputeengine.domain.NewInstance;
-import org.jclouds.googlecomputeengine.domain.NewInstance.Disk;
+import org.jclouds.googlecomputeengine.domain.AttachDisk;
 import org.jclouds.googlecomputeengine.domain.Operation;
 import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
-import org.jclouds.googlecomputeengine.options.AttachDiskOptions;
-import org.jclouds.googlecomputeengine.options.AttachDiskOptions.DiskMode;
-import org.jclouds.googlecomputeengine.options.AttachDiskOptions.DiskType;
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.Test;
 
@@ -53,7 +50,7 @@ import com.google.inject.Module;
 public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
 
    private static final String INSTANCE_NETWORK_NAME = "instance-api-live-test-network";
-   private static final String INSTANCE_NAME = "test-1";
+   private static final String INSTANCE_NAME = "instance-api-test-instance-1";
    private static final String DISK_NAME = "instance-live-test-disk";
    private static final String IPV4_RANGE = "10.0.0.0/8";
    private static final String METADATA_ITEM_KEY = "instanceLiveTestTestProp";
@@ -63,6 +60,8 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
    private static final String ATTACH_DISK_DEVICE_NAME = "attach-disk-1";
    private static final int DEFAULT_DISK_SIZE_GB = 10;
 
+   private static final String DEFAULT_BOOT_DISK_NAME = "persistent-disk-0";
+
    private NewInstance instance;
 
    @Override
@@ -85,7 +84,8 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
             INSTANCE_NAME, // name
             getDefaultMachineTypeUrl(), // machineType
             getNetworkUrl(INSTANCE_NETWORK_NAME), // network
-            Arrays.asList(Disk.newBootDisk(imageUri), Disk.existingDisk(getDiskUrl(DISK_NAME))), // disks
+            Arrays.asList(AttachDisk.newBootDisk(imageUri),
+                  AttachDisk.existingDisk(getDiskUrl(DISK_NAME))), // disks
             "a description" // description
       );
       instance.tags().items().addAll(Arrays.asList("foo", "bar"));
@@ -107,7 +107,7 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
       assertOperationDoneSuccessfully(api.networks().createInIPv4Range
               (INSTANCE_NETWORK_NAME, IPV4_RANGE));
 
-      assertOperationDoneSuccessfully(diskApi().create("instance-live-test-disk", DEFAULT_DISK_SIZE_GB));
+      assertOperationDoneSuccessfully(diskApi().create(DISK_NAME, DEFAULT_DISK_SIZE_GB));
       assertOperationDoneSuccessfully(api().create(instance));
    }
 
@@ -118,6 +118,35 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
       assertInstanceEquals(instance, this.instance);
    }
 
+   @Test(groups = "live", dependsOnMethods = "testInsertInstance")
+   public void testSetDiskAutoDelete(){
+
+      assertTrue(existsDiskWithNameAndAutoDelete(INSTANCE_NAME, DEFAULT_BOOT_DISK_NAME, true));
+
+      Operation o = api().setDiskAutoDelete(INSTANCE_NAME, DEFAULT_BOOT_DISK_NAME, false);
+      assertOperationDoneSuccessfully(o);
+
+      assertTrue(existsDiskWithNameAndAutoDelete(INSTANCE_NAME, DEFAULT_BOOT_DISK_NAME, false));
+
+      o = api().setDiskAutoDelete(INSTANCE_NAME, DEFAULT_BOOT_DISK_NAME, true);
+
+      assertOperationDoneSuccessfully(o);
+      assertTrue(existsDiskWithNameAndAutoDelete(INSTANCE_NAME, DEFAULT_BOOT_DISK_NAME, true));
+   }
+
+   private boolean existsDiskWithNameAndAutoDelete(String instanceName, final String diskName, final boolean autoDelete){
+      Instance revertedInstance = api().get(instanceName);
+
+      return Iterables.any(revertedInstance.disks(), new Predicate<AttachedDisk>() {
+         @Override
+         public boolean apply(AttachedDisk disk) {
+            return disk.type() == AttachedDisk.Type.PERSISTENT &&
+            diskName.equals(disk.deviceName()) &&
+            disk.autoDelete() == autoDelete;
+         }
+      });
+   }
+
    @Test(groups = "live", dependsOnMethods = "testListInstance")
    public void testSetMetadataForInstance() {
       Instance originalInstance = api().get(INSTANCE_NAME);
@@ -150,9 +179,13 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
 
       Instance originalInstance = api().get(INSTANCE_NAME);
       assertOperationDoneSuccessfully(api().attachDisk(INSTANCE_NAME,
-                  new AttachDiskOptions().type(DiskType.PERSISTENT)
-                        .source(getDiskUrl(ATTACH_DISK_NAME)).mode(DiskMode.READ_ONLY)
-                        .deviceName(ATTACH_DISK_DEVICE_NAME)));
+                  AttachDisk.create(AttachDisk.Type.PERSISTENT,
+                                    AttachDisk.Mode.READ_ONLY,
+                                    getDiskUrl(ATTACH_DISK_NAME),
+                                    ATTACH_DISK_DEVICE_NAME,
+                                    false,
+                                    null,
+                                    false)));
 
       Instance modifiedInstance = api().get(INSTANCE_NAME);
 
@@ -167,7 +200,7 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
       }));
    }
 
-   @Test(groups = "live", dependsOnMethods = "testAttachDiskToInstance")
+   @Test(groups = "live", dependsOnMethods = "testAttachDiskToInstance", alwaysRun = true)
    public void testDetachDiskFromInstance() {
       Instance originalInstance = api().get(INSTANCE_NAME);
       assertOperationDoneSuccessfully(api().detachDisk(INSTANCE_NAME, ATTACH_DISK_DEVICE_NAME));
@@ -196,7 +229,7 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
       assertOperationDoneSuccessfully(api().reset(INSTANCE_NAME));
    }
 
-   @Test(groups = "live", dependsOnMethods = "testResetInstance")
+   @Test(groups = "live", dependsOnMethods = {"testSetDiskAutoDelete", "testResetInstance"}, alwaysRun = true)
    public void testDeleteInstance() {
       assertOperationDoneSuccessfully(api().delete(INSTANCE_NAME));
       assertOperationDoneSuccessfully(diskApi().delete(DISK_NAME));

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/4e5581f8/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiMockTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiMockTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiMockTest.java
new file mode 100644
index 0000000..369bced
--- /dev/null
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiMockTest.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.googlecomputeengine.features;
+
+import static org.testng.Assert.assertEquals;
+
+import org.jclouds.googlecomputeengine.domain.Operation;
+import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiMockTest;
+import org.jclouds.googlecomputeengine.parse.ParseZoneOperationTest;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "InstanceApiMockTest", singleThreaded = true)
+public class InstanceApiMockTest extends BaseGoogleComputeEngineApiMockTest {
+
+   public void setDiskAutoDeleteResponseIs2xx() throws Exception {
+      server.enqueue(jsonResponse("/zone_operation.json"));
+
+      InstanceApi instanceApi = api().instancesInZone("us-central1-a");
+
+      Operation o = instanceApi.setDiskAutoDelete("test-1", "test-disk-1", true);
+      int port = server.getPort();
+      // Endpoint is different for URIs such as zone and selfLink.
+      assertEquals(o, new ParseZoneOperationTest().expected("http://localhost:" + port + "/projects"));
+
+      assertSent(server, "POST", "/projects/party/zones/us-central1-a/instances/test-1/setDiskAutoDelete"
+          + "?deviceName=test-disk-1&autoDelete=true");
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/4e5581f8/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseZoneOperationTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseZoneOperationTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseZoneOperationTest.java
index 5856687..0c47de8 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseZoneOperationTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseZoneOperationTest.java
@@ -36,12 +36,17 @@ public class ParseZoneOperationTest extends BaseGoogleComputeEngineParseTest<Ope
 
    @Override @Consumes(APPLICATION_JSON)
    public Operation expected() {
+      return expected(BASE_URL);
+   }
+
+   @Consumes(APPLICATION_JSON)
+   public Operation expected(String baseUrl) {
       return Operation.create( //
             "13053095055850848306", // id
-            URI.create(BASE_URL + "/party/zones/us-central1-a/operations/operation-1354084865060"),
+            URI.create(baseUrl + "/party/zones/us-central1-a/operations/operation-1354084865060"),
             "operation-1354084865060", // name
             null, // description
-            URI.create(BASE_URL + "/party/zones/us-central1-a/instances/test-1"),
+            URI.create(baseUrl + "/party/zones/us-central1-a/instances/test-1"),
             "13053094017547040099", // targetId
             null, // clientOperationId
             Operation.Status.DONE, // status
@@ -56,7 +61,7 @@ public class ParseZoneOperationTest extends BaseGoogleComputeEngineParseTest<Ope
             "insert", // operationType
             null, // errors
             null, // region
-            URI.create(BASE_URL + "/party/zones/us-central1-a") // zone
+            URI.create(baseUrl + "/party/zones/us-central1-a") // zone
       );
    }
 }

http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/4e5581f8/google-compute-engine/src/test/resources/instance_attach_disk.json
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/resources/instance_attach_disk.json b/google-compute-engine/src/test/resources/instance_attach_disk.json
index dc6c707..add9ab9 100644
--- a/google-compute-engine/src/test/resources/instance_attach_disk.json
+++ b/google-compute-engine/src/test/resources/instance_attach_disk.json
@@ -2,5 +2,6 @@
     "type": "PERSISTENT",
     "mode": "READ_ONLY",
     "source": "https://www.googleapis.com/compute/v1/projects/party/zones/us-central1-a/disks/testimage1",
-    "boot": false
+    "boot": false,
+    "autoDelete": true
 }
\ No newline at end of file