/// <summary> /// Set PE protection. /// </summary> private void SetPEReprotect() { var request = new ReprotectRequest(); if (this.ProtectionEntity == null) { var pe = RecoveryServicesClient.GetAzureSiteRecoveryProtectionEntity( this.protectionContainerId, this.protectionEntityId); this.ProtectionEntity = new ASRProtectionEntity(pe.ProtectionEntity); this.ValidateUsageById( this.ProtectionEntity.ReplicationProvider, this.protectionEntityId); } request.ReplicationProviderSettings = string.Empty; request.ReplicationProvider = this.ProtectionEntity.ReplicationProvider; request.FailoverDirection = this.Direction; LongRunningOperationResponse response = RecoveryServicesClient.StartAzureSiteRecoveryReprotection( this.protectionContainerId, this.protectionEntityId, request); JobResponse jobResponse = RecoveryServicesClient .GetAzureSiteRecoveryJobDetails(PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location)); WriteObject(new ASRJob(jobResponse.Job)); }
/// <summary> /// Set PE protection. /// </summary> private void SetPEReprotect() { var request = new ReprotectRequest(); request.FailoverDirection = this.Direction; 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 ((this.Direction == Constants.PrimaryToRecovery && this.ProtectionEntity.ActiveLocation == Constants.RecoveryLocation) || (this.Direction == Constants.RecoveryToPrimary && this.ProtectionEntity.ActiveLocation == Constants.PrimaryLocation)) { throw new ArgumentException("Parameter value is not correct.", "Direction"); } if (0 == string.Compare( this.ProtectionEntity.ReplicationProvider, Constants.HyperVReplicaAzure, StringComparison.OrdinalIgnoreCase)) { if (this.Direction == Constants.PrimaryToRecovery) { AzureReprotectInput reprotectInput = new AzureReprotectInput() { HvHostVmId = this.ProtectionEntity.FabricObjectId, VmName = this.ProtectionEntity.Name, OSType = this.ProtectionEntity.OS, VHDId = this.ProtectionEntity.OSDiskId }; request.ReplicationProviderSettings = reprotectInput; } } LongRunningOperationResponse response = RecoveryServicesClient.StartAzureSiteRecoveryReprotection( this.protectionContainerId, this.protectionEntityId, request); JobResponse jobResponse = RecoveryServicesClient .GetAzureSiteRecoveryJobDetails(PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location)); WriteObject(new ASRJob(jobResponse.Job)); }
/// <summary> /// Re-protects the Azure Site Recovery protection entity. /// </summary> /// <param name="protectionContainerId">Protection Container ID</param> /// <param name="protectionEntityId">Recovery Plan ID</param> /// <param name="request">Re-protect request.</param> /// <returns>Job response</returns> public LongRunningOperationResponse StartAzureSiteRecoveryReprotection( string protectionContainerId, string protectionEntityId, ReprotectRequest request) { return this.GetSiteRecoveryClient().ProtectionEntity.BeginReprotect( protectionContainerId, protectionEntityId, request, this.GetRequestHeaders()); }
/// <summary> /// Creates a profile /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.SiteRecovery.IProtectionEntityOperations. /// </param> /// <param name='pcName'> /// Required. Parent Protection Container name. /// </param> /// <param name='name'> /// Required. Protection entity name. /// </param> /// <param name='parameters'> /// Required. Reprotect request after failover. /// </param> /// <param name='customRequestHeaders'> /// Optional. Request header parameters. /// </param> /// <returns> /// A standard service response for long running operations. /// </returns> public static Task<LongRunningOperationResponse> ReprotectAsync(this IProtectionEntityOperations operations, string pcName, string name, ReprotectRequest parameters, CustomRequestHeaders customRequestHeaders) { return operations.ReprotectAsync(pcName, name, parameters, customRequestHeaders, CancellationToken.None); }
/// <summary> /// Creates a profile /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.SiteRecovery.IProtectionEntityOperations. /// </param> /// <param name='pcName'> /// Required. Parent Protection Container name. /// </param> /// <param name='name'> /// Required. Protection entity name. /// </param> /// <param name='parameters'> /// Required. Reprotect request after failover. /// </param> /// <param name='customRequestHeaders'> /// Optional. Request header parameters. /// </param> /// <returns> /// A standard service response for long running operations. /// </returns> public static LongRunningOperationResponse Reprotect(this IProtectionEntityOperations operations, string pcName, string name, ReprotectRequest parameters, CustomRequestHeaders customRequestHeaders) { return Task.Factory.StartNew((object s) => { return ((IProtectionEntityOperations)s).ReprotectAsync(pcName, name, parameters, customRequestHeaders); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult(); }