@@ -62,6 +62,8 @@ public class SetAzureSiteRecoveryProtectionEntity : RecoveryServicesCmdletBase
62
62
/// </summary>
63
63
[ Parameter ( ParameterSetName = ASRParameterSets . ByPEObject , Mandatory = true , ValueFromPipeline = true ) ]
64
64
[ Parameter ( ParameterSetName = ASRParameterSets . ByPEObjectE2AEnable , Mandatory = true , ValueFromPipeline = true ) ]
65
+ [ Parameter ( ParameterSetName = ASRParameterSets . EnableReplicationGroup , Mandatory = true ) ]
66
+ [ Parameter ( ParameterSetName = ASRParameterSets . DisableReplicationGroup , Mandatory = true ) ]
65
67
[ ValidateNotNullOrEmpty ]
66
68
public ASRProtectionEntity ProtectionEntity { get ; set ; }
67
69
@@ -110,6 +112,44 @@ public class SetAzureSiteRecoveryProtectionEntity : RecoveryServicesCmdletBase
110
112
/// </summary>
111
113
[ Parameter ( Mandatory = false ) ]
112
114
public SwitchParameter Force { get ; set ; }
115
+
116
+ /// <summary>
117
+ /// Gets or sets RPO in seconds.
118
+ /// </summary>
119
+ [ Parameter ( ParameterSetName = ASRParameterSets . EnableReplicationGroup , Mandatory = true ) ]
120
+ [ ValidateNotNullOrEmpty ]
121
+ public int RPO { get ; set ; }
122
+
123
+ /// <summary>
124
+ /// Gets or sets Replication type (sync/async).
125
+ /// </summary>
126
+ [ Parameter ( ParameterSetName = ASRParameterSets . EnableReplicationGroup , Mandatory = true ) ]
127
+ [ ValidateNotNullOrEmpty ]
128
+ [ ValidateSet (
129
+ Constants . Sync ,
130
+ Constants . Async ) ]
131
+ public string Replicationtype { get ; set ; }
132
+
133
+ /// <summary>
134
+ /// Gets or sets Recovery array id.
135
+ /// </summary>
136
+ [ Parameter ( ParameterSetName = ASRParameterSets . EnableReplicationGroup , Mandatory = true ) ]
137
+ [ ValidateNotNullOrEmpty ]
138
+ public string RecoveryArrayId { get ; set ; }
139
+
140
+ /// <summary>
141
+ /// Gets or sets switch parameter. On passing true, replica LUNs will get deleted.
142
+ /// </summary>
143
+ [ Parameter ( ParameterSetName = ASRParameterSets . DisableReplicationGroup , Mandatory = false ) ]
144
+ [ ValidateNotNullOrEmpty ]
145
+ public SwitchParameter DeleteReplicaLuns { get ; set ; }
146
+
147
+ /// <summary>
148
+ /// Gets or sets Recovery container id for SAN to delete replica LUNs.
149
+ /// </summary>
150
+ [ Parameter ( ParameterSetName = ASRParameterSets . DisableReplicationGroup , Mandatory = false ) ]
151
+ [ ValidateNotNullOrEmpty ]
152
+ public string RecoveryContainerId { get ; set ; }
113
153
#endregion Parameters
114
154
115
155
/// <summary>
@@ -119,6 +159,8 @@ public override void ExecuteCmdlet()
119
159
{
120
160
switch ( this . ParameterSetName )
121
161
{
162
+ case ASRParameterSets . EnableReplicationGroup :
163
+ case ASRParameterSets . DisableReplicationGroup :
122
164
case ASRParameterSets . ByPEObject :
123
165
case ASRParameterSets . ByPEObjectE2AEnable :
124
166
this . Id = this . ProtectionEntity . ID ;
@@ -163,56 +205,69 @@ public override void ExecuteCmdlet()
163
205
{
164
206
try
165
207
{
166
- if ( this . Protection == Constants . EnableProtection )
208
+ string profileId = string . Empty ;
209
+ string replicationProvider = null ;
210
+
211
+ if ( this . ProtectionEntity == null )
167
212
{
168
- string profileId = string . Empty ;
169
- var input = new EnableProtectionInput ( ) ;
213
+ var pe = RecoveryServicesClient . GetAzureSiteRecoveryProtectionEntity (
214
+ this . ProtectionContainerId ,
215
+ this . Id ) ;
216
+ this . ProtectionEntity = new ASRProtectionEntity ( pe . ProtectionEntity ) ;
217
+ }
170
218
171
- if ( this . ProtectionEntity == null )
219
+ // Get the replciation provider from profile object otherwise assume its E2E.
220
+ // Let the call go without profileId set.
221
+ if ( this . ProtectionProfile != null )
222
+ {
223
+ profileId = this . ProtectionProfile . ID ;
224
+ replicationProvider = this . ProtectionProfile . ReplicationProvider ;
225
+ }
226
+ else
227
+ {
228
+ this . WriteWarningWithTimestamp (
229
+ string . Format (
230
+ Properties . Resources . MandatoryParamFromNextRelease ,
231
+ "ProtectionProfile" ) ) ;
232
+ string pcId = this . ProtectionContainerId ?? this . ProtectionEntity . ProtectionContainerId ;
233
+ var pc = RecoveryServicesClient . GetAzureSiteRecoveryProtectionContainer (
234
+ pcId ) ;
235
+
236
+ // PC will have all profiles associated with same replciation providers only.
237
+ replicationProvider =
238
+ pc . ProtectionContainer . AvailableProtectionProfiles . Count < 1 ?
239
+ null :
240
+ pc . ProtectionContainer . AvailableProtectionProfiles [ 0 ] . ReplicationProvider ;
241
+
242
+ if ( replicationProvider != Constants . HyperVReplica && replicationProvider != Constants . San )
172
243
{
173
- var pe = RecoveryServicesClient . GetAzureSiteRecoveryProtectionEntity (
174
- this . ProtectionContainerId ,
175
- this . Id ) ;
176
- this . ProtectionEntity = new ASRProtectionEntity ( pe . ProtectionEntity ) ;
244
+ throw new Exception ( "Please provide the protection profile object. It can be chosen from available protection profiles of the protection container." ) ;
177
245
}
246
+ }
178
247
179
- // Get the replciation provider from profile object otherwise assume its E2E.
180
- // Let the call go without profileId set.
181
- string replicationProvider = null ;
248
+ if ( this . ParameterSetName == ASRParameterSets . ByIDs )
249
+ {
250
+ this . ValidateUsageById ( replicationProvider , "Id" ) ;
251
+ }
182
252
183
- if ( this . ProtectionProfile != null )
184
- {
185
- profileId = this . ProtectionProfile . ID ;
186
- replicationProvider = this . ProtectionProfile . ReplicationProvider ;
187
- }
188
- else
189
- {
190
- this . WriteWarningWithTimestamp (
191
- string . Format (
192
- Properties . Resources . MandatoryParamFromNextRelease ,
193
- "ProtectionProfile" ) ) ;
194
- string pcId = this . ProtectionContainerId ?? this . ProtectionEntity . ProtectionContainerId ;
195
- var pc = RecoveryServicesClient . GetAzureSiteRecoveryProtectionContainer (
196
- pcId ) ;
197
-
198
- // PC will have all profiles associated with same replciation providers only.
199
- replicationProvider =
200
- pc . ProtectionContainer . AvailableProtectionProfiles . Count < 1 ?
201
- null :
202
- pc . ProtectionContainer . AvailableProtectionProfiles [ 0 ] . ReplicationProvider ;
203
-
204
- if ( replicationProvider != Constants . HyperVReplica )
205
- {
206
- throw new Exception ( "Please provide the protection profile object. It can be chosen from available protection profiles of the protection container." ) ;
207
- }
208
- }
253
+ if ( this . Protection == Constants . EnableProtection )
254
+ {
255
+ var input = new EnableProtectionInput ( ) ;
209
256
210
- if ( this . ParameterSetName == ASRParameterSets . ByIDs )
257
+ if ( replicationProvider == Constants . San )
211
258
{
212
- this . ValidateUsageById ( replicationProvider , "Id" ) ;
213
- }
259
+ SanEnableProtectionInput sanInput = new SanEnableProtectionInput ( ) ;
260
+ sanInput . FabricId = this . ProtectionEntity . ServerId ;
261
+ sanInput . FabricReplicationGroupId = this . ProtectionEntity . ID ;
214
262
215
- if ( replicationProvider == Constants . HyperVReplicaAzure )
263
+ sanInput . CloudId = this . ProtectionContainerId ;
264
+ sanInput . RemoteArrayId = this . RecoveryArrayId ;
265
+ sanInput . ReplicationType = this . Replicationtype ;
266
+ sanInput . Rpo = this . RPO ;
267
+
268
+ input . ReplicationProviderInput = DataContractUtils . Serialize < SanEnableProtectionInput > ( sanInput ) ;
269
+ }
270
+ else if ( replicationProvider == Constants . HyperVReplicaAzure )
216
271
{
217
272
input . ProtectionProfileId = this . ProtectionProfile . ID ;
218
273
AzureEnableProtectionInput azureInput = new AzureEnableProtectionInput ( ) ;
@@ -261,10 +316,33 @@ public override void ExecuteCmdlet()
261
316
}
262
317
else
263
318
{
264
- this . jobResponse =
265
- RecoveryServicesClient . DisbleProtection (
266
- this . ProtectionContainerId ,
267
- this . Id ) ;
319
+ DisableProtectionInput input = null ;
320
+ string recoveryCloudId = string . Empty ;
321
+ Utilities . GetCloudIdFromContainerId ( this . RecoveryContainerId , out recoveryCloudId ) ;
322
+
323
+ if ( replicationProvider == Constants . San )
324
+ {
325
+ input = new DisableProtectionInput ( ) ;
326
+ SanDisableProtectionInput sanInput = new SanDisableProtectionInput ( ) ;
327
+ sanInput . DeleteReplicaLuns = this . DeleteReplicaLuns ;
328
+ sanInput . TargetCloudIdForLunDeletion = recoveryCloudId ;
329
+
330
+ input . ReplicationProviderInput = DataContractUtils . Serialize < SanDisableProtectionInput > ( sanInput ) ;
331
+
332
+ this . jobResponse =
333
+ RecoveryServicesClient . DisableProtection (
334
+ this . ProtectionContainerId ,
335
+ this . ProtectionEntity . FabricObjectId ,
336
+ input ) ;
337
+ }
338
+ else
339
+ {
340
+ this . jobResponse =
341
+ RecoveryServicesClient . DisableProtection (
342
+ this . ProtectionContainerId ,
343
+ this . Id ,
344
+ input ) ;
345
+ }
268
346
}
269
347
270
348
this . WriteJob ( this . jobResponse . Job ) ;
0 commit comments