/// <summary> /// Starts PE Unplanned failover. /// </summary> private void StartPEUnplannedFailover() { var request = new UnplannedFailoverRequest(); request.FailoverDirection = this.Direction; request.SourceSiteOperations = this.PerformSourceSideActions ? Constants.Required : Constants.NotRequired; LongRunningOperationResponse response = RecoveryServicesClient.StartAzureSiteRecoveryUnplannedFailover( this.protectionContainerId, this.protectionEntityId, request); if (string.IsNullOrEmpty(this.ProtectionEntity.ReplicationProvider)) { // fetch the latest PE object // As get PE by name is failing before protection, get all & filter. // Once after we fix get pe by name, change the logic to use the same. ProtectionEntityListResponse protectionEntityListResponse = RecoveryServicesClient.GetAzureSiteRecoveryProtectionEntity( this.ProtectionEntity.ProtectionContainerId); foreach (ProtectionEntity pe in protectionEntityListResponse.ProtectionEntities) { if (0 == string.Compare(this.ProtectionEntity.FriendlyName, pe.Properties.FriendlyName, true)) { this.ProtectionEntity = new ASRProtectionEntity(pe); break; } } } request.ReplicationProvider = this.ProtectionEntity.ReplicationProvider; request.ReplicationProviderSettings = new FailoverReplicationProviderSpecificInput(); if (0 == string.Compare( this.ProtectionEntity.ReplicationProvider, Constants.HyperVReplicaAzure, StringComparison.OrdinalIgnoreCase)) { if (this.Direction == Constants.PrimaryToRecovery) { AzureFailoverInput failoverInput = new AzureFailoverInput() { PrimaryKekCertificatePfx = string.Empty, SecondaryKekCertificatePfx = string.Empty, VaultLocation = this.GetCurrentValutLocation() }; request.ReplicationProviderSettings = failoverInput; } } JobResponse jobResponse = RecoveryServicesClient .GetAzureSiteRecoveryJobDetails(PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location)); WriteObject(new ASRJob(jobResponse.Job)); }
/// <summary> /// Starts PE Planned failover. /// </summary> private void StartPEPlannedFailover() { var request = new PlannedFailoverRequest(); if (this.ProtectionEntity == null) { var pe = RecoveryServicesClient.GetAzureSiteRecoveryProtectionEntity( this.ProtectionContainerId, this.ProtectionEntityId); this.ProtectionEntity = new ASRProtectionEntity(pe.ProtectionEntity); this.ValidateUsageById(this.ProtectionEntity.ReplicationProvider, Constants.ProtectionEntityId); } if (this.ProtectionEntity.ReplicationProvider == Constants.HyperVReplicaAzure) { if (this.Direction == Constants.PrimaryToRecovery) { var blob = new AzureFailoverInput(); blob.VaultLocation = this.GetCurrentValutLocation(); request.ReplicationProviderSettings = DataContractUtils.Serialize <AzureFailoverInput>(blob); } else { var blob = new AzureFailbackInput(); blob.CreateRecoveryVmIfDoesntExist = false; blob.SkipDataSync = this.Optimize == Constants.ForDowntime ? true : false; request.ReplicationProviderSettings = DataContractUtils.Serialize <AzureFailbackInput>(blob); } } else { request.ReplicationProviderSettings = string.Empty; } request.ReplicationProvider = this.ProtectionEntity.ReplicationProvider; request.FailoverDirection = this.Direction; this.jobResponse = RecoveryServicesClient.StartAzureSiteRecoveryPlannedFailover( this.ProtectionContainerId, this.ProtectionEntityId, request); this.WriteJob(this.jobResponse.Job); if (this.WaitForCompletion.IsPresent) { this.WaitForJobCompletion(this.jobResponse.Job.ID); } }
/// <summary> /// Starts PE Test failover. /// </summary> private void StartPETestFailover() { var request = new TestFailoverRequest(); if (this.ProtectionEntity == null) { var pe = RecoveryServicesClient.GetAzureSiteRecoveryProtectionEntity( this.ProtectionContainerId, this.ProtectionEntityId); this.ProtectionEntity = new ASRProtectionEntity(pe.ProtectionEntity); this.ValidateUsageById( this.ProtectionEntity.ReplicationProvider, Constants.ProtectionEntityId); } request.ReplicationProviderSettings = string.Empty; if (this.ProtectionEntity.ReplicationProvider == Constants.HyperVReplicaAzure) { if (this.Direction == Constants.PrimaryToRecovery) { var blob = new AzureFailoverInput(); blob.VaultLocation = this.GetCurrentValutLocation(); request.ReplicationProviderSettings = DataContractUtils.Serialize <AzureFailoverInput>(blob); } } request.ReplicationProvider = this.ProtectionEntity.ReplicationProvider; request.FailoverDirection = this.Direction; request.NetworkID = this.networkId; request.NetworkType = this.networkType; this.jobResponse = RecoveryServicesClient.StartAzureSiteRecoveryTestFailover( this.ProtectionContainerId, this.ProtectionEntityId, request); this.WriteJob(this.jobResponse.Job); if (this.WaitForCompletion.IsPresent) { this.WaitForJobCompletion(this.jobResponse.Job.ID); } }
/// <summary> /// Starts RP Planned failover. /// </summary> private void StartRpUnPlannedFailover() { RpUnplannedFailoverRequest request = new RpUnplannedFailoverRequest(); if (this.RecoveryPlan == null) { var rp = RecoveryServicesClient.GetAzureSiteRecoveryRecoveryPlan( this.RPId); this.RecoveryPlan = new ASRRecoveryPlan(rp.RecoveryPlan); this.ValidateUsageById( this.RecoveryPlan.ReplicationProvider, Constants.RPId); } request.ReplicationProviderSettings = string.Empty; if (this.RecoveryPlan.ReplicationProvider == Constants.HyperVReplicaAzure) { request.ReplicationProvider = this.RecoveryPlan.ReplicationProvider; if (this.Direction == Constants.PrimaryToRecovery) { var blob = new AzureFailoverInput(); blob.VaultLocation = this.GetCurrentValutLocation(); request.ReplicationProviderSettings = DataContractUtils.Serialize <AzureFailoverInput>(blob); } } request.ReplicationProvider = this.RecoveryPlan.ReplicationProvider; request.FailoverDirection = this.Direction; request.PrimaryAction = this.PerformSourceSideActions; this.jobResponse = RecoveryServicesClient.StartAzureSiteRecoveryUnplannedFailover( this.RPId, request); this.WriteJob(this.jobResponse.Job); if (this.WaitForCompletion.IsPresent) { this.WaitForJobCompletion(this.jobResponse.Job.ID); } }