private void SetRPIReprotect()
{
ReverseReplicationInputProperties plannedFailoverInputProperties = new ReverseReplicationInputProperties()
{
FailoverDirection = this.Direction,
ProviderSpecificDetails = new ReverseReplicationProviderSpecificInput()
};
ReverseReplicationInput input = new ReverseReplicationInput()
{
Properties = plannedFailoverInputProperties
};
// fetch the latest Protectable item objects
ReplicationProtectedItemResponse replicationProtectedItemResponse =
RecoveryServicesClient.GetAzureSiteRecoveryReplicationProtectedItem(this.fabricName,
this.protectionContainerName, this.ReplicationProtectedItem.Name);
ProtectableItemResponse protectableItemResponse =
RecoveryServicesClient.GetAzureSiteRecoveryProtectableItem(this.fabricName, this.protectionContainerName,
Utilities.GetValueFromArmId(replicationProtectedItemResponse.ReplicationProtectedItem.Properties.ProtectableItemId,
ARMResourceTypeConstants.ProtectableItems));
var aSRProtectableItem = new ASRProtectableItem(protectableItemResponse.ProtectableItem);
if (0 == string.Compare(
this.ReplicationProtectedItem.ReplicationProvider,
Constants.HyperVReplicaAzure,
StringComparison.OrdinalIgnoreCase))
{
if (this.Direction == Constants.PrimaryToRecovery)
{
HyperVReplicaAzureReprotectInput 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
};
HyperVReplicaAzureReplicationDetails providerSpecificDetails =
(HyperVReplicaAzureReplicationDetails)replicationProtectedItemResponse.ReplicationProtectedItem.Properties.ProviderSpecificDetails;
reprotectInput.StorageAccountId = providerSpecificDetails.RecoveryAzureStorageAccount;
input.Properties.ProviderSpecificDetails = reprotectInput;
}
}
LongRunningOperationResponse response =
RecoveryServicesClient.StartAzureSiteRecoveryReprotection(
this.fabricName,
this.protectionContainerName,
this.ReplicationProtectedItem.Name,
input);
JobResponse jobResponse =
RecoveryServicesClient
.GetAzureSiteRecoveryJobDetails(PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location));
WriteObject(new ASRJob(jobResponse.Job));
}