Add OS disk type in template options (#46)

* Add OS disk type in template options

* Fix review and code style
This commit is contained in:
Simone Locci 2019-09-18 16:34:34 +02:00 committed by Ignasi Barrera
parent 6a076fe0c8
commit fa1962b223
2 changed files with 29 additions and 7 deletions

View File

@ -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();
}

View File

@ -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);
}
}
}