/// <summary> /// Gets the quotas of the subscription in the Batch Service. /// </summary> /// <param name="location">The location to use when getting the Batch subscription quotas.</param> /// <returns>A PSBatchSubscriptionQuotas object containing the subscription quotas.</returns> public virtual PSBatchSubscriptionQuotas GetSubscriptionQuotas(string location) { if (string.IsNullOrEmpty(location)) { throw new ArgumentNullException("location"); } WriteVerbose(string.Format(Resources.GettingSubscriptionQuotas, location)); SubscriptionQuotasGetResult response = this.BatchManagementClient.Subscription.GetSubscriptionQuotas(location); return(new PSBatchSubscriptionQuotas(location, response)); }
public PSBatchSubscriptionQuotas(string location, SubscriptionQuotasGetResult subscriptionQuotasResponse) { if (string.IsNullOrEmpty(location)) { throw new ArgumentNullException("location"); } if (subscriptionQuotasResponse == null) { throw new ArgumentNullException("subscriptionQuotasResponse"); } this.Location = location; this.AccountQuota = subscriptionQuotasResponse.AccountQuota.GetValueOrDefault(); }
/// <summary> /// Performs various Batch account operations using the Batch Management library. /// </summary> /// <param name="accessToken">The access token to use for authentication.</param> /// <param name="subscriptionId">The subscription id to use for creating the Batch management client</param> /// <param name="location">The location where the Batch account will be created.</param> /// <returns>A <see cref="System.Threading.Tasks.Task"/> object that represents the asynchronous operation.</returns> private static async Task PerformBatchAccountOperationsAsync(string accessToken, string subscriptionId, string location) { using (BatchManagementClient batchManagementClient = new BatchManagementClient(new TokenCredentials(accessToken))) { batchManagementClient.SubscriptionId = subscriptionId; // Get the account quota for the subscription SubscriptionQuotasGetResult quotaResponse = await batchManagementClient.Subscription.GetSubscriptionQuotasAsync(location); Console.WriteLine("Your subscription can create {0} account(s) in the {1} region.", quotaResponse.AccountQuota, location); Console.WriteLine(); // Create account string accountName = PromptUserForAccountName(); Console.WriteLine("Creating account {0}...", accountName); await batchManagementClient.Account.CreateAsync(ResourceGroupName, accountName, new BatchAccountCreateParameters() { Location = location }); Console.WriteLine("Account {0} created", accountName); Console.WriteLine(); // Get account Console.WriteLine("Getting account {0}...", accountName); AccountResource account = await batchManagementClient.Account.GetAsync(ResourceGroupName, accountName); Console.WriteLine("Got account {0}:", account.Name); Console.WriteLine(" Account location: {0}", account.Location); Console.WriteLine(" Account resource type: {0}", account.Type); Console.WriteLine(" Account id: {0}", account.Id); Console.WriteLine(); // Print account quotas Console.WriteLine("Quotas for account {0}:", account.Name); Console.WriteLine(" Core quota: {0}", account.CoreQuota); Console.WriteLine(" Pool quota: {0}", account.PoolQuota); Console.WriteLine(" Active job and job schedule quota: {0}", account.ActiveJobAndJobScheduleQuota); Console.WriteLine(); // Get account keys Console.WriteLine("Getting account keys of account {0}...", account.Name); BatchAccountListKeyResult accountKeys = await batchManagementClient.Account.ListKeysAsync(ResourceGroupName, account.Name); Console.WriteLine(" Primary key of account {0}: {1}", account.Name, accountKeys.Primary); Console.WriteLine(" Secondary key of account {0}: {1}", account.Name, accountKeys.Secondary); Console.WriteLine(); // Regenerate primary account key Console.WriteLine("Regenerating the primary key of account {0}...", account.Name); BatchAccountRegenerateKeyResult newKeys = await batchManagementClient.Account.RegenerateKeyAsync( ResourceGroupName, account.Name, new BatchAccountRegenerateKeyParameters() { KeyName = AccountKeyType.Primary }); Console.WriteLine(" New primary key of account {0}: {1}", account.Name, newKeys.Primary); Console.WriteLine(" Secondary key of account {0}: {1}", account.Name, newKeys.Secondary); Console.WriteLine(); // List total number of accounts under the subscription id IPage <AccountResource> listResponse = await batchManagementClient.Account.ListAsync(); var accounts = new List <AccountResource>(); accounts.AddRange(listResponse); var nextLink = listResponse.NextPageLink; while (nextLink != null) { listResponse = await batchManagementClient.Account.ListNextAsync(nextLink); accounts.AddRange(listResponse); nextLink = listResponse.NextPageLink; } Console.WriteLine("Total number of Batch accounts under subscription id {0}: {1}", batchManagementClient.SubscriptionId, accounts.Count()); // Determine how many additional accounts can be created in the target region int numAccountsInRegion = accounts.Count(o => o.Location == account.Location); Console.WriteLine("Accounts in {0}: {1}", account.Location, numAccountsInRegion); Console.WriteLine("You can create {0} more accounts in the {1} region.", quotaResponse.AccountQuota - numAccountsInRegion, account.Location); Console.WriteLine(); // List accounts in the subscription Console.WriteLine("Listing all Batch accounts under subscription id {0}...", batchManagementClient.SubscriptionId); foreach (AccountResource acct in accounts) { Console.WriteLine(" {0} - {1} | Location: {2}", accounts.IndexOf(acct) + 1, acct.Name, acct.Location); } Console.WriteLine(); // Delete account Console.Write("Hit ENTER to delete account {0}: ", account.Name); Console.ReadLine(); Console.WriteLine("Deleting account {0}...", account.Name); try { await batchManagementClient.Account.DeleteAsync(ResourceGroupName, account.Name); } catch (CloudException ex) { /* Account deletion is a long running operation. This .DeleteAsync() method will submit the account deletion request and * poll for the status of the long running operation until the account is deleted. Currently, querying for the operation * status after the account is deleted will return a 404 error, so we have to add this catch statement. This behavior will * be fixed in a future service release. */ if (ex.Response.StatusCode != HttpStatusCode.NotFound) { throw; } } Console.WriteLine("Account {0} deleted", account.Name); Console.WriteLine(); } }