/// <summary> /// Update replication protection direction for replication protected item. /// </summary> private void SetRPIReprotect() { var plannedFailoverInputProperties = new ReverseReplicationInputProperties { FailoverDirection = this.Direction, ProviderSpecificDetails = new ReverseReplicationProviderSpecificInput() }; var input = new ReverseReplicationInput { Properties = plannedFailoverInputProperties }; // fetch the latest Protectable item objects var replicationProtectedItemResponse = this.RecoveryServicesClient .GetAzureSiteRecoveryReplicationProtectedItem( this.fabricName, this.protectionContainerName, this.ReplicationProtectedItem.Name); validateRPISwitchParam(); var protectableItemResponse = this.RecoveryServicesClient .GetAzureSiteRecoveryProtectableItem( this.fabricName, this.protectionContainerName, Utilities.GetValueFromArmId( replicationProtectedItemResponse.Properties.ProtectableItemId, ARMResourceTypeConstants.ProtectableItems)); var asrProtectableItem = new ASRProtectableItem(protectableItemResponse); if (0 == string.Compare( this.ReplicationProtectedItem.ReplicationProvider, Constants.HyperVReplicaAzure, StringComparison.OrdinalIgnoreCase)) { if (this.Direction == Constants.PrimaryToRecovery) { var reprotectInput = new HyperVReplicaAzureReprotectInput { HvHostVmId = asrProtectableItem.FabricObjectId, VmName = asrProtectableItem.FriendlyName, OsType = string.Compare( asrProtectableItem.OS, "Windows") == 0 || string.Compare( asrProtectableItem.OS, "Linux") == 0 ? asrProtectableItem.OS : "Windows", VHDId = asrProtectableItem.OSDiskId }; var providerSpecificDetails = (HyperVReplicaAzureReplicationDetails)replicationProtectedItemResponse .Properties.ProviderSpecificDetails; reprotectInput.StorageAccountId = this.RecoveryAzureStorageAccountId == null ? providerSpecificDetails.RecoveryAzureStorageAccount : this.RecoveryAzureStorageAccountId; reprotectInput.LogStorageAccountId = this.LogStorageAccountId == null ? providerSpecificDetails.RecoveryAzureLogStorageAccountId : this.LogStorageAccountId; input.Properties.ProviderSpecificDetails = reprotectInput; } } else if (string.Compare( this.ReplicationProtectedItem.ReplicationProvider, Constants.InMageAzureV2, StringComparison.OrdinalIgnoreCase) == 0) { // Validate the direction as RecoveryToPrimary. if (this.Direction == Constants.RecoveryToPrimary) { // Set the InMage Provider specific input in the Reprotect Input. var reprotectInput = new InMageReprotectInput { ProcessServerId = this.ProcessServer.Id, MasterTargetId = this.MasterTarget != null ? this.MasterTarget.Id : this.ProcessServer .Id, // Assumption: PS and MT may or may not be same. RunAsAccountId = this.Account != null ? this.Account.AccountId : null, RetentionDrive = this.RetentionVolume.VolumeName, DatastoreName = this.DataStore.SymbolicName, ProfileId = this.ProtectionContainerMapping.PolicyId, DiskExclusionInput = new InMageDiskExclusionInput { VolumeOptions = new List <InMageVolumeExclusionOptions>(), DiskSignatureOptions = null }, DisksToInclude = null }; // excluding the azure temporary storage. reprotectInput.DiskExclusionInput.VolumeOptions.Add( new InMageVolumeExclusionOptions { VolumeLabel = Constants.TemporaryStorage, OnlyExcludeIfSingleVolume = Constants.Yes }); input.Properties.ProviderSpecificDetails = reprotectInput; } else { // PrimaryToRecovery Direction is Invalid for InMageAzureV2. new ArgumentException(Resources.InvalidDirectionForAzureToVMWare); } } else if (string.Compare( this.ReplicationProtectedItem.ReplicationProvider, Constants.InMage, StringComparison.OrdinalIgnoreCase) == 0) { // Validate the Direction as RecoveryToPrimary. if (this.Direction == Constants.RecoveryToPrimary) { // Set the InMageAzureV2 Provider specific input in the Reprotect Input. var reprotectInput = new InMageAzureV2ReprotectInput { ProcessServerId = this.ProcessServer.Id, MasterTargetId = this.MasterTarget != null ? this.MasterTarget.Id : this.ProcessServer .Id, // Assumption: PS and MT are same. RunAsAccountId = this.Account.AccountId, PolicyId = this.ProtectionContainerMapping.PolicyId, StorageAccountId = this.RecoveryAzureStorageAccountId, LogStorageAccountId = this.LogStorageAccountId, DisksToInclude = null }; input.Properties.ProviderSpecificDetails = reprotectInput; } else { // PrimaryToRecovery Direction is Invalid for InMage. new ArgumentException(Resources.InvalidDirectionForVMWareToAzure); } } var response = this.RecoveryServicesClient.StartAzureSiteRecoveryReprotection( this.fabricName, this.protectionContainerName, this.ReplicationProtectedItem.Name, input); var jobResponse = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails( PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location)); this.WriteObject(new ASRJob(jobResponse)); }
/// <summary> /// RPI Reprotect. /// </summary> private void SetRPIReprotect() { var plannedFailoverInputProperties = new ReverseReplicationInputProperties { FailoverDirection = this.Direction, ProviderSpecificDetails = new ReverseReplicationProviderSpecificInput() }; var input = new ReverseReplicationInput { Properties = plannedFailoverInputProperties }; // fetch the latest Protectable item objects var replicationProtectedItemResponse = this.RecoveryServicesClient .GetAzureSiteRecoveryReplicationProtectedItem( this.fabricName, this.protectionContainerName, this.ReplicationProtectedItem.Name); var protectableItemResponse = this.RecoveryServicesClient .GetAzureSiteRecoveryProtectableItem( this.fabricName, this.protectionContainerName, Utilities.GetValueFromArmId( replicationProtectedItemResponse.Properties.ProtectableItemId, ARMResourceTypeConstants.ProtectableItems)); var aSRProtectableItem = new ASRProtectableItem(protectableItemResponse); if (0 == string.Compare( this.ReplicationProtectedItem.ReplicationProvider, Constants.HyperVReplicaAzure, StringComparison.OrdinalIgnoreCase)) { if (this.Direction == Constants.PrimaryToRecovery) { var reprotectInput = new HyperVReplicaAzureReprotectInput { HvHostVmId = aSRProtectableItem.FabricObjectId, VmName = aSRProtectableItem.FriendlyName, OsType = (string.Compare( aSRProtectableItem.OS, "Windows") == 0) || (string.Compare( aSRProtectableItem.OS, "Linux") == 0) ? aSRProtectableItem.OS : "Windows", VHDId = aSRProtectableItem.OSDiskId }; var providerSpecificDetails = (HyperVReplicaAzureReplicationDetails)replicationProtectedItemResponse .Properties.ProviderSpecificDetails; reprotectInput.StorageAccountId = providerSpecificDetails.RecoveryAzureStorageAccount; input.Properties.ProviderSpecificDetails = reprotectInput; } } var response = this.RecoveryServicesClient.StartAzureSiteRecoveryReprotection( this.fabricName, this.protectionContainerName, this.ReplicationProtectedItem.Name, input); var jobResponse = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails( PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location)); this.WriteObject(new ASRJob(jobResponse)); }