/// <summary> /// Starts replication protected item unplanned failover. /// </summary> private void StartRPIUnplannedFailover() { var unplannedFailoverInputProperties = new UnplannedFailoverInputProperties { FailoverDirection = this.Direction, SourceSiteOperations = this.PerformSourceSideAction ? "Required" : "NotRequired", ProviderSpecificDetails = new ProviderSpecificFailoverInput() }; var input = new UnplannedFailoverInput { Properties = unplannedFailoverInputProperties }; if (0 == string.Compare( this.ReplicationProtectedItem.ReplicationProvider, Constants.HyperVReplicaAzure, StringComparison.OrdinalIgnoreCase)) { if (this.Direction == Constants.PrimaryToRecovery) { var failoverInput = new HyperVReplicaAzureFailoverProviderInput { PrimaryKekCertificatePfx = this.primaryKekCertpfx, SecondaryKekCertificatePfx = this.secondaryKekCertpfx, VaultLocation = "dummy", RecoveryPointId = this.RecoveryPoint == null ? null : this.RecoveryPoint.ID }; input.Properties.ProviderSpecificDetails = failoverInput; } } else if (string.Compare( this.ReplicationProtectedItem.ReplicationProvider, Constants.InMageAzureV2, StringComparison.OrdinalIgnoreCase) == 0) { this.InMageAzureV2UnplannedFailover(input); } else if (string.Compare( this.ReplicationProtectedItem.ReplicationProvider, Constants.InMage, StringComparison.OrdinalIgnoreCase) == 0) { this.InMageUnplannedFailover(input); } else if (0 == string.Compare( this.ReplicationProtectedItem.ReplicationProvider, Constants.A2A, StringComparison.OrdinalIgnoreCase)) { var failoverInput = new A2AFailoverProviderInput() { RecoveryPointId = this.RecoveryPoint == null ? null : this.RecoveryPoint.ID }; input.Properties.ProviderSpecificDetails = failoverInput; } var response = this.RecoveryServicesClient.StartAzureSiteRecoveryUnplannedFailover( this.fabricName, this.protectionContainerName, this.ReplicationProtectedItem.Name, input); var jobResponse = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails( PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location)); this.WriteObject(new ASRJob(jobResponse)); }
/// <summary> /// Starts RPI Test failover. /// </summary> private void StartRPITestFailover() { var testFailoverInputProperties = new TestFailoverInputProperties { FailoverDirection = this.Direction, NetworkId = this.networkId, NetworkType = this.networkType, ProviderSpecificDetails = new ProviderSpecificFailoverInput(), SkipTestFailoverCleanup = bool.TrueString }; var input = new TestFailoverInput { Properties = testFailoverInputProperties }; if (0 == string.Compare( this.ReplicationProtectedItem.ReplicationProvider, Constants.HyperVReplicaAzure, StringComparison.OrdinalIgnoreCase)) { if (this.Direction == Constants.PrimaryToRecovery) { var failoverInput = new HyperVReplicaAzureFailoverProviderInput { PrimaryKekCertificatePfx = this.primaryKekCertpfx, SecondaryKekCertificatePfx = this.secondaryKekCertpfx }; if (this.IsParameterBound(c => c.RecoveryPoint)) { failoverInput.RecoveryPointId = this.RecoveryPoint != null ? this.RecoveryPoint.ID : null; } input.Properties.ProviderSpecificDetails = failoverInput; } else { new ArgumentException( Resources .UnsupportedDirectionForTFO); // Throw Unsupported Direction Exception } } else if (string.Compare( this.ReplicationProtectedItem.ReplicationProvider, Constants.InMageAzureV2, StringComparison.OrdinalIgnoreCase) == 0) { // Validate if the Replication Protection Item is part of any Replication Group. Guid guidResult; var parseFlag = Guid.TryParse( ((ASRInMageAzureV2SpecificRPIDetails)this.ReplicationProtectedItem .ProviderSpecificDetails).MultiVmGroupName, out guidResult); if (parseFlag == false || guidResult == Guid.Empty || string.Compare( ((ASRInMageAzureV2SpecificRPIDetails)this.ReplicationProtectedItem .ProviderSpecificDetails).MultiVmGroupName, ((ASRInMageAzureV2SpecificRPIDetails)this.ReplicationProtectedItem .ProviderSpecificDetails).MultiVmGroupId) != 0) { // Replication Group was created at the time of Protection. throw new InvalidOperationException( string.Format( Resources.UnsupportedReplicationProtectionActionForTestFailover, this.ReplicationProtectedItem.ReplicationProvider)); } // Validate the Direction as PrimaryToRecovery. if (this.Direction == Constants.PrimaryToRecovery) { // Set the InMageAzureV2 Provider specific input in the Test Failover Input. var failoverInput = new InMageAzureV2FailoverProviderInput { RecoveryPointId = this.RecoveryPoint != null ? this.RecoveryPoint.ID : null }; input.Properties.ProviderSpecificDetails = failoverInput; } else { // RecoveryToPrimary Direction is Invalid for InMageAzureV2. new ArgumentException(Resources.InvalidDirectionForVMWareToAzure); } } else if (string.Compare( this.ReplicationProtectedItem.ReplicationProvider, Constants.InMage, StringComparison.OrdinalIgnoreCase) == 0) { throw new InvalidOperationException( string.Format( Resources.UnsupportedReplicationProviderForTestFailover, this.ReplicationProtectedItem.ReplicationProvider)); } else if (Constants.A2A.Equals( this.ReplicationProtectedItem.ReplicationProvider, StringComparison.OrdinalIgnoreCase)) { var failoverInput = new A2AFailoverProviderInput() { RecoveryPointId = this.RecoveryPoint != null ? this.RecoveryPoint.ID : null, CloudServiceCreationOption = this.CloudServiceCreationOption }; input.Properties.ProviderSpecificDetails = failoverInput; input.Properties.SkipTestFailoverCleanup = true.ToString(); } var response = this.RecoveryServicesClient.StartAzureSiteRecoveryTestFailover( this.fabricName, this.protectionContainerName, this.ReplicationProtectedItem.Name, input); var jobResponse = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails( PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location)); this.WriteObject(new ASRJob(jobResponse)); }