-
Notifications
You must be signed in to change notification settings - Fork 1
/
ManageAzureBatchwithSDK.cs
52 lines (47 loc) · 2.62 KB
/
ManageAzureBatchwithSDK.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Create a new Batch account
await batchManagementClient.Account.CreateAsync("MyResourceGroup",
"mynewaccount",
new BatchAccountCreateParameters() { Location = "West US" });
// Get the new account from the Batch service
AccountResource account = await batchManagementClient.Account.GetAsync(
"MyResourceGroup",
"mynewaccount");
// Delete the account
await batchManagementClient.Account.DeleteAsync("MyResourceGroup",
account.Name);
// Get and print the primary and secondary keys
BatchAccountListKeyResult accountKeys =
await batchManagementClient.Account.ListKeysAsync("MyResourceGroup", "mybatchaccount");
Console.WriteLine("Primary key: {0}", accountKeys.Primary);
Console.WriteLine("Secondary key: {0}", accountKeys.Secondary);
// Regenerate the primary key
BatchAccountRegenerateKeyResponse newKeys =
await batchManagementClient.Account.RegenerateKeyAsync(
"MyResourceGroup", "mybatchaccount",
new BatchAccountRegenerateKeyParameters() {
KeyName = AccountKeyType.Primary
});
// Get a collection of all Batch accounts within the subscription
BatchAccountListResponse listResponse =
await batchManagementClient.Account.ListAsync(new AccountListParameters());
IList<AccountResource> accounts = listResponse.Accounts;
Console.WriteLine("Total number of Batch accounts under subscription id {0}: {1}",
creds.SubscriptionId,
accounts.Count);
// Get a count of all accounts within the target region
string region = "westus";
int accountsInRegion = accounts.Count(o => o.Location == region);
// Get the account quota for the specified region
SubscriptionQuotasGetResponse quotaResponse = await batchManagementClient.Subscriptions.GetSubscriptionQuotasAsync(region);
Console.WriteLine("Account quota for {0} region: {1}", region, quotaResponse.AccountQuota);
// Determine how many accounts can be created in the target region
Console.WriteLine("Accounts in {0}: {1}", region, accountsInRegion);
Console.WriteLine("You can create {0} accounts in the {1} region.", quotaResponse.AccountQuota - accountsInRegion, region);
// First obtain the Batch account
BatchAccountGetResponse getResponse =
await batchManagementClient.Account.GetAsync("MyResourceGroup", "mybatchaccount");
AccountResource account = getResponse.Resource;
// Now print the compute resource quotas for the account
Console.WriteLine("Core quota: {0}", account.Properties.CoreQuota);
Console.WriteLine("Pool quota: {0}", account.Properties.PoolQuota);
Console.WriteLine("Active job and job schedule quota: {0}", account.Properties.ActiveJobAndJobScheduleQuota);