Skip to content

Extending support for Azure fabrics in create and list/get fabric. #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,9 @@ public FabricResponse GetAzureSiteRecoveryFabric(string fabricName)
/// </summary>
/// <param name="createAndAssociatePolicyInput">Policy Input</param>
/// <returns>Long operation response</returns>
public LongRunningOperationResponse CreateAzureSiteRecoveryFabric(string fabricName, string fabricType = null)
public LongRunningOperationResponse CreateAzureSiteRecoveryFabric(string fabricName, FabricCreationInput input)
{
if (string.IsNullOrEmpty(fabricType))
{
fabricType = FabricProviders.HyperVSite;
}

FabricCreationInputProperties fabricCreationInputProperties = new FabricCreationInputProperties()
{
FabricType = fabricType,
};

FabricCreationInput fabricCreationInput = new FabricCreationInput()
{
Properties = fabricCreationInputProperties
};

return this.GetSiteRecoveryClient().Fabrics.BeginCreating(fabricName, fabricCreationInput,
return this.GetSiteRecoveryClient().Fabrics.BeginCreating(fabricName, input,
this.GetRequestHeaders(false));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,17 @@ public class NewAzureRmSiteRecoveryFabric : SiteRecoveryCmdletBase
[Parameter(ParameterSetName = ASRParameterSets.Default, Mandatory = false)]
[ValidateNotNullOrEmpty]
[ValidateSet(
Constants.HyperVSite)]
Constants.HyperVSite,
Constants.Azure)]
public string Type { get; set; }

/// <summary>
/// Gets or Sets the Fabric type
/// </summary>
[Parameter(ParameterSetName = ASRParameterSets.Default, Mandatory = false)]
[ValidateNotNullOrEmpty]
public string Location { get; set; }

#endregion Parameters

/// <summary>
Expand All @@ -56,10 +64,35 @@ public override void ExecuteSiteRecoveryCmdlet()
{
base.ExecuteSiteRecoveryCmdlet();

string fabricType = string.IsNullOrEmpty(this.Type)? FabricProviders.HyperVSite : this.Type;
FabricCreationInputProperties fabricCreationInputProperties = new FabricCreationInputProperties();

if (!string.IsNullOrEmpty(this.Type) &&
string.Compare(this.Type, Constants.Azure, StringComparison.OrdinalIgnoreCase) == 0 &&
string.IsNullOrEmpty(this.Location))
{
throw new InvalidOperationException(
string.Format(
Properties.Resources.LocationNotSpecifiedForAzureFabric));
}

if (!string.IsNullOrEmpty(this.Type) &&
string.Compare(this.Type, Constants.Azure, StringComparison.OrdinalIgnoreCase) == 0 &&
!string.IsNullOrEmpty(this.Location))
{
fabricCreationInputProperties.CustomDetails = new AzureFabricCreationInput()
{
// TODO : (AvRai) Validate that passed location is a valid Azure locations.
Location = this.Location
};
}

FabricCreationInput fabricCreationInput = new FabricCreationInput()
{
Properties = fabricCreationInputProperties
};

LongRunningOperationResponse response =
RecoveryServicesClient.CreateAzureSiteRecoveryFabric(this.Name, fabricType);
RecoveryServicesClient.CreateAzureSiteRecoveryFabric(this.Name, fabricCreationInput);

JobResponse jobResponse =
RecoveryServicesClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,11 @@ public static class Constants
/// </summary>
public const string HyperVSite = "HyperVSite";

/// <summary>
/// FabricType - Azure.
/// </summary>
public const string Azure = "Azure";

/// <summary>
/// FabricType - VMware.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,14 @@ public ASRFabric(Fabric fabric)
this.ID = fabric.Id;
this.Type = fabric.Properties.CustomDetails.InstanceType;
this.SiteIdentifier = fabric.Properties.InternalIdentifier;

if (
string.Compare(fabric.Properties.CustomDetails.InstanceType, "Azure", StringComparison.OrdinalIgnoreCase) ==
0)
{
var azureFabricSpecificDetails = fabric.Properties.CustomDetails as AzureFabricSpecificDetails;
this.Location = azureFabricSpecificDetails != null ? azureFabricSpecificDetails.Location : null;
}
}

#endregion
Expand Down Expand Up @@ -291,6 +299,11 @@ public ASRFabric(Fabric fabric)
/// </summary>
public string SiteIdentifier { get; set; }

/// <summary>
/// Gets or sets Location.
/// </summary>
public string Location { get; set; }

#endregion
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -349,4 +349,7 @@ Please provide a storage account with the same location as that of the vault.</v
<data name="ReplicationProtectedItemNotFound" xml:space="preserve">
<value>Replication Protected Item"{0}" is not associated with Protection Container "{1}"</value>
</data>
<data name="LocationNotSpecifiedForAzureFabric" xml:space="preserve">
<value>Location is not specified for creating Azure fabric.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,15 @@ public override void ExecuteSiteRecoveryCmdlet()
this.MyInvocation.MyCommand.Name,
"New-AzureRmSiteRecoveryFabric"));

FabricCreationInputProperties fabricCreationInputProperties = new FabricCreationInputProperties();

FabricCreationInput fabricCreationInput = new FabricCreationInput()
{
Properties = fabricCreationInputProperties
};

LongRunningOperationResponse response =
RecoveryServicesClient.CreateAzureSiteRecoveryFabric(this.Name, FabricProviders.HyperVSite);
RecoveryServicesClient.CreateAzureSiteRecoveryFabric(this.Name, fabricCreationInput);

JobResponse jobResponse =
RecoveryServicesClient
Expand Down