protected override void ProcessRecord()
        {
            ExecutionBlock(() =>
            {
                base.ProcessRecord();

                WriteDebug(Resources.MakingClientCall);
                string itemName = string.Empty;

                CSMSetProtectionRequest input = new CSMSetProtectionRequest();
                input.Properties = new CSMSetProtectionRequestProperties();
                input.Properties.PolicyId = Policy.PolicyId;

                if (Item.GetType() == typeof(AzureRMBackupItem))
                {
                    itemName = (Item as AzureRMBackupItem).ItemName;
                }

                else if (Item.GetType() == typeof(AzureRMBackupContainer))
                {
                    WriteDebug(String.Format(Resources.ContainerTypeInput, Item.GetType()));

                    if ((Item as AzureRMBackupContainer).ContainerType == AzureBackupContainerType.AzureVM.ToString())
                    {
                        itemName = (Item as AzureRMBackupContainer).ContainerUniqueName;
                    }
                    else
                    {
                        throw new Exception(Resources.UnknownItemType);
                    }
                }

                else
                {
                    throw new Exception(Resources.UnknownItemType);
                }

                var operationId = AzureBackupClient.EnableProtection(Item.ResourceGroupName, Item.ResourceName, Item.ContainerUniqueName, itemName, input);
                WriteDebug(Resources.EnableAzureBackupProtection);

                var operationStatus = TrackOperation(Item.ResourceGroupName, Item.ResourceName, operationId);
                this.WriteObject(GetCreatedJobs(Item.ResourceGroupName, 
                    Item.ResourceName, 
                    new Models.AzureRMBackupVault(Item.ResourceGroupName, Item.ResourceName, Item.Location), 
                    operationStatus.JobList).FirstOrDefault());
            });
        }
        //[Fact]
        public void EnableAzureBackupProtectionTest()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                var client = GetServiceClient<BackupServicesManagementClient>();
                CSMSetProtectionRequest input = new CSMSetProtectionRequest();
                input.Properties = new CSMSetProtectionRequestProperties();
                input.Properties.PolicyId = ConfigurationManager.AppSettings["PolicyId"];
                string itemName = ConfigurationManager.AppSettings["AzureBackupItemName"];
                string containerName = ConfigurationManager.AppSettings["ContainerName"];

                var response = client.DataSource.EnableProtectionCSM(BackupServicesTestsBase.ResourceGroupName, 
                    BackupServicesTestsBase.ResourceName, 
                    GetCustomRequestHeaders(), 
                    containerName, 
                    itemName, 
                    input);

                Assert.Equal(HttpStatusCode.Accepted, response.StatusCode);
            }
        }
예제 #3
0
 /// <summary>
 /// Enable Protection
 /// </summary>
 /// <param name="request"></param>
 /// <returns></returns>
 public Guid EnableProtection(string resourceGroupName, string resourceName, string containerName, string itemName, CSMSetProtectionRequest request)
 {
     var response = AzureBackupClient.DataSource.EnableProtectionCSMAsync(resourceGroupName, resourceName, GetCustomRequestHeaders(), containerName, itemName, request, CmdletCancellationToken).Result;
     return response.OperationId;
 }
 /// <summary>
 /// Enable protection for given item.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.BackupServices.IDataSourceOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required.
 /// </param>
 /// <param name='resourceName'>
 /// Required.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Optional. Request header parameters.
 /// </param>
 /// <param name='containerName'>
 /// Required. containerName.
 /// </param>
 /// <param name='itemName'>
 /// Required. itemName.
 /// </param>
 /// <param name='csmparameters'>
 /// Required. Set protection request input.
 /// </param>
 /// <returns>
 /// The definition of a Operation Response.
 /// </returns>
 public static Task<OperationResponse> EnableProtectionCSMAsync(this IDataSourceOperations operations, string resourceGroupName, string resourceName, CustomRequestHeaders customRequestHeaders, string containerName, string itemName, CSMSetProtectionRequest csmparameters)
 {
     return operations.EnableProtectionCSMAsync(resourceGroupName, resourceName, customRequestHeaders, containerName, itemName, csmparameters, CancellationToken.None);
 }
 /// <summary>
 /// Enable protection for given item.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.BackupServices.IDataSourceOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required.
 /// </param>
 /// <param name='resourceName'>
 /// Required.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Optional. Request header parameters.
 /// </param>
 /// <param name='containerName'>
 /// Required. containerName.
 /// </param>
 /// <param name='itemName'>
 /// Required. itemName.
 /// </param>
 /// <param name='csmparameters'>
 /// Required. Set protection request input.
 /// </param>
 /// <returns>
 /// The definition of a Operation Response.
 /// </returns>
 public static OperationResponse EnableProtectionCSM(this IDataSourceOperations operations, string resourceGroupName, string resourceName, CustomRequestHeaders customRequestHeaders, string containerName, string itemName, CSMSetProtectionRequest csmparameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IDataSourceOperations)s).EnableProtectionCSMAsync(resourceGroupName, resourceName, customRequestHeaders, containerName, itemName, csmparameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }