コード例 #1
0
        /// <summary>
        ///     Create stirage service
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public StorageAccount CreateStorageService(StorageAccountCreateParameters input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }
            // storage services must use lowercase names
            input.Name = input.Name.ToLowerInvariant(); 

            var existing = GetStorageService(input.Name);
            if(existing != null)
            {
                return existing;
            }

            var affinityGroupManager = new AzureAffinityGroupManager();
            affinityGroupManager.EnsureAffinityGroupExists(input.AffinityGroup);

            TestEasyLog.Instance.Info(string.Format("Creating storage service '{0}'", input.Name));

            StorageManagementClient.StorageAccounts.CreateAsync(input, new CancellationToken()).Wait();

            existing = GetStorageService(input.Name);

            if (string.Compare(existing.Name, AzureServiceConstants.DefaultStorageServiceName,
                   StringComparison.InvariantCultureIgnoreCase) != 0) // never remember default storage service to avoid deletion
            {
                Dependencies.TestResourcesCollector.Remember(AzureResourceType.StorageService, existing.Name, existing.Name);
            }

            return existing;
        }
コード例 #2
0
 private void AddService(StorageAccountCreateParameters createParameters)
 {
     Add(a =>
     {
         a.Name = createParameters.Name;
     });
 }
 /// <summary>
 /// The Begin Creating Storage Account operation creates a new storage
 /// account in Azure.  (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/hh264518.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Storage.IStorageAccountOperations.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Begin Creating Storage Account
 /// operation.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static AzureOperationResponse BeginCreating(this IStorageAccountOperations operations, StorageAccountCreateParameters parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IStorageAccountOperations)s).BeginCreatingAsync(parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
コード例 #4
0
 /// <summary>
 /// The Create Storage Account operation creates a new storage account
 /// in Windows Azure.  (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/hh264518.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Storage.IStorageAccountOperations.
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to the Create Storage Account operation.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static OperationResponse BeginCreating(this IStorageAccountOperations operations, StorageAccountCreateParameters parameters)
 {
     try
     {
         return operations.BeginCreatingAsync(parameters).Result;
     }
     catch (AggregateException ex)
     {
         if (ex.InnerExceptions.Count > 1)
         {
             throw;
         }
         else
         {
             throw ex.InnerException;
         }
     }
 }
        public void CanAbortStorageAccountMigrationToSrp()
        {
            TestLogTracingInterceptor.Current.Start();

            using (var undoContext = UndoContext.Current)
            {
                undoContext.Start();
                var mgmt = TestBase.GetServiceClient<ManagementClient>();
                var storage = TestBase.GetServiceClient<StorageManagementClient>();

                try
                {
                    var location = mgmt.GetDefaultLocation("Storage");
                    const string westUS = "West US";
                    if (mgmt.Locations.List().Any(
                        c => string.Equals(c.Name, westUS, StringComparison.OrdinalIgnoreCase)))
                    {
                        location = westUS;
                    }

                    var storageAccountName = HttpMockServer.GetAssetName(
                        "teststorage1234",
                        "teststorage").ToLower();

                    Assert.True(storage.StorageAccounts
                               .CheckNameAvailability(storageAccountName).IsAvailable);

                    // Create
                    var storageCreateParams = new StorageAccountCreateParameters
                    {
                        Location = location,
                        AffinityGroup = null,
                        Label = "Test测试1",
                        Description = "Test测试2",
                        Name = storageAccountName,
                        AccountType = StorageAccountTypes.StandardGRS,
                        ExtendedProperties = new Dictionary<string, string>
                        {
                            { "foo1", "bar" },
                            { "foo2", "baz" }
                        }
                    };
                    var st1 = storage.StorageAccounts.Create(storageCreateParams);

                    // Get
                    var storageCreated = storage.StorageAccounts
                                        .Get(storageAccountName).StorageAccount;
                    VerifyStorageAccount(
                        storageCreated,
                        storageCreateParams.Name,
                        storageCreateParams.Label,
                        storageCreateParams.Description,
                        storageCreateParams.Location,
                        storageCreateParams.AccountType);
                    Assert.True(storageCreated.ExtendedProperties["foo1"] == "bar");
                    Assert.True(storageCreated.ExtendedProperties["foo2"] == "baz");

                    var response = storage.StorageAccounts.PrepareMigration(storageAccountName);
                    Assert.Equal(OperationStatus.Succeeded, response.Status);

                    storageCreated = storage.StorageAccounts.Get(storageAccountName).StorageAccount;
                    Assert.Equal(IaaSClassicToArmMigrationState.Prepared, storageCreated.MigrationState);

                    response = storage.StorageAccounts.AbortMigration(storageAccountName);
                    Assert.Equal(OperationStatus.Succeeded, response.Status);
                }
                finally
                {
                    undoContext.Dispose();
                    mgmt.Dispose();
                    storage.Dispose();
                    TestLogTracingInterceptor.Current.Stop();
                }
            }
        }
        public void CanCreateUpdateGetAndDeleteStorageAccounts()
        {
            TestLogTracingInterceptor.Current.Start();

            using (var undoContext = UndoContext.Current)
            {
                undoContext.Start();
                var mgmt = TestBase.GetServiceClient<ManagementClient>();
                var storage = TestBase.GetServiceClient<StorageManagementClient>();

                try
                {
                    var location = mgmt.GetDefaultLocation("Storage");
                    const string westUS = "West US";
                    if (mgmt.Locations.List().Any(
                        c => string.Equals(c.Name, westUS, StringComparison.OrdinalIgnoreCase)))
                    {
                        location = westUS;
                    }

                    var storageAccountName = HttpMockServer.GetAssetName(
                        "teststorage1234",
                        "teststorage").ToLower();

                    Assert.True(storage.StorageAccounts
                               .CheckNameAvailability(storageAccountName).IsAvailable);

                    // Create
                    var storageCreateParams = new StorageAccountCreateParameters
                    {
                        Location = location,
                        AffinityGroup = null,
                        Label = "Test测试1",
                        Description = "Test测试2",
                        Name = storageAccountName,
                        AccountType = StorageAccountTypes.StandardGRS,
                        ExtendedProperties = new Dictionary<string, string>
                        {
                            { "foo1", "bar" },
                            { "foo2", "baz" }
                        }
                    };
                    var st1 = storage.StorageAccounts.Create(storageCreateParams);

                    // Get
                    var storageCreated = storage.StorageAccounts
                                        .Get(storageAccountName).StorageAccount;
                    VerifyStorageAccount(
                        storageCreated,
                        storageCreateParams.Name,
                        storageCreateParams.Label,
                        storageCreateParams.Description,
                        storageCreateParams.Location,
                        storageCreateParams.AccountType);
                    Assert.True(storageCreated.ExtendedProperties["foo1"] == "bar");
                    Assert.True(storageCreated.ExtendedProperties["foo2"] == "baz");

                    // Update
                    var storageUpdateParams = new StorageAccountUpdateParameters
                    {
                        Label = "Test测试3",
                        Description = "Test测试4",
                        AccountType = StorageAccountTypes.StandardRAGRS
                    };
                    var st2 = storage.StorageAccounts.Update(
                        storageAccountName,
                        storageUpdateParams);

                    // List
                    var storageUpdated = storage.StorageAccounts.List()
                                        .First(s => s.Name == storageAccountName);
                    VerifyStorageAccount(
                        storageUpdated,
                        storageAccountName,
                        storageUpdateParams.Label,
                        storageUpdateParams.Description,
                        storageCreateParams.Location,
                        storageUpdateParams.AccountType);

                    // Keys
                    var st3 = storage.StorageAccounts.GetKeys(storageAccountName);

                    var st4 = storage.StorageAccounts.RegenerateKeys(
                        new StorageAccountRegenerateKeysParameters
                        {
                            Name = storageAccountName,
                            KeyType = StorageKeyType.Primary
                        });

                    var st5 = storage.StorageAccounts.GetKeys(storageAccountName);

                    Assert.True(st5.PrimaryKey != st3.PrimaryKey
                             && st5.SecondaryKey == st3.SecondaryKey);

                    // Delete
                    var st6 = storage.StorageAccounts.Delete(storageAccountName);

                    Assert.True(!storage.StorageAccounts.List()
                                .StorageAccounts.Any(s => s.Name == storageAccountName));
                }
                finally
                {
                    undoContext.Dispose();
                    mgmt.Dispose();
                    storage.Dispose();
                    TestLogTracingInterceptor.Current.Stop();
                }
            }
        }
        public void BackupRestore()
        {
            using (var context = UndoContext.Current)
            {
                context.Start("ResourceProviderFunctionalTests", "BackupRestore");

                TryCreateApiService();

                // create storage account with blob container for the API Management backup
                var storageManagementClient = GetServiceClient<StorageManagementClient>();

                var storageAccountName = TestUtilities.GenerateName("hydraapimstorage");
                Assert.True(
                    storageManagementClient.StorageAccounts.CheckNameAvailability(storageAccountName).IsAvailable,
                    "Could not generate unique storage account name");

                var storageCreateParams = new StorageAccountCreateParameters
                {
                    Name = storageAccountName,
                    Location = Location,
                    AffinityGroup = null,
                    Label = "ApimHydraBackupRestoreTest",
                    Description = "Api Management hydra client backup/restore test",
                    AccountType = StorageAccountTypes.StandardGRS
                };
                storageManagementClient.StorageAccounts.Create(storageCreateParams);
                var storageKeysResponse = storageManagementClient.StorageAccounts.GetKeys(storageAccountName);

                const string apimBackupContainerName = "apimbackupcontainer";

                // create API Management backup
                var apiManagementClient = GetServiceClient<ApiManagementClient>(new CSMTestEnvironmentFactory());
                apiManagementClient.RefreshAccessToken();

                const string apimBackupName = "apimbackup.zip";
                var backupRestoreParameters = new ApiServiceBackupRestoreParameters
                {
                    StorageAccount = storageAccountName,
                    AccessKey = storageKeysResponse.PrimaryKey,
                    ContainerName = apimBackupContainerName,
                    BackupName = apimBackupName
                };
                var response =
                    apiManagementClient.ResourceProvider.Backup(
                        ResourceGroupName,
                        ApiManagementServiceName,
                        backupRestoreParameters);

                Assert.Equal(HttpStatusCode.OK, response.StatusCode);

                // restore Api Management service from backup

                apiManagementClient.RefreshAccessToken();

                response =
                    apiManagementClient.ResourceProvider.Restore(
                        ResourceGroupName,
                        ApiManagementServiceName,
                        backupRestoreParameters);

                Assert.NotNull(response);
                Assert.Equal(HttpStatusCode.OK, response.StatusCode);

                var getResponse = apiManagementClient.ResourceProvider.Get(ResourceGroupName, ApiManagementServiceName);
                Assert.NotNull(getResponse);
                Assert.Equal(HttpStatusCode.OK, getResponse.StatusCode);
                Assert.NotNull(getResponse.Value);
                Assert.Equal("Succeeded", getResponse.Value.Properties.ProvisioningState);
            }
        }
 /// <summary>
 /// The Create Storage Account operation creates a new storage account
 /// in Azure.  (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/hh264518.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Storage.IStorageAccountOperations.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Create Storage Account
 /// operation.
 /// </param>
 /// <returns>
 /// The response body contains the status of the specified asynchronous
 /// operation, indicating whether it has succeeded, is inprogress, or
 /// has failed. Note that this status is distinct from the HTTP status
 /// code returned for the Get Operation Status operation itself. If
 /// the asynchronous operation succeeded, the response body includes
 /// the HTTP status code for the successful request. If the
 /// asynchronous operation failed, the response body includes the HTTP
 /// status code for the failed request and error information regarding
 /// the failure.
 /// </returns>
 public static Task<OperationStatusResponse> CreateAsync(this IStorageAccountOperations operations, StorageAccountCreateParameters parameters)
 {
     return operations.CreateAsync(parameters, CancellationToken.None);
 }
 /// <summary>
 /// The Begin Creating Storage Account operation creates a new storage
 /// account in Azure.  (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/hh264518.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Storage.IStorageAccountOperations.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Begin Creating Storage Account
 /// operation.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static Task<AzureOperationResponse> BeginCreatingAsync(this IStorageAccountOperations operations, StorageAccountCreateParameters parameters)
 {
     return operations.BeginCreatingAsync(parameters, CancellationToken.None);
 }
コード例 #10
0
        /// <summary>
        /// Creates storage service if it does not exist.
        /// </summary>
        /// <param name="name">The storage service name</param>
        /// <param name="label">The storage service label</param>
        /// <param name="location">The location name. If not provided default one will be used</param>
        /// <param name="affinityGroup">The affinity group name</param>
        public void CreateStorageServiceIfNotExist(
            string name,
            string label = null,
            string location = null,
            string affinityGroup = null)
        {
            if (!StorageServiceExists(name))
            {
                var createParameters = new StorageAccountCreateParameters {Name = name, Label = label, AccountType = "Standard_LRS"};
             
                if (!string.IsNullOrEmpty(affinityGroup))
                {
                    createParameters.AffinityGroup = affinityGroup;
                }
                else
                {
                    location = string.IsNullOrEmpty(location) ? GetDefaultLocation() : location;
                    createParameters.Location = location;
                }

                TranslateException(() => StorageClient.StorageAccounts.Create(createParameters));
            }
        }
コード例 #11
0
        internal void ExecuteCommand()
        {
            ServiceManagementProfile.Initialize();

            var parameters = new StorageAccountCreateParameters
            {
                Name =  this.StorageAccountName,
                Label =  this.Label,
                Description = this.Description,
                AffinityGroup = this.AffinityGroup,
                Location = this.Location,
                AccountType = string.IsNullOrEmpty(this.Type) ? StorageAccountTypes.StandardGRS : this.Type
            };

            ExecuteClientActionNewSM(
                parameters,
                CommandRuntime.ToString(),
                () => this.StorageClient.StorageAccounts.Create(parameters));
        }
コード例 #12
0
 private static StorageAccountCreateParameters CreateStorageAccountParameters(DeveloperParameters developerOptions)
 {
     var parameters = new StorageAccountCreateParameters
     {
         Description = developerOptions.Description,
         //GeoReplicationEnabled = developerOptions.GeoReplicationEnabled,
         // for now. not sure what the label entails.
         Label = developerOptions.StorageAccountName,
         Name = developerOptions.StorageAccountName
     };
     if (developerOptions.AffinityGroup != null)
     {
         parameters.AffinityGroup = developerOptions.AffinityGroup;
     }
     else if (developerOptions.Location != null)
     {
         parameters.Location = developerOptions.Location;
     }
     else
     {
         throw new ArgumentException(
             "Must have a value for either AffinityGroup or Location. Please verify your settings in the manifest file.");
     }
     return parameters;
 }
        private async void CreateStorageAccount()
        {
            Host.StatusMessage = "Creating Storage Account";

            var acct = new StorageAccountCreateParameters
            {
                ServiceName = NewStorageAccountName,
                Location = SelectedLocation.Name
            };

            await _storageClient.StorageAccounts.CreateAsync(acct);

            Host.StatusMessage = "Storage Account Created";

            await GetStorageAccounts();
        }