/// <summary> /// Queries by name. /// </summary> private void GetByName() { RecoveryPlanListResponse recoveryPlanListResponse = RecoveryServicesClient.GetAzureSiteRecoveryRecoveryPlan(); bool found = false; foreach (RecoveryPlan recoveryPlan in recoveryPlanListResponse.RecoveryPlans) { if (0 == string.Compare(this.Name, recoveryPlan.Name, true)) { this.WriteRecoveryPlan(recoveryPlan); found = true; } } if (!found) { throw new InvalidOperationException( string.Format( Properties.Resources.RecoveryPlanNotFound, this.Name, PSRecoveryServicesClient.asrVaultCreds.ResourceName)); } }
/// <summary> /// Sets RP Commit. /// </summary> private void SetRpCommit() { var request = new CommitFailoverRequest(); if (this.RecoveryPlan == null) { var rp = RecoveryServicesClient.GetAzureSiteRecoveryRecoveryPlan( this.RPId); this.RecoveryPlan = new ASRRecoveryPlan(rp.RecoveryPlan); this.ValidateUsageById(this.RecoveryPlan.ReplicationProvider, "RPId"); } request.ReplicationProvider = this.RecoveryPlan.ReplicationProvider; request.ReplicationProviderSettings = string.Empty; request.FailoverDirection = this.Direction; this.jobResponse = RecoveryServicesClient.StartAzureSiteRecoveryCommitFailover( this.RPId); this.WriteJob(this.jobResponse.Job); if (this.WaitForCompletion.IsPresent) { this.WaitForJobCompletion(this.jobResponse.Job.ID); } }
/// <summary> /// Queries by ID. /// </summary> private void GetById() { RecoveryPlanResponse recoveryPlanResponse = RecoveryServicesClient.GetAzureSiteRecoveryRecoveryPlan(this.Id); this.WriteRecoveryPlan(recoveryPlanResponse.RecoveryPlan); }
/// <summary> /// Queries all / by default. /// </summary> private void GetByDefault() { RecoveryPlanListResponse recoveryPlanListResponse = RecoveryServicesClient.GetAzureSiteRecoveryRecoveryPlan(); this.WriteRecoveryPlans(recoveryPlanListResponse.RecoveryPlans); }
/// <summary> /// Queries by Friendly name. /// </summary> private void GetByFriendlyName() { RecoveryPlanListResponse recoveryPlanListResponse = RecoveryServicesClient.GetAzureSiteRecoveryRecoveryPlan(); bool found = false; foreach (RecoveryPlan recoveryPlan in recoveryPlanListResponse.RecoveryPlans) { if (0 == string.Compare(this.FriendlyName, recoveryPlan.Properties.FriendlyName, StringComparison.OrdinalIgnoreCase)) { var rp = RecoveryServicesClient.GetAzureSiteRecoveryRecoveryPlan(recoveryPlan.Name).RecoveryPlan; this.WriteRecoveryPlan(rp); if (!string.IsNullOrEmpty(this.Path)) { GetRecoveryPlanFile(rp); } found = true; } } if (!found) { throw new InvalidOperationException( string.Format( Properties.Resources.RecoveryPlanNotFound, this.FriendlyName, PSRecoveryServicesClient.asrVaultCreds.ResourceName)); } }
/// <summary> /// Queries by Name. /// </summary> private void GetByName() { try { var recoveryPlanResponse = RecoveryServicesClient.GetAzureSiteRecoveryRecoveryPlan(this.Name); if (recoveryPlanResponse.RecoveryPlan != null) { this.WriteRecoveryPlan(recoveryPlanResponse.RecoveryPlan); if (!string.IsNullOrEmpty(this.Path)) { GetRecoveryPlanFile(recoveryPlanResponse.RecoveryPlan); } } } catch (CloudException ex) { if (string.Compare(ex.Error.Code, "NotFound", StringComparison.OrdinalIgnoreCase) == 0) { throw new InvalidOperationException( string.Format( Properties.Resources.RecoveryPlanNotFound, this.Name, PSRecoveryServicesClient.asrVaultCreds.ResourceName)); } else { throw; } } }
/// <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 Test failover. /// </summary> private void StartRpTestFailover() { // Refresh RP Object var rp = RecoveryServicesClient.GetAzureSiteRecoveryRecoveryPlan(this.RecoveryPlan.Name); var recoveryPlanTestFailoverInputProperties = new RecoveryPlanTestFailoverInputProperties() { FailoverDirection = this.Direction, NetworkId = this.networkId, NetworkType = this.networkType, 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() }; recoveryPlanTestFailoverInputProperties.ProviderSpecificDetails.Add(recoveryPlanHyperVReplicaAzureFailoverInput); } else { new ArgumentException(Properties.Resources.UnsupportedDirectionForTFO);// Throw Unsupported Direction Exception } } } var recoveryPlanTestFailoverInput = new RecoveryPlanTestFailoverInput() { Properties = recoveryPlanTestFailoverInputProperties }; LongRunningOperationResponse response = RecoveryServicesClient.StartAzureSiteRecoveryTestFailover( this.RecoveryPlan.Name, recoveryPlanTestFailoverInput); JobResponse jobResponse = RecoveryServicesClient .GetAzureSiteRecoveryJobDetails(PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location)); WriteObject(new ASRJob(jobResponse.Job)); }
/// <summary> /// Starts RP Unplanned failover. /// </summary> private void StartRpUnplannedFailover() { // Refresh RP Object var rp = RecoveryServicesClient.GetAzureSiteRecoveryRecoveryPlan(this.RecoveryPlan.Name); var recoveryPlanUnplannedFailoverInputProperties = new RecoveryPlanUnplannedFailoverInputProperties() { FailoverDirection = this.Direction, SourceSiteOperations = this.PerformSourceSideActions ? "Required" : "NotRequired", //Required|NotRequired 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() }; recoveryPlanUnplannedFailoverInputProperties.ProviderSpecificDetails.Add(recoveryPlanHyperVReplicaAzureFailoverInput); } } } var recoveryPlanUnplannedFailoverInput = new RecoveryPlanUnplannedFailoverInput() { Properties = recoveryPlanUnplannedFailoverInputProperties }; LongRunningOperationResponse response = RecoveryServicesClient.StartAzureSiteRecoveryUnplannedFailover( this.RecoveryPlan.Name, recoveryPlanUnplannedFailoverInput); JobResponse jobResponse = RecoveryServicesClient .GetAzureSiteRecoveryJobDetails(PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location)); WriteObject(new ASRJob(jobResponse.Job)); }
/// <summary> /// Starts RP Planned failover. /// </summary> private void StartRpPlannedFailover() { RpPlannedFailoverRequest request = new RpPlannedFailoverRequest(); if (this.RecoveryPlan == null) { var rp = RecoveryServicesClient.GetAzureSiteRecoveryRecoveryPlan( this.RPId); this.RecoveryPlan = new ASRRecoveryPlan(rp.RecoveryPlan); this.ValidateUsageById( this.RecoveryPlan.ReplicationProvider, Constants.RPId); } if (this.RecoveryPlan.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); } } request.ReplicationProvider = this.RecoveryPlan.ReplicationProvider; request.FailoverDirection = this.Direction; this.jobResponse = RecoveryServicesClient.StartAzureSiteRecoveryPlannedFailover( this.RPId, request); this.WriteJob(this.jobResponse.Job); if (this.WaitForCompletion.IsPresent) { this.WaitForJobCompletion(this.jobResponse.Job.ID); } }
private void GetRecoveryPlanFile(RecoveryPlan recoveryPlan) { recoveryPlan = RecoveryServicesClient.GetAzureSiteRecoveryRecoveryPlan(recoveryPlan.Name).RecoveryPlan; if (string.IsNullOrEmpty(this.Path) || !Directory.Exists(System.IO.Path.GetDirectoryName(this.Path))) { throw new DirectoryNotFoundException(string.Format(Properties.Resources.DirectoryNotFound, System.IO.Path.GetDirectoryName(this.Path))); } string fullFileName = this.Path; using (System.IO.StreamWriter file = new System.IO.StreamWriter(@fullFileName, false)) { string json = JsonConvert.SerializeObject(recoveryPlan, Formatting.Indented); file.WriteLine(json); } }
/// <summary> /// Starts RP test failover. /// </summary> private void StartRpTestFailover() { RpTestFailoverRequest request = new RpTestFailoverRequest(); 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) { if (this.Direction == Constants.PrimaryToRecovery) { var blob = new AzureFailoverInput(); blob.VaultLocation = this.GetCurrentValutLocation(); request.ReplicationProviderSettings = DataContractUtils.Serialize <AzureFailoverInput>(blob); } } request.NetworkID = this.networkId; request.NetworkType = this.networkType; request.ReplicationProvider = this.RecoveryPlan.ReplicationProvider; request.FailoverDirection = this.Direction; this.jobResponse = RecoveryServicesClient.StartAzureSiteRecoveryTestFailover( this.RpId, request); this.WriteJob(this.jobResponse.Job); if (this.WaitForCompletion.IsPresent) { this.WaitForJobCompletion(this.jobResponse.Job.ID); } }