You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by na...@apache.org on 2019/09/18 14:37:07 UTC

[jclouds] branch 2.1.x updated: Add OS disk type in template options (#46)

This is an automated email from the ASF dual-hosted git repository.

nacx pushed a commit to branch 2.1.x
in repository https://gitbox.apache.org/repos/asf/jclouds.git


The following commit(s) were added to refs/heads/2.1.x by this push:
     new 8cac891  Add OS disk type in template options (#46)
8cac891 is described below

commit 8cac891d01fad0fed24b0816156f93eec9889bb8
Author: Simone Locci <si...@cloudesire.com>
AuthorDate: Wed Sep 18 16:34:34 2019 +0200

    Add OS disk type in template options (#46)
    
    * Add OS disk type in template options
    
    * Fix review and code style
---
 .../arm/compute/AzureComputeServiceAdapter.java    | 12 ++++++-----
 .../arm/compute/options/AzureTemplateOptions.java  | 24 ++++++++++++++++++++--
 2 files changed, 29 insertions(+), 7 deletions(-)

diff --git a/providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/AzureComputeServiceAdapter.java b/providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/AzureComputeServiceAdapter.java
index 7b766d7..6a21609 100644
--- a/providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/AzureComputeServiceAdapter.java
+++ b/providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/AzureComputeServiceAdapter.java
@@ -155,7 +155,7 @@ public class AzureComputeServiceAdapter implements ComputeServiceAdapter<Virtual
       IdReference availabilitySet = getAvailabilitySetIdReference(templateOptions.getAvailabilitySet());
       NetworkProfile networkProfile = createNetworkProfile(createNetworkInterfaceCards(name, locationName,
             templateOptions));
-      StorageProfile storageProfile = createStorageProfile(image, templateOptions.getDataDisks());
+      StorageProfile storageProfile = createStorageProfile(image, templateOptions);
       HardwareProfile hardwareProfile = HardwareProfile.builder().vmSize(hardwareId).build();
       OSProfile osProfile = createOsProfile(name, template);
       
@@ -515,8 +515,10 @@ public class AzureComputeServiceAdapter implements ComputeServiceAdapter<Virtual
       return ip;
    }
 
-   private StorageProfile createStorageProfile(Image image, List<DataDisk> dataDisks) {
-      return StorageProfile.create(createImageReference(image), createOSDisk(image), dataDisks);
+   private StorageProfile createStorageProfile(Image image, AzureTemplateOptions templateOptions) {
+      List<DataDisk> dataDisks = templateOptions.getDataDisks();
+      StorageAccountType osDiskStorageType = templateOptions.getOsDiskStorageType();
+      return StorageProfile.create(createImageReference(image), createOSDisk(image, osDiskStorageType), dataDisks);
    }
 
    private ImageReference createImageReference(Image image) {
@@ -525,14 +527,14 @@ public class AzureComputeServiceAdapter implements ComputeServiceAdapter<Virtual
             .version("latest").build();
    }
 
-   private OSDisk createOSDisk(Image image) {
+   private OSDisk createOSDisk(Image image, StorageAccountType osDiskStorageType) {
       OsFamily osFamily = image.getOperatingSystem().getFamily();
       String osType = osFamily == OsFamily.WINDOWS ? "Windows" : "Linux";
       return OSDisk.builder()
               .osType(osType)
               .caching(DataDisk.CachingTypes.READ_WRITE.toString())
               .createOption(CreationData.CreateOptions.FROM_IMAGE.toString())
-              .managedDiskParameters(ManagedDiskParameters.create(null, StorageAccountType.STANDARD_LRS.toString()))
+              .managedDiskParameters(ManagedDiskParameters.create(null, osDiskStorageType.toString()))
               .build();
    }
    
diff --git a/providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/options/AzureTemplateOptions.java b/providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/options/AzureTemplateOptions.java
index b551811..e6c3a03 100644
--- a/providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/options/AzureTemplateOptions.java
+++ b/providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/options/AzureTemplateOptions.java
@@ -24,6 +24,7 @@ import org.jclouds.azurecompute.arm.domain.AvailabilitySet;
 import org.jclouds.azurecompute.arm.domain.DataDisk;
 import org.jclouds.azurecompute.arm.domain.OSProfile.WindowsConfiguration;
 import org.jclouds.azurecompute.arm.domain.Secrets;
+import org.jclouds.azurecompute.arm.domain.StorageAccountType;
 import org.jclouds.compute.options.TemplateOptions;
 
 import com.google.common.base.MoreObjects;
@@ -43,6 +44,7 @@ public class AzureTemplateOptions extends TemplateOptions implements Cloneable {
    private WindowsConfiguration windowsConfiguration;
    private List<Secrets> secrets = ImmutableList.of();
    private String customData;
+   private StorageAccountType osDiskStorageType = StorageAccountType.STANDARD_LRS;
 
    /**
     * Sets the availability set where the nodes will be configured. If it does
@@ -138,6 +140,11 @@ public class AzureTemplateOptions extends TemplateOptions implements Cloneable {
       return this;
    }
 
+   public AzureTemplateOptions osDiskStorageType(StorageAccountType osDiskStorageType) {
+      this.osDiskStorageType = osDiskStorageType;
+      return this;
+   }
+
    public AvailabilitySet getAvailabilitySet() {
       return availabilitySet;
    }
@@ -170,6 +177,10 @@ public class AzureTemplateOptions extends TemplateOptions implements Cloneable {
       return customData;
    }
 
+   public StorageAccountType getOsDiskStorageType() {
+      return osDiskStorageType;
+   }
+
    @Override
    public AzureTemplateOptions clone() {
       AzureTemplateOptions options = new AzureTemplateOptions();
@@ -190,6 +201,7 @@ public class AzureTemplateOptions extends TemplateOptions implements Cloneable {
          eTo.windowsConfiguration(windowsConfiguration);
          eTo.secrets(secrets);
          eTo.customData(customData);
+         eTo.osDiskStorageType(osDiskStorageType);
       }
    }
 
@@ -306,7 +318,7 @@ public class AzureTemplateOptions extends TemplateOptions implements Cloneable {
       }
 
       /**
-       * @see AzureTemplateOptions#secrets(List)
+       * @see AzureTemplateOptions#secrets(Iterable)
        */
       public static AzureTemplateOptions secrets(Iterable<? extends Secrets> secrets) {
          AzureTemplateOptions options = new AzureTemplateOptions();
@@ -314,11 +326,19 @@ public class AzureTemplateOptions extends TemplateOptions implements Cloneable {
       }
 
       /**
-       * @see AzureTemplateOptions#customData
+       * @see AzureTemplateOptions#customData(String)
        */
       public static AzureTemplateOptions customData(String customData) {
          AzureTemplateOptions options = new AzureTemplateOptions();
          return options.customData(customData);
       }
+
+      /**
+       * @see AzureTemplateOptions#osDiskStorageType(StorageAccountType)
+       */
+      public static AzureTemplateOptions osDiskStorageType(StorageAccountType osDiskStorageType) {
+         AzureTemplateOptions options = new AzureTemplateOptions();
+         return options.osDiskStorageType(osDiskStorageType);
+      }
    }
 }