/// <summary> /// The Get Delete Operation Status operation returns the status of the /// specified operation. After calling an asynchronous operation, you /// can call Get Delete Operation Status to determine whether the /// operation has succeeded, failed, or is still in progress. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.Batch.IBatchManagementClient. /// </param> /// <param name='operationStatusLink'> /// Required. Location value returned by the BeginDeleting operation. /// </param> /// <returns> /// A standard service response for long running operations. /// </returns> public static LongRunningOperationResponse GetAccountDeleteOperationStatus(this IBatchManagementClient operations, string operationStatusLink) { return(Task.Factory.StartNew((object s) => { return ((IBatchManagementClient)s).GetAccountDeleteOperationStatusAsync(operationStatusLink); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
/// <summary> /// Creates new BatchClient instance /// </summary> /// <param name="batchManagementClient">The IBatchManagementClient instance</param> public BatchClient(IBatchManagementClient batchManagementClient, IResourceManagementClient resourceManagementClient) { BatchManagementClient = batchManagementClient; ResourceManagementClient = resourceManagementClient; }
/// <summary> /// Creates new BatchClient instance /// </summary> /// <param name="batchManagementClient">The IBatchManagementClient instance</param> public BatchClient(IBatchManagementClient batchManagementClient, IResourceManagementClient resourceManagementClient) { BatchManagementClient = batchManagementClient; ResourceManagementClient = resourceManagementClient; }
/// <summary> /// Performs various Batch account operations using the Batch Management library. /// </summary> /// <param name="context">The <see cref="Microsoft.Azure.Common.Authentication.Models.AzureContext"/> containing information /// about the user's Azure account and subscription.</param> /// <param name="accountName">The name of the Batch account to create.</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(AzureContext context, string accountName, string location) { using (IBatchManagementClient batchManagementClient = AzureSession.ClientFactory.CreateClient <BatchManagementClient>(context, AzureEnvironment.Endpoint.ResourceManager)) { // Get the account quota for the subscription SubscriptionQuotasGetResponse quotaResponse = await batchManagementClient.Subscriptions.GetSubscriptionQuotasAsync(location); Console.WriteLine("Your subscription can create {0} account(s) in the {1} region.", quotaResponse.AccountQuota, location); Console.WriteLine(); // Create account Console.WriteLine("Creating account {0} ...", accountName); await batchManagementClient.Accounts.CreateAsync(ResourceGroupName, accountName, new BatchAccountCreateParameters() { Location = location }); Console.WriteLine("Account {0} created", accountName); Console.WriteLine(); // Get account Console.WriteLine("Getting account {0} ...", accountName); BatchAccountGetResponse getResponse = await batchManagementClient.Accounts.GetAsync(ResourceGroupName, accountName); AccountResource account = getResponse.Resource; Console.WriteLine("Got account {0}:", accountName); Console.WriteLine(" Account location: {0}", account.Location); Console.WriteLine(" Account resource type: {0}", account.Type); Console.WriteLine(" Account id: {0}", account.Id); 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); Console.WriteLine(); // Get account keys Console.WriteLine("Getting account keys of account {0} ....", accountName); BatchAccountListKeyResponse accountKeys = await batchManagementClient.Accounts.ListKeysAsync(ResourceGroupName, accountName); Console.WriteLine("Primary key of account {0}:", accountName); Console.WriteLine(accountKeys.PrimaryKey); Console.WriteLine("Secondary key of account {0}:", accountName); Console.WriteLine(accountKeys.SecondaryKey); Console.WriteLine(); // Regenerate account key Console.WriteLine("Regenerating the primary key of account {0} ....", accountName); BatchAccountRegenerateKeyResponse newKeys = await batchManagementClient.Accounts.RegenerateKeyAsync(ResourceGroupName, accountName, new BatchAccountRegenerateKeyParameters() { KeyName = AccountKeyType.Primary }); Console.WriteLine("New primary key of account {0}:", accountName); Console.WriteLine(newKeys.PrimaryKey); Console.WriteLine("Secondary key of account {0}:", accountName); Console.WriteLine(newKeys.SecondaryKey); Console.WriteLine(); // List accounts Console.WriteLine("Listing all Batch accounts under subscription id {0} ...", context.Subscription.Id); BatchAccountListResponse listResponse = await batchManagementClient.Accounts.ListAsync(new AccountListParameters()); IList <AccountResource> accounts = listResponse.Accounts; Console.WriteLine("Total number of Batch accounts under subscription id {0}: {1}", context.Subscription.Id, accounts.Count); for (int i = 0; i < accounts.Count; i++) { Console.WriteLine(" {0} - {1}", i + 1, accounts[i].Name); } Console.WriteLine(); // Delete account Console.WriteLine("Deleting account {0} ...", accountName); await batchManagementClient.Accounts.DeleteAsync(ResourceGroupName, accountName); Console.WriteLine("Account {0} deleted", accountName); Console.WriteLine(); } }
// Performs various Batch account operations private static async Task PerformBatchAccountOperationsAsync(AzureProfile profile, string location) { using (IBatchManagementClient batchManagementClient = AzureSession.ClientFactory.CreateClient <BatchManagementClient>(profile, AzureEnvironment.Endpoint.ResourceManager)) { Console.WriteLine("The Batch account name must be 3 to 24 characters, and it must only contain lowercase letters and numbers."); Console.WriteLine("Please input the account name you want to create: "); string accountName = Console.ReadLine(); Console.WriteLine(); // Create account Console.WriteLine("Creating account {0} ...", accountName); await batchManagementClient.Accounts.CreateAsync(ResourceGroupName, accountName, new BatchAccountCreateParameters() { Location = location }); Console.WriteLine("Account {0} created", accountName); Console.WriteLine(); // Get acount Console.WriteLine("Getting account {0} ...", accountName); BatchAccountGetResponse getRespone = await batchManagementClient.Accounts.GetAsync(ResourceGroupName, accountName); AccountResource account = getRespone.Resource; Console.WriteLine("Got account {0}:", accountName); Console.WriteLine(" Account location: {0}", account.Location); Console.WriteLine(" Account resource type: {0}", account.Type); Console.WriteLine(" Account id: {0}", account.Id); Console.WriteLine(); // Get account keys Console.WriteLine("Getting Account keys of account {0} ....", accountName); BatchAccountListKeyResponse accountKeys = await batchManagementClient.Accounts.ListKeysAsync(ResourceGroupName, accountName); Console.WriteLine("Primary key of account {0}:", accountName); Console.WriteLine(accountKeys.PrimaryKey); Console.WriteLine("Secondary key of account {0}:", accountName); Console.WriteLine(accountKeys.SecondaryKey); Console.WriteLine(); // Regenerate account key Console.WriteLine("Regenerating the primary key of account {0} ....", accountName); BatchAccountRegenerateKeyResponse newKeys = await batchManagementClient.Accounts.RegenerateKeyAsync(ResourceGroupName, accountName, new BatchAccountRegenerateKeyParameters() { KeyName = AccountKeyType.Primary }); Console.WriteLine("New primary key of account {0}:", accountName); Console.WriteLine(newKeys.PrimaryKey); Console.WriteLine("Secondary key of account {0}:", accountName); Console.WriteLine(newKeys.SecondaryKey); Console.WriteLine(); // list accounts Console.WriteLine("Listing all Batch accounts under subscription id {0} ...", profile.DefaultSubscription.Id); BatchAccountListResponse listResponse = await batchManagementClient.Accounts.ListAsync(new AccountListParameters()); IList <AccountResource> accounts = listResponse.Accounts; Console.WriteLine("Total number of Batch accounts under subscription id {0}: {1}", profile.DefaultSubscription.Id, accounts.Count); for (int i = 0; i < accounts.Count; i++) { Console.WriteLine(" {0} - {1}", i + 1, accounts[i].Name); } Console.WriteLine(); // delete account Console.WriteLine("Deleting account {0} ...", accountName); await batchManagementClient.Accounts.DeleteAsync(ResourceGroupName, accountName); Console.WriteLine("Account {0} deleted", accountName); Console.WriteLine(); } }
/// <summary> /// The Get Account Create Operation Status operation returns the /// status of the account creation operation. After calling an /// asynchronous operation, you can call this method to determine /// whether the operation has succeeded, failed, or is still in /// progress. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.Batch.IBatchManagementClient. /// </param> /// <param name='operationStatusLink'> /// Required. Location value returned by the BeginCreating operation. /// </param> /// <returns> /// Values returned by the Create operation. /// </returns> public static Task <BatchAccountCreateResponse> GetAccountCreateOperationStatusAsync(this IBatchManagementClient operations, string operationStatusLink) { return(operations.GetAccountCreateOperationStatusAsync(operationStatusLink, CancellationToken.None)); }