Exemplo n.º 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));
        }
        /// <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));
        }