Skip to content

Commit dccc0e3

Browse files
committed
Merge pull request #38 from AsrOneSdk/sanjkuma-dev
Network object should be supported for VM/RP TFO
2 parents 1b27986 + 372a1d0 commit dccc0e3

File tree

6 files changed

+164
-34
lines changed

6 files changed

+164
-34
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,16 @@ public PSRecoveryServicesClient()
9191
/// <param name="azureSubscription">Azure Subscription</param>
9292
public PSRecoveryServicesClient(AzureSubscription azureSubscription)
9393
{
94+
if (ServicePointManager.ServerCertificateValidationCallback == null)
95+
{
96+
ServicePointManager.ServerCertificateValidationCallback =
97+
delegate { return true; };
98+
}
99+
94100
this.recoveryServicesClient =
95101
AzureSession.ClientFactory.CreateClient<RecoveryServicesManagementClient>(azureSubscription, AzureEnvironment.Endpoint.ServiceManagement);
96102
}
97103

98-
99104
/// <summary>
100105
/// Retrieves Azure Cloud services.
101106
/// </summary>

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/RecoveryServicesCmdletBase.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ protected void ValidateUsageById(string replicationProvider)
174174
{
175175
throw new Exception("Call using ID parameter is not supported.");
176176
}
177+
else
178+
{
179+
this.WriteWarning("Call using 'ID' parameter will not be supported from next release. Please use full object parameter instead.");
180+
}
177181
}
178182

179183
/// <summary>

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,15 @@ public class StartAzureSiteRecoveryPlannedFailoverJob : RecoveryServicesCmdletBa
5858
/// Gets or sets Recovery Plan object.
5959
/// </summary>
6060
[Parameter(ParameterSetName = ASRParameterSets.ByRPObject, Mandatory = true, ValueFromPipeline = true)]
61+
[Parameter(ParameterSetName = ASRParameterSets.ByRPObjectE2AFailback, Mandatory = true, ValueFromPipeline = true)]
6162
[ValidateNotNullOrEmpty]
6263
public ASRRecoveryPlan RecoveryPlan { get; set; }
6364

6465
/// <summary>
6566
/// Gets or sets Protection Entity object.
6667
/// </summary>
6768
[Parameter(ParameterSetName = ASRParameterSets.ByPEObject, Mandatory = true, ValueFromPipeline = true)]
69+
[Parameter(ParameterSetName = ASRParameterSets.ByPEObjectE2AFailback, Mandatory = true, ValueFromPipeline = true)]
6870
[ValidateNotNullOrEmpty]
6971
public ASRProtectionEntity ProtectionEntity { get; set; }
7072

@@ -86,6 +88,8 @@ public class StartAzureSiteRecoveryPlannedFailoverJob : RecoveryServicesCmdletBa
8688
/// <summary>
8789
/// Gets or sets the Optimize value.
8890
/// </summary>
91+
[Parameter(ParameterSetName = ASRParameterSets.ByPEObjectE2AFailback)]
92+
[Parameter(ParameterSetName = ASRParameterSets.ByPEObjectE2AFailback)]
8993
[ValidateSet(
9094
Constants.ForDowntime,
9195
Constants.ForSynchronization)]
@@ -160,8 +164,8 @@ private void StartPEPlannedFailover()
160164
else
161165
{
162166
var blob = new AzureFailbackInput();
163-
blob.CreateRecoveryVmIfDoesntExist = false;
164-
blob.SkipDataSync = true;
167+
blob.CreateRecoveryVmIfDoesntExist = true;
168+
blob.SkipDataSync = this.Optimize == Constants.ForDowntime ? true : false;
165169
request.ReplicationProviderSettings = DataContractUtils.Serialize<AzureFailbackInput>(blob);
166170
}
167171
}

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

Lines changed: 93 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace Microsoft.Azure.Commands.RecoveryServices
2323
/// <summary>
2424
/// Used to initiate a commit operation.
2525
/// </summary>
26-
[Cmdlet(VerbsLifecycle.Start, "AzureSiteRecoveryTestFailoverJob", DefaultParameterSetName = ASRParameterSets.ByRPObject)]
26+
[Cmdlet(VerbsLifecycle.Start, "AzureSiteRecoveryTestFailoverJob", DefaultParameterSetName = ASRParameterSets.ByPEId)]
2727
[OutputType(typeof(ASRJob))]
2828
public class StartAzureSiteRecoveryTestFailoverJob : RecoveryServicesCmdletBase
2929
{
@@ -47,28 +47,46 @@ public class StartAzureSiteRecoveryTestFailoverJob : RecoveryServicesCmdletBase
4747
/// Gets or sets ID of the Recovery Plan.
4848
/// </summary>
4949
[Parameter(ParameterSetName = ASRParameterSets.ByRPId, Mandatory = true)]
50+
[Parameter(ParameterSetName = ASRParameterSets.ByRPIdWithLogicalNetworkID, Mandatory = true)]
51+
[Parameter(ParameterSetName = ASRParameterSets.ByRPIdWithVMNetworkID, Mandatory = true)]
52+
[Parameter(ParameterSetName = ASRParameterSets.ByRPIdWithVMNetwork, Mandatory = true)]
5053
[ValidateNotNullOrEmpty]
5154
public string RpId { get; set; }
5255

5356
/// <summary>
54-
/// Gets or sets ID of the Recovery Plan.
57+
/// Gets or sets Network.
5558
/// </summary>
59+
[Parameter]
60+
[Parameter(ParameterSetName = ASRParameterSets.ByPEObjectWithVMNetwork, Mandatory = true)]
61+
[Parameter(ParameterSetName = ASRParameterSets.ByRPObjectWithVMNetwork, Mandatory = true)]
62+
[Parameter(ParameterSetName = ASRParameterSets.ByRPIdWithVMNetwork, Mandatory = true)]
63+
[Parameter(ParameterSetName = ASRParameterSets.ByPEIdWithVMNetwork, Mandatory = true)]
5664
public ASRNetwork Network { get; set; }
5765

66+
/// <summary>
67+
/// Gets or sets NetworkType.
68+
/// </summary>
69+
[Parameter(Mandatory = false)]
70+
[ValidateSet(
71+
Constants.None,
72+
Constants.New,
73+
Constants.Existing)]
74+
public string NetworkType { get; set; }
75+
5876
/// <summary>
5977
/// Gets or sets Recovery Plan object.
6078
/// </summary>
6179
[Parameter(ParameterSetName = ASRParameterSets.ByRPObject, Mandatory = true, ValueFromPipeline = true)]
80+
[Parameter(ParameterSetName = ASRParameterSets.ByRPObjectWithLogicalNetworkID, Mandatory = true)]
81+
[Parameter(ParameterSetName = ASRParameterSets.ByRPObjectWithVMNetworkID, Mandatory = true)]
82+
[Parameter(ParameterSetName = ASRParameterSets.ByRPObjectWithVMNetwork, Mandatory = true)]
6283
[ValidateNotNullOrEmpty]
6384
public ASRRecoveryPlan RecoveryPlan { get; set; }
6485

6586
/// <summary>
6687
/// Gets or sets failover direction for the recovery plan.
6788
/// </summary>
68-
[Parameter(ParameterSetName = ASRParameterSets.ByRPObject, Mandatory = true)]
69-
[Parameter(ParameterSetName = ASRParameterSets.ByRPId, Mandatory = true)]
70-
[Parameter(ParameterSetName = ASRParameterSets.ByPEObject, Mandatory = true)]
71-
[Parameter(ParameterSetName = ASRParameterSets.ByPEId, Mandatory = true)]
89+
[Parameter(Mandatory = true)]
7290
[ValidateSet(
7391
Constants.PrimaryToRecovery,
7492
Constants.RecoveryToPrimary)]
@@ -80,6 +98,7 @@ public class StartAzureSiteRecoveryTestFailoverJob : RecoveryServicesCmdletBase
8098
[Parameter(ParameterSetName = ASRParameterSets.ByPEId, Mandatory = true)]
8199
[Parameter(ParameterSetName = ASRParameterSets.ByPEIdWithLogicalNetworkID, Mandatory = true)]
82100
[Parameter(ParameterSetName = ASRParameterSets.ByPEIdWithVMNetworkID, Mandatory = true)]
101+
[Parameter(ParameterSetName = ASRParameterSets.ByPEIdWithVMNetwork, Mandatory = true)]
83102
[ValidateNotNullOrEmpty]
84103
public string ProtectionEntityId { get; set; }
85104

@@ -89,6 +108,7 @@ public class StartAzureSiteRecoveryTestFailoverJob : RecoveryServicesCmdletBase
89108
[Parameter(ParameterSetName = ASRParameterSets.ByPEId, Mandatory = true)]
90109
[Parameter(ParameterSetName = ASRParameterSets.ByPEIdWithLogicalNetworkID, Mandatory = true)]
91110
[Parameter(ParameterSetName = ASRParameterSets.ByPEIdWithVMNetworkID, Mandatory = true)]
111+
[Parameter(ParameterSetName = ASRParameterSets.ByPEIdWithVMNetwork, Mandatory = true)]
92112
[ValidateNotNullOrEmpty]
93113
public string ProtectionContainerId { get; set; }
94114

@@ -98,6 +118,7 @@ public class StartAzureSiteRecoveryTestFailoverJob : RecoveryServicesCmdletBase
98118
[Parameter(ParameterSetName = ASRParameterSets.ByPEObject, Mandatory = true, ValueFromPipeline = true)]
99119
[Parameter(ParameterSetName = ASRParameterSets.ByPEObjectWithLogicalNetworkID, Mandatory = true)]
100120
[Parameter(ParameterSetName = ASRParameterSets.ByPEObjectWithVMNetworkID, Mandatory = true)]
121+
[Parameter(ParameterSetName = ASRParameterSets.ByPEObjectWithVMNetwork, Mandatory = true)]
101122
[ValidateNotNullOrEmpty]
102123
public ASRProtectionEntity ProtectionEntity { get; set; }
103124

@@ -112,13 +133,17 @@ public class StartAzureSiteRecoveryTestFailoverJob : RecoveryServicesCmdletBase
112133
/// </summary>
113134
[Parameter(ParameterSetName = ASRParameterSets.ByPEObjectWithLogicalNetworkID, Mandatory = true)]
114135
[Parameter(ParameterSetName = ASRParameterSets.ByPEIdWithLogicalNetworkID, Mandatory = true)]
136+
[Parameter(ParameterSetName = ASRParameterSets.ByRPObjectWithLogicalNetworkID, Mandatory = true)]
137+
[Parameter(ParameterSetName = ASRParameterSets.ByRPIdWithLogicalNetworkID, Mandatory = true)]
115138
public string LogicalNetworkId { get; set; }
116139

117140
/// <summary>
118141
/// Gets or sets VM network ID.
119142
/// </summary>
120143
[Parameter(ParameterSetName = ASRParameterSets.ByPEObjectWithVMNetworkID, Mandatory = true)]
121144
[Parameter(ParameterSetName = ASRParameterSets.ByPEIdWithVMNetworkID, Mandatory = true)]
145+
[Parameter(ParameterSetName = ASRParameterSets.ByRPObjectWithVMNetworkID, Mandatory = true)]
146+
[Parameter(ParameterSetName = ASRParameterSets.ByRPIdWithVMNetworkID, Mandatory = true)]
122147
public string VmNetworkId { get; set; }
123148
#endregion Parameters
124149

@@ -129,13 +154,60 @@ public override void ExecuteCmdlet()
129154
{
130155
try
131156
{
157+
if (this.NetworkType == null)
158+
{
159+
this.WriteWarning("'NetworkType' will be a mandatory paramter from next release.");
160+
}
161+
162+
if (this.VmNetworkId != null)
163+
{
164+
this.WriteWarning("Call using 'NetworkId' parameter will not be supported from next release. Please use 'Network' parameter instead.");
165+
}
166+
167+
if (this.NetworkType == Constants.Existing && (this.Network == null && this.VmNetworkId == null))
168+
{
169+
throw new Exception("Existing Network details were not supplied.");
170+
}
171+
132172
switch (this.ParameterSetName)
133173
{
134174
case ASRParameterSets.ByRPObject:
135175
this.RpId = this.RecoveryPlan.ID;
176+
this.networkType = "DisconnectedVMNetworkTypeForTestFailover";
136177
this.StartRpTestFailover();
137178
break;
138179
case ASRParameterSets.ByRPId:
180+
this.networkType = "DisconnectedVMNetworkTypeForTestFailover";
181+
this.StartRpTestFailover();
182+
break;
183+
case ASRParameterSets.ByRPObjectWithVMNetwork:
184+
this.networkType = "UseVMNetworkTypeForTestFailover";
185+
this.networkId = this.Network.ID;
186+
this.StartRpTestFailover();
187+
break;
188+
case ASRParameterSets.ByRPObjectWithVMNetworkID:
189+
this.networkType = "UseVMNetworkTypeForTestFailover";
190+
this.networkId = this.VmNetworkId;
191+
this.StartRpTestFailover();
192+
break;
193+
case ASRParameterSets.ByRPIdWithVMNetwork:
194+
this.networkType = "UseVMNetworkTypeForTestFailover";
195+
this.networkId = this.Network.ID;
196+
this.StartRpTestFailover();
197+
break;
198+
case ASRParameterSets.ByRPIdWithVMNetworkID:
199+
this.networkType = "UseVMNetworkTypeForTestFailover";
200+
this.networkId = this.VmNetworkId;
201+
this.StartRpTestFailover();
202+
break;
203+
case ASRParameterSets.ByRPIdWithLogicalNetworkID:
204+
this.networkType = "CreateVMNetworkTypeForTestFailover";
205+
this.networkId = this.LogicalNetworkId;
206+
this.StartRpTestFailover();
207+
break;
208+
case ASRParameterSets.ByRPObjectWithLogicalNetworkID:
209+
this.networkType = "CreateVMNetworkTypeForTestFailover";
210+
this.networkId = this.LogicalNetworkId;
139211
this.StartRpTestFailover();
140212
break;
141213
case ASRParameterSets.ByPEObject:
@@ -152,7 +224,13 @@ public override void ExecuteCmdlet()
152224
this.networkId = this.VmNetworkId;
153225
this.UpdateRequiredParametersAndStartFailover();
154226
break;
227+
case ASRParameterSets.ByPEObjectWithVMNetwork:
228+
this.networkType = "UseVMNetworkTypeForTestFailover";
229+
this.networkId = this.Network.ID;
230+
this.UpdateRequiredParametersAndStartFailover();
231+
break;
155232
case ASRParameterSets.ByPEId:
233+
this.networkType = "DisconnectedVMNetworkTypeForTestFailover";
156234
this.StartPETestFailover();
157235
break;
158236
case ASRParameterSets.ByPEIdWithLogicalNetworkID:
@@ -165,6 +243,11 @@ public override void ExecuteCmdlet()
165243
this.networkId = this.VmNetworkId;
166244
this.StartPETestFailover();
167245
break;
246+
case ASRParameterSets.ByPEIdWithVMNetwork:
247+
this.networkType = "UseVMNetworkTypeForTestFailover";
248+
this.networkId = this.Network.ID;
249+
this.StartPETestFailover();
250+
break;
168251
}
169252
}
170253
catch (Exception exception)
@@ -180,20 +263,6 @@ private void StartRpTestFailover()
180263
{
181264
RpTestFailoverRequest request = new RpTestFailoverRequest();
182265

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-
if (string.IsNullOrEmpty(this.networkType))
192-
{
193-
request.NetworkType = "DisconnectedVMNetworkTypeForTestFailover";
194-
}
195-
}
196-
197266
if (this.RecoveryPlan == null)
198267
{
199268
var rp = RecoveryServicesClient.GetAzureSiteRecoveryRecoveryPlan(
@@ -215,6 +284,9 @@ private void StartRpTestFailover()
215284
}
216285
}
217286

287+
request.NetworkID = this.networkId;
288+
request.NetworkType = this.networkType;
289+
218290
request.ReplicationProvider = this.RecoveryPlan.ReplicationProvider;
219291
request.FailoverDirection = this.Direction;
220292

@@ -262,17 +334,7 @@ private void StartPETestFailover()
262334
request.ReplicationProvider = this.ProtectionEntity.ReplicationProvider;
263335
request.FailoverDirection = this.Direction;
264336

265-
if (this.Network != null)
266-
{
267-
request.NetworkID = this.Network.ID;
268-
this.networkType = "UseVMNetworkTypeForTestFailover";
269-
}
270-
else
271-
{
272-
request.NetworkID = this.networkId;
273-
}
274-
275-
request.FailoverDirection = this.Direction;
337+
request.NetworkID = this.networkId;
276338
request.NetworkType = this.networkType;
277339

278340
this.jobResponse =

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/lib/PSObjects.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,21 @@ public class Constants
9898
/// </summary>
9999
public const string ResourceNamespace = "WAHyperVRecoveryManager";
100100

101+
/// <summary>
102+
/// Represents None string value.
103+
/// </summary>
104+
public const string None = "None";
105+
106+
/// <summary>
107+
/// Represents Existing string value.
108+
/// </summary>
109+
public const string Existing = "Existing";
110+
111+
/// <summary>
112+
/// Represents New string value.
113+
/// </summary>
114+
public const string New = "New";
115+
101116
/// <summary>
102117
/// Represents direction primary to secondary.
103118
/// </summary>

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/lib/PSParameterSets.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,36 @@ internal static class ASRParameterSets
6464
/// </summary>
6565
internal const string ByPEObjectWithLogicalNetworkID = "ByPEObjectWithLogicalNetworkID";
6666

67+
/// <summary>
68+
/// When only RP Object is passed along with VM network ID to the command.
69+
/// </summary>
70+
internal const string ByRPObjectWithVMNetworkID = "ByRPObjectWithVMNetworkID";
71+
72+
/// <summary>
73+
/// When only RP Id is passed along with VM network ID to the command.
74+
/// </summary>
75+
internal const string ByRPIdWithVMNetworkID = "ByRPIdWithVMNetworkID";
76+
77+
/// <summary>
78+
/// When only RP Object is passed along with VM network to the command.
79+
/// </summary>
80+
internal const string ByRPObjectWithVMNetwork = "ByRPObjectWithVMNetwork";
81+
82+
/// <summary>
83+
/// When only RP Id is passed along with VM network to the command.
84+
/// </summary>
85+
internal const string ByRPIdWithVMNetwork = "ByRPIdWithVMNetwork";
86+
6787
/// <summary>
6888
/// When only PE Object is passed along with VM network ID to the command.
6989
/// </summary>
7090
internal const string ByPEObjectWithVMNetworkID = "ByPEObjectWithVMNetworkID";
7191

92+
/// <summary>
93+
/// When only PE Object is passed along with VM network to the command.
94+
/// </summary>
95+
internal const string ByPEObjectWithVMNetwork = "ByPEObjectWithVMNetwork";
96+
7297
/// <summary>
7398
/// When only PC and PE ids are passed to the command.
7499
/// </summary>
@@ -79,11 +104,26 @@ internal static class ASRParameterSets
79104
/// </summary>
80105
internal const string ByPEIdWithLogicalNetworkID = "ByPEIdWithLogicalNetworkID";
81106

107+
/// <summary>
108+
/// When only RP object is passed along with logical network ID to the command.
109+
/// </summary>
110+
internal const string ByRPObjectWithLogicalNetworkID = "ByRPObjectWithLogicalNetworkID";
111+
112+
/// <summary>
113+
/// When only RP Id is passed along with logical network ID to the command.
114+
/// </summary>
115+
internal const string ByRPIdWithLogicalNetworkID = "ByRPIdWithLogicalNetworkID";
116+
82117
/// <summary>
83118
/// When only PC and PE ids are passed along with VM network ID to the command.
84119
/// </summary>
85120
internal const string ByPEIdWithVMNetworkID = "ByPEIdWithVMNetworkID";
86121

122+
/// <summary>
123+
/// When only PC and PE ids are passed along with VM network to the command.
124+
/// </summary>
125+
internal const string ByPEIdWithVMNetwork = "ByPEIdWithVMNetwork";
126+
87127
/// <summary>
88128
/// When only ID is passed to the command.
89129
/// </summary>

0 commit comments

Comments
 (0)