/// <summary> /// Switch the Azure Site Recovery protection entity replication direction. /// </summary> /// <param name="fabricName">Fabric Name</param> /// <param name="protectionContainerName">Protection Conatiner Name</param> /// <param name="input">Input for Switch</param> /// <returns>Job Response</returns> public PSSiteRecoveryLongRunningOperation StartSwitchProtection( string fabricName, string protectionContainerName, SwitchProtectionInput input) { var op = this.GetSiteRecoveryClient() .ReplicationProtectionContainers.BeginSwitchProtectionWithHttpMessagesAsync( fabricName, protectionContainerName, input, this.GetRequestHeaders(true)) .GetAwaiter() .GetResult(); var result = SiteRecoveryAutoMapperProfile.Mapper.Map <PSSiteRecoveryLongRunningOperation>(op); return(result); }
/// <summary> /// Switches protection from one container to another or one replication provider to another. /// </summary> private void A2ARPIReprotect() { var switchProtectionInputProperties = new SwitchProtectionInputProperties() { ReplicationProtectedItemName = this.ReplicationProtectedItem.Name, ProviderSpecificDetails = new SwitchProtectionProviderSpecificInput() }; var fabricFriendlyName = this.ReplicationProtectedItem.PrimaryFabricFriendlyName; SwitchProtectionInput input = new SwitchProtectionInput() { Properties = switchProtectionInputProperties }; if (0 == string.Compare( this.ReplicationProtectedItem.ReplicationProvider, Constants.A2A, StringComparison.OrdinalIgnoreCase)) { var a2aSwitchInput = new A2ASwitchProtectionInput() { PolicyId = this.ProtectionContainerMapping.PolicyId, RecoveryContainerId = this.ProtectionContainerMapping.TargetProtectionContainerId, VmDisks = new List <A2AVmDiskInputDetails>(), VmManagedDisks = new List <A2AVmManagedDiskInputDetails>(), RecoveryResourceGroupId = this.RecoveryResourceGroupId, RecoveryCloudServiceId = this.RecoveryCloudServiceId, RecoveryAvailabilitySetId = this.RecoveryAvailabilitySetId, RecoveryBootDiagStorageAccountId = this.RecoveryBootDiagStorageAccountId, }; // Fetch the latest Protected item objects var replicationProtectedItemResponse = RecoveryServicesClient.GetAzureSiteRecoveryReplicationProtectedItem( this.fabricName, this.protectionContainerName, this.ReplicationProtectedItem.Name); if (fabricFriendlyName != this.ProtectionContainerMapping.TargetFabricFriendlyName) { throw new ArgumentException( string.Format(Resources.InvalidSwitchParamRPIAndProtectionContainerMapping, fabricFriendlyName, this.ProtectionContainerMapping.TargetFabricFriendlyName)); } // unmanagedDisk case if (((A2AReplicationDetails)replicationProtectedItemResponse.Properties.ProviderSpecificDetails).ProtectedDisks != null && ((A2AReplicationDetails)replicationProtectedItemResponse.Properties.ProviderSpecificDetails).ProtectedDisks.Count > 0) { populateUnManagedDiskInputDetails(fabricFriendlyName, a2aSwitchInput, replicationProtectedItemResponse); } else if (this.AzureToAzureDiskReplicationConfiguration == null && ((A2AReplicationDetails)replicationProtectedItemResponse.Properties.ProviderSpecificDetails).ProtectedManagedDisks != null) { populateManagedDiskInputDetails(a2aSwitchInput, replicationProtectedItemResponse); } input.Properties.ProviderSpecificDetails = a2aSwitchInput; } var response = RecoveryServicesClient.StartSwitchProtection( this.fabricName, this.protectionContainerName, input); var jobResponse = RecoveryServicesClient .GetAzureSiteRecoveryJobDetails( PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location)); WriteObject(new ASRJob(jobResponse)); }
/// <summary> /// Switches protection from one container to another or one replication /// provider to another. /// </summary> /// <remarks> /// Operation to switch protection from one container to another or one /// replication provider to another. /// </remarks> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='fabricName'> /// Unique fabric name. /// </param> /// <param name='protectionContainerName'> /// Protection container name. /// </param> /// <param name='switchInput'> /// Switch protection input. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <ProtectionContainer> BeginSwitchProtectionAsync(this IReplicationProtectionContainersOperations operations, string fabricName, string protectionContainerName, SwitchProtectionInput switchInput, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.BeginSwitchProtectionWithHttpMessagesAsync(fabricName, protectionContainerName, switchInput, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Switches protection from one container to another or one replication /// provider to another. /// </summary> /// <remarks> /// Operation to switch protection from one container to another or one /// replication provider to another. /// </remarks> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='fabricName'> /// Unique fabric name. /// </param> /// <param name='protectionContainerName'> /// Protection container name. /// </param> /// <param name='switchInput'> /// Switch protection input. /// </param> public static ProtectionContainer BeginSwitchProtection(this IReplicationProtectionContainersOperations operations, string fabricName, string protectionContainerName, SwitchProtectionInput switchInput) { return(operations.BeginSwitchProtectionAsync(fabricName, protectionContainerName, switchInput).GetAwaiter().GetResult()); }
/// <summary> /// Switches protection from one container to another or one replication provider to another. /// </summary> private void A2ARPIReprotect() { var switchProtectionInputProperties = new SwitchProtectionInputProperties() { ReplicationProtectedItemName = this.ReplicationProtectedItem.Name, ProviderSpecificDetails = new SwitchProtectionProviderSpecificInput() }; var fabricFriendlyName = this.ReplicationProtectedItem.PrimaryFabricFriendlyName; SwitchProtectionInput input = new SwitchProtectionInput() { Properties = switchProtectionInputProperties }; if (0 == string.Compare( this.ReplicationProtectedItem.ReplicationProvider, Constants.A2A, StringComparison.OrdinalIgnoreCase)) { var a2aSwitchInput = new A2ASwitchProtectionInput() { PolicyId = this.ProtectionContainerMapping.PolicyId, RecoveryContainerId = this.ProtectionContainerMapping.TargetProtectionContainerId, VmDisks = new List <A2AVmDiskInputDetails>(), RecoveryResourceGroupId = this.RecoveryResourceGroupId, RecoveryCloudServiceId = this.RecoveryCloudServiceId, RecoveryAvailabilitySetId = this.RecoveryAvailabilitySetId }; // Fetch the latest Protected item objects var replicationProtectedItemResponse = RecoveryServicesClient.GetAzureSiteRecoveryReplicationProtectedItem( this.fabricName, this.protectionContainerName, this.ReplicationProtectedItem.Name); if (fabricFriendlyName != this.ProtectionContainerMapping.TargetFabricFriendlyName) { throw new ArgumentException( string.Format(Resources.InvalidSwitchParamRPIAndProtectionContainerMapping, fabricFriendlyName, this.ProtectionContainerMapping.TargetFabricFriendlyName)); } // At a time only Disk or managedDisk details will be present. // Will check with retieved protectedItem weather correct disk mapping is passed and then create the relevant object // and pass as input to service. if (this.AzureToAzureDiskReplicationConfiguration == null || this.AzureToAzureDiskReplicationConfiguration.Length == 0) { if (fabricFriendlyName != this.ProtectionContainerMapping.TargetFabricFriendlyName && RecoveryAzureStorageAccountId == null) { throw new ArgumentException(Resources.InvalidRecoveryAzureStorageAccountId); } foreach (var disk in ((A2AReplicationDetails)replicationProtectedItemResponse .Properties.ProviderSpecificDetails) .ProtectedDisks) { a2aSwitchInput.VmDisks.Add(new A2AVmDiskInputDetails { DiskUri = disk.RecoveryDiskUri, RecoveryAzureStorageAccountId = fabricFriendlyName == this.ProtectionContainerMapping.TargetFabricFriendlyName && this.RecoveryAzureStorageAccountId == null ? disk.PrimaryDiskAzureStorageAccountId : this.RecoveryAzureStorageAccountId, PrimaryStagingAzureStorageAccountId = this.LogStorageAccountId, }); } } else { foreach (ASRAzuretoAzureDiskReplicationConfig disk in this.AzureToAzureDiskReplicationConfiguration) { if (string.IsNullOrEmpty(disk.LogStorageAccountId)) { throw new PSArgumentException( string.Format( Properties.Resources.InvalidPrimaryStagingAzureStorageAccountIdDiskInput, disk.VhdUri)); } if (string.IsNullOrEmpty(disk.RecoveryAzureStorageAccountId)) { throw new PSArgumentException( string.Format( Properties.Resources.InvalidRecoveryAzureStorageAccountIdDiskInput, disk.VhdUri)); } a2aSwitchInput.VmDisks.Add(new A2AVmDiskInputDetails { DiskUri = disk.VhdUri, RecoveryAzureStorageAccountId = disk.RecoveryAzureStorageAccountId, PrimaryStagingAzureStorageAccountId = disk.LogStorageAccountId }); } } input.Properties.ProviderSpecificDetails = a2aSwitchInput; } var response = RecoveryServicesClient.StartSwitchProtection( this.fabricName, this.protectionContainerName, input); var jobResponse = RecoveryServicesClient .GetAzureSiteRecoveryJobDetails( PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location)); WriteObject(new ASRJob(jobResponse)); }