コード例 #1
0
        /// <summary>
        ///     Starts recovery plan unplanned failover.
        /// </summary>
        private void StartRpUnplannedFailover()
        {
            // Refresh RP Object
            var rp = this.RecoveryServicesClient.GetAzureSiteRecoveryRecoveryPlan(
                this.RecoveryPlan.Name);

            var recoveryPlanUnplannedFailoverInputProperties =
                new RecoveryPlanUnplannedFailoverInputProperties
            {
                FailoverDirection =
                    this.Direction == PossibleOperationsDirections.PrimaryToRecovery.ToString()
                            ? PossibleOperationsDirections.PrimaryToRecovery
                            : PossibleOperationsDirections.RecoveryToPrimary,
                SourceSiteOperations = this.PerformSourceSideAction
                        ? SourceSiteOperations.Required
                        : SourceSiteOperations.NotRequired, //Required|NotRequired
                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"
                        };
                        if (this.RecoveryTag != null)
                        {
                            var recoveryPointType =
                                this.RecoveryTag ==
                                Constants.RecoveryTagLatestAvailableApplicationConsistent
                               ? HyperVReplicaAzureRpRecoveryPointType.LatestApplicationConsistent
                               : this.RecoveryTag == Constants.RecoveryTagLatestAvailable
                                   ? HyperVReplicaAzureRpRecoveryPointType.LatestProcessed
                                   : HyperVReplicaAzureRpRecoveryPointType.Latest;

                            recoveryPlanHyperVReplicaAzureFailoverInput.RecoveryPointType = recoveryPointType;
                        }
                        recoveryPlanUnplannedFailoverInputProperties.ProviderSpecificDetails.Add(
                            recoveryPlanHyperVReplicaAzureFailoverInput);
                    }
                }
                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.RecoveryTagLatestAvailable
                                    ? InMageV2RpRecoveryPointType.LatestProcessed
                                    : this.RecoveryTag == Constants.RecoveryTagLatestAvailableCrashConsistent
                                        ? InMageV2RpRecoveryPointType.LatestCrashConsistent
                                        : InMageV2RpRecoveryPointType.Latest;

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

                        // Add the InMageAzureV2 Provider specific input in the Planned Failover Input.
                        recoveryPlanUnplannedFailoverInputProperties.ProviderSpecificDetails.Add(
                            recoveryPlanInMageAzureV2FailoverInput);
                    }
                }
                else if (string.Compare(
                             replicationProvider,
                             Constants.InMage,
                             StringComparison.OrdinalIgnoreCase) ==
                         0)
                {
                    // Check if the Direction is RecoveryToPrimary.
                    if (this.Direction == Constants.RecoveryToPrimary)
                    {
                        // Set the Recovery Point Types for InMage.
                        var recoveryPointType =
                            this.RecoveryTag ==
                            Constants.RecoveryTagLatestAvailableApplicationConsistent
                                ? RpInMageRecoveryPointType.LatestTag
                                : RpInMageRecoveryPointType.LatestTime;

                        // Create the InMage Provider specific input.
                        var recoveryPlanInMageFailoverInput = new RecoveryPlanInMageFailoverInput
                        {
                            RecoveryPointType = recoveryPointType
                        };

                        // Add the InMage Provider specific input in the Planned Failover Input.
                        recoveryPlanUnplannedFailoverInputProperties.ProviderSpecificDetails.Add(
                            recoveryPlanInMageFailoverInput);
                    }
                }
                else if (0 == string.Compare(
                             replicationProvider,
                             Constants.A2A,
                             StringComparison.OrdinalIgnoreCase))
                {
                    A2ARpRecoveryPointType recoveryPointType = A2ARpRecoveryPointType.Latest;

                    switch (this.RecoveryTag)
                    {
                    case Constants.RecoveryTagLatestAvailableCrashConsistent:
                        recoveryPointType = A2ARpRecoveryPointType.LatestCrashConsistent;
                        break;

                    case Constants.RecoveryTagLatestAvailableApplicationConsistent:
                        recoveryPointType = A2ARpRecoveryPointType.LatestApplicationConsistent;
                        break;

                    case Constants.RecoveryTagLatestAvailable:
                        recoveryPointType = A2ARpRecoveryPointType.LatestProcessed;
                        break;

                    case Constants.RecoveryTagLatest:
                        recoveryPointType = A2ARpRecoveryPointType.Latest;
                        break;
                    }

                    var recoveryPlanA2AFailoverInput = new RecoveryPlanA2AFailoverInput()
                    {
                        RecoveryPointType = recoveryPointType
                    };
                    recoveryPlanUnplannedFailoverInputProperties.ProviderSpecificDetails.Add(recoveryPlanA2AFailoverInput);
                }
            }

            var recoveryPlanUnplannedFailoverInput = new RecoveryPlanUnplannedFailoverInput
            {
                Properties = recoveryPlanUnplannedFailoverInputProperties
            };

            var response = this.RecoveryServicesClient.StartAzureSiteRecoveryUnplannedFailover(
                this.RecoveryPlan.Name,
                recoveryPlanUnplannedFailoverInput);

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

            this.WriteObject(new ASRJob(jobResponse));
        }
コード例 #2
0
 /// <summary>
 /// Converts the <see cref="sourceValue" /> parameter to the <see cref="destinationType" /> parameter using <see cref="formatProvider"
 /// /> and <see cref="ignoreCase" />
 /// </summary>
 /// <param name="sourceValue">the <see cref="System.Object"/> to convert from</param>
 /// <param name="destinationType">the <see cref="System.Type" /> to convert to</param>
 /// <param name="formatProvider">not used by this TypeConverter.</param>
 /// <param name="ignoreCase">when set to <c>true</c>, will ignore the case when converting.</param>
 /// <returns>
 /// an instance of <see cref="A2ARpRecoveryPointType" />, or <c>null</c> if there is no suitable conversion.
 /// </returns>
 public override object ConvertFrom(object sourceValue, global::System.Type destinationType, global::System.IFormatProvider formatProvider, bool ignoreCase) => A2ARpRecoveryPointType.CreateFrom(sourceValue);