Skip to content

Commit ce7173d

Browse files
committed
UFO/TFO
1 parent f98ac03 commit ce7173d

File tree

2 files changed

+145
-21
lines changed

2 files changed

+145
-21
lines changed

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Service/StartAzureSiteRecoveryTestFailoverJob.cs

Lines changed: 93 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using System;
16-
using System.Diagnostics;
1716
using System.Management.Automation;
18-
using System.Threading;
1917
using Microsoft.Azure.Commands.RecoveryServices.SiteRecovery;
20-
using Microsoft.WindowsAzure;
18+
using Microsoft.Azure.Portal.RecoveryServices.Models.Common;
2119
using Microsoft.WindowsAzure.Management.SiteRecovery.Models;
2220

2321
namespace Microsoft.Azure.Commands.RecoveryServices
@@ -52,6 +50,11 @@ public class StartAzureSiteRecoveryTestFailoverJob : RecoveryServicesCmdletBase
5250
[ValidateNotNullOrEmpty]
5351
public string RpId { get; set; }
5452

53+
/// <summary>
54+
/// Gets or sets ID of the Recovery Plan.
55+
/// </summary>
56+
public ASRNetwork Network { get; set; }
57+
5558
/// <summary>
5659
/// Gets or sets Recovery Plan object.
5760
/// </summary>
@@ -175,11 +178,55 @@ public override void ExecuteCmdlet()
175178
/// </summary>
176179
private void StartRpTestFailover()
177180
{
178-
RpTestFailoverRequest recoveryPlanTestFailoverRequest = new RpTestFailoverRequest();
179-
recoveryPlanTestFailoverRequest.FailoverDirection = this.Direction;
181+
RpTestFailoverRequest request = new RpTestFailoverRequest();
182+
183+
if (this.Network != null)
184+
{
185+
request.NetworkID = this.Network.ID;
186+
request.NetworkType = "UseVMNetworkTypeForTestFailover";
187+
}
188+
else
189+
{
190+
request.NetworkID = this.networkId;
191+
}
192+
193+
if (this.RecoveryPlan == null)
194+
{
195+
var rp = RecoveryServicesClient.GetAzureSiteRecoveryRecoveryPlan(
196+
this.RpId);
197+
this.RecoveryPlan = new ASRRecoveryPlan(rp.RecoveryPlan);
198+
199+
this.ValidateUsageById(this.RecoveryPlan.ReplicationProvider);
200+
}
201+
202+
request.ReplicationProviderSettings = string.Empty;
203+
204+
if (this.RecoveryPlan.ReplicationProvider == Constants.HyperVReplicaAzure)
205+
{
206+
request.ReplicationProvider = this.RecoveryPlan.ReplicationProvider;
207+
if (this.Direction == Constants.PrimaryToRecovery)
208+
{
209+
var blob = new AzureFailoverInput();
210+
blob.VaultLocation = this.GetCurrentValutLocation();
211+
request.ReplicationProviderSettings = DataContractUtils.Serialize<AzureFailoverInput>(blob);
212+
}
213+
}
214+
215+
request.FailoverDirection = this.Direction;
216+
217+
if (this.Network != null)
218+
{
219+
request.NetworkID = this.Network.ID;
220+
this.networkType = "UseVMNetworkTypeForTestFailover";
221+
}
222+
else
223+
{
224+
request.NetworkID = this.networkId;
225+
}
226+
180227
this.jobResponse = RecoveryServicesClient.StartAzureSiteRecoveryTestFailover(
181228
this.RpId,
182-
recoveryPlanTestFailoverRequest);
229+
request);
183230

184231
this.WriteJob(this.jobResponse.Job);
185232

@@ -194,18 +241,51 @@ private void StartRpTestFailover()
194241
/// </summary>
195242
private void StartPETestFailover()
196243
{
197-
var tfoReqeust = new TestFailoverRequest();
198-
tfoReqeust.NetworkID = this.networkId;
199-
tfoReqeust.FailoverDirection = this.Direction;
200-
tfoReqeust.NetworkType = this.networkType;
201-
tfoReqeust.ReplicationProvider = string.Empty;
202-
tfoReqeust.ReplicationProviderSettings = string.Empty;
244+
var request = new TestFailoverRequest();
245+
246+
if (this.ProtectionEntity == null)
247+
{
248+
var pe = RecoveryServicesClient.GetAzureSiteRecoveryProtectionEntity(
249+
this.ProtectionContainerId,
250+
this.ProtectionEntityId);
251+
this.ProtectionEntity = new ASRProtectionEntity(pe.ProtectionEntity);
252+
253+
this.ValidateUsageById(this.ProtectionEntity.ReplicationProvider);
254+
}
255+
256+
request.ReplicationProviderSettings = string.Empty;
257+
258+
if (this.ProtectionEntity.ReplicationProvider == Constants.HyperVReplicaAzure)
259+
{
260+
request.ReplicationProvider = this.ProtectionEntity.ReplicationProvider;
261+
if (this.Direction == Constants.PrimaryToRecovery)
262+
{
263+
var blob = new AzureFailoverInput();
264+
blob.VaultLocation = this.GetCurrentValutLocation();
265+
request.ReplicationProviderSettings = DataContractUtils.Serialize<AzureFailoverInput>(blob);
266+
}
267+
}
268+
269+
request.FailoverDirection = this.Direction;
270+
271+
if (this.Network != null)
272+
{
273+
request.NetworkID = this.Network.ID;
274+
this.networkType = "UseVMNetworkTypeForTestFailover";
275+
}
276+
else
277+
{
278+
request.NetworkID = this.networkId;
279+
}
280+
281+
request.FailoverDirection = this.Direction;
282+
request.NetworkType = this.networkType;
203283

204284
this.jobResponse =
205285
RecoveryServicesClient.StartAzureSiteRecoveryTestFailover(
206286
this.ProtectionContainerId,
207287
this.ProtectionEntityId,
208-
tfoReqeust);
288+
request);
209289
this.WriteJob(this.jobResponse.Job);
210290

211291
if (this.WaitForCompletion.IsPresent)

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Service/StartAzureSiteRecoveryUnPlannedFailoverJob.cs

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using System.Management.Automation;
1818
using System.Threading;
1919
using Microsoft.Azure.Commands.RecoveryServices.SiteRecovery;
20+
using Microsoft.Azure.Portal.RecoveryServices.Models.Common;
2021
using Microsoft.WindowsAzure;
2122
using Microsoft.WindowsAzure.Management.SiteRecovery.Models;
2223

@@ -140,14 +141,35 @@ public override void ExecuteCmdlet()
140141
/// </summary>
141142
private void StartPEUnplannedFailover()
142143
{
143-
var ufoReqeust = new UnplannedFailoverRequest();
144-
ufoReqeust.FailoverDirection = this.Direction;
145-
ufoReqeust.SourceSiteOperations = this.PerformSourceSiteOperations;
144+
var request = new UnplannedFailoverRequest();
145+
if (this.ProtectionEntity == null)
146+
{
147+
var pe = RecoveryServicesClient.GetAzureSiteRecoveryProtectionEntity(
148+
this.ProtectionContainerId,
149+
this.ProtectionEntityId);
150+
this.ProtectionEntity = new ASRProtectionEntity(pe.ProtectionEntity);
151+
152+
this.ValidateUsageById(this.ProtectionEntity.ReplicationProvider);
153+
}
154+
155+
if (this.ProtectionEntity.ReplicationProvider == Constants.HyperVReplicaAzure)
156+
{
157+
request.ReplicationProvider = this.ProtectionEntity.ReplicationProvider;
158+
if (this.Direction == Constants.PrimaryToRecovery)
159+
{
160+
var blob = new AzureFailoverInput();
161+
blob.VaultLocation = this.GetCurrentValutLocation();
162+
request.ReplicationProviderSettings = DataContractUtils.Serialize<AzureFailoverInput>(blob);
163+
}
164+
}
165+
166+
request.FailoverDirection = this.Direction;
167+
request.SourceSiteOperations = this.PerformSourceSiteOperations;
146168
this.jobResponse =
147169
RecoveryServicesClient.StartAzureSiteRecoveryUnplannedFailover(
148170
this.ProtectionContainerId,
149171
this.ProtectionEntityId,
150-
ufoReqeust);
172+
request);
151173
this.WriteJob(this.jobResponse.Job);
152174

153175
if (this.WaitForCompletion.IsPresent)
@@ -161,12 +183,34 @@ private void StartPEUnplannedFailover()
161183
/// </summary>
162184
private void StartRpUnPlannedFailover()
163185
{
164-
RpUnplannedFailoverRequest recoveryPlanUnPlannedFailoverRequest = new RpUnplannedFailoverRequest();
165-
recoveryPlanUnPlannedFailoverRequest.FailoverDirection = this.Direction;
166-
recoveryPlanUnPlannedFailoverRequest.PrimaryAction = this.PrimaryAction;
186+
RpUnplannedFailoverRequest request = new RpUnplannedFailoverRequest();
187+
188+
if (this.RecoveryPlan == null)
189+
{
190+
var rp = RecoveryServicesClient.GetAzureSiteRecoveryRecoveryPlan(
191+
this.RPId);
192+
this.RecoveryPlan = new ASRRecoveryPlan(rp.RecoveryPlan);
193+
194+
this.ValidateUsageById(this.RecoveryPlan.ReplicationProvider);
195+
}
196+
197+
if (this.RecoveryPlan.ReplicationProvider == Constants.HyperVReplicaAzure)
198+
{
199+
request.ReplicationProvider = this.RecoveryPlan.ReplicationProvider;
200+
if (this.Direction == Constants.PrimaryToRecovery)
201+
{
202+
var blob = new AzureFailoverInput();
203+
blob.VaultLocation = this.GetCurrentValutLocation();
204+
request.ReplicationProviderSettings = DataContractUtils.Serialize<AzureFailoverInput>(blob);
205+
}
206+
}
207+
208+
request.FailoverDirection = this.Direction;
209+
request.PrimaryAction = this.PrimaryAction;
210+
167211
this.jobResponse = RecoveryServicesClient.StartAzureSiteRecoveryUnplannedFailover(
168212
this.RPId,
169-
recoveryPlanUnPlannedFailoverRequest);
213+
request);
170214

171215
this.WriteJob(this.jobResponse.Job);
172216

0 commit comments

Comments
 (0)