Skip to content

Commit d01635e

Browse files
author
Jill Grant
authored
Merge pull request #284451 from wiboris/patch-1
Update managed-identity-pools.md
2 parents 8d1beee + 5766533 commit d01635e

File tree

4 files changed

+167
-103
lines changed

4 files changed

+167
-103
lines changed

articles/batch/batch-customer-managed-key.md

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Configure customer-managed keys for your Azure Batch account with Azure Key Vault and Managed Identity
33
description: Learn how to encrypt Batch data using customer-managed keys.
44
ms.topic: how-to
5-
ms.date: 04/03/2023
5+
ms.date: 08/12/2024
66
ms.devlang: csharp
77
ms.custom: devx-track-azurecli
88
---
@@ -136,27 +136,33 @@ As an example using the Batch management .NET client, you can create a Batch acc
136136
and customer-managed keys.
137137

138138
```c#
139-
EncryptionProperties encryptionProperties = new EncryptionProperties()
139+
string subscriptionId = "Your SubscriptionID";
140+
string resourceGroupName = "Your ResourceGroup name";
141+
142+
var credential = new DefaultAzureCredential();
143+
ArmClient _armClient = new ArmClient(credential);
144+
145+
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
146+
ResourceGroupResource resourceGroupResource = _armClient.GetResourceGroupResource(resourceGroupResourceId);
147+
148+
var data = new BatchAccountCreateOrUpdateContent(AzureLocation.EastUS)
140149
{
141-
KeySource = KeySource.MicrosoftKeyVault,
142-
KeyVaultProperties = new KeyVaultProperties()
150+
Encryption = new BatchAccountEncryptionConfiguration()
143151
{
144-
KeyIdentifier = "Your Key Azure Resource Manager Resource ID"
145-
}
146-
};
152+
KeySource = BatchAccountKeySource.MicrosoftKeyVault,
153+
KeyIdentifier = new Uri("Your Key Azure Resource Manager Resource ID"),
154+
},
147155

148-
BatchAccountIdentity identity = new BatchAccountIdentity()
149-
{
150-
Type = ResourceIdentityType.UserAssigned,
151-
UserAssignedIdentities = new Dictionary<string, BatchAccountIdentityUserAssignedIdentitiesValue>
156+
Identity = new ManagedServiceIdentity(ManagedServiceIdentityType.UserAssigned)
152157
{
153-
["Your Identity Azure Resource Manager ResourceId"] = new BatchAccountIdentityUserAssignedIdentitiesValue()
158+
UserAssignedIdentities = {
159+
[new ResourceIdentifier("Your Identity Azure Resource Manager ResourceId")] = new UserAssignedIdentity(),
160+
},
154161
}
155162
};
156-
var parameters = new BatchAccountCreateParameters(TestConfiguration.ManagementRegion, encryption:encryptionProperties, identity: identity);
157163

158-
var account = await batchManagementClient.Account.CreateAsync("MyResourceGroup",
159-
"mynewaccount", parameters);
164+
var lro = resourceGroupResource.GetBatchAccounts().CreateOrUpdate(WaitUntil.Completed, "Your BatchAccount name", data);
165+
BatchAccountResource batchAccount = lro.Value;
160166
```
161167

162168
## Update the customer-managed key version

articles/batch/batch-management-dotnet.md

Lines changed: 72 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Use the Batch Management .NET library to manage account resources
33
description: Create, delete, and modify Azure Batch account resources with the Batch Management .NET library.
44
ms.topic: how-to
5-
ms.date: 06/13/2024
5+
ms.date: 08/12/2024
66
ms.devlang: csharp
77
ms.custom: has-adal-ref, devx-track-csharp, devx-track-dotnet
88
---
@@ -20,53 +20,67 @@ You can lower maintenance overhead in your Azure Batch applications by using the
2020
2121
## Create and delete Batch accounts
2222

23-
One of the primary features of the Batch Management API is to create and delete [Batch accounts](accounts.md) in an Azure region. To do so, use [BatchManagementClient.Account.CreateAsync](/dotnet/api/microsoft.azure.management.batch.batchaccountoperationsextensions.createasync) and [DeleteAsync](/dotnet/api/microsoft.azure.management.batch.batchaccountoperationsextensions.deleteasync), or their synchronous counterparts.
23+
One of the primary features of the Batch Management API is to create and delete [Batch accounts](accounts.md) in an Azure region. To do so, use [BatchAccountCollection.CreateOrUpdate](/dotnet/api/azure.resourcemanager.batch.batchaccountcollection.createorupdate) and [Delete](/dotnet/api/azure.resourcemanager.batch.batchaccountresource.delete), or their asynchronous counterparts.
2424

25-
The following code snippet creates an account, obtains the newly created account from the Batch service, and then deletes it. In this snippet and the others in this article, `batchManagementClient` is a fully initialized instance of [BatchManagementClient](/dotnet/api/microsoft.azure.management.batch.batchmanagementclient).
25+
The following code snippet creates an account, obtains the newly created account from the Batch service, and then deletes it.
2626

2727
```csharp
28-
// Create a new Batch account
29-
await batchManagementClient.Account.CreateAsync("MyResourceGroup",
30-
"mynewaccount",
31-
new BatchAccountCreateParameters() { Location = "West US" });
32-
33-
// Get the new account from the Batch service
34-
AccountResource account = await batchManagementClient.Account.GetAsync(
35-
"MyResourceGroup",
36-
"mynewaccount");
37-
38-
// Delete the account
39-
await batchManagementClient.Account.DeleteAsync("MyResourceGroup", account.Name);
28+
string subscriptionId = "Your SubscriptionID";
29+
string resourceGroupName = "Your ResourceGroup name";
30+
31+
var credential = new DefaultAzureCredential();
32+
ArmClient _armClient = new ArmClient(credential);
33+
34+
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
35+
ResourceGroupResource resourceGroupResource = _armClient.GetResourceGroupResource(resourceGroupResourceId);
36+
37+
var data = new BatchAccountCreateOrUpdateContent(AzureLocation.EastUS);
38+
39+
// Create a new batch account
40+
resourceGroupResource.GetBatchAccounts().CreateOrUpdate(WaitUntil.Completed, "Your BatchAccount name", data);
41+
42+
// Get an existing batch account
43+
BatchAccountResource batchAccount = resourceGroupResource.GetBatchAccount("Your BatchAccount name");
44+
45+
// Delete the batch account
46+
batchAccount.Delete(WaitUntil.Completed);
4047
```
4148

4249
> [!NOTE]
43-
> Applications that use the Batch Management .NET library and its BatchManagementClient class require service administrator or coadministrator access to the subscription that owns the Batch account to be managed. For more information, see the Microsoft Entra ID section and the [AccountManagement](https://github.com/Azure-Samples/azure-batch-samples/tree/master/CSharp/AccountManagement) code sample.
50+
> Applications that use the Batch Management .NET library require service administrator or coadministrator access to the subscription that owns the Batch account to be managed. For more information, see the Microsoft Entra ID section and the [AccountManagement](https://github.com/Azure-Samples/azure-batch-samples/tree/master/CSharp/AccountManagement) code sample.
4451
4552
## Retrieve and regenerate account keys
4653

47-
Obtain primary and secondary account keys from any Batch account within your subscription by using [GetKeysAsync](/dotnet/api/microsoft.azure.management.batch.batchaccountoperationsextensions.getkeysasync). You can regenerate those keys by using [RegenerateKeyAsync](/dotnet/api/microsoft.azure.management.batch.batchaccountoperationsextensions.regeneratekeyasync).
54+
Obtain primary and secondary account keys from any Batch account within your subscription by using [GetKeys](/dotnet/api/azure.resourcemanager.batch.batchaccountresource.getkeys). You can regenerate those keys by using [RegenerateKey](/dotnet/api/microsoft.azure.management.batch.batchaccountoperationsextensions.regeneratekey).
4855

4956
```csharp
57+
string subscriptionId = "Your SubscriptionID";
58+
string resourceGroupName = "Your ResourceGroup name";
59+
60+
var credential = new DefaultAzureCredential();
61+
ArmClient _armClient = new ArmClient(credential);
62+
63+
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
64+
ResourceGroupResource resourceGroupResource = _armClient.GetResourceGroupResource(resourceGroupResourceId);
65+
66+
var data = new BatchAccountCreateOrUpdateContent(AzureLocation.EastUS);
67+
68+
// Get an existing batch account
69+
BatchAccountResource batchAccount = resourceGroupResource.GetBatchAccount("Your BatchAccount name");
70+
5071
// Get and print the primary and secondary keys
51-
BatchAccountGetKeyResult accountKeys =
52-
await batchManagementClient.Account.GetKeysAsync(
53-
"MyResourceGroup",
54-
"mybatchaccount");
72+
BatchAccountKeys accountKeys = batchAccount.GetKeys();
73+
5574
Console.WriteLine("Primary key: {0}", accountKeys.Primary);
5675
Console.WriteLine("Secondary key: {0}", accountKeys.Secondary);
5776

5877
// Regenerate the primary key
59-
BatchAccountRegenerateKeyResponse newKeys =
60-
await batchManagementClient.Account.RegenerateKeyAsync(
61-
"MyResourceGroup",
62-
"mybatchaccount",
63-
new BatchAccountRegenerateKeyParameters() {
64-
KeyName = AccountKeyType.Primary
65-
});
78+
BatchAccountRegenerateKeyContent regenerateKeyContent = new BatchAccountRegenerateKeyContent(BatchAccountKeyType.Primary);
79+
batchAccount.RegenerateKey(regenerateKeyContent);
6680
```
6781

6882
> [!TIP]
69-
> You can create a streamlined connection workflow for your management applications. First, obtain an account key for the Batch account you wish to manage with [GetKeysAsync](/dotnet/api/microsoft.azure.management.batch.batchaccountoperationsextensions.getkeysasync). Then, use this key when initializing the Batch .NET library's [BatchSharedKeyCredentials](/dotnet/api/microsoft.azure.batch.auth.batchsharedkeycredentials) class, which is used when initializing [BatchClient](/dotnet/api/microsoft.azure.batch.batchclient).
83+
> You can create a streamlined connection workflow for your management applications. First, obtain an account key for the Batch account you wish to manage with [GetKeys](/dotnet/api/azure.resourcemanager.batch.batchaccountresource.getkeys). Then, use this key when initializing the Batch .NET library's [BatchSharedKeyCredentials](/dotnet/api/microsoft.azure.batch.auth.batchsharedkeycredentials) class, which is used when initializing [BatchClient](/dotnet/api/microsoft.azure.batch.batchclient).
7084
7185
## Check Azure subscription and Batch account quotas
7286

@@ -76,28 +90,30 @@ Azure subscriptions and the individual Azure services like Batch all have defaul
7690

7791
Before creating a Batch account in a region, you can check your Azure subscription to see whether you are able to add an account in that region.
7892

79-
In the code snippet below, we first use **ListAsync** to get a collection of all Batch accounts that are within a subscription. Once we've obtained this collection, we determine how many accounts are in the target region. Then we use **GetQuotasAsync** to obtain the Batch account quota and determine how many accounts (if any) can be created in that region.
93+
In the code snippet below, we first use **GetBatchAccounts** to get a collection of all Batch accounts that are within a subscription. Once we've obtained this collection, we determine how many accounts are in the target region. Then we use **GetBatchQuotas** to obtain the Batch account quota and determine how many accounts (if any) can be created in that region.
8094

8195
```csharp
96+
string subscriptionId = "Your SubscriptionID";
97+
ArmClient _armClient = new ArmClient(new DefaultAzureCredential());
98+
99+
ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier(subscriptionId);
100+
SubscriptionResource subscriptionResource = _armClient.GetSubscriptionResource(subscriptionResourceId);
101+
82102
// Get a collection of all Batch accounts within the subscription
83-
BatchAccountListResponse listResponse =
84-
await batchManagementClient.BatchAccount.ListAsync(new AccountListParameters());
85-
IList<AccountResource> accounts = listResponse.Accounts;
86-
Console.WriteLine("Total number of Batch accounts under subscription id {0}: {1}",
87-
creds.SubscriptionId,
88-
accounts.Count);
103+
var batchAccounts = subscriptionResource.GetBatchAccounts();
104+
Console.WriteLine("Total number of Batch accounts under subscription id {0}: {1}", subscriptionId, batchAccounts.Count());
89105

90106
// Get a count of all accounts within the target region
91-
string region = "westus";
92-
int accountsInRegion = accounts.Count(o => o.Location == region);
107+
string region = "eastus";
108+
int accountsInRegion = batchAccounts.Count(o => o.Data.Location == region);
93109

94110
// Get the account quota for the specified region
95-
SubscriptionQuotasGetResponse quotaResponse = await batchManagementClient.Location.GetQuotasAsync(region);
96-
Console.WriteLine("Account quota for {0} region: {1}", region, quotaResponse.AccountQuota);
111+
BatchLocationQuota batchLocationQuota = subscriptionResource.GetBatchQuotas(AzureLocation.EastUS);
112+
Console.WriteLine("Account quota for {0} region: {1}", region, batchLocationQuota.AccountQuota);
97113

98114
// Determine how many accounts can be created in the target region
99115
Console.WriteLine("Accounts in {0}: {1}", region, accountsInRegion);
100-
Console.WriteLine("You can create {0} accounts in the {1} region.", quotaResponse.AccountQuota - accountsInRegion, region);
116+
Console.WriteLine("You can create {0} accounts in the {1} region.", batchLocationQuota.AccountQuota - accountsInRegion, region);
101117
```
102118

103119
In the snippet above, `creds` is an instance of **TokenCredentials**. To see an example of creating this object, see the [AccountManagement](https://github.com/Azure-Samples/azure-batch-samples/tree/master/CSharp/AccountManagement) code sample on GitHub.
@@ -107,15 +123,22 @@ In the snippet above, `creds` is an instance of **TokenCredentials**. To see an
107123
Before increasing compute resources in your Batch solution, you can check to ensure the resources you want to allocate won't exceed the account's quotas. In the code snippet below, we print the quota information for the Batch account named `mybatchaccount`. In your own application, you could use such information to determine whether the account can handle the additional resources to be created.
108124

109125
```csharp
110-
// First obtain the Batch account
111-
BatchAccountGetResponse getResponse =
112-
await batchManagementClient.Account.GetAsync("MyResourceGroup", "mybatchaccount");
113-
AccountResource account = getResponse.Resource;
126+
string subscriptionId = "Your SubscriptionID";
127+
string resourceGroupName = "Your ResourceGroup name";
128+
129+
var credential = new DefaultAzureCredential();
130+
ArmClient _armClient = new ArmClient(credential);
131+
132+
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
133+
ResourceGroupResource resourceGroupResource = _armClient.GetResourceGroupResource(resourceGroupResourceId);
134+
135+
// Get an existing batch account
136+
BatchAccountResource batchAccount = resourceGroupResource.GetBatchAccount("Your BatchAccount name");
114137

115138
// Now print the compute resource quotas for the account
116-
Console.WriteLine("Core quota: {0}", account.Properties.CoreQuota);
117-
Console.WriteLine("Pool quota: {0}", account.Properties.PoolQuota);
118-
Console.WriteLine("Active job and job schedule quota: {0}", account.Properties.ActiveJobAndJobScheduleQuota);
139+
Console.WriteLine("Core quota: {0}", batchAccount.Data.DedicatedCoreQuota);
140+
Console.WriteLine("Pool quota: {0}", batchAccount.Data.PoolQuota);
141+
Console.WriteLine("Active job and job schedule quota: {0}", batchAccount.Data.ActiveJobAndJobScheduleQuota);
119142
```
120143

121144
> [!IMPORTANT]
@@ -152,4 +175,4 @@ To run the sample application successfully, you must first register it with your
152175
## Next steps
153176

154177
- Learn about the [Batch service workflow and primary resources](batch-service-workflow-features.md) such as pools, nodes, jobs, and tasks.
155-
- Learn the basics of developing a Batch-enabled application using the [Batch .NET client library](quick-run-dotnet.md) or [Python](quick-run-python.md). These quickstarts guide you through a sample application that uses the Batch service to execute a workload on multiple compute nodes, using Azure Storage for workload file staging and retrieval.git pus
178+
- Learn the basics of developing a Batch-enabled application using the [Batch .NET client library](quick-run-dotnet.md) or [Python](quick-run-python.md). These quickstarts guide you through a sample application that uses the Batch service to execute a workload on multiple compute nodes, using Azure Storage for workload file staging and retrieval.

articles/batch/create-pool-availability-zones.md

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Create a pool across availability zones
33
description: Learn how to create a Batch pool with zonal policy to help protect against failures.
44
ms.topic: how-to
5-
ms.date: 05/25/2023
5+
ms.date: 08/12/2024
66
ms.devlang: csharp
77
ms.custom:
88
---
@@ -33,10 +33,47 @@ The following examples show how to create a Batch pool across Availability Zones
3333
### Batch Management Client .NET SDK
3434

3535
```csharp
36-
pool.DeploymentConfiguration.VirtualMachineConfiguration.NodePlacementConfiguration = new NodePlacementConfiguration()
36+
var credential = new DefaultAzureCredential();
37+
ArmClient _armClient = new ArmClient(credential);
38+
39+
var batchAccountIdentifier = ResourceIdentifier.Parse("your-batch-account-resource-id");
40+
41+
BatchAccountResource batchAccount = _armClient.GetBatchAccountResource(batchAccountIdentifier);
42+
43+
var poolName = "pool2";
44+
var imageReference = new BatchImageReference()
45+
{
46+
Publisher = "canonical",
47+
Offer = "0001-com-ubuntu-server-jammy",
48+
Sku = "22_04-lts",
49+
Version = "latest"
50+
};
51+
string nodeAgentSku = "batch.node.ubuntu 22.04";
52+
53+
var batchAccountPoolData = new BatchAccountPoolData()
54+
{
55+
VmSize = "Standard_DS1_v2",
56+
DeploymentConfiguration = new BatchDeploymentConfiguration()
3757
{
38-
Policy = NodePlacementPolicyType.Zonal
39-
};
58+
VmConfiguration = new BatchVmConfiguration(imageReference, nodeAgentSku)
59+
{
60+
NodePlacementPolicy = BatchNodePlacementPolicyType.Zonal,
61+
},
62+
},
63+
ScaleSettings = new BatchAccountPoolScaleSettings()
64+
{
65+
FixedScale = new BatchAccountFixedScaleSettings()
66+
{
67+
TargetDedicatedNodes = 5,
68+
ResizeTimeout = TimeSpan.FromMinutes(15),
69+
}
70+
},
71+
72+
};
73+
74+
ArmOperation<BatchAccountPoolResource> armOperation = batchAccount.GetBatchAccountPools().CreateOrUpdate(
75+
WaitUntil.Completed, poolName, batchAccountPoolData);
76+
BatchAccountPoolResource pool = armOperation.Value;
4077

4178
```
4279

0 commit comments

Comments
 (0)