Skip to content

Commit 8e01d78

Browse files
Merge pull request #115187 from JnHs/jh-batch-ci-sdk
updating topics with current info
2 parents 35a35e1 + f45d0a1 commit 8e01d78

File tree

2 files changed

+100
-58
lines changed

2 files changed

+100
-58
lines changed

articles/batch/batch-custom-images.md

Lines changed: 68 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
---
22
title: Provision a custom pool from a managed image
33
description: Create a Batch pool from a managed image resource to provision compute nodes with the software and data for your application.
4-
ms.topic: article
5-
ms.date: 09/16/2019
4+
ms.topic: conceptual
5+
ms.date: 05/22/2020
66
---
77

88
# Use a managed image to create a pool of virtual machines
99

10-
To create a custom image for your Batch pool's virtual machines (VMs), you can use either the [Shared Image Gallery](batch-sig-images.md), or a *managed image* resource.
10+
To create a custom image for your Batch pool's virtual machines (VMs), you can use a managed image to create a [Shared Image Gallery](batch-sig-images.md). Using just a managed image is also supported, but only for API versions up to and including 2019-08-01.
1111

12-
> [!TIP]
12+
> [!IMPORTANT]
1313
> In most cases, you should create custom images using the Shared Image Gallery. By using the Shared Image Gallery, you can provision pools faster, scale larger quantities of VMs, and have improved reliability when provisioning VMs. To learn more, see [Use the Shared Image Gallery to create a custom pool](batch-sig-images.md).
1414
1515
## Prerequisites
1616

17-
- **A managed image resource**. To create a pool of virtual machines using a custom image, you need to have or create a managed image resource in the same Azure subscription and region as the Batch account. The image should be created from snapshots of the VM's OS disk and optionally its attached data disks. For more information and steps to prepare a managed image, see the following section.
17+
- **A managed image resource**. To create a pool of virtual machines using a custom image, you need to have or create a managed image resource in the same Azure subscription and region as the Batch account. The image should be created from snapshots of the VM's OS disk and optionally its attached data disks.
1818
- Use a unique custom image for each pool you create.
19-
- To create a pool with the image using the Batch APIs, specify the **resource ID** of the image, which is of the form `/subscriptions/xxxx-xxxxxx-xxxxx-xxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/myImage`. To use the portal, use the **name** of the image.
19+
- To create a pool with the image using the Batch APIs, specify the **resource ID** of the image, which is of the form `/subscriptions/xxxx-xxxxxx-xxxxx-xxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/myImage`.
2020
- The managed image resource should exist for the lifetime of the pool to allow scale-up and can be removed after the pool is deleted.
2121

22-
- **Azure Active Directory (AAD) authentication**. The Batch client API must use AAD authentication. Azure Batch support for AAD is documented in [Authenticate Batch service solutions with Active Directory](batch-aad-auth.md).
22+
- **Azure Active Directory (Azure AD) authentication**. The Batch client API must use Azure AD authentication. Azure Batch support for Azure AD is documented in [Authenticate Batch service solutions with Active Directory](batch-aad-auth.md).
2323

2424
## Prepare a custom image
2525

@@ -29,16 +29,14 @@ In Azure, you can prepare a managed image from:
2929
- A generalized Azure VM with managed disks
3030
- A generalized on-premises VHD uploaded to the cloud
3131

32-
To scale Batch pools reliably with a custom image, we recommend creating a managed image using *only* the first method: using snapshots of the VM's disks. See the following steps to prepare a VM, take a snapshot, and create an image from the snapshot.
32+
To scale Batch pools reliably with a managed image, we recommend creating the managed image using *only* the first method: using snapshots of the VM's disks. The following steps show how to prepare a VM, take a snapshot, and create a managed image from the snapshot.
3333

3434
### Prepare a VM
3535

3636
If you are creating a new VM for the image, use a first party Azure Marketplace image supported by Batch as the base image for your managed image. Only first party images can be used as a base image. To get a full list of Azure Marketplace image references supported by Azure Batch, see the [List node agent SKUs](/java/api/com.microsoft.azure.batch.protocol.accounts.listnodeagentskus) operation.
3737

3838
> [!NOTE]
39-
> You can't use a third-party image that has additional license and purchase terms as your base image. For information about these Marketplace images, see the guidance for [Linux](../virtual-machines/linux/cli-ps-findimage.md#deploy-an-image-with-marketplace-terms
40-
) or [Windows](../virtual-machines/windows/cli-ps-findimage.md#deploy-an-image-with-marketplace-terms
41-
) VMs.
39+
> You can't use a third-party image that has additional license and purchase terms as your base image. For information about these Marketplace images, see the guidance for [Linux](../virtual-machines/linux/cli-ps-findimage.md#deploy-an-image-with-marketplace-terms) or [Windows](../virtual-machines/windows/cli-ps-findimage.md#deploy-an-image-with-marketplace-terms) VMs.
4240
4341
- Ensure the VM is created with a managed disk. This is the default storage setting when you create a VM.
4442
- Do not install Azure extensions, such as the Custom Script extension, on the VM. If the image contains a pre-installed extension, Azure may encounter problems when deploying the Batch pool.
@@ -54,29 +52,70 @@ A snapshot is a full, read-only copy of a VHD. To create a snapshot of a VM's OS
5452

5553
To create a managed image from a snapshot, use Azure command-line tools such as the [az image create](/cli/azure/image) command. You can create an image by specifying an OS disk snapshot and optionally one or more data disk snapshots.
5654

57-
## Create a pool from a custom image in the portal
55+
## Create a pool from a custom image
5856

59-
Once you have saved your custom image and you know its resource ID or name, create a Batch pool from that image. The following steps show you how to create a pool from the Azure portal.
57+
Once you have found the resource ID of your managed image, create a custom image pool from that image. The following steps show you how to create a custom image pool using either Batch Service or Batch Management.
6058

6159
> [!NOTE]
62-
> If you are creating the pool using one of the Batch APIs, make sure that the identity you use for AAD authentication has permissions to the image resource. See [Authenticate Batch service solutions with Active Directory](batch-aad-auth.md).
60+
> Make sure that the identity you use for Azure AD authentication has permissions to the image resource. See [Authenticate Batch service solutions with Active Directory](batch-aad-auth.md).
6361
>
6462
> The resource for the managed image must exist for the lifetime of the pool. If the underlying resource is deleted, the pool cannot be scaled.
6563
66-
1. Navigate to your Batch account in the Azure portal. This account must be in the same subscription and region as the resource group containing the custom image.
67-
2. In the **Settings** window on the left, select the **Pools** menu item.
68-
3. In the **Pools** window, select the **Add** command.
69-
4. On the **Add Pool** window, select **Custom Image (Linux/Windows)** from the **Image Type** dropdown. From the **Custom VM image** dropdown, select the image name (short form of the resource ID).
70-
5. Select the correct **Publisher/Offer/Sku** for your custom image.
71-
6. Specify the remaining required settings, including the **Node size**, **Target dedicated nodes**, and **Low-priority nodes**, as well as any desired optional settings.
72-
73-
For example, for a Microsoft Windows Server Datacenter 2016 custom image, the **Add Pool** window appears as shown below:
74-
75-
![Add pool from custom Windows image](media/batch-custom-images/add-pool-custom-image.png)
76-
77-
To check whether an existing pool is based on a custom image, see the **Operating System** property in the resource summary section of the **Pool** window. If the pool was created from a custom image, it is set to **Custom VM Image**.
78-
79-
All custom images associated with a pool are displayed on the pool's **Properties** window.
64+
### Batch Service .NET SDK
65+
66+
```csharp
67+
private static VirtualMachineConfiguration CreateVirtualMachineConfiguration(ImageReference imageReference)
68+
{
69+
return new VirtualMachineConfiguration(
70+
imageReference: imageReference,
71+
nodeAgentSkuId: "batch.node.windows amd64");
72+
}
73+
74+
private static ImageReference CreateImageReference()
75+
{
76+
return new ImageReference(
77+
virtualMachineImageId: "/subscriptions/{sub id}/resourceGroups/{resource group name}/providers/Microsoft.Compute/images/{image definition name}");
78+
}
79+
80+
private static void CreateBatchPool(BatchClient batchClient, VirtualMachineConfiguration vmConfiguration)
81+
{
82+
try
83+
{
84+
CloudPool pool = batchClient.PoolOperations.CreatePool(
85+
poolId: PoolId,
86+
targetDedicatedComputeNodes: PoolNodeCount,
87+
virtualMachineSize: PoolVMSize,
88+
virtualMachineConfiguration: vmConfiguration);
89+
90+
pool.Commit();
91+
}
92+
```
93+
94+
### Batch Management REST API
95+
96+
REST API URI
97+
98+
```http
99+
PUT https://management.azure.com/subscriptions/{sub id}/resourceGroups/{resource group name}/providers/Microsoft.Batch/batchAccounts/{account name}/pools/{pool name}?api-version=2020-03-01
100+
```
101+
102+
Request Body
103+
104+
```json
105+
{
106+
"properties": {
107+
"vmSize": "{VM size}",
108+
"deploymentConfiguration": {
109+
"virtualMachineConfiguration": {
110+
"imageReference": {
111+
"id": "/subscriptions/{sub id}/resourceGroups/{resource group name}/providers/Microsoft.Compute/images/{image name}"
112+
},
113+
"nodeAgentSkuId": "{Node Agent SKU ID}"
114+
}
115+
}
116+
}
117+
}
118+
```
80119

81120
## Considerations for large pools
82121

@@ -108,4 +147,5 @@ For more information on using Packer to create a VM, see [Build a Linux image wi
108147

109148
## Next steps
110149

150+
- Learn how to use the [Shared Image Gallery](batch-sig-images.md) to create a custom pool.
111151
- For an in-depth overview of Batch, see [Batch service workflow and resources](batch-service-workflow-features.md).

0 commit comments

Comments
 (0)