|
2 | 2 | title: Use ephemeral OS disk nodes for Azure Batch pools |
3 | 3 | description: Learn how and why to create a Batch pool that uses ephemeral OS disk nodes. |
4 | 4 | ms.topic: how-to |
5 | | -ms.date: 03/27/2025 |
| 5 | +ms.date: 03/06/2026 |
6 | 6 | ms.devlang: csharp |
7 | 7 | # Customer intent: "As a cloud architect, I want to configure Azure Batch pools with ephemeral OS disks, so that I can reduce costs and improve application performance for stateless workloads." |
8 | 8 | --- |
@@ -40,30 +40,102 @@ The following example shows how to create a Batch pool where the nodes use ephem |
40 | 40 |
|
41 | 41 | ### Code examples |
42 | 42 |
|
43 | | -This code snippet shows how to create a pool with ephemeral OS disks using Azure Batch Python SDK with the Ephemeral OS disk using the temporary disk (cache). |
| 43 | +This code snippet shows how to create a pool with ephemeral OS disks using the azure-mgmt-batch Python SDK with the ephemeral OS disk using the temporary disk (cache). |
44 | 44 |
|
45 | 45 | ```python |
46 | | -virtual_machine_configuration=batch.models.VirtualMachineConfiguration( |
47 | | - image_reference=image_ref_to_use, |
48 | | - node_agent_sku_id=node_sku_id, |
49 | | - os_disk=batch.models.OSDisk( |
50 | | - ephemeral_os_disk_settings=batch.models.DiffDiskSettings( |
51 | | - placement=batch.models.DiffDiskPlacement.cache_disk |
52 | | - ) |
53 | | - ) |
| 46 | +from azure.identity import DefaultAzureCredential |
| 47 | +from azure.mgmt.batch import BatchManagementClient |
| 48 | +from azure.mgmt.batch.models import ( |
| 49 | + BatchAccountPoolData, |
| 50 | + DeploymentConfiguration, |
| 51 | + VirtualMachineConfiguration, |
| 52 | + ImageReference, |
| 53 | + OSDisk, |
| 54 | + DiffDiskSettings, |
| 55 | + DiffDiskPlacement, |
54 | 56 | ) |
| 57 | + |
| 58 | + |
| 59 | +def create_pool_with_ephemeral_os_disk(): |
| 60 | + client = BatchManagementClient( |
| 61 | + credential=DefaultAzureCredential(), |
| 62 | + subscription_id="subscriptionId", |
| 63 | + ) |
| 64 | + |
| 65 | + pool = client.pool.create( |
| 66 | + resource_group_name="resourceGroupName", |
| 67 | + account_name="accountName", |
| 68 | + pool_name="ephemeralOSDiskPool", |
| 69 | + parameters=BatchAccountPoolData( |
| 70 | + vm_size="standard_ds1_v2", |
| 71 | + deployment_configuration=DeploymentConfiguration( |
| 72 | + virtual_machine_configuration=VirtualMachineConfiguration( |
| 73 | + image_reference=ImageReference( |
| 74 | + publisher="Canonical", |
| 75 | + offer="UbuntuServer", |
| 76 | + sku="22.04-LTS", |
| 77 | + ), |
| 78 | + node_agent_sku_id="batch.node.ubuntu 22.04", |
| 79 | + os_disk=OSDisk( |
| 80 | + ephemeral_os_disk_settings=DiffDiskSettings( |
| 81 | + placement=DiffDiskPlacement.CACHE_DISK |
| 82 | + ) |
| 83 | + ), |
| 84 | + ) |
| 85 | + ), |
| 86 | + ), |
| 87 | + ) |
55 | 88 | ``` |
56 | 89 |
|
57 | | -This is the same code snippet but for creating a pool with ephemeral OS disks using the Azure Batch .NET SDK and C#. |
| 90 | +This is the same code snippet but for creating a pool with ephemeral OS disks using the Azure.ResourceManager.Batch SDK and C#. |
58 | 91 |
|
59 | 92 | ```csharp |
60 | | -VirtualMachineConfiguration virtualMachineConfiguration = new VirtualMachineConfiguration( |
61 | | - imageReference: imageReference, |
62 | | - nodeAgentSkuId: nodeAgentSku |
63 | | - ); |
64 | | -virtualMachineConfiguration.OSDisk = new OSDisk(); |
65 | | -virtualMachineConfiguration.OSDisk.EphemeralOSDiskSettings = new DiffDiskSettings(); |
66 | | -virtualMachineConfiguration.OSDisk.EphemeralOSDiskSettings.Placement = DiffDiskPlacement.CacheDisk; |
| 93 | +using Azure; |
| 94 | +using Azure.Identity; |
| 95 | +using Azure.ResourceManager; |
| 96 | +using Azure.ResourceManager.Batch; |
| 97 | +using Azure.ResourceManager.Batch.Models; |
| 98 | + |
| 99 | +//... |
| 100 | +
|
| 101 | +public async Task SetEphemeralOSDisk() |
| 102 | +{ |
| 103 | + ArmClient client = new ArmClient(new DefaultAzureCredential()); |
| 104 | + |
| 105 | + ResourceIdentifier batchAccountResourceId = |
| 106 | + BatchAccountResource.CreateResourceIdentifier("subscriptionId", "resourceGroupName", "accountName"); |
| 107 | + BatchAccountResource batchAccount = client.GetBatchAccountResource(batchAccountResourceId); |
| 108 | + |
| 109 | + BatchAccountPoolCollection poolCollection = batchAccount.GetBatchAccountPools(); |
| 110 | + |
| 111 | + BatchAccountPoolData poolData = new BatchAccountPoolData() |
| 112 | + { |
| 113 | + VmSize = "standard_ds1_v2", |
| 114 | + DeploymentConfiguration = new BatchDeploymentConfiguration() |
| 115 | + { |
| 116 | + VmConfiguration = new BatchVmConfiguration( |
| 117 | + imageReference: new BatchImageReference() |
| 118 | + { |
| 119 | + Publisher = "Canonical", |
| 120 | + Offer = "UbuntuServer", |
| 121 | + Sku = "22.04-LTS" |
| 122 | + }, |
| 123 | + nodeAgentSkuId: "batch.node.ubuntu 22.04") |
| 124 | + { |
| 125 | + OSDisk = new BatchOSDisk() |
| 126 | + { |
| 127 | + EphemeralOSDiskSettings = new DiffDiskSettings() |
| 128 | + { |
| 129 | + Placement = BatchDiffDiskPlacement.CacheDisk |
| 130 | + } |
| 131 | + } |
| 132 | + } |
| 133 | + } |
| 134 | + }; |
| 135 | + |
| 136 | + ArmOperation<BatchAccountPoolResource> pool = await poolCollection.CreateOrUpdateAsync( |
| 137 | + WaitUntil.Completed, "ephemeralOSDiskPool", poolData); |
| 138 | +} |
67 | 139 | ``` |
68 | 140 |
|
69 | 141 | ## Next steps |
|
0 commit comments