コード例 #1
0
        private string CreateStandardStorageAccount(StorageManagementClient client)
        {
            string storageAccountName;

            var i = 0;

            do
            {
                storageAccountName = GetRandomStorageAccountName(i);
                i++;
            }while (i < 10 && (bool)!client.StorageAccounts.CheckNameAvailability(storageAccountName).NameAvailable);

            SM.ExtendedLocation extendedLocation = null;
            if (this.EdgeZone != null)
            {
                extendedLocation = new SM.ExtendedLocation {
                    Name = this.EdgeZone, Type = CM.ExtendedLocationTypes.EdgeZone
                };
            }

            var storaeAccountParameter = new StorageAccountCreateParameters
            {
                Location         = this.Location ?? this.VM.Location,
                ExtendedLocation = extendedLocation
            };

            storaeAccountParameter.SetAsStandardGRS();

            try
            {
                client.StorageAccounts.Create(this.ResourceGroupName, storageAccountName, storaeAccountParameter);
                var getresponse = client.StorageAccounts.GetProperties(this.ResourceGroupName, storageAccountName);
                WriteWarning(string.Format(Properties.Resources.CreatingStorageAccountForBootDiagnostics, storageAccountName));

                return(getresponse.PrimaryEndpoints.Blob);
            }
            catch (Exception e)
            {
                // Failed to create a storage account for boot diagnostics.
                WriteWarning(string.Format(Properties.Resources.ErrorDuringCreatingStorageAccountForBootDiagnostics, e));
                return(null);
            }
        }