Skip to content

Commit 4f1c11f

Browse files
authored
mgmt Compute, convenience method for disk HyperVGeneration (Azure#38165)
* mgmt Compute, convenience method for disk HyperVGeneration
1 parent 1d5093c commit 4f1c11f

File tree

4 files changed

+62
-3
lines changed

4 files changed

+62
-3
lines changed

sdk/resourcemanager/azure-resourcemanager-compute/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "java",
44
"TagPrefix": "java/resourcemanager/azure-resourcemanager-compute",
5-
"Tag": "java/resourcemanager/azure-resourcemanager-compute_fa84e8a69a"
5+
"Tag": "java/resourcemanager/azure-resourcemanager-compute_09f29433c3"
66
}

sdk/resourcemanager/azure-resourcemanager-compute/src/main/java/com/azure/resourcemanager/compute/implementation/DiskImpl.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.azure.resourcemanager.compute.models.EncryptionSettingsCollection;
1919
import com.azure.resourcemanager.compute.models.EncryptionType;
2020
import com.azure.resourcemanager.compute.models.GrantAccessData;
21+
import com.azure.resourcemanager.compute.models.HyperVGeneration;
2122
import com.azure.resourcemanager.compute.models.OperatingSystemTypes;
2223
import com.azure.resourcemanager.compute.models.Snapshot;
2324
import com.azure.resourcemanager.compute.fluent.models.DiskInner;
@@ -147,6 +148,11 @@ public Integer logicalSectorSizeInBytes() {
147148
return this.innerModel().creationData().logicalSectorSize();
148149
}
149150

151+
@Override
152+
public HyperVGeneration hyperVGeneration() {
153+
return this.innerModel().hyperVGeneration();
154+
}
155+
150156
@Override
151157
public DiskImpl withLinuxFromVhd(String vhdUrl) {
152158
this
@@ -462,4 +468,10 @@ private DiskSkuTypes fromSnapshotSkuType(SnapshotSkuType skuType) {
462468
}
463469
return DiskSkuTypes.fromStorageAccountType(DiskStorageAccountTypes.fromString(skuType.toString()));
464470
}
471+
472+
@Override
473+
public DiskImpl withHyperVGeneration(HyperVGeneration hyperVGeneration) {
474+
this.innerModel().withHyperVGeneration(hyperVGeneration);
475+
return this;
476+
}
465477
}

sdk/resourcemanager/azure-resourcemanager-compute/src/main/java/com/azure/resourcemanager/compute/models/Disk.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ public interface Disk extends GroupableResource<ComputeManager, DiskInner>, Refr
8989
/** @return logical sector size in bytes for Premium SSD v2 and Ultra disks. */
9090
Integer logicalSectorSizeInBytes();
9191

92+
/** @return the hypervisor generation. */
93+
HyperVGeneration hyperVGeneration();
94+
9295
/** The entirety of the managed disk definition. */
9396
interface Definition
9497
extends DefinitionStages.Blank,
@@ -445,6 +448,16 @@ interface WithLogicalSectorSize {
445448
WithCreate withLogicalSectorSizeInBytes(int logicalSectorSizeInBytes);
446449
}
447450

451+
/** The stage of the managed disk definition allowing to specify hypervisor generation. */
452+
interface WithHyperVGeneration {
453+
/**
454+
* Specifies the hypervisor generation.
455+
* @param hyperVGeneration the hypervisor generation
456+
* @return the next stage of the definition
457+
*/
458+
WithCreate withHyperVGeneration(HyperVGeneration hyperVGeneration);
459+
}
460+
448461
/**
449462
* The stage of the definition which contains all the minimum required inputs for the resource to be created,
450463
* but also allows for any other optional settings to be specified.
@@ -456,7 +469,8 @@ interface WithCreate
456469
WithAvailabilityZone,
457470
WithDiskEncryption,
458471
WithHibernationSupport,
459-
WithLogicalSectorSize {
472+
WithLogicalSectorSize,
473+
WithHyperVGeneration {
460474

461475
/**
462476
* Begins creating the disk resource.
@@ -530,6 +544,16 @@ interface WithHibernationSupport {
530544
*/
531545
Update withoutHibernationSupport();
532546
}
547+
548+
/** The stage of the managed disk update allowing to specify hypervisor generation. */
549+
interface WithHyperVGeneration {
550+
/**
551+
* Specifies the hypervisor generation.
552+
* @param hyperVGeneration the hypervisor generation
553+
* @return the next stage of the update
554+
*/
555+
Update withHyperVGeneration(HyperVGeneration hyperVGeneration);
556+
}
533557
}
534558

535559
/** The template for an update operation, containing all the settings that can be modified. */
@@ -540,6 +564,7 @@ interface Update
540564
UpdateStages.WithSize,
541565
UpdateStages.WithOSSettings,
542566
UpdateStages.WithDiskEncryption,
543-
UpdateStages.WithHibernationSupport {
567+
UpdateStages.WithHibernationSupport,
568+
UpdateStages.WithHyperVGeneration {
544569
}
545570
}

sdk/resourcemanager/azure-resourcemanager-compute/src/test/java/com/azure/resourcemanager/compute/ManagedDiskOperationsTests.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.azure.resourcemanager.compute.models.Disk;
1313
import com.azure.resourcemanager.compute.models.DiskCreateOption;
1414
import com.azure.resourcemanager.compute.models.DiskSkuTypes;
15+
import com.azure.resourcemanager.compute.models.HyperVGeneration;
1516
import com.azure.resourcemanager.compute.models.Snapshot;
1617
import com.azure.resourcemanager.compute.models.SnapshotSkuType;
1718
import com.azure.resourcemanager.resources.models.ResourceGroup;
@@ -404,4 +405,25 @@ public void canCreateWithLogicalSectorSize() {
404405
Assertions.assertEquals(DiskSkuTypes.PREMIUM_V2_LRS, disk.sku());
405406
Assertions.assertEquals(512, disk.logicalSectorSizeInBytes());
406407
}
408+
409+
@Test
410+
public void canCreateAndUpdateManagedDiskWithHyperVGeneration() {
411+
Disk disk =
412+
computeManager
413+
.disks()
414+
.define(generateRandomResourceName("disk", 15))
415+
.withRegion(Region.US_EAST)
416+
.withNewResourceGroup(rgName)
417+
.withData()
418+
.withSizeInGB(1)
419+
.withSku(DiskSkuTypes.STANDARD_LRS)
420+
.withHyperVGeneration(HyperVGeneration.V1)
421+
.create();
422+
disk.refresh();
423+
Assertions.assertEquals(disk.hyperVGeneration(), HyperVGeneration.V1);
424+
425+
disk.update().withHyperVGeneration(HyperVGeneration.V2).apply();
426+
disk.refresh();
427+
Assertions.assertEquals(disk.hyperVGeneration(), HyperVGeneration.V2);
428+
}
407429
}

0 commit comments

Comments
 (0)