Skip to content

Commit 15d9010

Browse files
committed
updated code to support secondary read only storage accounts and also LRS, ZRS, GRS, PLRS
1 parent 6902bbe commit 15d9010

11 files changed

+129
-21
lines changed

Elastacloud.AzureManagement.Fluent/Clients/Helpers/FluentManagementEventArgs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ public FluentManagementEventArgs(int percentageUpdate, string contextString)
3636
/// An event handler which is used to generate a perentage status update and associated description
3737
/// </summary>
3838
public delegate void FluentClientEventHandler(int percentage, string description);
39-
}
39+
}

Elastacloud.AzureManagement.Fluent/Clients/Helpers/GenerateEventClientBase.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
1+
/************************************************************************************************************
2+
* This software is distributed under a GNU Lesser License by Elastacloud Limited and it is free to *
3+
* modify and distribute providing the terms of the license are followed. From the root of the source the *
4+
* license can be found in /Resources/license.txt *
5+
* *
6+
* Web at: www.elastacloud.com *
7+
* Email: [email protected] *
8+
************************************************************************************************************/
9+
610
using Elastacloud.AzureManagement.Fluent.Clients.Interfaces;
711

812
namespace Elastacloud.AzureManagement.Fluent.Clients.Helpers

Elastacloud.AzureManagement.Fluent/Clients/Helpers/IWebsiteRequestHelper.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
using System.Collections.Generic;
2-
using System.Linq;
3-
using System.Text;
4-
using System.Threading.Tasks;
1+
/************************************************************************************************************
2+
* This software is distributed under a GNU Lesser License by Elastacloud Limited and it is free to *
3+
* modify and distribute providing the terms of the license are followed. From the root of the source the *
4+
* license can be found in /Resources/license.txt *
5+
* *
6+
* Web at: www.elastacloud.com *
7+
* Email: [email protected] *
8+
************************************************************************************************************/
9+
510

611
namespace Elastacloud.AzureManagement.Fluent.Clients.Helpers
712
{

Elastacloud.AzureManagement.Fluent/Clients/Helpers/ServiceCertificateModel.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
1+
/************************************************************************************************************
2+
* This software is distributed under a GNU Lesser License by Elastacloud Limited and it is free to *
3+
* modify and distribute providing the terms of the license are followed. From the root of the source the *
4+
* license can be found in /Resources/license.txt *
5+
* *
6+
* Web at: www.elastacloud.com *
7+
* Email: [email protected] *
8+
************************************************************************************************************/
9+
410
using System.Security.Cryptography.X509Certificates;
511
using System.Text;
612
using System.Threading.Tasks;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/************************************************************************************************************
2+
* This software is distributed under a GNU Lesser License by Elastacloud Limited and it is free to *
3+
* modify and distribute providing the terms of the license are followed. From the root of the source the *
4+
* license can be found in /Resources/license.txt *
5+
* *
6+
* Web at: www.elastacloud.com *
7+
* Email: [email protected] *
8+
************************************************************************************************************/
9+
10+
namespace Elastacloud.AzureManagement.Fluent.Clients.Helpers
11+
{
12+
/// <summary>
13+
/// The storage details that the account will enable
14+
/// </summary>
15+
public class StorageManagementOptions
16+
{
17+
/// <summary>
18+
/// Whether or not the storage supported is secondary read only as well
19+
/// </summary>
20+
public bool SecondaryReadOnly { get; set; }
21+
/// <summary>
22+
/// The type of storage account whether GRS, LRS or premium
23+
/// </summary>
24+
public StorageType StorageType { get; set; }
25+
26+
/// <summary>
27+
/// Defaults enabled for the
28+
/// </summary>
29+
public static StorageManagementOptions GetDefaultOptions
30+
{
31+
get
32+
{
33+
return new StorageManagementOptions()
34+
{
35+
SecondaryReadOnly = false,
36+
StorageType = StorageType.Standard_LRS
37+
};
38+
}
39+
}
40+
}
41+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/************************************************************************************************************
2+
* This software is distributed under a GNU Lesser License by Elastacloud Limited and it is free to *
3+
* modify and distribute providing the terms of the license are followed. From the root of the source the *
4+
* license can be found in /Resources/license.txt *
5+
* *
6+
* Web at: www.elastacloud.com *
7+
* Email: [email protected] *
8+
************************************************************************************************************/
9+
namespace Elastacloud.AzureManagement.Fluent.Clients.Helpers
10+
{
11+
public enum StorageType
12+
{
13+
// ReSharper disable once InconsistentNaming
14+
Standard_LRS,
15+
// ReSharper disable once InconsistentNaming
16+
Standard_ZRS,
17+
// ReSharper disable once InconsistentNaming
18+
Standard_GRS,
19+
// ReSharper disable once InconsistentNaming
20+
Standard_RAGRS,
21+
// ReSharper disable once InconsistentNaming
22+
Premium_LRS
23+
}
24+
}

Elastacloud.AzureManagement.Fluent/Clients/Helpers/WebsiteRequestHelper.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
using System;
1+
/************************************************************************************************************
2+
* This software is distributed under a GNU Lesser License by Elastacloud Limited and it is free to *
3+
* modify and distribute providing the terms of the license are followed. From the root of the source the *
4+
* license can be found in /Resources/license.txt *
5+
* *
6+
* Web at: www.elastacloud.com *
7+
* Email: [email protected] *
8+
************************************************************************************************************/
9+
10+
using System;
211
using System.Net;
312
using System.Net.Http;
413
using System.Net.Http.Headers;

Elastacloud.AzureManagement.Fluent/Clients/Interfaces/IStorageClient.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
************************************************************************************************************/
99

1010
using System.Collections.Generic;
11+
using Elastacloud.AzureManagement.Fluent.Clients.Helpers;
1112
using Elastacloud.AzureManagement.Fluent.Helpers;
1213
using Elastacloud.AzureManagement.Fluent.Types;
1314

@@ -21,11 +22,11 @@ public interface IStorageClient
2122
/// <summary>
2223
/// Creates a new storage account given a name and location
2324
/// </summary>
24-
void CreateNewStorageAccount(string name, string location = LocationConstants.NorthEurope);
25+
void CreateNewStorageAccount(string name, string location = LocationConstants.NorthEurope, StorageManagementOptions options = null);
2526
/// <summary>
2627
/// Create the storage account if an account by the same name doesn't exist
2728
/// </summary>
28-
void CreateStorageAccountIfNotExists(string name, string location = LocationConstants.NorthEurope);
29+
void CreateStorageAccountIfNotExists(string name, string location = LocationConstants.NorthEurope, StorageManagementOptions options = null);
2930
/// <summary>
3031
/// Deletes a storage account if it exists
3132
/// </summary>

Elastacloud.AzureManagement.Fluent/Clients/StorageClient.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Linq;
1212
using System.Security.Cryptography.X509Certificates;
1313
using System.Text;
14+
using Elastacloud.AzureManagement.Fluent.Clients.Helpers;
1415
using Elastacloud.AzureManagement.Fluent.Clients.Interfaces;
1516
using Elastacloud.AzureManagement.Fluent.Commands.Storage;
1617
using Elastacloud.AzureManagement.Fluent.Helpers;
@@ -56,10 +57,14 @@ public StorageClient(string accountName, string accountKey)
5657
/// <summary>
5758
/// Creates a new storage account given a name and location
5859
/// </summary>
59-
public void CreateNewStorageAccount(string name, string location = LocationConstants.NorthEurope)
60+
public void CreateNewStorageAccount(string name, string location = LocationConstants.NorthEurope
61+
, StorageManagementOptions options = null)
6062
{
63+
if (options == null)
64+
options = StorageManagementOptions.GetDefaultOptions;
65+
6166
// issue the create storage account command
62-
var create = new CreateStorageAccountCommand(name, "Created with Fluent Management", location)
67+
var create = new CreateStorageAccountCommand(name, "Created with Fluent Management", options, location)
6368
{
6469
SubscriptionId = SubscriptionId,
6570
Certificate = ManagementCertificate
@@ -81,7 +86,8 @@ public void CreateNewStorageAccount(string name, string location = LocationConst
8186
/// <summary>
8287
/// Create the storage account if an account by the same name doesn't exist
8388
/// </summary>
84-
public void CreateStorageAccountIfNotExists(string name, string location = LocationConstants.NorthEurope)
89+
public void CreateStorageAccountIfNotExists(string name,
90+
string location = LocationConstants.NorthEurope, StorageManagementOptions options = null)
8591
{
8692
if (GetStorageAccountList().All(a => a.Name != name))
8793
{

Elastacloud.AzureManagement.Fluent/Commands/Storage/CreateStorageAccountCommand.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using System;
1111
using System.Text;
1212
using System.Xml.Linq;
13+
using Elastacloud.AzureManagement.Fluent.Clients.Helpers;
1314
using Elastacloud.AzureManagement.Fluent.Commands.Services;
1415
using Elastacloud.AzureManagement.Fluent.Helpers;
1516

@@ -20,16 +21,22 @@ namespace Elastacloud.AzureManagement.Fluent.Commands.Storage
2021
/// </summary>
2122
internal class CreateStorageAccountCommand : ServiceCommand
2223
{
23-
internal CreateStorageAccountCommand(string name, string description, string location = LocationConstants.NorthEurope)
24+
internal CreateStorageAccountCommand(string name, string description,
25+
StorageManagementOptions options,
26+
string location = LocationConstants.NorthEurope
27+
)
2428
{
2529
Name = name.ToLower();
2630
Description = description;
2731
Location = location;
2832
HttpVerb = HttpVerbPost;
2933
ServiceType = "services";
3034
OperationId = "storageservices";
35+
StorageOptions = options;
3136
}
3237

38+
public StorageManagementOptions StorageOptions { get; set; }
39+
3340
protected override string CreatePayload()
3441
{
3542
/* <?xml version="1.0" encoding="utf-8"?>
@@ -47,7 +54,10 @@ protected override string CreatePayload()
4754
new XElement(ns + "ServiceName", Name),
4855
new XElement(ns + "Description", Description),
4956
new XElement(ns + "Label", Convert.ToBase64String(Encoding.UTF8.GetBytes(Name))),
50-
new XElement(ns + "Location", Location)));
57+
new XElement(ns + "Location", Location),
58+
new XElement(ns + "SecondaryReadEnabled", StorageOptions.SecondaryReadOnly),
59+
new XElement(ns + "AccountType", StorageOptions.StorageType.ToString())
60+
));
5161
return doc.ToStringFullXmlDeclaration();
5262
}
5363
}

Elastacloud.AzureManagement.Fluent/Elastacloud.AzureManagement.Fluent.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@
9292
<Compile Include="Clients\Helpers\FluentManagementEventArgs.cs" />
9393
<Compile Include="Clients\Helpers\GenerateEventClientBase.cs" />
9494
<Compile Include="Clients\Helpers\ServiceCertificateModel.cs" />
95+
<Compile Include="Clients\Helpers\StorageManagementOptions.cs" />
96+
<Compile Include="Clients\Helpers\StorageType.cs" />
9597
<Compile Include="Clients\ImageManagementClient.cs" />
9698
<Compile Include="Clients\Interfaces\IGenerateUpdateEvent.cs" />
9799
<Compile Include="Clients\Interfaces\IImageManagementClient.cs" />

0 commit comments

Comments
 (0)