コード例 #1
0
        public static void StorageAccountTestInit(TestContext testContext)
        {
            TestBase.TestClassInitialize(testContext);

            if (isResourceMode)
            {
                NodeJSAgent.AgentConfig.UseEnvVar = false;

                AzureEnvironment environment = Utility.GetTargetEnvironment();
                managementClient = new ManagementClient(Utility.GetCertificateCloudCredential(),
                                                        environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ServiceManagement));

                accountUtils = new AccountUtils(lang, isResourceMode);

                accountName = accountUtils.GenerateAccountName();

                resourceLocation  = isMooncake ? Constants.MCLocation.ChinaEast : allowedLocation;
                resourceManager   = new ResourceManagerWrapper();
                resourceGroupName = accountUtils.GenerateResourceGroupName();
                resourceManager.CreateResourceGroup(resourceGroupName, resourceLocation);

                var parameters = new SRPModel.StorageAccountCreateParameters(new SRPModel.Sku(SRPModel.SkuName.StandardGRS), SRPModel.Kind.StorageV2,
                                                                             isMooncake ? Constants.MCLocation.ChinaEast : allowedLocation);
                accountUtils.SRPStorageClient.StorageAccounts.CreateAsync(resourceGroupName, accountName, parameters, CancellationToken.None).Wait();

                //resourceGroupName = "weitest";
                //accountName = "weitesttemp";
            }
        }
コード例 #2
0
 /// <summary>
 /// Asynchronously creates a new storage account with the specified
 /// parameters. Existing accounts cannot be updated with this API and
 /// should instead use the Update Storage Account API. If an account
 /// is already created and subsequent PUT request is issued with exact
 /// same set of properties, then HTTP 200 would be returned.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Storage.IStorageAccountOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group within the user's
 /// subscription.
 /// </param>
 /// <param name='accountName'>
 /// Required. The name of the storage account within the specified
 /// resource group. Storage account names must be between 3 and 24
 /// characters in length and use numbers and lower-case letters only.
 /// </param>
 /// <param name='parameters'>
 /// Required. The parameters to provide for the created account.
 /// </param>
 /// <returns>
 /// The Create storage account operation response.
 /// </returns>
 public static StorageAccountCreateResponse BeginCreate(this IStorageAccountOperations operations, string resourceGroupName, string accountName, StorageAccountCreateParameters parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IStorageAccountOperations)s).BeginCreateAsync(resourceGroupName, accountName, parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
コード例 #3
0
        /// <summary>
        /// Create storage account
        /// </summary>
        /// <param name="resourceGroupName"></param>
        /// <param name="storageAccountName"></param>
        /// <param name="location"></param>
        /// <param name="storageAccountSuffix"></param>
        /// <param name="kind"></param>
        /// <returns></returns>
        public string CreateStorageAccount(
            string resourceGroupName,
            string storageAccountName,
            string location,
            out string storageAccountSuffix,
            Kind kind         = Kind.Storage,
            bool?isHnsEnabled = default(bool?))
        {
            var stoInput = new StorageAccountCreateParameters
            {
                Location = location,
                Kind     = kind,
                Sku      = new Microsoft.Azure.Management.Storage.Models.Sku
                {
                    Name = Microsoft.Azure.Management.Storage.Models.SkuName.StandardGRS
                },
                IsHnsEnabled = isHnsEnabled
            };

            // Retrieve the storage account
            storageManagementClient.StorageAccounts.Create(
                resourceGroupName,
                storageAccountName,
                stoInput
                );

            // Retrieve the storage account primary access key
            var accessKey =
                storageManagementClient.StorageAccounts.ListKeys(
                    resourceGroupName,
                    storageAccountName
                    ).Keys[0].Value;

            ThrowIfTrue(
                string.IsNullOrEmpty(accessKey),
                "storageManagementClient.StorageAccounts.ListKeys returned null."
                );

            // Set the storage account suffix
            var getResponse =
                storageManagementClient.StorageAccounts.GetProperties(
                    resourceGroupName,
                    storageAccountName
                    );

            storageAccountSuffix = getResponse.PrimaryEndpoints.Blob.ToString();
            storageAccountSuffix = storageAccountSuffix.Replace("https://", "").TrimEnd('/');
            storageAccountSuffix = storageAccountSuffix.Replace(storageAccountName, "").TrimStart('.');
            // Remove the opening "blob." if it exists.
            storageAccountSuffix = storageAccountSuffix.Replace("blob.", "");

            return(accessKey);
        }
コード例 #4
0
        public void StorageAccountCreateTest()
        {
            var handler = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK };

            using (var context = UndoContext.Current)
            {
                context.Start();

                var resourcesClient = StorageManagementTestUtilities.GetResourceManagementClient(handler);
                var storageMgmtClient = StorageManagementTestUtilities.GetStorageManagementClient(handler);

                // Create resource group
                var rgname = StorageManagementTestUtilities.CreateResourceGroup(resourcesClient);

                // Create storage account
                string accountName = TestUtilities.GenerateName("sto");
                StorageAccountCreateParameters parameters = StorageManagementTestUtilities.GetDefaultStorageAccountParameters();
                var createRequest = storageMgmtClient.StorageAccounts.Create(rgname, accountName, parameters);

                Assert.Equal(createRequest.StorageAccount.Location, StorageManagementTestUtilities.DefaultLocation);
                Assert.Equal(createRequest.StorageAccount.AccountType, AccountType.StandardGRS);
                Assert.Equal(createRequest.StorageAccount.Tags.Count, 2);

                // Make sure a second create returns immediately
                createRequest = storageMgmtClient.StorageAccounts.Create(rgname, accountName, parameters);
                Assert.Equal(createRequest.StatusCode, HttpStatusCode.OK);

                Assert.Equal(createRequest.StorageAccount.Location, StorageManagementTestUtilities.DefaultLocation);
                Assert.Equal(createRequest.StorageAccount.AccountType, AccountType.StandardGRS);
                Assert.Equal(createRequest.StorageAccount.Tags.Count, 2);

                // Create storage account with only required params
                accountName = TestUtilities.GenerateName("sto");
                parameters = new StorageAccountCreateParameters
                {
                    AccountType = AccountType.StandardGRS,
                    Location = StorageManagementTestUtilities.DefaultLocation
                };
                createRequest = storageMgmtClient.StorageAccounts.Create(rgname, accountName, parameters);

                Assert.Equal(createRequest.StorageAccount.Location, StorageManagementTestUtilities.DefaultLocation);
                Assert.Equal(createRequest.StorageAccount.AccountType, AccountType.StandardGRS);
                Assert.Empty(createRequest.StorageAccount.Tags);
            }
        }
コード例 #5
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            StorageAccountCreateParameters createParameters = new StorageAccountCreateParameters()
            {
                Location = this.Location,
                AccountType = ParseAccountType(this.Type)
            };

            var createAccountResponse = this.StorageClient.StorageAccounts.Create(
                this.ResourceGroupName,
                this.Name,
                createParameters);

            var getAccountResponse = this.StorageClient.StorageAccounts.GetProperties(this.ResourceGroupName, this.Name);

            this.WriteStorageAccount(getAccountResponse.StorageAccount);
        }
コード例 #6
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            StorageAccountCreateParameters createParameters = new StorageAccountCreateParameters()
            {
                Location = this.Location,
                AccountType = ParseAccountType(this.Type),
                Tags = TagsConversionHelper.CreateTagDictionary(Tags, validate: true)
            };

            var createAccountResponse = this.StorageClient.StorageAccounts.Create(
                this.ResourceGroupName,
                this.Name,
                createParameters);

            var getAccountResponse = this.StorageClient.StorageAccounts.GetProperties(this.ResourceGroupName, this.Name);

            this.WriteStorageAccount(getAccountResponse.StorageAccount);
        }
コード例 #7
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            StorageAccountCreateParameters createParameters = new StorageAccountCreateParameters()
            {
                Location = this.Location,
                AccountType = ParseAccountType(this.Type),
                Tags = TagsConversionHelper.CreateTagDictionary(Tags, validate: true)
            };

            var createAccountResponse = this.StorageClient.StorageAccounts.Create(
                this.ResourceGroupName,
                this.Name,
                createParameters);

            var storageAccount = this.StorageClient.StorageAccounts.GetProperties(this.ResourceGroupName, this.Name).StorageAccount;

            this.WriteStorageAccount(storageAccount);
        }
コード例 #8
0
        public static async Task <AzureResourceProperties> CreateStorageAsync()
        {
            var subscription  = TestUtility.EventHubsSubscription;
            var resourceGroup = TestUtility.EventHubsResourceGroup;
            var token         = await AquireManagementTokenAsync();

            string CreateName() => $"neteventhubstrackone{ Guid.NewGuid().ToString("D").Substring(0, 4) }";

            using (var client = new StorageManagementClient(TestUtility.ResourceManager, new TokenCredentials(token))
            {
                SubscriptionId = subscription
            })
            {
                var location = await QueryResourceGroupLocationAsync(token, resourceGroup, subscription);

                var sku            = new StorageManagement.Sku(StorageManagement.SkuName.StandardLRS, StorageManagement.SkuTier.Standard);
                var parameters     = new StorageManagement.StorageAccountCreateParameters(sku, StorageManagement.Kind.BlobStorage, location: location, tags: GetResourceTags(), accessTier: StorageManagement.AccessTier.Hot);
                var storageAccount = await CreateRetryPolicy <StorageManagement.StorageAccount>().ExecuteAsync(() => client.StorageAccounts.CreateAsync(resourceGroup, CreateName(), parameters));

                var storageKeys = await CreateRetryPolicy <StorageManagement.StorageAccountListKeysResult>().ExecuteAsync(() => client.StorageAccounts.ListKeysAsync(resourceGroup, storageAccount.Name));

                return(new AzureResourceProperties(storageAccount.Name, $"DefaultEndpointsProtocol=https;AccountName={ storageAccount.Name };AccountKey={ storageKeys.Keys[0].Value };EndpointSuffix={ TestUtility.StorageEndpointSuffix }", true));
            }
        }
コード例 #9
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            WriteWarning("The usage of Tags parameter in this cmdlet will be modified in a future release. This will impact creating, updating and appending tags for Azure resources. For more details about the change, please visit https://github.com/Azure/azure-powershell/issues/726#issuecomment-213545494");

            CheckNameAvailabilityResult checkNameAvailabilityResult = this.StorageClient.StorageAccounts.CheckNameAvailability(this.Name);
            if (!checkNameAvailabilityResult.NameAvailable.Value)
            {
                throw new System.ArgumentException(checkNameAvailabilityResult.Message, "Name");
            }

            StorageAccountCreateParameters createParameters = new StorageAccountCreateParameters()
            {
                Location = this.Location,
                Kind = ParseAccountKind(Kind),
                Sku = new Sku(ParseSkuName(this.SkuName)),
                Tags = TagsConversionHelper.CreateTagDictionary(Tags, validate: true),
            };

            if (this.CustomDomainName != null)
            {
                createParameters.CustomDomain = new CustomDomain()
                {
                    Name = CustomDomainName,
                    UseSubDomain = UseSubDomain
                };
            }
            else if (UseSubDomain != null)
            {
                throw new System.ArgumentException(string.Format("UseSubDomain must be set together with CustomDomainName."));
            }

            if (this.EnableEncryptionService != null)
            {
                createParameters.Encryption = ParseEncryption(EnableEncryptionService);
            }

            if (this.AccessTier != null)
            {
                createParameters.AccessTier = ParseAccessTier(AccessTier);
            }

            var createAccountResponse = this.StorageClient.StorageAccounts.Create(
                this.ResourceGroupName,
                this.Name,
                createParameters);

            var storageAccount = this.StorageClient.StorageAccounts.GetProperties(this.ResourceGroupName, this.Name);

            this.WriteStorageAccount(storageAccount);
        }
コード例 #10
0
        private Uri CreateStandardStorageAccount(StorageManagementClient client)
        {
            string storageAccountName;

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

            var storaeAccountParameter = new StorageAccountCreateParameters
            {
                AccountType = AccountType.StandardGRS,
                Location = this.Location ?? this.VM.Location,
            };

            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.StorageAccount.PrimaryEndpoints.Blob;
            }
            catch (Exception e)
            {
                // Failed to create a storage account for boot diagnostics.
                WriteWarning(string.Format(Properties.Resources.ErrorDuringCreatingStorageAccountForBootDiagnostics, e));
                return null;
            }
        }
コード例 #11
0
        public string TryCreateStorageAccount(string resourceGroupName, string storageAccountName, string label, string description, string location, out string storageAccountSuffix)
        {
            var stoInput = new StorageAccountCreateParameters
            {
                Location = location,
                AccountType = AccountType.StandardGRS
            };

            // retrieve the storage account
            StorageManagementClient.StorageAccounts.Create(resourceGroupName, storageAccountName, stoInput);

            // retrieve the storage account primary access key
            var accessKey = StorageManagementClient.StorageAccounts.ListKeys(resourceGroupName, storageAccountName).StorageAccountKeys.Key1;
            ThrowIfTrue(string.IsNullOrEmpty(accessKey), "storageManagementClient.StorageAccounts.ListKeys returned null.");

            // set the storage account suffix
            var getResponse = StorageManagementClient.StorageAccounts.GetProperties(resourceGroupName, storageAccountName);
            storageAccountSuffix = getResponse.StorageAccount.PrimaryEndpoints.Blob.ToString();
            storageAccountSuffix = storageAccountSuffix.Replace("https://", "").TrimEnd('/');
            storageAccountSuffix = storageAccountSuffix.Replace(storageAccountName, "").TrimStart('.');

            return accessKey;
        }
コード例 #12
0
        protected StorageAccount CreateStorageAccount(string rgName, string storageAccountName)
        {
            try
            {
                // Create the resource Group.
                var resourceGroup = m_ResourcesClient.ResourceGroups.CreateOrUpdate(
                    rgName,
                    new ResourceGroup
                    {
                        Location = m_location
                    });

                var stoInput = new StorageAccountCreateParameters
                {
                    Location = m_location,
                    AccountType = AccountType.StandardGRS
                };

                StorageAccount storageAccountOutput = m_SrpClient.StorageAccounts.Create(rgName,
                    storageAccountName, stoInput).StorageAccount;
                bool created = false;
                while (!created)
                {
                    ComputeManagementTestUtilities.WaitSeconds(10);
                    var stos = m_SrpClient.StorageAccounts.ListByResourceGroup(rgName);
                    created =
                        stos.StorageAccounts.Any(
                            t =>
                                StringComparer.OrdinalIgnoreCase.Equals(t.Name, storageAccountName));
                }

                storageAccountOutput.Name = storageAccountName; // TODO: try to remove this in a future recording

                return storageAccountOutput;
            }
            catch
            {
                var deleteRg1Response = m_ResourcesClient.ResourceGroups.Delete(rgName);
                Assert.True(deleteRg1Response.StatusCode == HttpStatusCode.OK);
                throw;
            }
        }
        /// <summary>
        /// Returns default values to create a storage account
        /// </summary>
        /// <returns>The parameters to provide for the account</returns>
        private static StorageAccountCreateParameters GetDefaultStorageAccountParameters()
        {
            StorageAccountCreateParameters account = new StorageAccountCreateParameters
            {
                Location = DefaultLocation,
                Tags = DefaultTags,
                AccountType = DefaultAccountType
            };

            return account;
        }
        /// <summary>
        /// Returns default values to create a storage account
        /// </summary>
        /// <returns>The parameters to provide for the account</returns>
        private static StorageAccountCreateParameters GetDefaultStorageAccountParameters()
        {
            StorageAccountCreateParameters account = new StorageAccountCreateParameters
            {
                Location = DefaultLocation,
                Kind = DefaultKind,
                Tags = DefaultTags,
                Sku = DefaultSku
            };

            return account;
        }
コード例 #15
0
 /// <summary>
 /// Asynchronously creates a new storage account with the specified
 /// parameters. Existing accounts cannot be updated with this API and
 /// should instead use the Update Storage Account API. If an account
 /// is already created and subsequent PUT request is issued with exact
 /// same set of properties, then HTTP 200 would be returned.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Storage.IStorageAccountOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group within the user's
 /// subscription.
 /// </param>
 /// <param name='accountName'>
 /// Required. The name of the storage account within the specified
 /// resource group. Storage account names must be between 3 and 24
 /// characters in length and use numbers and lower-case letters only.
 /// </param>
 /// <param name='parameters'>
 /// Required. The parameters to provide for the created account.
 /// </param>
 /// <returns>
 /// The Create storage account operation response.
 /// </returns>
 public static Task<StorageAccountCreateResponse> BeginCreateAsync(this IStorageAccountOperations operations, string resourceGroupName, string accountName, StorageAccountCreateParameters parameters)
 {
     return operations.BeginCreateAsync(resourceGroupName, accountName, parameters, CancellationToken.None);
 }
コード例 #16
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            CheckNameAvailabilityResult checkNameAvailabilityResult = this.StorageClient.StorageAccounts.CheckNameAvailability(this.Name);
            if (!checkNameAvailabilityResult.NameAvailable.Value)
            {
                throw new System.ArgumentException(checkNameAvailabilityResult.Message, "Name");
            }

            StorageAccountCreateParameters createParameters = new StorageAccountCreateParameters()
            {
                Location = this.Location,
                Kind = ParseAccountKind(Kind),
                Sku = new Sku(ParseSkuName(this.SkuName)),
                Tags = TagsConversionHelper.CreateTagDictionary(Tag, validate: true),
            };

            if (this.CustomDomainName != null)
            {
                createParameters.CustomDomain = new CustomDomain()
                {
                    Name = CustomDomainName,
                    UseSubDomain = UseSubDomain
                };
            }
            else if (UseSubDomain != null)
            {
                throw new System.ArgumentException(string.Format("UseSubDomain must be set together with CustomDomainName."));
            }

            if (this.EnableEncryptionService != null)
            {
                createParameters.Encryption = ParseEncryption(EnableEncryptionService);
            }

            if (this.AccessTier != null)
            {
                createParameters.AccessTier = ParseAccessTier(AccessTier);
            }

            var createAccountResponse = this.StorageClient.StorageAccounts.Create(
                this.ResourceGroupName,
                this.Name,
                createParameters);

            var storageAccount = this.StorageClient.StorageAccounts.GetProperties(this.ResourceGroupName, this.Name);

            this.WriteStorageAccount(storageAccount);
        }
コード例 #17
0
ファイル: AzureDemo.cs プロジェクト: haliferi/azurenuget
 public void CreateStorageAccount()
 {
     using (var storageManagementClient = new StorageManagementClient(azureLogin.Credentials))
     {
         var sacp = new StorageAccountCreateParameters()
         {
             AccountType = AccountType.StandardLRS,
             Location = demo.Location,
         };
         HandleResult("Create Storage Account", 
             () => storageManagementClient.StorageAccounts.Create(demo.Group, demo.Storage, sacp),
             t => t.Status.ToString());
     }
 }