Skip to content

Commit 6598e22

Browse files
committed
Merge pull request #5 from AsrOneSdk/devA2A-avrai
Extending support for Azure fabrics in create and list/get fabric.
2 parents c62ea0d + a40dad2 commit 6598e22

File tree

7 files changed

+76
-21
lines changed

7 files changed

+76
-21
lines changed

src/ResourceManager/SiteRecovery/Commands.SiteRecovery/Common/PSSiteRecoveryFabricClient.cs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,9 @@ public FabricResponse GetAzureSiteRecoveryFabric(string fabricName)
5252
/// </summary>
5353
/// <param name="createAndAssociatePolicyInput">Policy Input</param>
5454
/// <returns>Long operation response</returns>
55-
public LongRunningOperationResponse CreateAzureSiteRecoveryFabric(string fabricName, string fabricType = null)
55+
public LongRunningOperationResponse CreateAzureSiteRecoveryFabric(string fabricName, FabricCreationInput input)
5656
{
57-
if (string.IsNullOrEmpty(fabricType))
58-
{
59-
fabricType = FabricProviders.HyperVSite;
60-
}
61-
62-
FabricCreationInputProperties fabricCreationInputProperties = new FabricCreationInputProperties()
63-
{
64-
FabricType = fabricType,
65-
};
66-
67-
FabricCreationInput fabricCreationInput = new FabricCreationInput()
68-
{
69-
Properties = fabricCreationInputProperties
70-
};
71-
72-
return this.GetSiteRecoveryClient().Fabrics.BeginCreating(fabricName, fabricCreationInput,
57+
return this.GetSiteRecoveryClient().Fabrics.BeginCreating(fabricName, input,
7358
this.GetRequestHeaders(false));
7459
}
7560

src/ResourceManager/SiteRecovery/Commands.SiteRecovery/Fabrics/NewAzureRmSiteRecoveryFabric.cs

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,17 @@ public class NewAzureRmSiteRecoveryFabric : SiteRecoveryCmdletBase
4444
[Parameter(ParameterSetName = ASRParameterSets.Default, Mandatory = false)]
4545
[ValidateNotNullOrEmpty]
4646
[ValidateSet(
47-
Constants.HyperVSite)]
47+
Constants.HyperVSite,
48+
Constants.Azure)]
4849
public string Type { get; set; }
4950

51+
/// <summary>
52+
/// Gets or Sets the Fabric type
53+
/// </summary>
54+
[Parameter(ParameterSetName = ASRParameterSets.Default, Mandatory = false)]
55+
[ValidateNotNullOrEmpty]
56+
public string Location { get; set; }
57+
5058
#endregion Parameters
5159

5260
/// <summary>
@@ -56,10 +64,35 @@ public override void ExecuteSiteRecoveryCmdlet()
5664
{
5765
base.ExecuteSiteRecoveryCmdlet();
5866

59-
string fabricType = string.IsNullOrEmpty(this.Type)? FabricProviders.HyperVSite : this.Type;
67+
FabricCreationInputProperties fabricCreationInputProperties = new FabricCreationInputProperties();
68+
69+
if (!string.IsNullOrEmpty(this.Type) &&
70+
string.Compare(this.Type, Constants.Azure, StringComparison.OrdinalIgnoreCase) == 0 &&
71+
string.IsNullOrEmpty(this.Location))
72+
{
73+
throw new InvalidOperationException(
74+
string.Format(
75+
Properties.Resources.LocationNotSpecifiedForAzureFabric));
76+
}
77+
78+
if (!string.IsNullOrEmpty(this.Type) &&
79+
string.Compare(this.Type, Constants.Azure, StringComparison.OrdinalIgnoreCase) == 0 &&
80+
!string.IsNullOrEmpty(this.Location))
81+
{
82+
fabricCreationInputProperties.CustomDetails = new AzureFabricCreationInput()
83+
{
84+
// TODO : (AvRai) Validate that passed location is a valid Azure locations.
85+
Location = this.Location
86+
};
87+
}
88+
89+
FabricCreationInput fabricCreationInput = new FabricCreationInput()
90+
{
91+
Properties = fabricCreationInputProperties
92+
};
6093

6194
LongRunningOperationResponse response =
62-
RecoveryServicesClient.CreateAzureSiteRecoveryFabric(this.Name, fabricType);
95+
RecoveryServicesClient.CreateAzureSiteRecoveryFabric(this.Name, fabricCreationInput);
6396

6497
JobResponse jobResponse =
6598
RecoveryServicesClient

src/ResourceManager/SiteRecovery/Commands.SiteRecovery/Models/PSConstants.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,11 @@ public static class Constants
297297
/// </summary>
298298
public const string HyperVSite = "HyperVSite";
299299

300+
/// <summary>
301+
/// FabricType - Azure.
302+
/// </summary>
303+
public const string Azure = "Azure";
304+
300305
/// <summary>
301306
/// FabricType - VMware.
302307
/// </summary>

src/ResourceManager/SiteRecovery/Commands.SiteRecovery/Models/PSObjects.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,14 @@ public ASRFabric(Fabric fabric)
261261
this.ID = fabric.Id;
262262
this.Type = fabric.Properties.CustomDetails.InstanceType;
263263
this.SiteIdentifier = fabric.Properties.InternalIdentifier;
264+
265+
if (
266+
string.Compare(fabric.Properties.CustomDetails.InstanceType, "Azure", StringComparison.OrdinalIgnoreCase) ==
267+
0)
268+
{
269+
var azureFabricSpecificDetails = fabric.Properties.CustomDetails as AzureFabricSpecificDetails;
270+
this.Location = azureFabricSpecificDetails != null ? azureFabricSpecificDetails.Location : null;
271+
}
264272
}
265273

266274
#endregion
@@ -291,6 +299,11 @@ public ASRFabric(Fabric fabric)
291299
/// </summary>
292300
public string SiteIdentifier { get; set; }
293301

302+
/// <summary>
303+
/// Gets or sets Location.
304+
/// </summary>
305+
public string Location { get; set; }
306+
294307
#endregion
295308
}
296309

src/ResourceManager/SiteRecovery/Commands.SiteRecovery/Properties/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ResourceManager/SiteRecovery/Commands.SiteRecovery/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,4 +349,7 @@ Please provide a storage account with the same location as that of the vault.</v
349349
<data name="ReplicationProtectedItemNotFound" xml:space="preserve">
350350
<value>Replication Protected Item"{0}" is not associated with Protection Container "{1}"</value>
351351
</data>
352+
<data name="LocationNotSpecifiedForAzureFabric" xml:space="preserve">
353+
<value>Location is not specified for creating Azure fabric.</value>
354+
</data>
352355
</root>

src/ResourceManager/SiteRecovery/Commands.SiteRecovery/Site/NewAzureSiteRecoverySite.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,15 @@ public override void ExecuteSiteRecoveryCmdlet()
5858
this.MyInvocation.MyCommand.Name,
5959
"New-AzureRmSiteRecoveryFabric"));
6060

61+
FabricCreationInputProperties fabricCreationInputProperties = new FabricCreationInputProperties();
62+
63+
FabricCreationInput fabricCreationInput = new FabricCreationInput()
64+
{
65+
Properties = fabricCreationInputProperties
66+
};
67+
6168
LongRunningOperationResponse response =
62-
RecoveryServicesClient.CreateAzureSiteRecoveryFabric(this.Name, FabricProviders.HyperVSite);
69+
RecoveryServicesClient.CreateAzureSiteRecoveryFabric(this.Name, fabricCreationInput);
6370

6471
JobResponse jobResponse =
6572
RecoveryServicesClient

0 commit comments

Comments
 (0)