13
13
// ----------------------------------------------------------------------------------
14
14
15
15
using System ;
16
- using System . Diagnostics ;
17
16
using System . Management . Automation ;
18
- using System . Threading ;
19
17
using Microsoft . Azure . Commands . RecoveryServices . SiteRecovery ;
20
- using Microsoft . WindowsAzure ;
18
+ using Microsoft . Azure . Portal . RecoveryServices . Models . Common ;
21
19
using Microsoft . WindowsAzure . Management . SiteRecovery . Models ;
22
20
23
21
namespace Microsoft . Azure . Commands . RecoveryServices
@@ -52,6 +50,11 @@ public class StartAzureSiteRecoveryTestFailoverJob : RecoveryServicesCmdletBase
52
50
[ ValidateNotNullOrEmpty ]
53
51
public string RpId { get ; set ; }
54
52
53
+ /// <summary>
54
+ /// Gets or sets ID of the Recovery Plan.
55
+ /// </summary>
56
+ public ASRNetwork Network { get ; set ; }
57
+
55
58
/// <summary>
56
59
/// Gets or sets Recovery Plan object.
57
60
/// </summary>
@@ -175,11 +178,55 @@ public override void ExecuteCmdlet()
175
178
/// </summary>
176
179
private void StartRpTestFailover ( )
177
180
{
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
+
180
227
this . jobResponse = RecoveryServicesClient . StartAzureSiteRecoveryTestFailover (
181
228
this . RpId ,
182
- recoveryPlanTestFailoverRequest ) ;
229
+ request ) ;
183
230
184
231
this . WriteJob ( this . jobResponse . Job ) ;
185
232
@@ -194,18 +241,51 @@ private void StartRpTestFailover()
194
241
/// </summary>
195
242
private void StartPETestFailover ( )
196
243
{
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 ;
203
283
204
284
this . jobResponse =
205
285
RecoveryServicesClient . StartAzureSiteRecoveryTestFailover (
206
286
this . ProtectionContainerId ,
207
287
this . ProtectionEntityId ,
208
- tfoReqeust ) ;
288
+ request ) ;
209
289
this . WriteJob ( this . jobResponse . Job ) ;
210
290
211
291
if ( this . WaitForCompletion . IsPresent )
0 commit comments