/// <summary>
 /// Creates a new Azure backup vault.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.BackupServices.IVaultOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of resource group to which vault belongs
 /// </param>
 /// <param name='resourceName'>
 /// Required. The name of the vault
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters to create or update the vault
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Optional. Request header parameters.
 /// </param>
 /// <returns>
 /// Vault information.
 /// </returns>
 public static AzureBackupVaultGetResponse CreateOrUpdate(this IVaultOperations operations, string resourceGroupName, string resourceName, AzureBackupVaultCreateOrUpdateParameters parameters, CustomRequestHeaders customRequestHeaders)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IVaultOperations)s).CreateOrUpdateAsync(resourceGroupName, resourceName, parameters, customRequestHeaders);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
Пример #2
0
        /// <summary>
        /// Creates or updates the vault identified by client
        /// </summary>
        /// <param name="location"></param>
        /// <param name="skuParam"></param>
        /// <returns></returns>
        public AzureBackupVault CreateOrUpdateAzureBackupVault(string resourceGroupName, string vaultName, string location)
        {
            var createResourceParameters = new AzureBackupVaultCreateOrUpdateParameters()
            {
                Location = location,
                Properties = new AzureBackupVaultProperties()
                {
                    Sku = new SkuProperties()
                    {
                        Name = defaultSKU,
                    },
                },
            };

            var response = AzureBackupVaultClient.Vault.CreateOrUpdateAsync(resourceGroupName, vaultName, createResourceParameters, GetCustomRequestHeaders(), CmdletCancellationToken).Result;
            return response.Vault;
        }
Пример #3
0
        public void DeleteVaultRemovesVaultTest()
        {
            using (UndoContext undoContext = UndoContext.Current)
            {
                undoContext.Start();

                BackupVaultServicesManagementClient client = GetServiceClient<BackupVaultServicesManagementClient>();

                string resourceGroupName = ConfigurationManager.AppSettings["resourceGroupName"];
                string location = ConfigurationManager.AppSettings["Location"];
                string resourceName = "delTestRes";
                string defaultSku = "standard";

                AzureBackupVaultCreateOrUpdateParameters parameters = new AzureBackupVaultCreateOrUpdateParameters()
                {
                    Location = location,
                    Properties = new AzureBackupVaultProperties()
                    {
                        Sku = new SkuProperties()
                        {
                            Name = defaultSku,
                        },
                    },
                };

                AzureBackupVaultGetResponse createResponse = client.Vault.CreateOrUpdate(resourceGroupName, resourceName, parameters, GetCustomRequestHeaders());
                Assert.True(createResponse.StatusCode == HttpStatusCode.OK || createResponse.StatusCode == HttpStatusCode.Created,
                            "Unable to create test resource");

                AzureBackupVaultGetResponse deleteResponse = client.Vault.Delete(resourceGroupName, resourceName, GetCustomRequestHeaders());
                Assert.NotNull(deleteResponse);
                Assert.Equal(deleteResponse.StatusCode, HttpStatusCode.OK);

                bool resourceDeleted = false;
                try
                {
                    AzureBackupVaultGetResponse getResponse = client.Vault.Get(resourceGroupName, resourceName, GetCustomRequestHeaders());
                }
                catch (Exception ex)
                {
                    if (ex.GetType() == typeof(Hyak.Common.CloudException))
                    {
                        Hyak.Common.CloudException cloudEx = ex as Hyak.Common.CloudException;
                        if (cloudEx != null &&
                            cloudEx.Error != null &&
                            !string.IsNullOrEmpty(cloudEx.Error.Code) &&
                            cloudEx.Error.Code == "ResourceNotFound")
                        {
                            resourceDeleted = true;
                        }
                    }
                }

                Assert.True(resourceDeleted, "Resource still exists after deletion");
            }
        }
Пример #4
0
        public void CreateOrUpdateVaultReturnsValidCodeTest()
        {
            using (UndoContext undoContext = UndoContext.Current)
            {
                undoContext.Start();

                BackupVaultServicesManagementClient client = GetServiceClient<BackupVaultServicesManagementClient>();

                string location = ConfigurationManager.AppSettings["Location"];
                string resourceGroupName = ConfigurationManager.AppSettings["resourceGroupName"];
                string resourceName = ConfigurationManager.AppSettings["ResourceName"];
                string armResourceId = ConfigurationManager.AppSettings["ARMResourceId"];
                string resourceType = ConfigurationManager.AppSettings["ResourceType"];
                string defaultSku = "standard";

                AzureBackupVaultCreateOrUpdateParameters parameters = new AzureBackupVaultCreateOrUpdateParameters()
                {
                    Location = location,
                    Properties = new AzureBackupVaultProperties()
                    {
                        Sku = new SkuProperties()
                        {
                            Name = defaultSku,
                        },
                    },
                };

                AzureBackupVaultGetResponse response = client.Vault.CreateOrUpdate(resourceGroupName, resourceName, parameters, GetCustomRequestHeaders());

                // Response Validation
                Assert.NotNull(response);
                Assert.True(response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Created,
                            "Status Code should either be OK or Created");
                Assert.NotNull(response.Vault);

                // Basic Validation
                //Assert.True(string.Equals(response.Vault.Id, armResourceId, StringComparison.OrdinalIgnoreCase),
                //            "Obtained vault ID doesn't match the input ARM resource ID");
                //Assert.True(string.Equals(response.Vault.Location, location),
                //            "Obtained vault location doesn't match the input resource location");
                //Assert.True(string.Equals(response.Vault.Name, resourceName),
                //            "Obtained vault name doesn't match the input resource name");
                //Assert.True(string.Equals(response.Vault.Type, resourceType),
                //            "Obtained vault type doesn't match the input resource type");
                //Assert.NotNull(response.Vault.Properties);
                //Assert.NotNull(response.Vault.Properties.Sku);
                //Assert.True(string.Equals(response.Vault.Properties.Sku.Name, defaultSku, StringComparison.OrdinalIgnoreCase),
                //            "Obtained vault SKU doesn't match the input resource SKU");
            }
        }
 /// <summary>
 /// Creates a new Azure backup vault.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.BackupServices.IVaultOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of resource group to which vault belongs
 /// </param>
 /// <param name='resourceName'>
 /// Required. The name of the vault
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters to create or update the vault
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Optional. Request header parameters.
 /// </param>
 /// <returns>
 /// Vault information.
 /// </returns>
 public static Task<AzureBackupVaultGetResponse> CreateOrUpdateAsync(this IVaultOperations operations, string resourceGroupName, string resourceName, AzureBackupVaultCreateOrUpdateParameters parameters, CustomRequestHeaders customRequestHeaders)
 {
     return operations.CreateOrUpdateAsync(resourceGroupName, resourceName, parameters, customRequestHeaders, CancellationToken.None);
 }