http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/2f110387/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/SubnetApi.java
----------------------------------------------------------------------
diff --git 
a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/SubnetApi.java
 
b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/SubnetApi.java
index 1ac38d8..8f30d6c 100644
--- 
a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/SubnetApi.java
+++ 
b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/SubnetApi.java
@@ -16,20 +16,7 @@
  */
 package org.jclouds.azurecompute.arm.features;
 
-import org.jclouds.Fallbacks.EmptyListOnNotFoundOr404;
-import org.jclouds.Fallbacks.NullOnNotFoundOr404;
-import org.jclouds.azurecompute.arm.domain.Subnet;
-import org.jclouds.azurecompute.arm.functions.FalseOn204;
-import org.jclouds.oauth.v2.filters.OAuthFilter;
-import org.jclouds.rest.binders.BindToJsonPayload;
-
-import org.jclouds.rest.annotations.Fallback;
-import org.jclouds.rest.annotations.QueryParams;
-import org.jclouds.rest.annotations.RequestFilters;
-import org.jclouds.rest.annotations.SelectJson;
-import org.jclouds.rest.annotations.ResponseParser;
-import org.jclouds.rest.annotations.PayloadParam;
-import org.jclouds.rest.annotations.MapBinder;
+import java.util.List;
 
 import javax.inject.Named;
 import javax.ws.rs.Consumes;
@@ -39,12 +26,24 @@ import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.core.MediaType;
-import java.util.List;
+
+import org.jclouds.Fallbacks.EmptyListOnNotFoundOr404;
+import org.jclouds.Fallbacks.NullOnNotFoundOr404;
+import org.jclouds.azurecompute.arm.domain.Subnet;
+import org.jclouds.azurecompute.arm.filters.ApiVersionFilter;
+import org.jclouds.azurecompute.arm.functions.FalseOn204;
+import org.jclouds.oauth.v2.filters.OAuthFilter;
+import org.jclouds.rest.annotations.Fallback;
+import org.jclouds.rest.annotations.MapBinder;
+import org.jclouds.rest.annotations.PayloadParam;
+import org.jclouds.rest.annotations.RequestFilters;
+import org.jclouds.rest.annotations.ResponseParser;
+import org.jclouds.rest.annotations.SelectJson;
+import org.jclouds.rest.binders.BindToJsonPayload;
 
 
@Path("/resourcegroups/{resourcegroup}/providers/Microsoft.Network/virtualNetworks/{virtualnetwork}/subnets")
 
-@QueryParams(keys = "api-version", values = "2015-06-15")
-@RequestFilters(OAuthFilter.class)
+@RequestFilters({ OAuthFilter.class, ApiVersionFilter.class })
 @Consumes(MediaType.APPLICATION_JSON)
 public interface SubnetApi {
 

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/2f110387/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/VMSizeApi.java
----------------------------------------------------------------------
diff --git 
a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/VMSizeApi.java
 
b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/VMSizeApi.java
index 345e08c..b5917ce 100644
--- 
a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/VMSizeApi.java
+++ 
b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/VMSizeApi.java
@@ -16,24 +16,24 @@
  */
 package org.jclouds.azurecompute.arm.features;
 
-import org.jclouds.Fallbacks.EmptyListOnNotFoundOr404;
-import org.jclouds.azurecompute.arm.domain.VMSize;
-import org.jclouds.oauth.v2.filters.OAuthFilter;
-import org.jclouds.rest.annotations.Fallback;
-import org.jclouds.rest.annotations.QueryParams;
-import org.jclouds.rest.annotations.RequestFilters;
-import org.jclouds.rest.annotations.SelectJson;
+import java.util.List;
 
 import javax.inject.Named;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.core.MediaType;
-import java.util.List;
+
+import org.jclouds.Fallbacks.EmptyListOnNotFoundOr404;
+import org.jclouds.azurecompute.arm.domain.VMSize;
+import org.jclouds.azurecompute.arm.filters.ApiVersionFilter;
+import org.jclouds.oauth.v2.filters.OAuthFilter;
+import org.jclouds.rest.annotations.Fallback;
+import org.jclouds.rest.annotations.RequestFilters;
+import org.jclouds.rest.annotations.SelectJson;
 
 @Path("/providers/Microsoft.Compute/locations/{location}/vmSizes")
-@QueryParams(keys = "api-version", values = "2015-06-15")
-@RequestFilters(OAuthFilter.class)
+@RequestFilters({ OAuthFilter.class, ApiVersionFilter.class })
 @Consumes(MediaType.APPLICATION_JSON)
 public interface VMSizeApi {
 

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/2f110387/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/VirtualMachineApi.java
----------------------------------------------------------------------
diff --git 
a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/VirtualMachineApi.java
 
b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/VirtualMachineApi.java
index 14f3c70..2dd6d34 100644
--- 
a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/VirtualMachineApi.java
+++ 
b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/VirtualMachineApi.java
@@ -16,10 +16,25 @@
  */
 package org.jclouds.azurecompute.arm.features;
 
+import java.net.URI;
+import java.util.List;
+
+import javax.inject.Named;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
 import org.jclouds.Fallbacks;
 import org.jclouds.azurecompute.arm.domain.VirtualMachine;
 import org.jclouds.azurecompute.arm.domain.VirtualMachineInstance;
 import org.jclouds.azurecompute.arm.domain.VirtualMachineProperties;
+import org.jclouds.azurecompute.arm.filters.ApiVersionFilter;
 import org.jclouds.azurecompute.arm.functions.URIParser;
 import org.jclouds.oauth.v2.filters.OAuthFilter;
 import org.jclouds.rest.annotations.Fallback;
@@ -32,27 +47,13 @@ import org.jclouds.rest.annotations.ResponseParser;
 import org.jclouds.rest.annotations.SelectJson;
 import org.jclouds.rest.binders.BindToJsonPayload;
 
-import javax.inject.Named;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-import java.net.URI;
-import java.util.List;
-
 /**
  * The Virtual Machine API includes operations for managing the virtual 
machines in your subscription.
  *
  * @see <a 
href="https://msdn.microsoft.com/en-us/library/azure/mt163630.aspx";>docs</a>
  */
 
@Path("/resourceGroups/{resourceGroup}/providers/Microsoft.Compute/virtualMachines")
-@RequestFilters(OAuthFilter.class)
-@QueryParams(keys = "api-version", values = "2015-06-15")
+@RequestFilters({ OAuthFilter.class, ApiVersionFilter.class })
 @Consumes(MediaType.APPLICATION_JSON)
 public interface VirtualMachineApi {
 
@@ -66,14 +67,14 @@ public interface VirtualMachineApi {
    VirtualMachine get(@PathParam("name") String name);
 
    /**
-    * The Get Virtual Machine details
+    * Get information about the model view and instance view of a virtual 
machine:
     */
    @Named("GetVirtualMachineInstance")
    @GET
    @Path("/{name}/instanceView")
    @Fallback(Fallbacks.NullOnNotFoundOr404.class)
    VirtualMachineInstance getInstanceDetails(@PathParam("name") String name);
-
+   
    /**
     * The Create Virtual Machine
     */

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/2f110387/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/VirtualNetworkApi.java
----------------------------------------------------------------------
diff --git 
a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/VirtualNetworkApi.java
 
b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/VirtualNetworkApi.java
index 0acbdee..1e657f3 100644
--- 
a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/VirtualNetworkApi.java
+++ 
b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/VirtualNetworkApi.java
@@ -15,22 +15,7 @@
  * limitations under the License.
  */
 package org.jclouds.azurecompute.arm.features;
-import org.jclouds.Fallbacks.EmptyListOnNotFoundOr404;
-import org.jclouds.Fallbacks.NullOnNotFoundOr404;
-
-import org.jclouds.azurecompute.arm.domain.VirtualNetwork;
-
-import org.jclouds.azurecompute.arm.functions.FalseOn204;
-import org.jclouds.oauth.v2.filters.OAuthFilter;
-
-import org.jclouds.rest.annotations.Fallback;
-import org.jclouds.rest.annotations.QueryParams;
-import org.jclouds.rest.annotations.RequestFilters;
-import org.jclouds.rest.annotations.SelectJson;
-import org.jclouds.rest.annotations.ResponseParser;
-import org.jclouds.rest.annotations.PayloadParam;
-import org.jclouds.rest.annotations.MapBinder;
-import org.jclouds.rest.binders.BindToJsonPayload;
+import java.util.List;
 
 import javax.inject.Named;
 import javax.ws.rs.Consumes;
@@ -40,11 +25,23 @@ import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.core.MediaType;
-import java.util.List;
+
+import org.jclouds.Fallbacks.EmptyListOnNotFoundOr404;
+import org.jclouds.Fallbacks.NullOnNotFoundOr404;
+import org.jclouds.azurecompute.arm.domain.VirtualNetwork;
+import org.jclouds.azurecompute.arm.filters.ApiVersionFilter;
+import org.jclouds.azurecompute.arm.functions.FalseOn204;
+import org.jclouds.oauth.v2.filters.OAuthFilter;
+import org.jclouds.rest.annotations.Fallback;
+import org.jclouds.rest.annotations.MapBinder;
+import org.jclouds.rest.annotations.PayloadParam;
+import org.jclouds.rest.annotations.RequestFilters;
+import org.jclouds.rest.annotations.ResponseParser;
+import org.jclouds.rest.annotations.SelectJson;
+import org.jclouds.rest.binders.BindToJsonPayload;
 
 
@Path("/resourcegroups/{resourcegroup}/providers/Microsoft.Network/virtualNetworks")
-@QueryParams(keys = "api-version", values = "2015-06-15")
-@RequestFilters(OAuthFilter.class)
+@RequestFilters({ OAuthFilter.class, ApiVersionFilter.class })
 @Consumes(MediaType.APPLICATION_JSON)
 public interface VirtualNetworkApi {
 

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/2f110387/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/filters/ApiVersionFilter.java
----------------------------------------------------------------------
diff --git 
a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/filters/ApiVersionFilter.java
 
b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/filters/ApiVersionFilter.java
new file mode 100644
index 0000000..904c2e8
--- /dev/null
+++ 
b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/filters/ApiVersionFilter.java
@@ -0,0 +1,90 @@
+/*
+ * 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.azurecompute.arm.filters;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static 
org.jclouds.azurecompute.arm.config.AzureComputeProperties.API_VERSION_PREFIX;
+import static org.jclouds.util.Maps2.transformKeys;
+import static org.jclouds.util.Predicates2.startsWith;
+
+import java.util.Map;
+
+import javax.inject.Inject;
+
+import org.jclouds.http.HttpException;
+import org.jclouds.http.HttpRequest;
+import org.jclouds.http.HttpRequestFilter;
+import org.jclouds.rest.config.InvocationConfig;
+import org.jclouds.rest.internal.GeneratedHttpRequest;
+
+import com.google.common.base.Function;
+import com.google.common.base.Predicate;
+import com.google.common.reflect.Invokable;
+
+/**
+ * Allow users to customize the api versions for each method call.
+ * <p>
+ * In Azure ARM, each method may have its own api version. This filter allows 
to
+ * configure the versions of each method, so there is no need to change the 
code
+ * when Azure deprecates old versions.
+ */
+public class ApiVersionFilter implements HttpRequestFilter {
+
+   private final InvocationConfig config;
+   private final Map<String, String> versions;
+
+   @Inject
+   ApiVersionFilter(InvocationConfig config, Function<Predicate<String>, 
Map<String, String>> filterStringsBoundByName) {
+      this.config = config;
+      this.versions = versions(filterStringsBoundByName);
+   }
+
+   @Override
+   public HttpRequest filter(HttpRequest request) throws HttpException {
+      checkArgument(request instanceof GeneratedHttpRequest,
+            "This filter can only be applied to GeneratedHttpRequest objects");
+      GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request;
+
+      // Look if there is a custom api version for the current method
+      String commandName = 
config.getCommandName(generatedRequest.getInvocation());
+      String customApiVersion = versions.get(commandName);
+
+      if (customApiVersion == null) {
+         // No custom config for the specific method. Let's look for custom
+         // config for the class
+         Invokable<?, ?> invoked = 
generatedRequest.getInvocation().getInvokable();
+         String className = 
invoked.getOwnerType().getRawType().getSimpleName();
+         customApiVersion = versions.get(className);
+      }
+
+      if (customApiVersion != null) {
+         return request.toBuilder().replaceQueryParam("api-version", 
customApiVersion).build();
+      }
+
+      return request;
+   }
+
+   private static Map<String, String> versions(Function<Predicate<String>, 
Map<String, String>> filterStringsBoundByName) {
+      Map<String, String> stringBoundWithApiVersionPrefix = 
filterStringsBoundByName
+            .apply(startsWith(API_VERSION_PREFIX));
+      return transformKeys(stringBoundWithApiVersionPrefix, new 
Function<String, String>() {
+         public String apply(String input) {
+            return input.replaceFirst(API_VERSION_PREFIX, "");
+         }
+      });
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/2f110387/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/functions/CleanupResources.java
----------------------------------------------------------------------
diff --git 
a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/functions/CleanupResources.java
 
b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/functions/CleanupResources.java
index 6970887..39cc32c 100644
--- 
a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/functions/CleanupResources.java
+++ 
b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/functions/CleanupResources.java
@@ -14,127 +14,163 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package  org.jclouds.azurecompute.arm.functions;
+package org.jclouds.azurecompute.arm.functions;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Predicates.notNull;
+import static com.google.common.collect.Iterables.filter;
+import static com.google.common.collect.Iterables.transform;
 import static 
org.jclouds.azurecompute.arm.config.AzureComputeProperties.TIMEOUT_RESOURCE_DELETED;
-import static 
org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_TERMINATED;
+import static org.jclouds.util.Closeables2.closeQuietly;
+
+import java.net.URI;
+import java.util.List;
+import java.util.Map;
 
 import javax.annotation.Resource;
 import javax.inject.Inject;
 import javax.inject.Named;
 import javax.inject.Singleton;
 
-import com.google.common.base.Predicate;
 import org.jclouds.azurecompute.arm.AzureComputeApi;
-import 
org.jclouds.azurecompute.arm.compute.config.AzureComputeServiceContextModule;
-import org.jclouds.azurecompute.arm.domain.Deployment;
+import org.jclouds.azurecompute.arm.domain.IdReference;
+import org.jclouds.azurecompute.arm.domain.IpConfiguration;
 import org.jclouds.azurecompute.arm.domain.NetworkInterfaceCard;
-import org.jclouds.azurecompute.arm.domain.NetworkSecurityGroup;
-import org.jclouds.azurecompute.arm.domain.PublicIPAddress;
+import org.jclouds.azurecompute.arm.domain.ResourceGroup;
+import org.jclouds.azurecompute.arm.domain.StorageServiceKeys;
 import org.jclouds.azurecompute.arm.domain.VirtualMachine;
+import org.jclouds.azurecompute.arm.util.BlobHelper;
 import org.jclouds.compute.reference.ComputeServiceConstants;
 import org.jclouds.logging.Logger;
 
 import com.google.common.base.Function;
-
-import java.net.URI;
+import com.google.common.base.Predicate;
+import com.google.common.base.Splitter;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
 
 @Singleton
 public class CleanupResources implements Function<String, Boolean> {
 
-   private final AzureComputeServiceContextModule.AzureComputeConstants 
azureComputeConstants;
    @Resource
    @Named(ComputeServiceConstants.COMPUTE_LOGGER)
    protected Logger logger = Logger.NULL;
 
    protected final AzureComputeApi api;
-   private Predicate<URI> nodeTerminated;
-   private Predicate<URI> resourceDeleted;
+   private final Predicate<URI> resourceDeleted;
+   private final StorageProfileToStorageAccountName 
storageProfileToStorageAccountName;
 
    @Inject
-   public CleanupResources(AzureComputeApi azureComputeApi,
-                           
AzureComputeServiceContextModule.AzureComputeConstants azureComputeConstants,
-                           @Named(TIMEOUT_NODE_TERMINATED) Predicate<URI> 
nodeTerminated,
-                           @Named(TIMEOUT_RESOURCE_DELETED) Predicate<URI> 
resourceDeleted) {
-      this.azureComputeConstants = azureComputeConstants;
+   CleanupResources(AzureComputeApi azureComputeApi, 
@Named(TIMEOUT_RESOURCE_DELETED) Predicate<URI> resourceDeleted,
+         StorageProfileToStorageAccountName 
storageProfileToStorageAccountName) {
       this.api = azureComputeApi;
-      this.nodeTerminated = nodeTerminated;
       this.resourceDeleted = resourceDeleted;
+      this.storageProfileToStorageAccountName = 
storageProfileToStorageAccountName;
    }
 
    @Override
-   public Boolean apply(String id) {
-
-      logger.debug("Destroying %s ...", id);
-      String storageAccountName = id.replaceAll("[^A-Za-z0-9 ]", "") + "stor";
-      String group = azureComputeConstants.azureResourceGroup();
-
-      VirtualMachine vm = api.getVirtualMachineApi(group).get(id);
-      if (vm != null) {
-         URI uri = api.getVirtualMachineApi(group).delete(id);
-         if (uri != null) {
-            boolean jobDone = nodeTerminated.apply(uri);
-            boolean storageAcctDeleteStatus = false;
-            boolean deploymentDeleteStatus = false;
-
-            if (jobDone) {
-               Deployment deployment = api.getDeploymentApi(group).get(id);
-               if (deployment != null) {
-                  uri = api.getDeploymentApi(group).delete(id);
-                  jobDone = resourceDeleted.apply(uri);
-                  if (jobDone) {
-                     deploymentDeleteStatus = true;
-                  }
-               } else {
-                  deploymentDeleteStatus = true;
+   public Boolean apply(final String id) {
+      logger.debug(">> destroying %s ...", id);
+
+      Map<String, VirtualMachine> resourceGroupNamesAndVirtualMachines = 
getResourceGroupNamesAndVirtualMachines(id);
+      if (resourceGroupNamesAndVirtualMachines.isEmpty())
+         return true;
+
+      String group = 
checkNotNull(resourceGroupNamesAndVirtualMachines.entrySet().iterator().next().getKey(),
+            "resourceGroup name must not be null");
+      VirtualMachine virtualMachine = 
checkNotNull(resourceGroupNamesAndVirtualMachines.get(group),
+            "virtualMachine must not be null");
+
+      boolean vmDeleted = deleteVirtualMachine(group, virtualMachine);
+      
+      // We don't delete the network here, as it is global to the resource
+      // group. It will be deleted when the resource group is deleted
+
+      for (String nicName : getNetworkCardInterfaceNames(virtualMachine)) {
+         NetworkInterfaceCard nic = 
api.getNetworkInterfaceCardApi(group).get(nicName);
+         Iterable<String> publicIps = getPublicIps(group, nic);
+
+         logger.debug(">> destroying nic %s...", nicName);
+         URI nicDeletionURI = 
api.getNetworkInterfaceCardApi(group).delete(nicName);
+         resourceDeleted.apply(nicDeletionURI);
+
+         for (String publicIp : publicIps) {
+            logger.debug(">> deleting public ip nic %s...", publicIp);
+            api.getPublicIPAddressApi(group).delete(publicIp);
+         }
+      }
+
+      String storageAccountName = 
storageProfileToStorageAccountName.apply(virtualMachine.properties().storageProfile());
+      StorageServiceKeys keys = 
api.getStorageAccountApi(group).getKeys(storageAccountName);
+
+      // Remove the virtual machine files
+      logger.debug(">> deleting virtual machine disk storage...");
+      BlobHelper blobHelper = new BlobHelper(storageAccountName, keys.key1());
+      try {
+         blobHelper.deleteContainerIfExists("vhds");
+
+         if (!blobHelper.customImageExists()) {
+            logger.debug(">> deleting storage account %s...", 
storageAccountName);
+            api.getStorageAccountApi(group).delete(storageAccountName);
+         } else {
+            logger.debug(">> the storage account contains custom images. Will 
not delete it!");
+         }
+      } finally {
+         closeQuietly(blobHelper);
+      }
+
+      deleteResourceGroupIfEmpty(group);
+
+      return vmDeleted;
+   }
+
+   public void deleteResourceGroupIfEmpty(String group) {
+      if (api.getVirtualMachineApi(group).list().isEmpty() 
+            && api.getStorageAccountApi(group).list().isEmpty()
+            && api.getNetworkInterfaceCardApi(group).list().isEmpty()
+            && api.getPublicIPAddressApi(group).list().isEmpty()) {
+         logger.debug(">> the resource group %s is empty. Deleting...", group);
+         resourceDeleted.apply(api.getResourceGroupApi().delete(group));
+      }
+   }
+
+   private Iterable<String> getPublicIps(String group, NetworkInterfaceCard 
nic) {
+      return transform(
+            filter(transform(nic.properties().ipConfigurations(), new 
Function<IpConfiguration, IdReference>() {
+               @Override
+               public IdReference apply(IpConfiguration input) {
+                  return input.properties().publicIPAddress();
                }
-               NetworkInterfaceCard nic = 
api.getNetworkInterfaceCardApi(group).get(id + "nic");
-               if (nic != null) {
-                  uri = api.getNetworkInterfaceCardApi(group).delete(id + 
"nic");
-                  if (uri != null) {
-                     jobDone = resourceDeleted.apply(uri);
-                     if (jobDone) {
-                        boolean ipDeleteStatus = false;
-                        PublicIPAddress ip = 
api.getPublicIPAddressApi(group).get(id + "publicip");
-                        if (ip != null) {
-                           ipDeleteStatus = 
api.getPublicIPAddressApi(group).delete(id + "publicip");
-                        } else {
-                           ipDeleteStatus = true;
-                        }
-
-                        // Get NSG
-                        boolean nsgDeleteStatus = false;
-                        NetworkSecurityGroup nsg = 
api.getNetworkSecurityGroupApi(group).get(id + "nsg");
-                        if (nsg != null) {
-                           uri = 
api.getNetworkSecurityGroupApi(group).delete(id + "nsg");
-                           jobDone = resourceDeleted.apply(uri);
-                           if (jobDone) {
-                              nsgDeleteStatus = true;
-
-                           }
-                        }
-                        else {
-                           nsgDeleteStatus = true;
-                        }
-
-                        return deploymentDeleteStatus && 
storageAcctDeleteStatus && ipDeleteStatus && nsgDeleteStatus;
-                     } else {
-                        return false;
-                     }
-                  } else {
-                     return false;
-                  }
-               } else {
-                  return false;
+            }), notNull()), new Function<IdReference, String>() {
+               @Override
+               public String apply(IdReference input) {
+                  return Iterables.getLast(Splitter.on("/").split(input.id()));
                }
-            } else {
-               return false;
-            }
-         } else {
-            return false;
+            });
+   }
+
+   private List<String> getNetworkCardInterfaceNames(VirtualMachine 
virtualMachine) {
+      List<String> nics = Lists.newArrayList();
+      for (IdReference idReference : 
virtualMachine.properties().networkProfile().networkInterfaces()) {
+         nics.add(Iterables.getLast(Splitter.on("/").split(idReference.id())));
+      }
+      return nics;
+   }
+
+   private boolean deleteVirtualMachine(String group, VirtualMachine 
virtualMachine) {
+      return 
resourceDeleted.apply(api.getVirtualMachineApi(group).delete(virtualMachine.name()));
+   }
+
+   private Map<String, VirtualMachine> 
getResourceGroupNamesAndVirtualMachines(String id) {
+      for (ResourceGroup resourceGroup : api.getResourceGroupApi().list()) {
+         String group = resourceGroup.name();
+         VirtualMachine virtualMachine = 
api.getVirtualMachineApi(group).get(id);
+         if (virtualMachine != null) {
+            return ImmutableMap.of(group, virtualMachine);
          }
-      } else {
-         return false;
       }
+      return Maps.newHashMap();
    }
 }

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/2f110387/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/functions/StorageProfileToStorageAccountName.java
----------------------------------------------------------------------
diff --git 
a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/functions/StorageProfileToStorageAccountName.java
 
b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/functions/StorageProfileToStorageAccountName.java
new file mode 100644
index 0000000..f624886
--- /dev/null
+++ 
b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/functions/StorageProfileToStorageAccountName.java
@@ -0,0 +1,38 @@
+/*
+ * 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.azurecompute.arm.functions;
+
+import java.net.URI;
+
+import org.jclouds.azurecompute.arm.domain.StorageProfile;
+
+import com.google.common.base.Function;
+import com.google.common.base.Splitter;
+import com.google.common.collect.Iterables;
+
+/**
+ * Returns the storage account name for a given storage profile.
+ */
+public class StorageProfileToStorageAccountName implements 
Function<StorageProfile, String> {
+
+   @Override
+   public String apply(StorageProfile input) {
+      String storageAccountNameURI = input.osDisk().vhd().uri();
+      return 
Iterables.get(Splitter.on(".").split(URI.create(storageAccountNameURI).getHost()),
 0);
+   }
+
+}

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/2f110387/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/util/BlobHelper.java
----------------------------------------------------------------------
diff --git 
a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/util/BlobHelper.java
 
b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/util/BlobHelper.java
index f5bfc75..b42ea5e 100644
--- 
a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/util/BlobHelper.java
+++ 
b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/util/BlobHelper.java
@@ -16,76 +16,68 @@
  */
 package org.jclouds.azurecompute.arm.util;
 
+import static org.jclouds.util.Closeables2.closeQuietly;
+
+import java.io.Closeable;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
 import org.jclouds.ContextBuilder;
-import org.jclouds.azure.storage.domain.BoundedSet;
 import org.jclouds.azureblob.AzureBlobClient;
 import org.jclouds.azureblob.domain.BlobProperties;
 import org.jclouds.azureblob.domain.ContainerProperties;
 import org.jclouds.azureblob.domain.ListBlobsResponse;
 import org.jclouds.azurecompute.arm.domain.VMImage;
-import org.jclouds.util.Closeables2;
 
-public class BlobHelper {
+public class BlobHelper implements Closeable {
 
-   public static void deleteContainerIfExists(String storage, String key, 
String containerName) {
-      final AzureBlobClient azureBlob = ContextBuilder.newBuilder("azureblob")
-              .credentials(storage, key)
-              .buildApi(AzureBlobClient.class);
+   private final String storageAccount;
+   private final AzureBlobClient azureBlob;
 
-      try {
-         azureBlob.deleteContainer(containerName);
-      }
-      finally {
-         Closeables2.closeQuietly(azureBlob);
-      }
+   public BlobHelper(String storageAccount, String key) {
+      this.storageAccount = storageAccount;
+      this.azureBlob = 
ContextBuilder.newBuilder("azureblob").credentials(storageAccount, key)
+            .buildApi(AzureBlobClient.class);
    }
 
-   public static boolean customImageExists(String storage, String key) {
-      final AzureBlobClient azureBlob = ContextBuilder.newBuilder("azureblob")
-              .credentials(storage, key)
-              .buildApi(AzureBlobClient.class);
+   @Override
+   public void close() throws IOException {
+      closeQuietly(azureBlob);
+   }
 
-      try {
-         return azureBlob.containerExists("system");
-      }
-      finally {
-         Closeables2.closeQuietly(azureBlob);
-      }
+   public void deleteContainerIfExists(String containerName) {
+      azureBlob.deleteContainer(containerName);
    }
 
-   public static List<VMImage> getImages(String containerName, String group,
-                                         String storageAccountName, String 
key, String offer, String location) {
-      final AzureBlobClient azureBlob = ContextBuilder.newBuilder("azureblob")
-              .credentials(storageAccountName, key)
-              .buildApi(AzureBlobClient.class);
+   public boolean hasContainers() {
+      return !azureBlob.listContainers().isEmpty();
+   }
 
+   public boolean customImageExists() {
+      return azureBlob.containerExists("system");
+   }
 
+   public List<VMImage> getImages(String containerName, String group, String 
offer, String location) {
       List<VMImage> list = new ArrayList<VMImage>();
-      try {
-         BoundedSet<ContainerProperties> containerList = 
azureBlob.listContainers();
-         for (ContainerProperties props : containerList) {
-            if (props.getName().equals("system")) {
-               ListBlobsResponse blobList = azureBlob.listBlobs("system");
-               String osDisk = "";
-               String dataDisk = "";
-
-               for (BlobProperties blob : blobList) {
-                  String name = blob.getName();
-
-                  if (dataDisk.length() == 0) dataDisk = name.substring(1 + 
name.lastIndexOf('/'));
-                  else if (osDisk.length() == 0) osDisk = name.substring(1 + 
name.lastIndexOf('/'));
-               }
-               final VMImage ref = VMImage.create(group, storageAccountName, 
osDisk, dataDisk, "test-create-image", "custom", location);
-               list.add(ref);
+
+      ContainerProperties systemContainer = 
azureBlob.getContainerProperties("system");
+      if (systemContainer != null) {
+         ListBlobsResponse blobList = 
azureBlob.listBlobs(systemContainer.getName());
+         for (BlobProperties blob : blobList) {
+            String name = blob.getName();
+
+            if (name.contains("-osDisk")) {
+               String imageName = name.substring(name.lastIndexOf('/') + 1, 
name.indexOf("-osDisk"));
+               String imageUrl = blob.getUrl().toString();
+
+               
list.add(VMImage.customImage().group(group).storage(storageAccount).vhd1(imageUrl).name(imageName)
+                     .offer(offer).location(location).build());
             }
          }
       }
-      finally {
-         Closeables2.closeQuietly(azureBlob);
-      }
+
       return list;
    }
+
 }

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/2f110387/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/util/DeploymentTemplateBuilder.java
----------------------------------------------------------------------
diff --git 
a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/util/DeploymentTemplateBuilder.java
 
b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/util/DeploymentTemplateBuilder.java
deleted file mode 100644
index e5b0a43..0000000
--- 
a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/util/DeploymentTemplateBuilder.java
+++ /dev/null
@@ -1,573 +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.azurecompute.arm.util;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-import 
org.jclouds.azurecompute.arm.compute.config.AzureComputeServiceContextModule;
-import 
org.jclouds.azurecompute.arm.compute.extensions.AzureComputeImageExtension;
-import org.jclouds.azurecompute.arm.compute.options.AzureTemplateOptions;
-import org.jclouds.azurecompute.arm.domain.DataDisk;
-import org.jclouds.azurecompute.arm.domain.DeploymentBody;
-import org.jclouds.azurecompute.arm.domain.DeploymentProperties;
-import org.jclouds.azurecompute.arm.domain.DeploymentTemplate;
-import org.jclouds.azurecompute.arm.domain.DiagnosticsProfile;
-import org.jclouds.azurecompute.arm.domain.DnsSettings;
-import org.jclouds.azurecompute.arm.domain.HardwareProfile;
-import org.jclouds.azurecompute.arm.domain.IdReference;
-import org.jclouds.azurecompute.arm.domain.ImageReference;
-import org.jclouds.azurecompute.arm.domain.IpConfiguration;
-import org.jclouds.azurecompute.arm.domain.IpConfigurationProperties;
-import org.jclouds.azurecompute.arm.domain.KeyVaultReference;
-import org.jclouds.azurecompute.arm.domain.NetworkInterfaceCardProperties;
-import org.jclouds.azurecompute.arm.domain.NetworkProfile;
-import org.jclouds.azurecompute.arm.domain.NetworkSecurityGroupProperties;
-import org.jclouds.azurecompute.arm.domain.NetworkSecurityRule;
-import org.jclouds.azurecompute.arm.domain.NetworkSecurityRuleProperties;
-import org.jclouds.azurecompute.arm.domain.OSDisk;
-import org.jclouds.azurecompute.arm.domain.OSProfile;
-import org.jclouds.azurecompute.arm.domain.PublicIPAddressProperties;
-import org.jclouds.azurecompute.arm.domain.ResourceDefinition;
-import org.jclouds.azurecompute.arm.domain.StorageProfile;
-import org.jclouds.azurecompute.arm.domain.StorageService;
-import 
org.jclouds.azurecompute.arm.domain.StorageService.StorageServiceProperties;
-import org.jclouds.azurecompute.arm.domain.TemplateParameterType;
-import org.jclouds.azurecompute.arm.domain.VHD;
-import org.jclouds.azurecompute.arm.domain.VirtualMachineProperties;
-import org.jclouds.compute.domain.Template;
-import org.jclouds.json.Json;
-import org.jclouds.predicates.Validator;
-import org.jclouds.predicates.validators.DnsNameValidator;
-
-import com.google.common.base.Joiner;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
-import com.google.common.collect.Lists;
-import com.google.inject.Inject;
-import com.google.inject.assistedinject.Assisted;
-
-import static com.google.common.io.BaseEncoding.base64;
-import static 
org.jclouds.azurecompute.arm.compute.extensions.AzureComputeImageExtension.CUSTOM_IMAGE_PREFIX;
-import static 
org.jclouds.azurecompute.arm.config.AzureComputeProperties.STORAGE_API_VERSION;
-
-public class DeploymentTemplateBuilder {
-   public interface Factory {
-      DeploymentTemplateBuilder create(@Assisted("group") String group, 
@Assisted("name") String name, Template template);
-   }
-
-   private final String name;
-   private final String azureGroup;
-   private final String group;
-   private final Template template;
-   private final Json json;
-
-   private AzureTemplateOptions options;
-   private Iterable<String> tags;
-   private Map<String, String> userMetaData;
-   private List<ResourceDefinition> resources;
-   private Map<String, String> variables;
-   private static String loginUser;
-   private static String loginPassword;
-   private String location;
-   private AzureComputeServiceContextModule.AzureComputeConstants 
azureComputeConstants;
-
-   private static final String DEPLOYMENT_MODE = "Incremental";
-
-   @Inject
-   DeploymentTemplateBuilder(Json json, @Assisted("group") String group, 
@Assisted("name") String name, @Assisted Template template,
-                             final 
AzureComputeServiceContextModule.AzureComputeConstants azureComputeConstants) {
-      this.name = name;
-      this.group = group;
-      this.template = template;
-      this.options = template.getOptions().as(AzureTemplateOptions.class);
-      this.tags = template.getOptions().getTags();
-      this.userMetaData = template.getOptions().getUserMetadata();
-      this.variables = new HashMap<String, String>();
-      this.resources = new ArrayList<ResourceDefinition>();
-      this.location = template.getLocation().getId();
-      this.json = json;
-
-      this.azureComputeConstants = azureComputeConstants;
-      this.azureGroup = this.azureComputeConstants.azureResourceGroup();
-
-      String[] defaultLogin = 
this.azureComputeConstants.azureDefaultImageLogin().split(":");
-      String defaultUser = null;
-      String defaultPassword = null;
-
-      if (defaultLogin.length == 2) {
-         defaultUser = defaultLogin[0].trim();
-         defaultPassword = defaultLogin[1].trim();
-      }
-
-      loginUser = options.getLoginUser() == null ? defaultUser : 
options.getLoginUser();
-      loginPassword = options.getLoginPassword() == null ? defaultPassword : 
options.getLoginPassword();
-   }
-
-   public static String getLoginUserUsername() {
-      return loginUser;
-   }
-
-   public static String getLoginPassword() {
-      return loginPassword;
-   }
-
-   public Template getTemplate() {
-      return template;
-   }
-
-   public DeploymentBody getDeploymentTemplate() {
-
-      addStorageResource();
-      addPublicIpAddress();
-      addNetworkSecurityGroup();
-      addNetworkInterfaceCard();
-      addVirtualMachine();
-
-
-      DeploymentTemplate.TemplateParameters templateParameters = null;
-      DeploymentTemplate.Parameters parameters = null;
-
-      if (keyVaultInUse()){
-         String[] keyVaultInfo = options.getKeyVaultIdAndSecret().split(":");
-         Preconditions.checkArgument(keyVaultInfo.length == 2);
-         String vaultId = keyVaultInfo[0].trim();
-         String secretName = keyVaultInfo[1].trim();
-
-         templateParameters = 
DeploymentTemplate.TemplateParameters.create(TemplateParameterType.create("securestring"));
-         parameters = 
DeploymentTemplate.Parameters.create(KeyVaultReference.create(KeyVaultReference.Reference.create(IdReference.create(vaultId),
 secretName)));
-      } else {
-         templateParameters = 
DeploymentTemplate.TemplateParameters.create(null);
-         parameters = DeploymentTemplate.Parameters.create(null);
-      }
-
-
-      DeploymentTemplate template = DeploymentTemplate.builder()
-              
.schema("https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#";)
-              .contentVersion("1.0.0.0")
-              .resources(resources)
-              .variables(variables)
-              .parameters(templateParameters)
-              .build();
-
-      DeploymentBody body = DeploymentBody.create(template, DEPLOYMENT_MODE, 
parameters);
-
-      return body;
-   }
-
-   public String getDeploymentTemplateJson(DeploymentProperties properties) {
-      return json.toJson(properties);
-   }
-
-   private void addStorageResource() {
-      String storageAccountName = null;
-
-      String imageName = template.getImage().getName();
-      if (imageName.startsWith(CUSTOM_IMAGE_PREFIX)) {
-         storageAccountName = template.getImage().getVersion();
-      }
-
-      if (Strings.isNullOrEmpty(storageAccountName)) {
-         storageAccountName = generateStorageAccountName(name);
-      }
-
-      Validator<String> validator = new DnsNameValidator(3, 24);
-      validator.validate(storageAccountName);
-
-      variables.put("storageAccountName", storageAccountName);
-
-      ResourceDefinition storageAccount = ResourceDefinition.builder()
-              .name("[variables('storageAccountName')]")
-              .type("Microsoft.Storage/storageAccounts")
-              .location(location)
-              .apiVersion(STORAGE_API_VERSION)
-              .properties(
-                      StorageServiceProperties.builder()
-                              
.accountType(StorageService.AccountType.Standard_LRS)
-                              .build()
-              )
-              .build();
-
-      resources.add(storageAccount);
-   }
-
-   private void addPublicIpAddress() {
-      String publicIPAddressName = name + "publicip";
-      String dnsLabelPrefix = options.getDNSLabelPrefix();
-
-      PublicIPAddressProperties.Builder properties = 
PublicIPAddressProperties.builder();
-
-      if (!Strings.isNullOrEmpty(dnsLabelPrefix)) {
-         
properties.dnsSettings(DnsSettings.builder().domainNameLabel(dnsLabelPrefix).build());
-         variables.put("dnsLabelPrefix", dnsLabelPrefix);
-      }
-
-      properties.publicIPAllocationMethod("Dynamic");
-      variables.put("publicIPAddressName", publicIPAddressName);
-      variables.put("publicIPAddressReference", 
"[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]");
-
-      ResourceDefinition publicIpAddress = ResourceDefinition.builder()
-              .name("[variables('publicIPAddressName')]")
-              .type("Microsoft.Network/publicIPAddresses")
-              .location(location)
-              .apiVersion(STORAGE_API_VERSION)
-              .properties(properties.build())
-              .build();
-
-      resources.add(publicIpAddress);
-   }
-
-   private void addNetworkInterfaceCard() {
-
-      List<IpConfiguration> ipConfigurations = new 
ArrayList<IpConfiguration>();
-
-      String ipConfigurationName = name + "ipconfig";
-      String subnetId = options.getSubnetId();
-      String vnetName = options.getVirtualNetworkName();
-
-      variables.put("ipConfigurationName", ipConfigurationName);
-      variables.put("subnetReference", subnetId);
-
-      IpConfiguration ipConfig = IpConfiguration.create(ipConfigurationName, 
null, null, null,
-              IpConfigurationProperties.builder()
-                      .privateIPAllocationMethod("Dynamic")
-                      
.publicIPAddress(IdReference.create("[variables('publicIPAddressReference')]"))
-                      
.subnet(IdReference.create("[variables('subnetReference')]"))
-                      .build());
-
-      ipConfigurations.add(ipConfig);
-
-      // Check to see if we have defined a network security group
-      IdReference networkSecurityGroup = null;
-      int ports[] = options.getInboundPorts();
-      if ((ports != null) && (ports.length > 0)) {
-         networkSecurityGroup = 
IdReference.create("[variables('networkSecurityGroupNameReference')]");
-      }
-
-      ArrayList<String> depends = new 
ArrayList<String>(Arrays.asList("[concat('Microsoft.Network/publicIPAddresses/',
 variables('publicIPAddressName'))]"));
-
-      NetworkInterfaceCardProperties.Builder 
networkInterfaceCardPropertiesBuilder = 
NetworkInterfaceCardProperties.builder();
-      networkInterfaceCardPropertiesBuilder.ipConfigurations(ipConfigurations);
-      if (networkSecurityGroup != null) {
-         
networkInterfaceCardPropertiesBuilder.networkSecurityGroup(networkSecurityGroup);
-         depends.add("[concat('Microsoft.Network/networkSecurityGroups/', 
variables('networkSecurityGroupName'))]");
-      }
-      NetworkInterfaceCardProperties networkInterfaceCardProperties = 
networkInterfaceCardPropertiesBuilder.build();
-
-      String networkInterfaceCardName = name + "nic";
-      variables.put("networkInterfaceCardName", networkInterfaceCardName);
-      variables.put("networkInterfaceCardReference", 
"[resourceId('Microsoft.Network/networkInterfaces',variables('networkInterfaceCardName'))]");
-
-      ResourceDefinition networkInterfaceCard = ResourceDefinition.builder()
-              .name("[variables('networkInterfaceCardName')]")
-              .type("Microsoft.Network/networkInterfaces")
-              .location(location)
-              .apiVersion(STORAGE_API_VERSION)
-              .dependsOn(depends)
-              .properties(networkInterfaceCardProperties)
-              .build();
-
-      resources.add(networkInterfaceCard);
-   }
-
-   private void addNetworkSecurityGroup() {
-      int inboundPorts[] = options.getInboundPorts();
-      if ((inboundPorts != null) && (inboundPorts.length > 0)) {
-         variables.put("networkSecurityGroupName", name + "nsg");
-         variables.put("networkSecurityGroupNameReference", 
"[resourceId('Microsoft.Network/networkSecurityGroups',variables('networkSecurityGroupName'))]");
-
-         List<String> portRanges = simplifyPorts(inboundPorts);
-
-         List<NetworkSecurityRule> rules = new 
ArrayList<NetworkSecurityRule>();
-         int priority = 1234;
-         for (String portRange : portRanges) {
-            NetworkSecurityRuleProperties ruleProperties = 
NetworkSecurityRuleProperties.builder()
-                    .description("default-allow-port-" + portRange)
-                    .protocol(NetworkSecurityRuleProperties.Protocol.All)
-                    .access(NetworkSecurityRuleProperties.Access.Allow)
-                    .sourcePortRange("*")
-                    .destinationPortRange(portRange)
-                    .sourceAddressPrefix("*")
-                    .destinationAddressPrefix("*")
-                    .priority(priority)
-                    .direction(NetworkSecurityRuleProperties.Direction.Inbound)
-                    .build();
-
-            NetworkSecurityRule networkSecurityRule = 
NetworkSecurityRule.create(
-                    "default-allow-port-" + portRange,
-                    null,
-                    null,
-                    ruleProperties);
-
-            rules.add(networkSecurityRule);
-            priority++;
-         }
-
-         NetworkSecurityGroupProperties networkSecurityGroupProperties = 
NetworkSecurityGroupProperties.builder()
-                 .securityRules(rules)
-                 .build();
-
-         ResourceDefinition networkSecurityGroup = ResourceDefinition.builder()
-                 .name("[variables('networkSecurityGroupName')]")
-                 
.type("Microsoft.Network/networkSecurityGroups").location(location)
-                 .apiVersion(STORAGE_API_VERSION)
-                 .properties(networkSecurityGroupProperties)
-                 .build();
-         resources.add(networkSecurityGroup);
-      }
-
-   }
-
-   /**
-    * Helper function for simplifying an array of ports to a list of ranges as 
list of strings
-    * @param ports array of int
-    * @return list of strings representing ranges
-    */
-   public static List<String> simplifyPorts(int[] ports) {
-      Preconditions.checkArgument(ports != null && ports.length != 0);
-      ArrayList<String> output = new ArrayList<String>();
-      Arrays.sort(ports);
-
-      int range_start = ports[0];
-      int range_end = ports[0];
-      for (int i = 1; i < ports.length; i++) {
-         if ((ports[i - 1] == ports[i] - 1) || (ports[i - 1] == ports[i])){
-            // Range continues.
-            range_end = ports[i];
-         }
-         else {
-            // Range ends.
-            output.add(formatRange(range_start, range_end));
-            range_start = ports[i];
-            range_end = ports[i];
-         }
-      }
-      // Make sure we get the last range.
-      output.add(formatRange(range_start, range_end));
-      return output;
-   }
-
-   private static String formatRange(int start, int finish) {
-      if (start == finish){
-         return Integer.toString(start);
-      }
-      else {
-         return String.format("%s-%s", Integer.toString(start), 
Integer.toString(finish));
-      }
-   }
-
-   private void addVirtualMachine() {
-      //Build OS Profile
-      final String computerName = name + "pc";
-
-      variables.put("loginUser", loginUser);
-      OSProfile.Builder profileBuilder = OSProfile.builder()
-              .adminUsername(loginUser)
-              .computerName(computerName);
-
-      profileBuilder.adminPassword(loginPassword);
-      //boolean usePublicKey = options.getPublicKey() != null;
-
-      if (keyVaultInUse()) {
-         OSProfile.LinuxConfiguration configuration = 
OSProfile.LinuxConfiguration.create("false",
-                 OSProfile.LinuxConfiguration.SSH.create(Arrays.asList(
-                         OSProfile.LinuxConfiguration.SSH.SSHPublicKey.create(
-                                 
"[concat('/home/',variables('loginUser'),'/.ssh/authorized_keys')]",
-                                 "[parameters('publicKeyFromAzureKeyVault')]"
-                         ))
-                 ));
-         profileBuilder.linuxConfiguration(configuration);
-      }
-
-      if (!Strings.isNullOrEmpty(options.getCustomData())){
-         String encodedCustomData = 
base64().encode(options.getCustomData().getBytes());
-         profileBuilder.customData(encodedCustomData);
-      }
-
-      OSProfile osProfile = profileBuilder.build();
-
-      //Build OsDisk
-      final String storageAccountContainerName = name + "vhds";
-      variables.put("storageAccountContainerName", 
storageAccountContainerName);
-
-      final String osDiskName = name + "osdisk";
-      variables.put("osDiskName", osDiskName);
-
-      boolean usingMarketplaceImage = true;
-      String cusotomImageUri = "";
-
-      // Handle custom image case if description starts with 
CUSTOM_IMAGE_PREFIX
-      String vhd1 = template.getImage().getProviderId();
-      String description = template.getImage().getDescription();
-      if (description.substring(0, 
CUSTOM_IMAGE_PREFIX.length()).equals(CUSTOM_IMAGE_PREFIX)) {
-         String storageName = template.getImage().getVersion();
-         cusotomImageUri = vhd1;
-         cusotomImageUri = "https://"; + storageName + 
".blob.core.windows.net/system/Microsoft.Compute/Images/" + 
AzureComputeImageExtension.CONTAINER_NAME + "/" + cusotomImageUri;
-      }
-
-      if (!cusotomImageUri.isEmpty()) {
-         usingMarketplaceImage = false;
-      }
-
-      OSDisk osDisk = 
getOsDisk("[concat('http://',variables('storageAccountName'),'.blob.core.windows.net/',variables('storageAccountContainerName'),'/',variables('osDiskName'),'.vhd')]",
 cusotomImageUri);
-
-      //Create Data Disk(s) and add to list
-      final String dataDiskName = name + "datadisk";
-      variables.put("dataDiskName", dataDiskName);
-
-      List<DataDisk> dataDisks = new ArrayList<DataDisk>();
-      DataDisk dataDisk = DataDisk.builder()
-              .name("[variables('dataDiskName')]")
-              
.diskSizeGB(azureComputeConstants.azureDefaultDataDiskSizeProperty())
-              .lun(0)
-              .vhd(
-                      
VHD.create("[concat('http://',variables('storageAccountName'),'.blob.core.windows.net/',variables('storageAccountContainerName'),'/',variables('dataDiskName'),'.vhd')]")
-              )
-              .createOption("Empty")
-              .build();
-
-      dataDisks.add(dataDisk);
-
-      //Create Storage Profile
-      StorageProfile.Builder storageProfileBuilder = StorageProfile.builder()
-              .osDisk(osDisk)
-              .dataDisks(dataDisks);
-
-      if (usingMarketplaceImage) {
-         //Build Image Reference if marketplace image is used
-         ImageReference imageReference = 
getImageReference(template.getImage().getProviderId(),
-                 template.getImage().getName(),
-                 template.getImage().getVersion());
-
-         storageProfileBuilder.imageReference(imageReference);
-      }
-      StorageProfile storageProfile = storageProfileBuilder.build();
-
-
-      //Create Network Profile for this VM (links to network interface cards)
-      NetworkProfile networkProfile = NetworkProfile.create(
-              Arrays.asList(
-                      
IdReference.create("[variables('networkInterfaceCardReference')]")
-              ));
-
-      //Boot Diagnostics
-      DiagnosticsProfile diagnosticsProfile = DiagnosticsProfile.create(
-              DiagnosticsProfile.BootDiagnostics.builder()
-                      .enabled(true)
-                      
.storageUri("[concat('http://',variables('storageAccountName'),'.blob.core.windows.net')]")
-                      .build());
-
-      //Build VirtualMachine properties based on above properties.
-      final String vmSize = template.getHardware().getId();
-      HardwareProfile hw = HardwareProfile.create(vmSize);
-
-      VirtualMachineProperties properties = VirtualMachineProperties.builder()
-              .hardwareProfile(hw)
-              .osProfile(osProfile)
-              .storageProfile(storageProfile)
-              .networkProfile(networkProfile)
-              .diagnosticsProfile(diagnosticsProfile)
-              .build();
-
-
-      String tagString = Joiner.on(",").join(Lists.newArrayList(tags));
-      if (tagString.isEmpty())
-         tagString = "jclouds";
-      userMetaData.put("tags", tagString);
-
-      variables.put("virtualMachineName", name);
-      ResourceDefinition virtualMachine = ResourceDefinition.builder()
-              .name("[variables('virtualMachineName')]")
-              .type("Microsoft.Compute/virtualMachines")
-              .location(location)
-              .apiVersion("2015-06-15")
-              
.dependsOn(Arrays.asList("[concat('Microsoft.Storage/storageAccounts/', 
variables('storageAccountName'))]",
-                      "[concat('Microsoft.Network/networkInterfaces/', 
variables('networkInterfaceCardName'))]"))
-              .tags(userMetaData)
-              .properties(properties)
-              .build();
-
-      resources.add(virtualMachine);
-   }
-
-
-   private ImageReference getImageReference(String publisher, String offer, 
String sku) {
-      return ImageReference.builder()
-              .publisher(publisher)
-              .offer(offer)
-              .sku(sku)
-              .version("latest")
-              .build();
-
-   }
-
-   private OSDisk getOsDisk(String vhdUri, String imageUri) {
-      OSDisk.Builder builder = OSDisk.builder();
-      builder.name("[variables('osDiskName')]");
-      builder.caching("ReadWrite");
-      builder.createOption("FromImage");
-      builder.vhd(VHD.create(vhdUri));
-
-      if (!imageUri.isEmpty()) {
-         builder.osType("Linux");
-         builder.image(VHD.create(imageUri));
-      }
-      return builder.build();
-   }
-
-   private boolean keyVaultInUse(){
-      return !Strings.isNullOrEmpty(options.getKeyVaultIdAndSecret());
-   }
-
-   /**
-    * Generates a valid storage account
-    *
-    * Storage account names must be between 3 and 24 characters in length and 
may contain numbers and lowercase letters only.
-    *
-    * @param name the node name
-    * @return the storage account name starting from a sanitized name (with 
only numbers and lowercase letters only ).
-    * If sanitized name is between 3 and 24 characters, storage account name 
is equals to sanitized name.
-    * If sanitized name is less than 3 characters, storage account is 
sanitized name plus 4 random chars.
-    * If sanitized name is more than 24 characters, storage account is first 
10 chars of sanitized name plus 4 random chars plus last 10 chars of sanitized 
name.
-    */
-   private static String generateStorageAccountName(String name) {
-      String storageAccountName = name.replaceAll("[^a-z0-9]", "");
-      int nameLength = storageAccountName.length();
-      if (nameLength >= 3 && nameLength <= 24) {
-         return storageAccountName;
-      }
-
-      String random = UUID.randomUUID().toString().replaceAll("[^a-z0-9]", 
"").substring(0, 4);
-      if (nameLength < 3) {
-         storageAccountName = new 
StringBuilder().append(storageAccountName).append(random).toString();
-      }
-      if (nameLength > 24) {
-         storageAccountName = shorten(storageAccountName, random);
-      }
-      return storageAccountName;
-   }
-
-   private static String shorten(String storageAccountName, String random) {
-      String prefix = storageAccountName.substring(0, 10);
-      String suffix = storageAccountName.substring(storageAccountName.length() 
- 10, storageAccountName.length());
-      return String.format("%s%s%s", prefix, random, suffix);
-   }
-}

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/2f110387/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/util/GetEnumValue.java
----------------------------------------------------------------------
diff --git 
a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/util/GetEnumValue.java
 
b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/util/GetEnumValue.java
index 4a61613..f42bad3 100644
--- 
a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/util/GetEnumValue.java
+++ 
b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/util/GetEnumValue.java
@@ -20,7 +20,6 @@ import java.util.EnumSet;
 
 public class GetEnumValue {
 
-   @SuppressWarnings("unchecked")
    public static <T extends Enum<T>> Enum<T> fromValueOrDefault(String text, 
Enum<T> defaultValue) {
       if (text != null) {
          EnumSet<T> elements = EnumSet.allOf(defaultValue.getDeclaringClass());

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/2f110387/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/compute/AzureComputeServiceLiveTest.java
----------------------------------------------------------------------
diff --git 
a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/compute/AzureComputeServiceLiveTest.java
 
b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/compute/AzureComputeServiceLiveTest.java
index d6fdd3c..c338954 100644
--- 
a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/compute/AzureComputeServiceLiveTest.java
+++ 
b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/compute/AzureComputeServiceLiveTest.java
@@ -16,21 +16,26 @@
  */
 package org.jclouds.azurecompute.arm.compute;
 
-import java.util.Map;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static 
org.jclouds.azurecompute.arm.config.AzureComputeProperties.IMAGE_PUBLISHERS;
+import static 
org.jclouds.azurecompute.arm.config.AzureComputeProperties.RESOURCE_GROUP_NAME;
+import static 
org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_RUNNING;
+import static 
org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_SUSPENDED;
+import static 
org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_TERMINATED;
+import static 
org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_PORT_OPEN;
+import static 
org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_SCRIPT_COMPLETE;
+import static 
org.jclouds.compute.options.TemplateOptions.Builder.authorizePublicKey;
+import static 
org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
+
 import java.util.Properties;
-import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 
 import org.jclouds.azurecompute.arm.AzureComputeProviderMetadata;
 import org.jclouds.azurecompute.arm.internal.AzureLiveTestUtils;
-import org.jclouds.compute.RunScriptOnNodesException;
-import org.jclouds.compute.domain.ExecResponse;
 import org.jclouds.compute.domain.NodeMetadata;
-import org.jclouds.compute.domain.OperatingSystem;
 import org.jclouds.compute.domain.Template;
+import org.jclouds.compute.domain.TemplateBuilder;
 import org.jclouds.compute.internal.BaseComputeServiceLiveTest;
-import org.jclouds.compute.predicates.NodePredicates;
-import org.jclouds.domain.LoginCredentials;
 import org.jclouds.logging.config.LoggingModule;
 import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
 import org.jclouds.providers.ProviderMetadata;
@@ -41,29 +46,18 @@ import 
org.jclouds.scriptbuilder.statements.login.AdminAccess;
 import org.jclouds.sshj.config.SshjSshClientModule;
 import org.testng.annotations.Test;
 
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
 import com.google.inject.Module;
 
-import static com.google.common.base.Preconditions.checkNotNull;
-import static 
org.jclouds.azurecompute.arm.config.AzureComputeProperties.IMAGE_PUBLISHERS;
-import static 
org.jclouds.azurecompute.arm.config.AzureComputeProperties.RESOURCE_GROUP_NAME;
-import static org.jclouds.compute.config.ComputeServiceProperties.TEMPLATE;
-import static 
org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_RUNNING;
-import static 
org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_SUSPENDED;
-import static 
org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_TERMINATED;
-import static 
org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_PORT_OPEN;
-import static 
org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_SCRIPT_COMPLETE;
-
 /**
  * Live tests for the {@link org.jclouds.compute.ComputeService} integration.
  */
 @Test(groups = "live", singleThreaded = true, testName = 
"AzureComputeServiceLiveTest")
 public class AzureComputeServiceLiveTest extends BaseComputeServiceLiveTest {
-   protected int nonBlockDurationSeconds = 30;
-
+   
    public AzureComputeServiceLiveTest() {
       provider = "azurecompute-arm";
-      nonBlockDurationSeconds = 300;
-      group = "az-u";
    }
 
    @Override
@@ -78,21 +72,20 @@ public class AzureComputeServiceLiveTest extends 
BaseComputeServiceLiveTest {
 
    @Override
    protected ProviderMetadata createProviderMetadata() {
-      AzureComputeProviderMetadata pm = 
AzureComputeProviderMetadata.builder().build();
-      return pm;
+      return AzureComputeProviderMetadata.builder().build();
    }
 
    @Override
    protected Properties setupProperties() {
       Properties properties = super.setupProperties();
-      long scriptTimeout = TimeUnit.MILLISECONDS.convert(60, TimeUnit.MINUTES);
-      properties.setProperty(TIMEOUT_SCRIPT_COMPLETE, scriptTimeout + "");
-      properties.setProperty(TIMEOUT_NODE_RUNNING, scriptTimeout + "");
-      properties.setProperty(TIMEOUT_PORT_OPEN, scriptTimeout + "");
-      properties.setProperty(TIMEOUT_NODE_TERMINATED, scriptTimeout + "");
-      properties.setProperty(TIMEOUT_NODE_SUSPENDED, scriptTimeout + "");
-      properties.put(RESOURCE_GROUP_NAME, "a4");
-      properties.put(TEMPLATE, "locationId=westeurope");
+      String defaultTimeout = String.valueOf(TimeUnit.MILLISECONDS.convert(60, 
TimeUnit.MINUTES));
+      properties.setProperty(TIMEOUT_SCRIPT_COMPLETE, defaultTimeout);
+      properties.setProperty(TIMEOUT_NODE_RUNNING, defaultTimeout);
+      properties.setProperty(TIMEOUT_PORT_OPEN, defaultTimeout);
+      properties.setProperty(TIMEOUT_NODE_TERMINATED, defaultTimeout);
+      properties.setProperty(TIMEOUT_NODE_SUSPENDED, defaultTimeout);
+      properties.put(RESOURCE_GROUP_NAME, "jc");
+      properties.put(PROPERTY_REGIONS, "eastus");
       properties.put(IMAGE_PUBLISHERS, "Canonical");
 
       AzureLiveTestUtils.defaultProperties(properties);
@@ -102,24 +95,27 @@ public class AzureComputeServiceLiveTest extends 
BaseComputeServiceLiveTest {
    }
 
    @Override
-   protected Template refreshTemplate() {
-      return this.template = 
addRunScriptToTemplate(this.buildTemplate(this.client.templateBuilder()));
+   protected TemplateBuilder templateBuilder() {
+      return super.templateBuilder().options(
+            
authorizePublicKey(keyPair.get("public")).overrideLoginPrivateKey(keyPair.get("private")));
    }
 
    @Override
    protected Template addRunScriptToTemplate(Template template) {
-      template.getOptions().runScript(Statements.newStatementList(new 
Statement[]{AdminAccess.standard(), Statements.exec("sleep 50"), 
InstallJDK.fromOpenJDK()}));
+      template.getOptions().runScript(
+            Statements.newStatementList(new Statement[] { 
AdminAccess.standard(), Statements.exec("sleep 50"),
+                  InstallJDK.fromOpenJDK() }));
       return template;
    }
-
+   
    @Override
-   @Test( enabled = false)
-   protected void weCanCancelTasks(NodeMetadata node) throws 
InterruptedException, ExecutionException {
-      return;
+   protected void checkUserMetadataContains(NodeMetadata node, 
ImmutableMap<String, String> userMetadata) {
+      // User metadata not yet supported
    }
 
    @Override
-   protected Map<? extends NodeMetadata, ExecResponse> 
runScriptWithCreds(String group, OperatingSystem os, LoginCredentials creds) 
throws RunScriptOnNodesException {
-      return 
this.client.runScriptOnNodesMatching(NodePredicates.runningInGroup(group), 
Statements.newStatementList(Statements.exec("sleep 50"), 
InstallJDK.fromOpenJDK()), 
org.jclouds.compute.options.TemplateOptions.Builder.overrideLoginCredentials(creds).nameTask("runScriptWithCreds"));
+   protected void checkTagsInNodeEquals(NodeMetadata node, 
ImmutableSet<String> tags) {
+      // Tags not yet supported
    }
+
 }

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/2f110387/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/compute/AzureTemplateBuilderLiveTest.java
----------------------------------------------------------------------
diff --git 
a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/compute/AzureTemplateBuilderLiveTest.java
 
b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/compute/AzureTemplateBuilderLiveTest.java
index 8756240..c20655b 100644
--- 
a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/compute/AzureTemplateBuilderLiveTest.java
+++ 
b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/compute/AzureTemplateBuilderLiveTest.java
@@ -16,33 +16,30 @@
  */
 package org.jclouds.azurecompute.arm.compute;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+import static 
org.jclouds.azurecompute.arm.config.AzureComputeProperties.RESOURCE_GROUP_NAME;
+import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+
+import java.io.IOException;
 import java.util.Properties;
 import java.util.Set;
-import java.util.concurrent.TimeUnit;
 
 import org.jclouds.azurecompute.arm.AzureComputeProviderMetadata;
+import org.jclouds.azurecompute.arm.domain.Region;
 import org.jclouds.azurecompute.arm.internal.AzureLiveTestUtils;
+import org.jclouds.compute.domain.OsFamily;
+import org.jclouds.compute.domain.Template;
 import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest;
 import org.jclouds.providers.ProviderMetadata;
 import org.jclouds.sshj.config.SshjSshClientModule;
 import org.testng.annotations.Test;
 
-import com.google.common.collect.ImmutableSet;
 import com.google.inject.Module;
 
-import static com.google.common.base.Preconditions.checkNotNull;
-import static 
org.jclouds.azurecompute.arm.config.AzureComputeProperties.RESOURCE_GROUP_NAME;
-import static 
org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_RUNNING;
-import static 
org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_SCRIPT_COMPLETE;
-
 @Test(groups = "live", testName = "AzureTemplateBuilderLiveTest")
 public class AzureTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
-   public String azureGroup;
-
-   @Override
-   protected Set<String> getIso3166Codes() {
-      return ImmutableSet.of("US-IA", "US-VA", "US-IL", "US-TX", "US-CA", 
"IE", "NL", "HK", "SG", "JP-11", "JP-27", "BR", "AU-NSW", "AU-VIC", "IN-GA", 
"IN-TN", "IN-MH", "CN-SH", "CN-BJ", "CA-ON", "CA-QC");
-   }
 
    public AzureTemplateBuilderLiveTest() {
       provider = "azurecompute-arm";
@@ -55,23 +52,33 @@ public class AzureTemplateBuilderLiveTest extends 
BaseTemplateBuilderLiveTest {
 
    @Override
    protected ProviderMetadata createProviderMetadata() {
-      AzureComputeProviderMetadata pm = 
AzureComputeProviderMetadata.builder().build();
-      return pm;
+      return AzureComputeProviderMetadata.builder().build();
    }
 
    @Override
    protected Properties setupProperties() {
-      azureGroup = "jc" + System.getProperty("user.name").substring(0, 3);
       Properties properties = super.setupProperties();
-      long scriptTimeout = TimeUnit.MILLISECONDS.convert(20, TimeUnit.MINUTES);
-      properties.setProperty(TIMEOUT_SCRIPT_COMPLETE, scriptTimeout + "");
-      properties.setProperty(TIMEOUT_NODE_RUNNING, scriptTimeout + "");
-      properties.put(RESOURCE_GROUP_NAME, azureGroup);
+      properties.put(RESOURCE_GROUP_NAME, "jc");
 
       AzureLiveTestUtils.defaultProperties(properties);
       checkNotNull(setIfTestSystemPropertyPresent(properties, 
"oauth.endpoint"), "test.oauth.endpoint");
 
       return properties;
-
+   }
+   
+   @Override
+   @Test
+   public void testDefaultTemplateBuilder() throws IOException {
+      Template defaultTemplate = 
view.getComputeService().templateBuilder().build();
+      
assertTrue(defaultTemplate.getImage().getOperatingSystem().getVersion().matches("1[45]\\.[01][04]\\.[0-9]-LTS"),
+            "Version mismatch, expected dd.dd.d-LTS, found: " + 
defaultTemplate.getImage().getOperatingSystem().getVersion());
+      assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), 
true);
+      
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), 
OsFamily.UBUNTU);
+      assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
+   }
+   
+   @Override
+   protected Set<String> getIso3166Codes() {
+      return Region.iso3166Codes();
    }
 }

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/2f110387/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/compute/extensions/AzureComputeImageExtensionLiveTest.java
----------------------------------------------------------------------
diff --git 
a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/compute/extensions/AzureComputeImageExtensionLiveTest.java
 
b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/compute/extensions/AzureComputeImageExtensionLiveTest.java
index 06f9ab7..de44668 100644
--- 
a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/compute/extensions/AzureComputeImageExtensionLiveTest.java
+++ 
b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/compute/extensions/AzureComputeImageExtensionLiveTest.java
@@ -16,29 +16,35 @@
  */
 package org.jclouds.azurecompute.arm.compute.extensions;
 
-import com.google.inject.Module;
-import org.jclouds.azurecompute.arm.AzureComputeProviderMetadata;
-import org.jclouds.azurecompute.arm.config.AzureComputeProperties;
-import org.jclouds.azurecompute.arm.internal.AzureLiveTestUtils;
-import org.jclouds.compute.config.ComputeServiceProperties;
-import org.jclouds.compute.extensions.internal.BaseImageExtensionLiveTest;
-import org.jclouds.providers.ProviderMetadata;
-import org.jclouds.sshj.config.SshjSshClientModule;
-import org.testng.annotations.Test;
-
-import java.util.Properties;
-import java.util.concurrent.TimeUnit;
-
 import static com.google.common.base.Preconditions.checkNotNull;
+import static 
org.jclouds.azurecompute.arm.config.AzureComputeProperties.IMAGE_PUBLISHERS;
 import static 
org.jclouds.azurecompute.arm.config.AzureComputeProperties.RESOURCE_GROUP_NAME;
 import static 
org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_RUNNING;
 import static 
org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_SUSPENDED;
 import static 
org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_TERMINATED;
 import static 
org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_PORT_OPEN;
 import static 
org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_SCRIPT_COMPLETE;
+import static 
org.jclouds.compute.options.TemplateOptions.Builder.authorizePublicKey;
+import static 
org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
+
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.TimeUnit;
+
+import org.jclouds.azurecompute.arm.AzureComputeProviderMetadata;
+import org.jclouds.azurecompute.arm.internal.AzureLiveTestUtils;
+import org.jclouds.compute.ComputeTestUtils;
+import org.jclouds.compute.domain.TemplateBuilder;
+import org.jclouds.compute.extensions.internal.BaseImageExtensionLiveTest;
+import org.jclouds.providers.ProviderMetadata;
+import org.jclouds.sshj.config.SshjSshClientModule;
+import org.testng.annotations.Test;
+
+import com.google.inject.Module;
 
 /**
- * Live tests for the {@link org.jclouds.compute.extensions.ImageExtension} 
integration.
+ * Live tests for the {@link org.jclouds.compute.extensions.ImageExtension}
+ * integration.
  */
 @Test(groups = "live", singleThreaded = true, testName = 
"AzureComputeImageExtensionLiveTest")
 public class AzureComputeImageExtensionLiveTest extends 
BaseImageExtensionLiveTest {
@@ -57,34 +63,33 @@ public class AzureComputeImageExtensionLiveTest extends 
BaseImageExtensionLiveTe
    @Override
    protected Properties setupProperties() {
       Properties properties = super.setupProperties();
-      long scriptTimeout = TimeUnit.MILLISECONDS.convert(60, TimeUnit.MINUTES);
-      properties.setProperty(TIMEOUT_SCRIPT_COMPLETE, scriptTimeout + "");
-      properties.setProperty(TIMEOUT_NODE_RUNNING, scriptTimeout + "");
-      properties.setProperty(TIMEOUT_PORT_OPEN, scriptTimeout + "");
-      properties.setProperty(TIMEOUT_NODE_TERMINATED, scriptTimeout + "");
-      properties.setProperty(TIMEOUT_NODE_SUSPENDED, scriptTimeout + "");
-      properties.put(RESOURCE_GROUP_NAME, "jcloudsgroup");
-
-      properties.put(ComputeServiceProperties.POLL_INITIAL_PERIOD, 1000);
-      properties.put(ComputeServiceProperties.POLL_MAX_PERIOD, 10000);
-      properties.setProperty(AzureComputeProperties.OPERATION_TIMEOUT, 
"46000000");
-      
properties.setProperty(AzureComputeProperties.OPERATION_POLL_INITIAL_PERIOD, 
"5");
-      properties.setProperty(AzureComputeProperties.OPERATION_POLL_MAX_PERIOD, 
"15");
-      properties.setProperty(AzureComputeProperties.TCP_RULE_FORMAT, 
"tcp_%s-%s");
-      properties.setProperty(AzureComputeProperties.TCP_RULE_REGEXP, 
"tcp_\\d{1,5}-\\d{1,5}");
+      String defaultTimeout = String.valueOf(TimeUnit.MILLISECONDS.convert(60, 
TimeUnit.MINUTES));
+      properties.setProperty(TIMEOUT_SCRIPT_COMPLETE, defaultTimeout);
+      properties.setProperty(TIMEOUT_NODE_RUNNING, defaultTimeout);
+      properties.setProperty(TIMEOUT_PORT_OPEN, defaultTimeout);
+      properties.setProperty(TIMEOUT_NODE_TERMINATED, defaultTimeout);
+      properties.setProperty(TIMEOUT_NODE_SUSPENDED, defaultTimeout);
+      properties.put(RESOURCE_GROUP_NAME, "jc");
+      properties.put(PROPERTY_REGIONS, "eastus");
+      properties.put(IMAGE_PUBLISHERS, "Canonical");
 
       AzureLiveTestUtils.defaultProperties(properties);
       checkNotNull(setIfTestSystemPropertyPresent(properties, 
"oauth.endpoint"), "test.oauth.endpoint");
 
       return properties;
-
    }
 
    @Override
    protected ProviderMetadata createProviderMetadata() {
-      AzureComputeProviderMetadata pm = 
AzureComputeProviderMetadata.builder().build();
-      return pm;
+      return AzureComputeProviderMetadata.builder().build();
    }
 
+   @Override
+   public TemplateBuilder getNodeTemplate() {
+      Map<String, String> keyPair = ComputeTestUtils.setupKeyPair();
+      return super.getNodeTemplate().options(
+            authorizePublicKey(keyPair.get("public"))
+            .overrideLoginPrivateKey(keyPair.get("private")));
+   }
 
 }

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/2f110387/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/DeploymentApiLiveTest.java
----------------------------------------------------------------------
diff --git 
a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/DeploymentApiLiveTest.java
 
b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/DeploymentApiLiveTest.java
index 7476828..42116c2 100644
--- 
a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/DeploymentApiLiveTest.java
+++ 
b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/DeploymentApiLiveTest.java
@@ -16,30 +16,19 @@
  */
 package org.jclouds.azurecompute.arm.features;
 
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
 import java.net.URI;
 import java.util.List;
 
 import org.jclouds.azurecompute.arm.compute.options.AzureTemplateOptions;
 import org.jclouds.azurecompute.arm.domain.Deployment;
 import org.jclouds.azurecompute.arm.domain.Deployment.ProvisioningState;
-import org.jclouds.azurecompute.arm.domain.DeploymentBody;
-import org.jclouds.azurecompute.arm.domain.DeploymentProperties;
 import org.jclouds.azurecompute.arm.domain.Subnet;
 import org.jclouds.azurecompute.arm.domain.VirtualNetwork;
 import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiLiveTest;
-import org.jclouds.azurecompute.arm.util.DeploymentTemplateBuilder;
-import org.jclouds.compute.domain.Hardware;
-import org.jclouds.compute.domain.HardwareBuilder;
-import org.jclouds.compute.domain.Image;
-import org.jclouds.compute.domain.ImageBuilder;
-import org.jclouds.compute.domain.OperatingSystem;
-import org.jclouds.compute.domain.OsFamily;
-import org.jclouds.compute.domain.Template;
-import org.jclouds.compute.domain.internal.TemplateImpl;
-import org.jclouds.compute.options.TemplateOptions;
-import org.jclouds.domain.Location;
-import org.jclouds.domain.LocationBuilder;
-import org.jclouds.domain.LocationScope;
 import org.jclouds.util.Predicates2;
 import org.testng.Assert;
 import org.testng.annotations.AfterClass;
@@ -49,10 +38,6 @@ import org.testng.annotations.Test;
 import com.google.common.base.Predicate;
 import com.google.common.net.UrlEscapers;
 
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertNull;
-import static org.testng.Assert.assertTrue;
-
 @Test(testName = "DeploymentApiLiveTest", singleThreaded = true)
 public class DeploymentApiLiveTest extends BaseAzureComputeApiLiveTest {
 
@@ -112,37 +97,6 @@ public class DeploymentApiLiveTest extends 
BaseAzureComputeApiLiveTest {
       return body;
    }
 
-   private Template getTemplate(TemplateOptions options) {
-      Location provider = (new 
LocationBuilder()).scope(LocationScope.PROVIDER).id("azurecompute-arm").description("azurecompute-arm").build();
-      Location region = (new 
LocationBuilder()).scope(LocationScope.REGION).id(LOCATION).description("West 
Europe").parent(provider).build();
-
-      OperatingSystem os = OperatingSystem.builder()
-              .family(OsFamily.UBUNTU)
-              .description("14.04.3-LTS")
-              .is64Bit(true)
-              .build();
-
-      Image image = (new ImageBuilder())
-              .id("UbuntuServer14.04.3-LTS")
-              .providerId("Canonical")
-              .name("UbuntuServer")
-              .description("14.04.3-LTS")
-              .version("14.04.3-LTS")
-              .operatingSystem(os)
-              .status(Image.Status.AVAILABLE)
-              .location(region)
-              .build();
-
-      Hardware hardware = (new HardwareBuilder()).id("Standard_A0").build();
-      return new TemplateImpl(image, hardware, region, options);
-   }
-
-   private DeploymentTemplateBuilder 
getDeploymentTemplateBuilderWithOptions(TemplateOptions options) {
-      Template template = getTemplate(options);
-      DeploymentTemplateBuilder templateBuilder = 
api.deploymentTemplateFactory().create(resourceGroupName, deploymentName, 
template);
-      return templateBuilder;
-   }
-
    @Test
    public void testValidate(){
       Deployment deploymentInvalid = null;
@@ -168,12 +122,40 @@ public class DeploymentApiLiveTest extends 
BaseAzureComputeApiLiveTest {
       AzureTemplateOptions options = new AzureTemplateOptions();
       options.authorizePublicKey(rsakey);
       options.subnetId(subnetId);
-      DeploymentTemplateBuilder templateBuilder = 
getDeploymentTemplateBuilderWithOptions(options);
-      DeploymentBody deploymentTemplateBody = 
templateBuilder.getDeploymentTemplate();
-
-      DeploymentProperties properties = 
DeploymentProperties.create(deploymentTemplateBody);
 
-      String deploymentTemplate = 
templateBuilder.getDeploymentTemplateJson(properties);
+      String deploymentTemplate = "{\n" +
+              "  \"id\": 
\"/subscriptions/04f7ec88-8e28-41ed-8537-5e17766001f5/resourceGroups/jims216group/providers/Microsoft.Resources/deployments/jcdep1458344383064\",\n"
 +
+              "  \"name\": \"jcdep1458344383064\",\n" +
+              "  \"properties\": {\n" +
+              "    \"parameters\": {\n" +
+              "      \"newStorageAccountName\": {\n" +
+              "        \"type\": \"String\",\n" +
+              "        \"value\": \"jcres1458344383064\"\n" +
+              "      },\n" +
+              "      \"storageAccountType\": {\n" +
+              "        \"type\": \"String\",\n" +
+              "        \"value\": \"Standard_LRS\"\n" +
+              "      },\n" +
+              "      \"location\": {\n" +
+              "        \"type\": \"String\",\n" +
+              "        \"value\": \"West US\"\n" +
+              "      }\n" +
+              "    },\n" +
+              "    \"mode\": \"Incremental\",\n" +
+              "    \"provisioningState\": \"Accepted\",\n" +
+              "    \"timestamp\": \"2016-03-18T23:39:47.3048037Z\",\n" +
+              "    \"duration\": \"PT2.4433028S\",\n" +
+              "    \"correlationId\": 
\"8dee9711-8632-4948-9fe6-368bb75e6438\",\n" +
+              "    \"providers\": [{\n" +
+              "      \"namespace\": \"Microsoft.Storage\",\n" +
+              "      \"resourceTypes\": [{\n" +
+              "        \"resourceType\": \"storageAccounts\",\n" +
+              "        \"locations\": [\"westus\"]\n" +
+              "      }]\n" +
+              "    }],\n" +
+              "    \"dependencies\": []\n" +
+              "  }\n" +
+              "}";
       deploymentTemplate = 
UrlEscapers.urlFormParameterEscaper().escape(deploymentTemplate);
 
       Deployment deploymentValid = api().validate(deploymentName, 
deploymentTemplate);

Reply via email to