Skip to content

Commit

Permalink
mgmt, compute, support write accelerator (#42796)
Browse files Browse the repository at this point in the history
  • Loading branch information
weidongxu-microsoft authored Nov 27, 2024
1 parent 0e56b30 commit 2e1ac76
Show file tree
Hide file tree
Showing 8 changed files with 260 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
### Features Added

- Supported `capacityReservationGroupId` and `withCapacityReservationGroup` methods for `VirtualMachine`.
- Supported enabling write accelerator for OS disk and data disks in `VirtualMachine` class.

### Breaking Changes

### Bugs Fixed

### Other Changes

## 2.44.0 (2024-10-25)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "java",
"TagPrefix": "java/resourcemanager/azure-resourcemanager-compute",
"Tag": "java/resourcemanager/azure-resourcemanager-compute_4ac5270961"
"Tag": "java/resourcemanager/azure-resourcemanager-compute_83a099fdb2"
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public String diskEncryptionSetId() {
return this.innerModel().managedDisk().diskEncryptionSet().id();
}

@Override
public boolean isWriteAcceleratorEnabled() {
return ResourceManagerUtils.toPrimitiveBoolean(this.innerModel().writeAcceleratorEnabled());
}

@Override
public String id() {
if (this.innerModel().managedDisk() == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,12 @@ public VirtualMachineImpl withDataDiskDefaultDeleteOptions(DeleteOptions deleteO
return this;
}

@Override
public VirtualMachineImpl withDataDiskDefaultWriteAcceleratorEnabled(boolean writeAcceleratorEnabled) {
this.managedDataDisks.setDefaultWriteAcceleratorEnabled(writeAcceleratorEnabled);
return this;
}

@Override
public VirtualMachineImpl withDataDiskDefaultDiskEncryptionSet(String diskEncryptionSetId) {
this.managedDataDisks.setDefaultEncryptionSet(diskEncryptionSetId);
Expand Down Expand Up @@ -962,6 +968,12 @@ public VirtualMachineImpl withOSDiskDeleteOptions(DeleteOptions deleteOptions) {
return this;
}

@Override
public VirtualMachineImpl withOSDiskWriteAcceleratorEnabled(boolean writeAcceleratorEnabled) {
this.innerModel().storageProfile().osDisk().withWriteAcceleratorEnabled(writeAcceleratorEnabled);
return this;
}

@Override
public VirtualMachineImpl withOSDiskDiskEncryptionSet(String diskEncryptionSetId) {
if (this.innerModel().storageProfile().osDisk().managedDisk() == null) {
Expand Down Expand Up @@ -1111,6 +1123,7 @@ public VirtualMachineImpl withNewDataDisk(int sizeInGB, int lun, VirtualMachineD
.withDiskSizeGB(sizeInGB)
.withCaching(options.cachingTypes())
.withDeleteOption(diskDeleteOptionsFromDeleteOptions(options.deleteOptions()))
.withWriteAcceleratorEnabled(options.writeAcceleratorEnabled())
.withManagedDisk(managedDiskParameters));
return this;
}
Expand Down Expand Up @@ -1164,6 +1177,7 @@ public VirtualMachineImpl withExistingDataDisk(Disk disk, int newSizeInGB, int l
.withDiskSizeGB(newSizeInGB)
.withCaching(options.cachingTypes())
.withDeleteOption(diskDeleteOptionsFromDeleteOptions(options.deleteOptions()))
.withWriteAcceleratorEnabled(options.writeAcceleratorEnabled())
.withManagedDisk(managedDiskParameters));
return this;
}
Expand Down Expand Up @@ -1211,6 +1225,7 @@ public VirtualMachineImpl withNewDataDiskFromImage(int imageLun, int newSizeInGB
.withDiskSizeGB(newSizeInGB)
.withCaching(options.cachingTypes())
.withDeleteOption(diskDeleteOptionsFromDeleteOptions(options.deleteOptions()))
.withWriteAcceleratorEnabled(options.writeAcceleratorEnabled())
.withManagedDisk(managedDiskParameters));
return this;
}
Expand Down Expand Up @@ -1666,6 +1681,17 @@ public String osDiskDiskEncryptionSetId() {
return this.storageProfile().osDisk().managedDisk().diskEncryptionSet().id();
}

@Override
public boolean isOsDiskWriteAcceleratorEnabled() {
if (this.storageProfile() == null || this.storageProfile().osDisk() == null) {
// write accelerator should only work for managed disk,
// but for potential future changes we didn't use "isManagedDiskEnabled()" here.
// ref https://learn.microsoft.com/azure/virtual-machines/how-to-enable-write-accelerator
return false;
}
return ResourceManagerUtils.toPrimitiveBoolean(this.storageProfile().osDisk().writeAcceleratorEnabled());
}

@Override
public boolean isOSDiskEphemeral() {
return this.storageProfile().osDisk().diffDiskSettings() != null
Expand Down Expand Up @@ -2900,6 +2926,7 @@ private class ManagedDataDiskCollection {
private CachingTypes defaultCachingType;
private StorageAccountTypes defaultStorageAccountType;
private DiskDeleteOptionTypes defaultDeleteOptions;
private Boolean defaultWriteAcceleratorEnabled;
private DiskEncryptionSetParameters defaultDiskEncryptionSet;

ManagedDataDiskCollection(VirtualMachineImpl vm) {
Expand All @@ -2918,6 +2945,10 @@ void setDefaultStorageAccountType(StorageAccountTypes defaultStorageAccountType)
this.defaultStorageAccountType = defaultStorageAccountType;
}

void setDefaultWriteAcceleratorEnabled(Boolean defaultWriteAcceleratorEnabled) {
this.defaultWriteAcceleratorEnabled = defaultWriteAcceleratorEnabled;
}

void setDefaultEncryptionSet(String diskEncryptionSetId) {
this.defaultDiskEncryptionSet = new DiskEncryptionSetParameters().withId(diskEncryptionSetId);
}
Expand Down Expand Up @@ -2996,6 +3027,7 @@ private void clear() {
defaultStorageAccountType = null;
defaultDeleteOptions = null;
defaultDiskEncryptionSet = null;
defaultWriteAcceleratorEnabled = null;
}

private boolean isPending() {
Expand Down Expand Up @@ -3040,6 +3072,9 @@ private void setAttachableNewDataDisks(Callable<Integer> nextLun) throws Excepti
if (dataDisk.deleteOption() == null) {
dataDisk.withDeleteOption(getDefaultDeleteOptions());
}
if (dataDisk.writeAcceleratorEnabled() == null) {
dataDisk.withWriteAcceleratorEnabled(getDefaultWriteAcceleratorEnabled());
}
setDefaultDiskEncryptionSetOptions(dataDisk);
// Don't set default storage account type for the attachable managed disks, it is already
// defined in the managed disk and not allowed to change.
Expand All @@ -3061,6 +3096,9 @@ private void setAttachableExistingDataDisks(Callable<Integer> nextLun) throws Ex
if (dataDisk.deleteOption() == null) {
dataDisk.withDeleteOption(getDefaultDeleteOptions());
}
if (dataDisk.writeAcceleratorEnabled() == null) {
dataDisk.withWriteAcceleratorEnabled(getDefaultWriteAcceleratorEnabled());
}
setDefaultDiskEncryptionSetOptions(dataDisk);
// Don't set default storage account type for the attachable managed disks, it is already
// defined in the managed disk and not allowed to change.
Expand Down Expand Up @@ -3088,6 +3126,9 @@ private void setImplicitDataDisks(Callable<Integer> nextLun) throws Exception {
if (dataDisk.deleteOption() == null) {
dataDisk.withDeleteOption(getDefaultDeleteOptions());
}
if (dataDisk.writeAcceleratorEnabled() == null) {
dataDisk.withWriteAcceleratorEnabled(getDefaultWriteAcceleratorEnabled());
}
setDefaultDiskEncryptionSetOptions(dataDisk);
dataDisk.withName(null);
dataDisks.add(dataDisk);
Expand All @@ -3104,6 +3145,9 @@ private void setImageBasedDataDisks() {
if (dataDisk.deleteOption() == null) {
dataDisk.withDeleteOption(getDefaultDeleteOptions());
}
if (dataDisk.writeAcceleratorEnabled() == null) {
dataDisk.withWriteAcceleratorEnabled(getDefaultWriteAcceleratorEnabled());
}
setDefaultDiskEncryptionSetOptions(dataDisk);
// Don't set default storage account type for the disk, either user has to specify it explicitly or let
// CRP pick it from the image
Expand Down Expand Up @@ -3144,6 +3188,10 @@ private DiskDeleteOptionTypes getDefaultDeleteOptions() {
return defaultDeleteOptions;
}

private Boolean getDefaultWriteAcceleratorEnabled() {
return defaultWriteAcceleratorEnabled;
}

private DiskEncryptionSetParameters getDefaultDiskEncryptionSetOptions() {
return defaultDiskEncryptionSet;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,13 @@ Mono<RunCommandResult> runShellScriptAsync(List<String> scriptLines,
/** @return resource ID of the disk encryption set of the OS disk */
String osDiskDiskEncryptionSetId();

/**
* Gets whether the write accelerator is enabled.
*
* @return whether the write accelerator is enabled
*/
boolean isOsDiskWriteAcceleratorEnabled();

/** @return whether the os disk is ephemeral*/
boolean isOSDiskEphemeral();

Expand Down Expand Up @@ -1229,6 +1236,18 @@ interface WithOSDiskSettings {
*/
WithCreate withOSDiskDeleteOptions(DeleteOptions deleteOptions);

/**
* Specifies the write accelerator for the OS disks.
* <p>
* Write Accelerator is generally available for M-series VMs in the Public Cloud.
* Enabling write accelerator for the operating system disk of the VM will reboot the VM.
* The Premium disk caching must be set to 'None' or 'Read Only'. All other caching modes are not supported.
*
* @param writeAcceleratorEnabled whether to enable the write accelerator
* @return the next stage of the definition
*/
WithCreate withOSDiskWriteAcceleratorEnabled(boolean writeAcceleratorEnabled);

/**
* Specifies the disk encryption set for the managed OS disk.
*
Expand Down Expand Up @@ -1848,6 +1867,14 @@ interface WithManagedCreate extends WithManagedDataDisk, WithAvailabilityZone, W
*/
WithManagedCreate withDataDiskDefaultDeleteOptions(DeleteOptions deleteOptions);

/**
* Specifies the write accelerator for managed data disks.
*
* @param writeAcceleratorEnabled whether to enable the write accelerator
* @return the next stage of the definition
*/
WithManagedCreate withDataDiskDefaultWriteAcceleratorEnabled(boolean writeAcceleratorEnabled);

/**
* Specifies the disk encryption set for the managed data disk.
*
Expand Down Expand Up @@ -2666,6 +2693,18 @@ interface Update extends Appliable<VirtualMachine>, Resource.UpdateWithTags<Upda
*/
Update withOSDiskEncryptionSettings(DiskEncryptionSettings settings);

/**
* Specifies the write accelerator for the OS disks.
* <p>
* Write Accelerator is generally available for M-series VMs in the Public Cloud.
* Enabling write accelerator for the operating system disk of the VM will reboot the VM.
* The Premium disk caching must be set to 'None' or 'Read Only'. All other caching modes are not supported.
*
* @param writeAcceleratorEnabled whether to enable the write accelerator
* @return the next stage of the update
*/
Update withOSDiskWriteAcceleratorEnabled(boolean writeAcceleratorEnabled);

/**
* Specifies the default caching type for the managed data disks.
*
Expand All @@ -2690,6 +2729,14 @@ interface Update extends Appliable<VirtualMachine>, Resource.UpdateWithTags<Upda
*/
Update withDataDiskDefaultDeleteOptions(DeleteOptions deleteOptions);

/**
* Specifies the write accelerator for managed data disks.
*
* @param writeAcceleratorEnabled whether to enable the write accelerator
* @return the next stage of the definition
*/
Update withDataDiskDefaultWriteAcceleratorEnabled(boolean writeAcceleratorEnabled);

/**
* Specifies the disk encryption set for the managed data disk.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,11 @@ public interface VirtualMachineDataDisk extends HasInnerModel<DataDisk>, HasName

/** @return the ID of disk encryption set */
String diskEncryptionSetId();

/**
* Gets whether the write accelerator is enabled.
*
* @return whether the write accelerator is enabled
*/
boolean isWriteAcceleratorEnabled();
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public final class VirtualMachineDiskOptions {
private StorageAccountTypes storageAccountType;
private CachingTypes cachingTypes;
private DeleteOptions deleteOptions;
private Boolean writeAcceleratorEnabled;

// DiskEncryptionSetParameters instance without ID means do not configure.
// If disk is already encrypted with CMK, it remains so when attached.
Expand All @@ -33,6 +34,15 @@ public DeleteOptions deleteOptions() {
return deleteOptions;
}

/**
* Gets whether the write accelerator is enabled. {@literal null} if no change.
*
* @return whether the write accelerator is enabled
*/
public Boolean writeAcceleratorEnabled() {
return writeAcceleratorEnabled;
}

/** @return whether disk encryption set is configured,
* either as the ID of disk encryption set, or as {@code null} to override default configuration. */
public boolean isDiskEncryptionSetConfigured() {
Expand All @@ -49,7 +59,7 @@ public String diskEncryptionSetId() {

/**
* Sets the storage account type.
*
* <p>
* Storage account type configured here will not work when attaching a disk.
*
* @param storageAccountType the storage account type
Expand Down Expand Up @@ -82,6 +92,21 @@ public VirtualMachineDiskOptions withDeleteOptions(DeleteOptions deleteOptions)
return this;
}

/**
* Enables/disables the write accelerator.
* <p>
* Write Accelerator is generally available for M-series VMs in the Public Cloud.
* Enabling write accelerator for the operating system disk of the VM will reboot the VM.
* The Premium disk caching must be set to 'None' or 'Read Only'. All other caching modes are not supported.
*
* @param writeAcceleratorEnabled whether to enable the write accelerator
* @return self
*/
public VirtualMachineDiskOptions withWriteAcceleratorEnabled(boolean writeAcceleratorEnabled) {
this.writeAcceleratorEnabled = writeAcceleratorEnabled;
return this;
}

/**
* Sets the ID of disk encryption set.
*
Expand Down
Loading

0 comments on commit 2e1ac76

Please sign in to comment.