Exemple #1
0
        /// <summary>
        /// Starts RP Planned failover.
        /// </summary>
        private void StartRpPlannedFailover()
        {
            // Refresh RP Object
            var rp = RecoveryServicesClient.GetAzureSiteRecoveryRecoveryPlan(this.RecoveryPlan.Name);

            var recoveryPlanPlannedFailoverInputProperties = new RecoveryPlanPlannedFailoverInputProperties()
            {
                FailoverDirection       = this.Direction,
                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()
                        };
                        recoveryPlanPlannedFailoverInputProperties.ProviderSpecificDetails.Add(recoveryPlanHyperVReplicaAzureFailoverInput);
                    }
                    else
                    {
                        var recoveryPlanHyperVReplicaAzureFailbackInput = new RecoveryPlanHyperVReplicaAzureFailbackInput()
                        {
                            InstanceType             = replicationProvider + "Failback",
                            DataSyncOption           = this.Optimize == Constants.ForDownTime ? Constants.ForDownTime : Constants.ForSynchronization,
                            RecoveryVmCreationOption = String.Compare(this.CreateVmIfNotFound, Constants.Yes, StringComparison.OrdinalIgnoreCase) == 0 ? Constants.CreateVmIfNotFound : Constants.NoAction
                        };
                        recoveryPlanPlannedFailoverInputProperties.ProviderSpecificDetails.Add(recoveryPlanHyperVReplicaAzureFailbackInput);
                    }
                }
            }

            var recoveryPlanPlannedFailoverInput = new RecoveryPlanPlannedFailoverInput()
            {
                Properties = recoveryPlanPlannedFailoverInputProperties
            };

            LongRunningOperationResponse response = RecoveryServicesClient.StartAzureSiteRecoveryPlannedFailover(
                this.RecoveryPlan.Name,
                recoveryPlanPlannedFailoverInput);

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

            WriteObject(new ASRJob(jobResponse.Job));
        }
Exemple #2
0
        /// <summary>
        ///     Starts Azure Site Recovery Planned failover.
        /// </summary>
        /// <param name="recoveryPlanName">Recovery Plan Name</param>
        /// <param name="input">Recovery Plan Planned Failover Input</param>
        /// <returns>Job response</returns>
        public PSSiteRecoveryLongRunningOperation StartAzureSiteRecoveryPlannedFailover(
            string recoveryPlanName,
            RecoveryPlanPlannedFailoverInput input)
        {
            var op = this.GetSiteRecoveryClient()
                     .ReplicationRecoveryPlans.BeginPlannedFailoverWithHttpMessagesAsync(
                recoveryPlanName,
                input,
                this.GetRequestHeaders(true))
                     .GetAwaiter()
                     .GetResult();
            var result = Mapper.Map <PSSiteRecoveryLongRunningOperation>(op);

            return(result);
        }
        /// <summary>
        ///     Starts RP Planned failover.
        /// </summary>
        private void StartRpPlannedFailover()
        {
            // Refresh RP Object
            var rp = this.RecoveryServicesClient.GetAzureSiteRecoveryRecoveryPlan(
                this.RecoveryPlan.Name);

            var recoveryPlanPlannedFailoverInputProperties =
                new RecoveryPlanPlannedFailoverInputProperties
            {
                FailoverDirection =
                    this.Direction == PossibleOperationsDirections.PrimaryToRecovery.ToString()
                            ? PossibleOperationsDirections.PrimaryToRecovery
                            : PossibleOperationsDirections.RecoveryToPrimary,
                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"
                        };
                        recoveryPlanPlannedFailoverInputProperties.ProviderSpecificDetails.Add(
                            recoveryPlanHyperVReplicaAzureFailoverInput);
                    }
                    else
                    {
                        var recoveryPlanHyperVReplicaAzureFailbackInput =
                            new RecoveryPlanHyperVReplicaAzureFailbackInput
                        {
                            DataSyncOption =
                                this.Optimize == Constants.ForDownTime
                                        ? DataSyncStatus.ForDownTime
                                        : DataSyncStatus.ForSynchronization,
                            RecoveryVmCreationOption = string.Compare(
                                this.CreateVmIfNotFound,
                                Constants.Yes,
                                StringComparison
                                .OrdinalIgnoreCase) ==
                                                       0 ? AlternateLocationRecoveryOption
                                                       .CreateVmIfNotFound : AlternateLocationRecoveryOption.NoAction
                        };
                        recoveryPlanPlannedFailoverInputProperties.ProviderSpecificDetails.Add(
                            recoveryPlanHyperVReplicaAzureFailbackInput);
                    }
                }
            }

            var recoveryPlanPlannedFailoverInput = new RecoveryPlanPlannedFailoverInput
            {
                Properties = recoveryPlanPlannedFailoverInputProperties
            };

            var response = this.RecoveryServicesClient.StartAzureSiteRecoveryPlannedFailover(
                this.RecoveryPlan.Name,
                recoveryPlanPlannedFailoverInput);

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

            this.WriteObject(new ASRJob(jobResponse));
        }
        /// <summary>
        ///     Starts RP Planned failover.
        /// </summary>
        private void StartRpPlannedFailover()
        {
            // Refresh RP Object
            var rp = this.RecoveryServicesClient.GetAzureSiteRecoveryRecoveryPlan(
                this.RecoveryPlan.Name);

            var recoveryPlanPlannedFailoverInputProperties =
                new RecoveryPlanPlannedFailoverInputProperties
            {
                FailoverDirection =
                    this.Direction == PossibleOperationsDirections.PrimaryToRecovery.ToString()
                            ? PossibleOperationsDirections.PrimaryToRecovery
                            : PossibleOperationsDirections.RecoveryToPrimary,
                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
                        };
                        recoveryPlanPlannedFailoverInputProperties.ProviderSpecificDetails.Add(
                            recoveryPlanHyperVReplicaAzureFailoverInput);
                    }
                    else
                    {
                        var recoveryPlanHyperVReplicaAzureFailbackInput =
                            new RecoveryPlanHyperVReplicaAzureFailbackInput
                        {
                            DataSyncOption =
                                this.Optimize == Constants.ForDownTime
                                        ? DataSyncStatus.ForDownTime
                                        : DataSyncStatus.ForSynchronization,
                            RecoveryVmCreationOption = string.Compare(
                                this.CreateVmIfNotFound,
                                Constants.Yes,
                                StringComparison
                                .OrdinalIgnoreCase) ==
                                                       0 ? AlternateLocationRecoveryOption
                                                       .CreateVmIfNotFound : AlternateLocationRecoveryOption.NoAction
                        };
                        recoveryPlanPlannedFailoverInputProperties.ProviderSpecificDetails.Add(
                            recoveryPlanHyperVReplicaAzureFailbackInput);
                    }
                }
                else if (0 ==
                         string.Compare(
                             replicationProvider,
                             Constants.InMageRcmFailback,
                             StringComparison.OrdinalIgnoreCase))
                {
                    this.MultiVmSyncPoint =
                        this.MyInvocation.BoundParameters.ContainsKey(
                            Utilities.GetMemberName(() => this.MultiVmSyncPoint))
                            ? this.MultiVmSyncPoint
                            : Constants.Enable;
                    var recoveryPointType =
                        this.RecoveryTag == Constants.RecoveryTagApplicationConsistent
                            ? InMageRcmFailbackRecoveryPointType.ApplicationConsistent
                            : InMageRcmFailbackRecoveryPointType.CrashConsistent;

                    // Validate the direction as RecoveryToPrimary.
                    if (this.Direction == Constants.RecoveryToPrimary)
                    {
                        var recoveryPlanFailoverInput =
                            new RecoveryPlanInMageRcmFailbackFailoverInput
                        {
                            RecoveryPointType   = recoveryPointType,
                            UseMultiVmSyncPoint =
                                this.MultiVmSyncPoint == Constants.Enable ?
                                Constants.True :
                                Constants.False
                        };
                        recoveryPlanPlannedFailoverInputProperties.ProviderSpecificDetails.Add(
                            recoveryPlanFailoverInput);
                    }
                    else
                    {
                        // PrimaryToRecovery direction is invalid for InMageRcmFailback.
                        new ArgumentException(Resources.InvalidDirectionForAzureToVMWare);
                    }
                }
                else if (string.Compare(
                             replicationProvider,
                             Constants.InMageAzureV2,
                             StringComparison.OrdinalIgnoreCase) ==
                         0 ||
                         string.Compare(
                             replicationProvider,
                             Constants.InMage,
                             StringComparison.OrdinalIgnoreCase) ==
                         0 ||
                         string.Compare(
                             replicationProvider,
                             Constants.InMageRcm,
                             StringComparison.OrdinalIgnoreCase) ==
                         0)
                {
                    throw new InvalidOperationException(
                              string.Format(
                                  Resources.UnsupportedReplicationProviderForPlannedFailover,
                                  replicationProvider));
                }
            }

            var recoveryPlanPlannedFailoverInput = new RecoveryPlanPlannedFailoverInput
            {
                Properties = recoveryPlanPlannedFailoverInputProperties
            };

            var response = this.RecoveryServicesClient.StartAzureSiteRecoveryPlannedFailover(
                this.RecoveryPlan.Name,
                recoveryPlanPlannedFailoverInput);

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

            this.WriteObject(new ASRJob(jobResponse));
        }
 /// <summary>
 /// Execute planned failover of the recovery plan.
 /// </summary>
 /// <remarks>
 /// The operation to start the planned 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'>
 /// Failover input.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <RecoveryPlan> BeginPlannedFailoverAsync(this IReplicationRecoveryPlansOperations operations, string recoveryPlanName, RecoveryPlanPlannedFailoverInput input, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.BeginPlannedFailoverWithHttpMessagesAsync(recoveryPlanName, input, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
 /// <summary>
 /// Execute planned failover of the recovery plan.
 /// </summary>
 /// <remarks>
 /// The operation to start the planned 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'>
 /// Failover input.
 /// </param>
 public static RecoveryPlan BeginPlannedFailover(this IReplicationRecoveryPlansOperations operations, string recoveryPlanName, RecoveryPlanPlannedFailoverInput input)
 {
     return(operations.BeginPlannedFailoverAsync(recoveryPlanName, input).GetAwaiter().GetResult());
 }
Exemple #7
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);
            }
        }
Exemple #8
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 Planned failover.
 /// </summary>
 /// <param name="recoveryPlanName">Recovery Plan Name</param>
 /// <param name="input">Recovery Plan Planned Failover Input</param>
 /// <returns>Job response</returns>
 public LongRunningOperationResponse StartAzureSiteRecoveryPlannedFailover(string recoveryPlanName, RecoveryPlanPlannedFailoverInput input)
 {
     return(this.GetSiteRecoveryClient().RecoveryPlan.BeginPlannedFailover(
                recoveryPlanName,
                input,
                this.GetRequestHeaders()));
 }