public async Task GetLocationQuotasAsync() { using (MockContext context = StartMockContextAndInitializeClients(GetType())) { BatchLocationQuota quotas = await BatchManagementClient.Location.GetQuotasAsync(Location); Assert.NotNull(quotas.AccountQuota); Assert.True(quotas.AccountQuota.Value > 0); } }
/// <summary> /// Gets the Batch service quotas for the specified subscription at the given region. /// </summary> /// <param name="location">The desired region for the quotas.</param> /// <returns>A PSBatchLocationQuotas object containing the quotas.</returns> public virtual PSBatchLocationQuotas GetLocationQuotas(string location) { if (string.IsNullOrEmpty(location)) { throw new ArgumentNullException("location"); } WriteVerbose(string.Format(Resources.GettingLocationQuotas, location)); BatchLocationQuota response = this.BatchManagementClient.Location.GetQuotas(location); return(new PSBatchLocationQuotas(location, response)); }
public PSBatchLocationQuotas(string location, BatchLocationQuota locationQuotasResponse) { if (string.IsNullOrEmpty(location)) { throw new ArgumentNullException("location"); } if (locationQuotasResponse == null) { throw new ArgumentNullException("locationQuotasResponse"); } this.Location = location; this.AccountQuota = locationQuotasResponse.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 BatchLocationQuota quotaResponse = await batchManagementClient.Location.GetQuotasAsync(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.BatchAccount.CreateAsync(ResourceGroupName, accountName, new BatchAccountCreateParameters() { Location = location }); Console.WriteLine("Account {0} created", accountName); Console.WriteLine(); // Get account Console.WriteLine("Getting account {0}...", accountName); BatchAccount account = await batchManagementClient.BatchAccount.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(" Dedicated core quota: {0}", account.DedicatedCoreQuota); Console.WriteLine(" Low priority core quota: {0}", account.LowPriorityCoreQuota); 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); BatchAccountKeys accountKeys = await batchManagementClient.BatchAccount.GetKeysAsync(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); BatchAccountKeys newKeys = await batchManagementClient.BatchAccount.RegenerateKeyAsync( ResourceGroupName, account.Name, 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 <BatchAccount> listResponse = await batchManagementClient.BatchAccount.ListAsync(); var accounts = new List <BatchAccount>(); accounts.AddRange(listResponse); var nextLink = listResponse.NextPageLink; while (nextLink != null) { listResponse = await batchManagementClient.BatchAccount.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 (BatchAccount 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.BatchAccount.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(); } }