private void StartPEPlannedFailover()
{
var plannedFailoverInputProperties = new PlannedFailoverInputProperties()
{
FailoverDirection = this.Direction,
ProviderSpecificDetails = new ProviderSpecificFailoverInput()
};
var input = new PlannedFailoverInput()
{
Properties = plannedFailoverInputProperties
};
// fetch the latest PE object
ProtectableItemResponse protectableItemResponse =
RecoveryServicesClient.GetAzureSiteRecoveryProtectableItem(this.fabricName,
this.ProtectionEntity.ProtectionContainerId, this.ProtectionEntity.Name);
ReplicationProtectedItemResponse replicationProtectedItemResponse =
RecoveryServicesClient.GetAzureSiteRecoveryReplicationProtectedItem(this.fabricName,
this.ProtectionEntity.ProtectionContainerId, Utilities.GetValueFromArmId(protectableItemResponse.ProtectableItem.Properties.ReplicationProtectedItemId, ARMResourceTypeConstants.ReplicationProtectedItems));
PolicyResponse policyResponse = RecoveryServicesClient.GetAzureSiteRecoveryPolicy(Utilities.GetValueFromArmId(replicationProtectedItemResponse.ReplicationProtectedItem.Properties.PolicyID, ARMResourceTypeConstants.ReplicationPolicies));
this.ProtectionEntity = new ASRProtectionEntity(protectableItemResponse.ProtectableItem, replicationProtectedItemResponse.ReplicationProtectedItem);
if (0 == string.Compare(
this.ProtectionEntity.ReplicationProvider,
Constants.HyperVReplicaAzure,
StringComparison.OrdinalIgnoreCase))
{
if (this.Direction == Constants.PrimaryToRecovery)
{
var failoverInput = new HyperVReplicaAzureFailoverProviderInput()
{
PrimaryKekCertificatePfx = primaryKekCertpfx,
SecondaryKekCertificatePfx = secondaryKekCertpfx,
VaultLocation = this.GetCurrentVaultLocation()
};
input.Properties.ProviderSpecificDetails = failoverInput;
}
else
{
var failbackInput = new HyperVReplicaAzureFailbackProviderInput()
{
DataSyncOption = this.Optimize == Constants.ForDownTime ? Constants.ForDownTime : Constants.ForSynchronization,
RecoveryVmCreationOption = String.Compare(this.CreateVmIfNotFound, Constants.Yes, StringComparison.OrdinalIgnoreCase) == 0 ? Constants.CreateVmIfNotFound : Constants.NoAction
};
if (String.Compare(this.CreateVmIfNotFound, Constants.Yes, StringComparison.OrdinalIgnoreCase) == 0 &&
string.Compare(RecoveryServicesClient.GetAzureSiteRecoveryFabric(this.fabricName).Fabric.Properties.CustomDetails.InstanceType, Constants.HyperVSite) == 0)
{
if(this.Server == null || string.Compare(this.Server.FabricType, Constants.HyperVSite) != 0)
{
throw new InvalidOperationException(
Properties.Resources.ImproperServerObjectPassedForHyperVFailback);
}
else
{
failbackInput.ProviderIdForAlternateRecovery = this.Server.ID;
}
}
input.Properties.ProviderSpecificDetails = failbackInput;
}
}
LongRunningOperationResponse response =
RecoveryServicesClient.StartAzureSiteRecoveryPlannedFailover(
this.fabricName,
this.protectionContainerName,
Utilities.GetValueFromArmId(replicationProtectedItemResponse.ReplicationProtectedItem.Id, ARMResourceTypeConstants.ReplicationProtectedItems),
input);
JobResponse jobResponse =
RecoveryServicesClient
.GetAzureSiteRecoveryJobDetails(PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location));
WriteObject(new ASRJob(jobResponse.Job));
}