Skip to content

Commit 1e574bc

Browse files
committed
cmdlet changes for SAN (cloud pairing, unpairing, enable and disable RG)
1 parent c4a929c commit 1e574bc

11 files changed

+536
-74
lines changed

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/PSRecoveryServicesClient/PSRecoveryServicesPEClient.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,17 @@ public ProtectionEntityResponse GetAzureSiteRecoveryProtectionEntity(
6060
/// Sets protection on Protection entity.
6161
/// </summary>
6262
/// <param name="protectionContainerId">Protection Container ID</param>
63-
/// <param name="virtualMachineId">Virtual Machine ID</param>
63+
/// <param name="protectionEntityId">Virtual Machine ID or Replication group Id</param>
6464
/// <param name="input">Enable protection input.</param>
6565
/// <returns>Job response</returns>
6666
public JobResponse EnableProtection(
6767
string protectionContainerId,
68-
string virtualMachineId,
68+
string protectionEntityId,
6969
EnableProtectionInput input)
7070
{
7171
return this.GetSiteRecoveryClient().ProtectionEntity.EnableProtection(
7272
protectionContainerId,
73-
virtualMachineId,
73+
protectionEntityId,
7474
input,
7575
this.GetRequestHeaders());
7676
}
@@ -79,15 +79,18 @@ public JobResponse EnableProtection(
7979
/// Sets protection on Protection entity.
8080
/// </summary>
8181
/// <param name="protectionContainerId">Protection Container ID</param>
82-
/// <param name="virtualMachineId">Virtual Machine ID</param>
82+
/// <param name="protectionEntityId">Virtual Machine ID or Replication group Id</param>
83+
/// <param name="input">Disable protection input.</param>
8384
/// <returns>Job response</returns>
84-
public JobResponse DisbleProtection(
85+
public JobResponse DisableProtection(
8586
string protectionContainerId,
86-
string virtualMachineId)
87+
string protectionEntityId,
88+
DisableProtectionInput input)
8789
{
8890
return this.GetSiteRecoveryClient().ProtectionEntity.DisableProtection(
8991
protectionContainerId,
90-
virtualMachineId,
92+
protectionEntityId,
93+
input,
9194
this.GetRequestHeaders());
9295
}
9396

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/PSRecoveryServicesClient/PSRecoveryServicesProtectionProfileClient.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@ public JobResponse StartCreateAndAssociateAzureSiteRecoveryProtectionProfileJob(
7979
/// Deletes and Dissociates Azure Site Recovery Protection Profile.
8080
/// </summary>
8181
/// <param name="protectionProfileId">Protection Profile ID</param>
82-
/// <param name="protectionProfileAssociationInput">Protection Profile Association Input</param>
82+
/// <param name="createAndAssociateProtectionProfileInput">Protection Profile Association Input</param>
8383
/// <returns>Job response</returns>
8484
public JobResponse StartDeleteAndDissociateAzureSiteRecoveryProtectionProfileJob(
8585
string protectionProfileId,
86-
ProtectionProfileAssociationInput protectionProfileAssociationInput)
86+
CreateAndAssociateProtectionProfileInput createAndAssociateProtectionProfileInput)
8787
{
8888
return this.GetSiteRecoveryClient().ProtectionProfile.DissociateAndDelete(
8989
protectionProfileId,
90-
protectionProfileAssociationInput,
90+
createAndAssociateProtectionProfileInput,
9191
this.GetRequestHeaders());
9292
}
9393
}

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

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ public class CreateAzureSiteRecoveryProtectionProfileObject : RecoveryServicesCm
3636
/// </summary>
3737
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToEnterprise, Mandatory = true)]
3838
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToAzure, Mandatory = true)]
39+
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToEnterpriseSan, Mandatory = true)]
3940
[ValidateNotNullOrEmpty]
4041
[ValidateSet(
4142
Constants.HyperVReplica,
42-
Constants.HyperVReplicaAzure)]
43+
Constants.HyperVReplicaAzure,
44+
Constants.San)]
4345
public string ReplicationProvider { get; set; }
4446

4547
/// <summary>
@@ -143,6 +145,34 @@ public class CreateAzureSiteRecoveryProtectionProfileObject : RecoveryServicesCm
143145
[DefaultValue(false)]
144146
public SwitchParameter AllowReplicaDeletion { get; set; }
145147

148+
/// <summary>
149+
/// Gets or sets the primary cloud id of the Protection Profile.
150+
/// </summary>
151+
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToEnterpriseSan)]
152+
[ValidateNotNullOrEmpty]
153+
public string PrimaryContainerId { get; set; }
154+
155+
/// <summary>
156+
/// Gets or sets the recovery cloud id of the Protection Profile.
157+
/// </summary>
158+
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToEnterpriseSan)]
159+
[ValidateNotNullOrEmpty]
160+
public string RecoveryContainerId { get; set; }
161+
162+
/// <summary>
163+
/// Gets or sets the primary array id of the Protection Profile.
164+
/// </summary>
165+
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToEnterpriseSan)]
166+
[ValidateNotNullOrEmpty]
167+
public string PrimaryArrayId { get; set; }
168+
169+
/// <summary>
170+
/// Gets or sets the recovery array id of the Protection Profile.
171+
/// </summary>
172+
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToEnterpriseSan)]
173+
[ValidateNotNullOrEmpty]
174+
public string RecoveryArrayId { get; set; }
175+
146176
#endregion Parameters
147177

148178
/// <summary>
@@ -160,6 +190,9 @@ public override void ExecuteCmdlet()
160190
case ASRParameterSets.EnterpriseToAzure:
161191
this.EnterpriseToAzureProtectionProfileObject();
162192
break;
193+
case ASRParameterSets.EnterpriseToEnterpriseSan:
194+
this.EnterpriseToEnterpriseSanProtectionProfileObject();
195+
break;
163196
}
164197
}
165198
catch (Exception exception)
@@ -257,5 +290,42 @@ private void EnterpriseToEnterpriseProtectionProfileObject()
257290

258291
this.WriteObject(protectionProfile);
259292
}
293+
294+
/// <summary>
295+
/// Creates an E2E San Protection Profile object
296+
/// </summary>
297+
private void EnterpriseToEnterpriseSanProtectionProfileObject()
298+
{
299+
if (string.Compare(this.ReplicationProvider, Constants.San, StringComparison.OrdinalIgnoreCase) != 0)
300+
{
301+
throw new InvalidOperationException(
302+
string.Format(
303+
Properties.Resources.IncorrectReplicationProvider,
304+
this.ReplicationProvider));
305+
}
306+
307+
string primaryCloudId = string.Empty;
308+
string recoveryCloudId = string.Empty;
309+
310+
Utilities.GetCloudIdFromContainerId(this.PrimaryContainerId, out primaryCloudId);
311+
Utilities.GetCloudIdFromContainerId(this.RecoveryContainerId, out recoveryCloudId);
312+
313+
ASRProtectionProfile protectionProfile = new ASRProtectionProfile()
314+
{
315+
ID = this.PrimaryContainerId,
316+
ReplicationProvider = this.ReplicationProvider,
317+
HyperVReplicaAzureProviderSettingsObject = null,
318+
HyperVReplicaProviderSettingsObject = null,
319+
SanProviderSettingsObject = new SanProviderSettings()
320+
{
321+
CloudId = primaryCloudId,
322+
RemoteCloudId = recoveryCloudId,
323+
ArrayUniqueId = this.PrimaryArrayId,
324+
RemoteArrayUniqueId = this.RecoveryArrayId
325+
}
326+
};
327+
328+
this.WriteObject(protectionProfile);
329+
}
260330
}
261331
}

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

Lines changed: 123 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ public class SetAzureSiteRecoveryProtectionEntity : RecoveryServicesCmdletBase
6262
/// </summary>
6363
[Parameter(ParameterSetName = ASRParameterSets.ByPEObject, Mandatory = true, ValueFromPipeline = true)]
6464
[Parameter(ParameterSetName = ASRParameterSets.ByPEObjectE2AEnable, Mandatory = true, ValueFromPipeline = true)]
65+
[Parameter(ParameterSetName = ASRParameterSets.EnableReplicationGroup, Mandatory = true)]
66+
[Parameter(ParameterSetName = ASRParameterSets.DisableReplicationGroup, Mandatory = true)]
6567
[ValidateNotNullOrEmpty]
6668
public ASRProtectionEntity ProtectionEntity { get; set; }
6769

@@ -110,6 +112,44 @@ public class SetAzureSiteRecoveryProtectionEntity : RecoveryServicesCmdletBase
110112
/// </summary>
111113
[Parameter(Mandatory = false)]
112114
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; }
113153
#endregion Parameters
114154

115155
/// <summary>
@@ -119,6 +159,8 @@ public override void ExecuteCmdlet()
119159
{
120160
switch (this.ParameterSetName)
121161
{
162+
case ASRParameterSets.EnableReplicationGroup:
163+
case ASRParameterSets.DisableReplicationGroup:
122164
case ASRParameterSets.ByPEObject:
123165
case ASRParameterSets.ByPEObjectE2AEnable:
124166
this.Id = this.ProtectionEntity.ID;
@@ -163,56 +205,69 @@ public override void ExecuteCmdlet()
163205
{
164206
try
165207
{
166-
if (this.Protection == Constants.EnableProtection)
208+
string profileId = string.Empty;
209+
string replicationProvider = null;
210+
211+
if (this.ProtectionEntity == null)
167212
{
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+
}
170218

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)
172243
{
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.");
177245
}
246+
}
178247

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+
}
182252

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();
209256

210-
if (this.ParameterSetName == ASRParameterSets.ByIDs)
257+
if (replicationProvider == Constants.San)
211258
{
212-
this.ValidateUsageById(replicationProvider, "Id");
213-
}
259+
SanEnableProtectionInput sanInput = new SanEnableProtectionInput();
260+
sanInput.FabricId = this.ProtectionEntity.ServerId;
261+
sanInput.FabricReplicationGroupId = this.ProtectionEntity.ID;
214262

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)
216271
{
217272
input.ProtectionProfileId = this.ProtectionProfile.ID;
218273
AzureEnableProtectionInput azureInput = new AzureEnableProtectionInput();
@@ -261,10 +316,33 @@ public override void ExecuteCmdlet()
261316
}
262317
else
263318
{
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+
}
268346
}
269347

270348
this.WriteJob(this.jobResponse.Job);

0 commit comments

Comments
 (0)