Skip to content

Commit

Permalink
Merge pull request #38 from AsrOneSdk/sanjkuma-dev
Browse files Browse the repository at this point in the history
Network object should be supported for VM/RP TFO
  • Loading branch information
sanjkuma committed Feb 5, 2015
2 parents 1b27986 + 372a1d0 commit dccc0e3
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,16 @@ public PSRecoveryServicesClient()
/// <param name="azureSubscription">Azure Subscription</param>
public PSRecoveryServicesClient(AzureSubscription azureSubscription)
{
if (ServicePointManager.ServerCertificateValidationCallback == null)
{
ServicePointManager.ServerCertificateValidationCallback =
delegate { return true; };
}

this.recoveryServicesClient =
AzureSession.ClientFactory.CreateClient<RecoveryServicesManagementClient>(azureSubscription, AzureEnvironment.Endpoint.ServiceManagement);
}


/// <summary>
/// Retrieves Azure Cloud services.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ protected void ValidateUsageById(string replicationProvider)
{
throw new Exception("Call using ID parameter is not supported.");
}
else
{
this.WriteWarning("Call using 'ID' parameter will not be supported from next release. Please use full object parameter instead.");
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ public class StartAzureSiteRecoveryPlannedFailoverJob : RecoveryServicesCmdletBa
/// Gets or sets Recovery Plan object.
/// </summary>
[Parameter(ParameterSetName = ASRParameterSets.ByRPObject, Mandatory = true, ValueFromPipeline = true)]
[Parameter(ParameterSetName = ASRParameterSets.ByRPObjectE2AFailback, Mandatory = true, ValueFromPipeline = true)]
[ValidateNotNullOrEmpty]
public ASRRecoveryPlan RecoveryPlan { get; set; }

/// <summary>
/// Gets or sets Protection Entity object.
/// </summary>
[Parameter(ParameterSetName = ASRParameterSets.ByPEObject, Mandatory = true, ValueFromPipeline = true)]
[Parameter(ParameterSetName = ASRParameterSets.ByPEObjectE2AFailback, Mandatory = true, ValueFromPipeline = true)]
[ValidateNotNullOrEmpty]
public ASRProtectionEntity ProtectionEntity { get; set; }

Expand All @@ -86,6 +88,8 @@ public class StartAzureSiteRecoveryPlannedFailoverJob : RecoveryServicesCmdletBa
/// <summary>
/// Gets or sets the Optimize value.
/// </summary>
[Parameter(ParameterSetName = ASRParameterSets.ByPEObjectE2AFailback)]
[Parameter(ParameterSetName = ASRParameterSets.ByPEObjectE2AFailback)]
[ValidateSet(
Constants.ForDowntime,
Constants.ForSynchronization)]
Expand Down Expand Up @@ -160,8 +164,8 @@ private void StartPEPlannedFailover()
else
{
var blob = new AzureFailbackInput();
blob.CreateRecoveryVmIfDoesntExist = false;
blob.SkipDataSync = true;
blob.CreateRecoveryVmIfDoesntExist = true;
blob.SkipDataSync = this.Optimize == Constants.ForDowntime ? true : false;
request.ReplicationProviderSettings = DataContractUtils.Serialize<AzureFailbackInput>(blob);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace Microsoft.Azure.Commands.RecoveryServices
/// <summary>
/// Used to initiate a commit operation.
/// </summary>
[Cmdlet(VerbsLifecycle.Start, "AzureSiteRecoveryTestFailoverJob", DefaultParameterSetName = ASRParameterSets.ByRPObject)]
[Cmdlet(VerbsLifecycle.Start, "AzureSiteRecoveryTestFailoverJob", DefaultParameterSetName = ASRParameterSets.ByPEId)]
[OutputType(typeof(ASRJob))]
public class StartAzureSiteRecoveryTestFailoverJob : RecoveryServicesCmdletBase
{
Expand All @@ -47,28 +47,46 @@ public class StartAzureSiteRecoveryTestFailoverJob : RecoveryServicesCmdletBase
/// Gets or sets ID of the Recovery Plan.
/// </summary>
[Parameter(ParameterSetName = ASRParameterSets.ByRPId, Mandatory = true)]
[Parameter(ParameterSetName = ASRParameterSets.ByRPIdWithLogicalNetworkID, Mandatory = true)]
[Parameter(ParameterSetName = ASRParameterSets.ByRPIdWithVMNetworkID, Mandatory = true)]
[Parameter(ParameterSetName = ASRParameterSets.ByRPIdWithVMNetwork, Mandatory = true)]
[ValidateNotNullOrEmpty]
public string RpId { get; set; }

/// <summary>
/// Gets or sets ID of the Recovery Plan.
/// Gets or sets Network.
/// </summary>
[Parameter]
[Parameter(ParameterSetName = ASRParameterSets.ByPEObjectWithVMNetwork, Mandatory = true)]
[Parameter(ParameterSetName = ASRParameterSets.ByRPObjectWithVMNetwork, Mandatory = true)]
[Parameter(ParameterSetName = ASRParameterSets.ByRPIdWithVMNetwork, Mandatory = true)]
[Parameter(ParameterSetName = ASRParameterSets.ByPEIdWithVMNetwork, Mandatory = true)]
public ASRNetwork Network { get; set; }

/// <summary>
/// Gets or sets NetworkType.
/// </summary>
[Parameter(Mandatory = false)]
[ValidateSet(
Constants.None,
Constants.New,
Constants.Existing)]
public string NetworkType { get; set; }

/// <summary>
/// Gets or sets Recovery Plan object.
/// </summary>
[Parameter(ParameterSetName = ASRParameterSets.ByRPObject, Mandatory = true, ValueFromPipeline = true)]
[Parameter(ParameterSetName = ASRParameterSets.ByRPObjectWithLogicalNetworkID, Mandatory = true)]
[Parameter(ParameterSetName = ASRParameterSets.ByRPObjectWithVMNetworkID, Mandatory = true)]
[Parameter(ParameterSetName = ASRParameterSets.ByRPObjectWithVMNetwork, Mandatory = true)]
[ValidateNotNullOrEmpty]
public ASRRecoveryPlan RecoveryPlan { get; set; }

/// <summary>
/// Gets or sets failover direction for the recovery plan.
/// </summary>
[Parameter(ParameterSetName = ASRParameterSets.ByRPObject, Mandatory = true)]
[Parameter(ParameterSetName = ASRParameterSets.ByRPId, Mandatory = true)]
[Parameter(ParameterSetName = ASRParameterSets.ByPEObject, Mandatory = true)]
[Parameter(ParameterSetName = ASRParameterSets.ByPEId, Mandatory = true)]
[Parameter(Mandatory = true)]
[ValidateSet(
Constants.PrimaryToRecovery,
Constants.RecoveryToPrimary)]
Expand All @@ -80,6 +98,7 @@ public class StartAzureSiteRecoveryTestFailoverJob : RecoveryServicesCmdletBase
[Parameter(ParameterSetName = ASRParameterSets.ByPEId, Mandatory = true)]
[Parameter(ParameterSetName = ASRParameterSets.ByPEIdWithLogicalNetworkID, Mandatory = true)]
[Parameter(ParameterSetName = ASRParameterSets.ByPEIdWithVMNetworkID, Mandatory = true)]
[Parameter(ParameterSetName = ASRParameterSets.ByPEIdWithVMNetwork, Mandatory = true)]
[ValidateNotNullOrEmpty]
public string ProtectionEntityId { get; set; }

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

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

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

/// <summary>
/// Gets or sets VM network ID.
/// </summary>
[Parameter(ParameterSetName = ASRParameterSets.ByPEObjectWithVMNetworkID, Mandatory = true)]
[Parameter(ParameterSetName = ASRParameterSets.ByPEIdWithVMNetworkID, Mandatory = true)]
[Parameter(ParameterSetName = ASRParameterSets.ByRPObjectWithVMNetworkID, Mandatory = true)]
[Parameter(ParameterSetName = ASRParameterSets.ByRPIdWithVMNetworkID, Mandatory = true)]
public string VmNetworkId { get; set; }
#endregion Parameters

Expand All @@ -129,13 +154,60 @@ public override void ExecuteCmdlet()
{
try
{
if (this.NetworkType == null)
{
this.WriteWarning("'NetworkType' will be a mandatory paramter from next release.");
}

if (this.VmNetworkId != null)
{
this.WriteWarning("Call using 'NetworkId' parameter will not be supported from next release. Please use 'Network' parameter instead.");
}

if (this.NetworkType == Constants.Existing && (this.Network == null && this.VmNetworkId == null))
{
throw new Exception("Existing Network details were not supplied.");
}

switch (this.ParameterSetName)
{
case ASRParameterSets.ByRPObject:
this.RpId = this.RecoveryPlan.ID;
this.networkType = "DisconnectedVMNetworkTypeForTestFailover";
this.StartRpTestFailover();
break;
case ASRParameterSets.ByRPId:
this.networkType = "DisconnectedVMNetworkTypeForTestFailover";
this.StartRpTestFailover();
break;
case ASRParameterSets.ByRPObjectWithVMNetwork:
this.networkType = "UseVMNetworkTypeForTestFailover";
this.networkId = this.Network.ID;
this.StartRpTestFailover();
break;
case ASRParameterSets.ByRPObjectWithVMNetworkID:
this.networkType = "UseVMNetworkTypeForTestFailover";
this.networkId = this.VmNetworkId;
this.StartRpTestFailover();
break;
case ASRParameterSets.ByRPIdWithVMNetwork:
this.networkType = "UseVMNetworkTypeForTestFailover";
this.networkId = this.Network.ID;
this.StartRpTestFailover();
break;
case ASRParameterSets.ByRPIdWithVMNetworkID:
this.networkType = "UseVMNetworkTypeForTestFailover";
this.networkId = this.VmNetworkId;
this.StartRpTestFailover();
break;
case ASRParameterSets.ByRPIdWithLogicalNetworkID:
this.networkType = "CreateVMNetworkTypeForTestFailover";
this.networkId = this.LogicalNetworkId;
this.StartRpTestFailover();
break;
case ASRParameterSets.ByRPObjectWithLogicalNetworkID:
this.networkType = "CreateVMNetworkTypeForTestFailover";
this.networkId = this.LogicalNetworkId;
this.StartRpTestFailover();
break;
case ASRParameterSets.ByPEObject:
Expand All @@ -152,7 +224,13 @@ public override void ExecuteCmdlet()
this.networkId = this.VmNetworkId;
this.UpdateRequiredParametersAndStartFailover();
break;
case ASRParameterSets.ByPEObjectWithVMNetwork:
this.networkType = "UseVMNetworkTypeForTestFailover";
this.networkId = this.Network.ID;
this.UpdateRequiredParametersAndStartFailover();
break;
case ASRParameterSets.ByPEId:
this.networkType = "DisconnectedVMNetworkTypeForTestFailover";
this.StartPETestFailover();
break;
case ASRParameterSets.ByPEIdWithLogicalNetworkID:
Expand All @@ -165,6 +243,11 @@ public override void ExecuteCmdlet()
this.networkId = this.VmNetworkId;
this.StartPETestFailover();
break;
case ASRParameterSets.ByPEIdWithVMNetwork:
this.networkType = "UseVMNetworkTypeForTestFailover";
this.networkId = this.Network.ID;
this.StartPETestFailover();
break;
}
}
catch (Exception exception)
Expand All @@ -180,20 +263,6 @@ private void StartRpTestFailover()
{
RpTestFailoverRequest request = new RpTestFailoverRequest();

if (this.Network != null)
{
request.NetworkID = this.Network.ID;
request.NetworkType = "UseVMNetworkTypeForTestFailover";
}
else
{
request.NetworkID = this.networkId;
if (string.IsNullOrEmpty(this.networkType))
{
request.NetworkType = "DisconnectedVMNetworkTypeForTestFailover";
}
}

if (this.RecoveryPlan == null)
{
var rp = RecoveryServicesClient.GetAzureSiteRecoveryRecoveryPlan(
Expand All @@ -215,6 +284,9 @@ private void StartRpTestFailover()
}
}

request.NetworkID = this.networkId;
request.NetworkType = this.networkType;

request.ReplicationProvider = this.RecoveryPlan.ReplicationProvider;
request.FailoverDirection = this.Direction;

Expand Down Expand Up @@ -262,17 +334,7 @@ private void StartPETestFailover()
request.ReplicationProvider = this.ProtectionEntity.ReplicationProvider;
request.FailoverDirection = this.Direction;

if (this.Network != null)
{
request.NetworkID = this.Network.ID;
this.networkType = "UseVMNetworkTypeForTestFailover";
}
else
{
request.NetworkID = this.networkId;
}

request.FailoverDirection = this.Direction;
request.NetworkID = this.networkId;
request.NetworkType = this.networkType;

this.jobResponse =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,21 @@ public class Constants
/// </summary>
public const string ResourceNamespace = "WAHyperVRecoveryManager";

/// <summary>
/// Represents None string value.
/// </summary>
public const string None = "None";

/// <summary>
/// Represents Existing string value.
/// </summary>
public const string Existing = "Existing";

/// <summary>
/// Represents New string value.
/// </summary>
public const string New = "New";

/// <summary>
/// Represents direction primary to secondary.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,36 @@ internal static class ASRParameterSets
/// </summary>
internal const string ByPEObjectWithLogicalNetworkID = "ByPEObjectWithLogicalNetworkID";

/// <summary>
/// When only RP Object is passed along with VM network ID to the command.
/// </summary>
internal const string ByRPObjectWithVMNetworkID = "ByRPObjectWithVMNetworkID";

/// <summary>
/// When only RP Id is passed along with VM network ID to the command.
/// </summary>
internal const string ByRPIdWithVMNetworkID = "ByRPIdWithVMNetworkID";

/// <summary>
/// When only RP Object is passed along with VM network to the command.
/// </summary>
internal const string ByRPObjectWithVMNetwork = "ByRPObjectWithVMNetwork";

/// <summary>
/// When only RP Id is passed along with VM network to the command.
/// </summary>
internal const string ByRPIdWithVMNetwork = "ByRPIdWithVMNetwork";

/// <summary>
/// When only PE Object is passed along with VM network ID to the command.
/// </summary>
internal const string ByPEObjectWithVMNetworkID = "ByPEObjectWithVMNetworkID";

/// <summary>
/// When only PE Object is passed along with VM network to the command.
/// </summary>
internal const string ByPEObjectWithVMNetwork = "ByPEObjectWithVMNetwork";

/// <summary>
/// When only PC and PE ids are passed to the command.
/// </summary>
Expand All @@ -79,11 +104,26 @@ internal static class ASRParameterSets
/// </summary>
internal const string ByPEIdWithLogicalNetworkID = "ByPEIdWithLogicalNetworkID";

/// <summary>
/// When only RP object is passed along with logical network ID to the command.
/// </summary>
internal const string ByRPObjectWithLogicalNetworkID = "ByRPObjectWithLogicalNetworkID";

/// <summary>
/// When only RP Id is passed along with logical network ID to the command.
/// </summary>
internal const string ByRPIdWithLogicalNetworkID = "ByRPIdWithLogicalNetworkID";

/// <summary>
/// When only PC and PE ids are passed along with VM network ID to the command.
/// </summary>
internal const string ByPEIdWithVMNetworkID = "ByPEIdWithVMNetworkID";

/// <summary>
/// When only PC and PE ids are passed along with VM network to the command.
/// </summary>
internal const string ByPEIdWithVMNetwork = "ByPEIdWithVMNetwork";

/// <summary>
/// When only ID is passed to the command.
/// </summary>
Expand Down

0 comments on commit dccc0e3

Please sign in to comment.