internal bool CheckNameAvailbility() { CheckNameAvailabilityResponse r = _storageManagementClient.StorageAccounts.CheckNameAvailability( _parameters.StorageAccountName); return(r.IsAvailable); }
/// <summary> /// Checks if the given storage service name is available to be created /// </summary> /// <param name="name">The name of the storage service</param> /// <returns></returns> public bool CheckStorageServiceAvailability(string name) { CheckNameAvailabilityResponse response = this.StorageClient.StorageAccounts.CheckNameAvailability(name); if (response != null && !response.IsAvailable) { WriteWarning(response.Reason); } return response.IsAvailable; }
public static CheckNameAvailabilityResponse Create(CheckNameAvailabilityResult rawResponse) { CheckNameAvailabilityResponse response = new CheckNameAvailabilityResponse(); response.NameAvailable = rawResponse.NameAvailable; response.Message = rawResponse.Message; response.Reason = rawResponse.Reason; return(response); }
public async Task <Response <CheckNameAvailabilityResponse> > CheckNameAvailabilityAsync(string subscriptionId, CheckNameAvailabilityContent content, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(subscriptionId, nameof(subscriptionId)); Argument.AssertNotNull(content, nameof(content)); using var message = CreateCheckNameAvailabilityRequest(subscriptionId, content); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); switch (message.Response.Status) { case 200: { CheckNameAvailabilityResponse value = default; using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); value = CheckNameAvailabilityResponse.DeserializeCheckNameAvailabilityResponse(document.RootElement); return(Response.FromValue(value, message.Response)); }
public static CheckNameAvailabilityResponse Create(Dictionary <string, object> output, bool isResourceMode) { CheckNameAvailabilityResponse response = new CheckNameAvailabilityResponse(); response.NameAvailable = Utility.ParseBoolFromJsonOutput(output, "nameAvailable"); response.StatusCode = Utility.ParseEnumFromJsonOutput <HttpStatusCode>(output, "statusCode"); if (isResourceMode) { response.Message = Utility.ParseStringFromJsonOutput(output, "message"); response.Reason = Utility.ParseEnumFromJsonOutput <Reason>(output, "reason"); } else { response.Message = Utility.ParseStringFromJsonOutput(output, "reason"); } return(response); }
public void TestCheckServerNameInvalid() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); string serverName = SqlManagementTestUtilities.GenerateName().ToUpperInvariant(); // upper case is invalid CheckNameAvailabilityResponse response = sqlClient.Servers.CheckNameAvailability(new CheckNameAvailabilityRequest { Name = serverName, }); Assert.False(response.Available); Assert.Equal(serverName, response.Name); Assert.NotNull(response.Message); Assert.Equal(CheckNameAvailabilityReason.Invalid, response.Reason); } }
public void TestCheckServerNameAlreadyExists() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { ResourceGroup resourceGroup = context.CreateResourceGroup(); Server server = context.CreateServer(resourceGroup); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); // Check name of a server that we know exists (because we just created it) CheckNameAvailabilityResponse response = sqlClient.Servers.CheckNameAvailability(new CheckNameAvailabilityRequest { Name = server.Name }); Assert.False(response.Available); Assert.Equal(server.Name, response.Name); Assert.NotNull(response.Message); Assert.Equal(CheckNameAvailabilityReason.AlreadyExists, response.Reason); } }
public void TestCheckServerNameAvailable() { string suiteName = this.GetType().FullName; using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); string serverName = SqlManagementTestUtilities.GenerateName(); CheckNameAvailabilityResponse response = sqlClient.Servers.CheckNameAvailability(new CheckNameAvailabilityRequest { Name = serverName }); Assert.True(response.Available); Assert.Equal(serverName, response.Name); Assert.Equal(null, response.Message); Assert.Equal(null, response.Reason); } }
public static void CreateIfNotExists() { try { CheckNameAvailabilityResponse availabilityResponse = null; LOG.InfoFormat("Checking Availability - StorageAccount: {0}, Region: {1}", AppConfig.AzureResourceName, AppConfig.AzureResourceLocation); Policy. Handle <Exception>(). WaitAndRetry( 5, retryCount => TimeSpan.FromSeconds(Math.Pow(5, retryCount))). Execute( () => { availabilityResponse = SMClient.StorageAccounts.CheckNameAvailability(AppConfig.AzureResourceName); } ); LOG.InfoFormat("Checked Availability - StorageAccount: {0}, Available: {1}", AppConfig.AzureResourceName, availabilityResponse.IsAvailable); if (!availabilityResponse.IsAvailable) { LOG.WarnFormat("Unavailable - StorageAccount: {0}", AppConfig.AzureResourceName); LOG.InfoFormat("Checking existence in current subscription - SubscriptionId: {0}, StorageAccount: {1}", AppConfig.SubscriptionId, AppConfig.AzureResourceName); } else { LOG.InfoFormat("Creating StorageAccount - StorageAccount: {0}, Available: {1}", AppConfig.AzureResourceName, availabilityResponse.IsAvailable); var operationResponse = SMClient.StorageAccounts.Create(new Microsoft.WindowsAzure.Management.Storage.Models.StorageAccountCreateParameters() { AccountType = "Standard_GRS", Name = AppConfig.AzureResourceName, Location = AppConfig.AzureResourceLocation, }); LOG.InfoFormat("Created StorageAccount - StorageAccount: {0}, Status: {1}", AppConfig.AzureResourceName, operationResponse.Status); } LOG.InfoFormat("Getting StorageAccount Information - StorageAccount: {0}", AppConfig.AzureResourceName); Policy .Handle <Exception>() .WaitAndRetry( 10, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), (exception, timeSpan, context) => { LOG.Warn(String.Format("Failed to get StorageAccount information, will retry - SubscriptionId: {0}, StorageAccount: {1}", AppConfig.SubscriptionId, AppConfig.AzureResourceName), exception); } ) .Execute( () => { var storageAccountResponse = SMClient.StorageAccounts.Get(AppConfig.AzureResourceName); Account = storageAccountResponse.StorageAccount; Name = storageAccountResponse.StorageAccount.Name; var storageAccountKeyResponse = SMClient.StorageAccounts.GetKeys(AppConfig.AzureResourceName); PrimaryKey = storageAccountKeyResponse.PrimaryKey; }); } catch (Exception ex) { LOG.Error(String.Format("Unable to get storage information - SubscriptionId: {0}, StorageAccount: {1}", AppConfig.SubscriptionId, AppConfig.AzureResourceName), ex); throw; } if (String.IsNullOrWhiteSpace(Name) || String.IsNullOrWhiteSpace(PrimaryKey)) { throw new ApplicationException(String.Format("Failed to get details of StorageAccount: {0}", AppConfig.AzureResourceName)); } LOG.InfoFormat("Found Storage Details - Name: {0}, PrimaryKey: {1}", Name, PrimaryKey); }