Exemplo n.º 1
0
        /// <summary>
        /// Starts RP Test failover.
        /// </summary>
        private void StartRpTestFailover()
        {
            // Refresh RP Object
            var rp = RecoveryServicesClient.GetAzureSiteRecoveryRecoveryPlan(this.RecoveryPlan.Name);

            var recoveryPlanTestFailoverInputProperties = new RecoveryPlanTestFailoverInputProperties()
            {
                FailoverDirection       = this.Direction,
                NetworkId               = this.networkId,
                NetworkType             = this.networkType,
                ProviderSpecificDetails = new List <RecoveryPlanProviderSpecificFailoverInput>()
            };

            foreach (string replicationProvider in rp.RecoveryPlan.Properties.ReplicationProviders)
            {
                if (0 == string.Compare(
                        replicationProvider,
                        Constants.HyperVReplicaAzure,
                        StringComparison.OrdinalIgnoreCase))
                {
                    if (this.Direction == Constants.PrimaryToRecovery)
                    {
                        var recoveryPlanHyperVReplicaAzureFailoverInput = new RecoveryPlanHyperVReplicaAzureFailoverInput()
                        {
                            InstanceType               = replicationProvider,
                            PrimaryKekCertificatePfx   = primaryKekCertpfx,
                            SecondaryKekCertificatePfx = secondaryKekCertpfx,
                            VaultLocation              = this.GetCurrentVaultLocation()
                        };
                        recoveryPlanTestFailoverInputProperties.ProviderSpecificDetails.Add(recoveryPlanHyperVReplicaAzureFailoverInput);
                    }
                    else
                    {
                        new ArgumentException(Properties.Resources.UnsupportedDirectionForTFO);// Throw Unsupported Direction Exception
                    }
                }
            }

            var recoveryPlanTestFailoverInput = new RecoveryPlanTestFailoverInput()
            {
                Properties = recoveryPlanTestFailoverInputProperties
            };

            LongRunningOperationResponse response = RecoveryServicesClient.StartAzureSiteRecoveryTestFailover(
                this.RecoveryPlan.Name,
                recoveryPlanTestFailoverInput);

            JobResponse jobResponse =
                RecoveryServicesClient
                .GetAzureSiteRecoveryJobDetails(PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location));

            WriteObject(new ASRJob(jobResponse.Job));
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Starts Azure Site Recovery test failover.
        /// </summary>
        /// <param name="recoveryPlanName">Recovery Plan Name</param>
        /// <param name="input">Recovery Plan Test Failover Input</param>
        /// <returns>Job response</returns>
        public PSSiteRecoveryLongRunningOperation StartAzureSiteRecoveryTestFailover(
            string recoveryPlanName,
            RecoveryPlanTestFailoverInput input)
        {
            var op = this.GetSiteRecoveryClient()
                     .ReplicationRecoveryPlans.BeginTestFailoverWithHttpMessagesAsync(
                recoveryPlanName,
                input,
                this.GetRequestHeaders(true))
                     .GetAwaiter()
                     .GetResult();
            var result = Mapper.Map <PSSiteRecoveryLongRunningOperation>(op);

            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Starts RP Test failover.
        /// </summary>
        private void StartRpTestFailover()
        {
            // Refresh RP Object
            var rp = this.RecoveryServicesClient.GetAzureSiteRecoveryRecoveryPlan(
                this.RecoveryPlan.Name);

            var recoveryPlanTestFailoverInputProperties =
                new RecoveryPlanTestFailoverInputProperties
            {
                FailoverDirection =
                    this.Direction == PossibleOperationsDirections.PrimaryToRecovery.ToString()
                            ? PossibleOperationsDirections.PrimaryToRecovery
                            : PossibleOperationsDirections.RecoveryToPrimary,
                NetworkId               = this.networkId,
                NetworkType             = this.networkType,
                ProviderSpecificDetails = new List <RecoveryPlanProviderSpecificFailoverInput>(),
                SkipTestFailoverCleanup = bool.TrueString
            };

            foreach (var replicationProvider in rp.Properties.ReplicationProviders)
            {
                if (0 ==
                    string.Compare(
                        replicationProvider,
                        Constants.HyperVReplicaAzure,
                        StringComparison.OrdinalIgnoreCase))
                {
                    if (this.Direction == Constants.PrimaryToRecovery)
                    {
                        var recoveryPlanHyperVReplicaAzureFailoverInput =
                            new RecoveryPlanHyperVReplicaAzureFailoverInput
                        {
                            PrimaryKekCertificatePfx   = this.primaryKekCertpfx,
                            SecondaryKekCertificatePfx = this.secondaryKekCertpfx,
                            VaultLocation = "dummy"
                        };
                        recoveryPlanTestFailoverInputProperties.ProviderSpecificDetails.Add(
                            recoveryPlanHyperVReplicaAzureFailoverInput);
                    }
                    else
                    {
                        throw new ArgumentException(
                                  Resources
                                  .UnsupportedDirectionForTFO); // Throw Unsupported Direction Exception
                    }
                }
                else if (string.Compare(
                             replicationProvider,
                             Constants.InMageAzureV2,
                             StringComparison.OrdinalIgnoreCase) ==
                         0)
                {
                    // Check if the Direction is PrimaryToRecovery.
                    if (this.Direction == Constants.PrimaryToRecovery)
                    {
                        // Set the Recovery Point Types for InMage.
                        var recoveryPointType =
                            this.RecoveryTag ==
                            Constants.RecoveryTagLatestAvailableApplicationConsistent
                                ? InMageV2RpRecoveryPointType.LatestApplicationConsistent
                                : this.RecoveryTag == Constants.RecoveryTagLatest
                                    ? InMageV2RpRecoveryPointType.Latest
                                    : InMageV2RpRecoveryPointType.LatestProcessed;

                        // Create the InMageAzureV2 Provider specific input.
                        var recoveryPlanInMageAzureV2FailoverInput =
                            new RecoveryPlanInMageAzureV2FailoverInput
                        {
                            RecoveryPointType = recoveryPointType,
                            VaultLocation     = "dummy"
                        };

                        // Add the InMageAzureV2 Provider specific input in the Test Failover Input.
                        recoveryPlanTestFailoverInputProperties.ProviderSpecificDetails.Add(
                            recoveryPlanInMageAzureV2FailoverInput);
                    }
                }
                else if (string.Compare(
                             replicationProvider,
                             Constants.InMage,
                             StringComparison.OrdinalIgnoreCase) ==
                         0)
                {
                    throw new InvalidOperationException(
                              string.Format(
                                  Resources.UnsupportedReplicationProviderForTestFailover,
                                  this.ReplicationProtectedItem.ReplicationProvider));
                }
                else if (string.Compare(
                             replicationProvider,
                             Constants.A2A,
                             StringComparison.OrdinalIgnoreCase) ==
                         0)
                {
                    // Set the Recovery Point Types for InMage.
                    var recoveryPointType =
                        this.RecoveryTag ==
                        Constants.RecoveryTagLatestAvailableApplicationConsistent
                            ? A2ARpRecoveryPointType.LatestApplicationConsistent
                            : this.RecoveryTag == Constants.RecoveryTagLatest
                                ? A2ARpRecoveryPointType.Latest
                                 : this.RecoveryTag == Constants.RecoveryTagLatestAvailableCrashConsistent
                                     ? A2ARpRecoveryPointType.LatestCrashConsistent
                                      : A2ARpRecoveryPointType.LatestProcessed;

                    // Create the InMageAzureV2 Provider specific input.
                    var recoveryPlanInMageAzureV2FailoverInput =
                        new RecoveryPlanA2AFailoverInput
                    {
                        RecoveryPointType          = recoveryPointType,
                        CloudServiceCreationOption = this.CloudServiceCreationOption
                    };

                    // Add the InMageAzureV2 Provider specific input in the Test Failover Input.
                    recoveryPlanTestFailoverInputProperties.ProviderSpecificDetails.Add(
                        recoveryPlanInMageAzureV2FailoverInput);
                }
            }

            var recoveryPlanTestFailoverInput =
                new RecoveryPlanTestFailoverInput
            {
                Properties = recoveryPlanTestFailoverInputProperties
            };

            var response = this.RecoveryServicesClient.StartAzureSiteRecoveryTestFailover(
                this.RecoveryPlan.Name,
                recoveryPlanTestFailoverInput);

            var jobResponse = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails(
                PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location));

            this.WriteObject(new ASRJob(jobResponse));
        }
 /// <summary>
 /// Execute test failover of the recovery plan.
 /// </summary>
 /// <remarks>
 /// The operation to start the test failover of a recovery plan.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='recoveryPlanName'>
 /// Recovery plan name.
 /// </param>
 /// <param name='input'>
 /// Recovery plan test failover input.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <RecoveryPlan> BeginTestFailoverAsync(this IReplicationRecoveryPlansOperations operations, string recoveryPlanName, RecoveryPlanTestFailoverInput input, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.BeginTestFailoverWithHttpMessagesAsync(recoveryPlanName, input, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
 /// <summary>
 /// Execute test failover of the recovery plan.
 /// </summary>
 /// <remarks>
 /// The operation to start the test failover of a recovery plan.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='recoveryPlanName'>
 /// Recovery plan name.
 /// </param>
 /// <param name='input'>
 /// Recovery plan test failover input.
 /// </param>
 public static RecoveryPlan BeginTestFailover(this IReplicationRecoveryPlansOperations operations, string recoveryPlanName, RecoveryPlanTestFailoverInput input)
 {
     return(operations.BeginTestFailoverAsync(recoveryPlanName, input).GetAwaiter().GetResult());
 }
Exemplo n.º 6
0
        public void RecoveryPlan_ValidateE2E()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                var client     = GetSiteRecoveryClient(CustomHttpHandler);
                var fabrics    = client.Fabrics.List(RequestHeaders).Fabrics.ToList();
                var containers =
                    client.ProtectionContainer.List(
                        fabrics.First().Name,
                        RequestHeaders)
                    .ProtectionContainers
                    .ToList();
                var vms =
                    client.ReplicationProtectedItem.List(
                        fabrics.First().Name,
                        containers.First().Name,
                        RequestHeaders)
                    .ReplicationProtectedItems
                    .ToList();

                // Create one recovery plan.
                var rpName = "Test-" + Guid.NewGuid().ToString();
                var input  = GetE2EInput(fabrics.First().Id, vms.First().Id);
                client.RecoveryPlan.Create(rpName, input, RequestHeaders);

                // Test failover.
                var tfoInput = new RecoveryPlanTestFailoverInput()
                {
                    Properties = new RecoveryPlanTestFailoverInputProperties()
                    {
                        FailoverDirection = "PrimaryToRecovery",
                        NetworkType       = "NoNetworkAttachAsInput"
                    }
                };
                client.RecoveryPlan.TestFailover(rpName, tfoInput, RequestHeaders);

                // Planned failover.
                var pfoInput = new RecoveryPlanPlannedFailoverInput()
                {
                    Properties = new RecoveryPlanPlannedFailoverInputProperties()
                    {
                        FailoverDirection = "PrimaryToRecovery"
                    }
                };
                client.RecoveryPlan.PlannedFailover(rpName, pfoInput, RequestHeaders);

                // Commit failover.
                client.RecoveryPlan.CommitFailover(rpName, RequestHeaders);

                // Reverse replicate.
                client.RecoveryPlan.Reprotect(rpName, RequestHeaders);

                // Unplanned failover.
                var ufoInput = new RecoveryPlanUnplannedFailoverInput()
                {
                    Properties = new RecoveryPlanUnplannedFailoverInputProperties()
                    {
                        FailoverDirection    = "RecoveryToPrimary",
                        SourceSiteOperations = "NotRequired"
                    }
                };
                client.RecoveryPlan.UnplannedFailover(rpName, ufoInput, RequestHeaders);

                // Reverse replicate.
                client.RecoveryPlan.Reprotect(rpName, RequestHeaders);
            }
        }
Exemplo n.º 7
0
        public void RecoveryPlan_ValidateE2A()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                var client     = GetSiteRecoveryClient(CustomHttpHandler);
                var fabrics    = client.Fabrics.List(RequestHeaders).Fabrics.ToList();
                var containers =
                    client.ProtectionContainer.List(
                        fabrics.First().Name,
                        RequestHeaders)
                    .ProtectionContainers
                    .ToList();
                var vms =
                    client.ReplicationProtectedItem.List(
                        fabrics.First().Name,
                        containers.First().Name,
                        RequestHeaders)
                    .ReplicationProtectedItems
                    .ToList();

                // Create one recovery plan.
                var rpName = "Test-" + Guid.NewGuid().ToString();
                var input  = GetE2AInput(fabrics.First().Id, vms.First().Id);
                client.RecoveryPlan.Create(rpName, input, RequestHeaders);

                // Test failover.
                var tfoInput = new RecoveryPlanTestFailoverInput()
                {
                    Properties = new RecoveryPlanTestFailoverInputProperties()
                    {
                        FailoverDirection       = "PrimaryToRecovery",
                        NetworkType             = "NoNetworkAttachAsInput",
                        ProviderSpecificDetails = new List <RecoveryPlanProviderSpecificFailoverInput>()
                        {
                            new RecoveryPlanHyperVReplicaAzureFailoverInput()
                            {
                                VaultLocation = "Southeast Asia"
                            }
                        }
                    }
                };
                client.RecoveryPlan.TestFailover(rpName, tfoInput, RequestHeaders);

                // Planned failover.
                var pfoInput = new RecoveryPlanPlannedFailoverInput()
                {
                    Properties = new RecoveryPlanPlannedFailoverInputProperties()
                    {
                        FailoverDirection       = "PrimaryToRecovery",
                        ProviderSpecificDetails = new List <RecoveryPlanProviderSpecificFailoverInput>()
                        {
                            new RecoveryPlanHyperVReplicaAzureFailoverInput()
                            {
                                VaultLocation = "Southeast Asia"
                            }
                        }
                    }
                };
                client.RecoveryPlan.PlannedFailover(rpName, pfoInput, RequestHeaders);

                // Commit failover.
                client.RecoveryPlan.CommitFailover(rpName, RequestHeaders);

                // Planned failback.
                var fbInput = new RecoveryPlanPlannedFailoverInput()
                {
                    Properties = new RecoveryPlanPlannedFailoverInputProperties()
                    {
                        FailoverDirection       = "RecoveryToPrimary",
                        ProviderSpecificDetails = new List <RecoveryPlanProviderSpecificFailoverInput>()
                        {
                            new RecoveryPlanHyperVReplicaAzureFailbackInput()
                            {
                                DataSyncOption           = "ForSyncronization",
                                RecoveryVmCreationOption = "NoAction"
                            }
                        }
                    }
                };
                client.RecoveryPlan.PlannedFailover(rpName, fbInput, RequestHeaders);

                // Commit failover.
                client.RecoveryPlan.CommitFailover(rpName, RequestHeaders);

                // Reverse replicate.
                client.RecoveryPlan.Reprotect(rpName, RequestHeaders);

                // Unplanned failover.
                var ufoInput = new RecoveryPlanUnplannedFailoverInput()
                {
                    Properties = new RecoveryPlanUnplannedFailoverInputProperties()
                    {
                        FailoverDirection       = "PrimaryToRecovery",
                        SourceSiteOperations    = "NotRequired",
                        ProviderSpecificDetails = new List <RecoveryPlanProviderSpecificFailoverInput>()
                        {
                            new RecoveryPlanHyperVReplicaAzureFailoverInput()
                            {
                                VaultLocation = "Southeast Asia"
                            }
                        }
                    }
                };
                client.RecoveryPlan.UnplannedFailover(rpName, ufoInput, RequestHeaders);
            }
        }
 /// <summary>
 /// Starts Azure Site Recovery test failover.
 /// </summary>
 /// <param name="recoveryPlanName">Recovery Plan Name</param>
 /// <param name="input">Recovery Plan Test Failover Input</param>
 /// <returns>Job response</returns>
 public LongRunningOperationResponse StartAzureSiteRecoveryTestFailover(string recoveryPlanName, RecoveryPlanTestFailoverInput input)
 {
     return(this.GetSiteRecoveryClient().RecoveryPlan.BeginTestFailover(
                recoveryPlanName,
                input,
                this.GetRequestHeaders()));
 }
Exemplo n.º 9
0
        /// <summary>
        ///     Starts RP Test failover.
        /// </summary>
        private void StartRpTestFailover()
        {
            // Refresh RP Object
            var rp = this.RecoveryServicesClient.GetAzureSiteRecoveryRecoveryPlan(
                this.RecoveryPlan.Name);

            var recoveryPlanTestFailoverInputProperties =
                new RecoveryPlanTestFailoverInputProperties
            {
                FailoverDirection =
                    this.Direction == PossibleOperationsDirections.PrimaryToRecovery.ToString()
                            ? PossibleOperationsDirections.PrimaryToRecovery
                            : PossibleOperationsDirections.RecoveryToPrimary,
                NetworkId               = this.networkId,
                NetworkType             = this.networkType,
                ProviderSpecificDetails = new List <RecoveryPlanProviderSpecificFailoverInput>()
            };

            foreach (var replicationProvider in rp.Properties.ReplicationProviders)
            {
                if (0 ==
                    string.Compare(
                        replicationProvider,
                        Constants.HyperVReplicaAzure,
                        StringComparison.OrdinalIgnoreCase))
                {
                    if (this.Direction == Constants.PrimaryToRecovery)
                    {
                        var recoveryPlanHyperVReplicaAzureFailoverInput =
                            new RecoveryPlanHyperVReplicaAzureFailoverInput
                        {
                            PrimaryKekCertificatePfx   = this.primaryKekCertpfx,
                            SecondaryKekCertificatePfx = this.secondaryKekCertpfx,
                            VaultLocation = "dummy"
                        };
                        recoveryPlanTestFailoverInputProperties.ProviderSpecificDetails.Add(
                            recoveryPlanHyperVReplicaAzureFailoverInput);
                    }
                    else
                    {
                        throw new ArgumentException(
                                  Resources
                                  .UnsupportedDirectionForTFO); // Throw Unsupported Direction Exception
                    }
                }
            }

            var recoveryPlanTestFailoverInput =
                new RecoveryPlanTestFailoverInput
            {
                Properties = recoveryPlanTestFailoverInputProperties
            };

            var response = this.RecoveryServicesClient.StartAzureSiteRecoveryTestFailover(
                this.RecoveryPlan.Name,
                recoveryPlanTestFailoverInput);

            var jobResponse = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails(
                PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location));

            this.WriteObject(new ASRJob(jobResponse));
        }