Skip to content

Commit 9f98d6d

Browse files
committed
Merge pull request #45 from AsrOneSdk/neha-dev
Bug fixes - GetVault
2 parents 4343459 + d8b6f89 commit 9f98d6d

File tree

9 files changed

+588
-425
lines changed

9 files changed

+588
-425
lines changed

src/Common/Commands.Common/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/Common/Commands.Common/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,6 +1490,9 @@ use and privacy statement at <url> and (c) agree to sharing my contact inf
14901490
<data name="RemoveProfileMessage" xml:space="preserve">
14911491
<value>Removing the Azure profile</value>
14921492
</data>
1493+
<data name="StorageAccountValidationUnsuccessful" xml:space="preserve">
1494+
<value>The Subscription or Storage account couldn’t be validated. For failovers to be successful, the Subscription should belong to your account, the Storage account to the Subscription and Storage account location must be the same as location of your Vault.</value>
1495+
</data>
14931496
<data name="SubscriptionDataFileDeprecated" xml:space="preserve">
14941497
<value>The SubscriptionDataFile parameter is deprecated. This parameter will be removed in a future release. See https://github.com/Azure/azure-powershell/wiki/Proposed-Design-Stateless-Azure-Profile for a description of the upcoming mechanism for providing alternate sources of subscription information.</value>
14951498
</data>

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Microsoft.Azure.Commands.RecoveryServices.dll-help.xml

Lines changed: 405 additions & 337 deletions
Large diffs are not rendered by default.

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

Lines changed: 65 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@
1616
using System.Collections.Generic;
1717
using Microsoft.Azure.Common.Extensions;
1818
using Microsoft.Azure.Common.Extensions.Models;
19+
using Microsoft.WindowsAzure.Commands.Common;
20+
using Microsoft.WindowsAzure.Management.SiteRecovery;
21+
using Microsoft.WindowsAzure.Management.SiteRecovery.Models;
1922

2023
namespace Microsoft.Azure.Commands.RecoveryServices
2124
{
2225
/// <summary>
2326
/// Recovery Services Client Helper Methods class
2427
/// </summary>
25-
public class PSRecoveryServicesClientHelper
28+
public partial class PSRecoveryServicesClient
2629
{
2730
/// <summary>
2831
/// Validates whether the subscription belongs to the currently logged account or not.
@@ -60,30 +63,6 @@ public static void ValidateSubscriptionAccountAssociation(string azureSubscripti
6063
}
6164
}
6265

63-
/// <summary>
64-
/// Validates whether the storage belongs to the currently logged account or not.
65-
/// </summary>
66-
/// <param name="azureStorageAccount">Storage Account details</param>
67-
public static void ValidateStorageAccountAssociation(string azureStorageAccount)
68-
{
69-
if (string.IsNullOrEmpty(azureStorageAccount))
70-
{
71-
throw new InvalidOperationException(
72-
string.Format(
73-
Properties.Resources.StorageAccountNameIsNotValid));
74-
}
75-
76-
bool associatedAccount = false;
77-
78-
if (!associatedAccount)
79-
{
80-
throw new InvalidOperationException(
81-
string.Format(
82-
Properties.Resources.StorageIsNotAssociatedWithTheAccount,
83-
azureStorageAccount));
84-
}
85-
}
86-
8766
/// <summary>
8867
/// Converts the Parameter set string of Replication Frequency in seconds to UShort.
8968
/// </summary>
@@ -126,5 +105,66 @@ public static void ValidateReplicationStartTime(TimeSpan? timeSpan)
126105
string.Format(Properties.Resources.ReplicationStartTimeInvalid));
127106
}
128107
}
108+
109+
/// <summary>
110+
/// Validates whether the storage belongs to the currently logged account or not.
111+
/// </summary>
112+
/// <param name="azureSubscription">Subscription ID</param>
113+
/// <param name="azureStorageAccount">Storage Account details</param>
114+
/// <param name="vaultLocation">Current Vault Location</param>
115+
/// <returns>Validation successful</returns>
116+
public bool ValidateStorageAccountAssociation(
117+
string azureSubscription,
118+
string azureStorageAccount,
119+
string vaultLocation)
120+
{
121+
if (string.IsNullOrEmpty(azureSubscription))
122+
{
123+
throw new InvalidOperationException(
124+
string.Format(
125+
Properties.Resources.SubscriptionIdIsNotValid));
126+
}
127+
128+
if (string.IsNullOrEmpty(azureStorageAccount))
129+
{
130+
throw new InvalidOperationException(
131+
string.Format(
132+
Properties.Resources.StorageAccountNameIsNotValid));
133+
}
134+
135+
bool associatedAccount = false;
136+
StorageAccountListResponse azureStorageListResponse = null;
137+
StorageAccountListResponse.StorageAccount currentStorageAccount = null;
138+
139+
try
140+
{
141+
azureStorageListResponse =
142+
this.GetSiteRecoveryClient().Storages.ListAzureStorages(azureSubscription);
143+
}
144+
catch (Exception)
145+
{
146+
return false;
147+
}
148+
149+
foreach (var storage in azureStorageListResponse.StorageAccounts)
150+
{
151+
if (string.Compare(
152+
azureStorageAccount,
153+
storage.Name,
154+
StringComparison.OrdinalIgnoreCase) == 0)
155+
{
156+
associatedAccount = true;
157+
currentStorageAccount = storage;
158+
break;
159+
}
160+
}
161+
162+
if (!associatedAccount)
163+
{
164+
return false;
165+
}
166+
167+
return true;
168+
}
129169
}
130170
}

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Properties/Resources.Designer.cs

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

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Properties/Resources.resx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,6 @@ ClientRequestId: {3}</value>
206206
<data name="VaultSettingsGenerationUnSupported" xml:space="preserve">
207207
<value>Cannot generate vault settings file for this vault. Download it from the Azure Portal.</value>
208208
</data>
209-
<data name="StorageIsNotAssociatedWithTheAccount" xml:space="preserve">
210-
<value>Storage account {0} is not associated with the account</value>
211-
</data>
212209
<data name="VaultCreationSuccessMessage" xml:space="preserve">
213210
<value>Vault has been created</value>
214211
</data>
@@ -242,4 +239,15 @@ ClientRequestId: {3}</value>
242239
<data name="VaultNotFound" xml:space="preserve">
243240
<value>Vault {0} is not associated with the given subscription.</value>
244241
</data>
242+
<data name="NewProtectionProfileObjectWhatIfMessage" xml:space="preserve">
243+
<value>Creates a new in-memory protection profile association object.</value>
244+
</data>
245+
<data name="ValidationUnsuccessfulWarning" xml:space="preserve">
246+
<value>Could not validate the storage account and subscription given.
247+
Are you sure you want to continue {0}?</value>
248+
</data>
249+
<data name="StorageIsNotInTheSameLocationAsVault" xml:space="preserve">
250+
<value>Storage account given is in {0} whereas the vault is in {1}.
251+
Please provide a storage account with the same location as that of the vault.</value>
252+
</data>
245253
</root>

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

Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using System.Management.Automation;
1818
using Microsoft.Azure.Commands.RecoveryServices.SiteRecovery;
1919
using Microsoft.Azure.Portal.RecoveryServices.Models.Common;
20+
using Microsoft.WindowsAzure.Commands.Common.Properties;
2021
using Microsoft.WindowsAzure.Management.SiteRecovery.Models;
2122
using Microsoft.WindowsAzure.Management.Storage.Models;
2223

@@ -29,8 +30,20 @@ namespace Microsoft.Azure.Commands.RecoveryServices
2930
[OutputType(typeof(ASRProtectionProfile))]
3031
public class CreateAzureSiteRecoveryProtectionProfileObject : RecoveryServicesCmdletBase
3132
{
33+
/// <summary>
34+
/// Holds Name (if passed) of the protection profile object.
35+
/// </summary>
36+
private string targetName = string.Empty;
37+
3238
#region Parameters
3339

40+
/// <summary>
41+
/// Gets or sets Name of the Protection Profile.
42+
/// </summary>
43+
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToEnterprise)]
44+
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToAzure)]
45+
public string Name { get; set; }
46+
3447
/// <summary>
3548
/// Gets or sets Replication Provider of the Protection Profile.
3649
/// </summary>
@@ -66,13 +79,6 @@ public class CreateAzureSiteRecoveryProtectionProfileObject : RecoveryServicesCm
6679
[ValidateNotNullOrEmpty]
6780
public string RecoveryAzureStorageAccount { get; set; }
6881

69-
/// <summary>
70-
/// Gets or sets a value indicating whether stored data needs to be encrypted.
71-
/// </summary>
72-
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToAzure)]
73-
[DefaultValue(false)]
74-
public SwitchParameter EncryptStoredData { get; set; }
75-
7682
/// <summary>
7783
/// Gets or sets Replication Frequency of the Protection Profile in seconds.
7884
/// </summary>
@@ -143,6 +149,12 @@ public class CreateAzureSiteRecoveryProtectionProfileObject : RecoveryServicesCm
143149
[DefaultValue(false)]
144150
public SwitchParameter AllowReplicaDeletion { get; set; }
145151

152+
/// <summary>
153+
/// Gets or sets switch parameter. On passing, command does not ask for confirmation.
154+
/// </summary>
155+
[Parameter(Mandatory = false)]
156+
public SwitchParameter Force { get; set; }
157+
146158
#endregion Parameters
147159

148160
/// <summary>
@@ -183,32 +195,61 @@ protected override void StopProcessing()
183195
/// </summary>
184196
private void EnterpriseToAzureProtectionProfileObject()
185197
{
186-
if (string.Compare(this.ReplicationProvider, Constants.HyperVReplicaAzure, StringComparison.OrdinalIgnoreCase) != 0)
198+
if (string.Compare(
199+
this.ReplicationProvider,
200+
Constants.HyperVReplicaAzure,
201+
StringComparison.OrdinalIgnoreCase) != 0)
187202
{
188203
throw new InvalidOperationException(
189204
string.Format(
190205
Properties.Resources.IncorrectReplicationProvider,
191206
this.ReplicationProvider));
192207
}
193208

194-
// Verify whether the subscription is associated with the account or not.
195-
PSRecoveryServicesClientHelper.ValidateSubscriptionAccountAssociation(this.RecoveryAzureSubscription);
196-
197209
// Verify whether the storage account is associated with the subscription or not.
198-
//// PSRecoveryServicesClientHelper.ValidateStorageAccountAssociation(this.RecoveryAzureStorageAccount);
210+
bool validationSuccessful = RecoveryServicesClient.ValidateStorageAccountAssociation(
211+
this.RecoveryAzureSubscription,
212+
this.RecoveryAzureStorageAccount,
213+
this.GetCurrentValutLocation());
199214

200-
PSRecoveryServicesClientHelper.ValidateReplicationStartTime(this.ReplicationStartTime);
215+
if (!validationSuccessful)
216+
{
217+
this.WriteWarning(string.Format(Resources.StorageAccountValidationUnsuccessful));
218+
219+
this.ConfirmAction(
220+
this.Force.IsPresent,
221+
string.Format(Properties.Resources.ValidationUnsuccessfulWarning, this.targetName),
222+
string.Format(Properties.Resources.NewProtectionProfileObjectWhatIfMessage),
223+
this.targetName,
224+
new Action(this.ProceedToCreateProtectionProfileObject));
225+
}
226+
else
227+
{
228+
this.ProceedToCreateProtectionProfileObject();
229+
}
230+
}
231+
232+
/// <summary>
233+
/// Proceeds to Create an E2A Protection Profile Object after all the validations are done.
234+
/// </summary>
235+
private void ProceedToCreateProtectionProfileObject()
236+
{
237+
PSRecoveryServicesClient.ValidateReplicationStartTime(this.ReplicationStartTime);
201238

202-
ushort replicationFrequencyInSeconds = PSRecoveryServicesClientHelper.ConvertReplicationFrequencyToUshort(this.ReplicationFrequencyInSeconds);
239+
ushort replicationFrequencyInSeconds =
240+
PSRecoveryServicesClient.ConvertReplicationFrequencyToUshort(
241+
this.ReplicationFrequencyInSeconds);
203242

204243
ASRProtectionProfile protectionProfile = new ASRProtectionProfile()
205244
{
245+
Name = this.Name,
206246
ReplicationProvider = this.ReplicationProvider,
207247
HyperVReplicaAzureProviderSettingsObject = new HyperVReplicaAzureProviderSettings()
208248
{
209249
RecoveryAzureSubscription = this.RecoveryAzureSubscription,
210250
RecoveryAzureStorageAccountName = this.RecoveryAzureStorageAccount,
211-
EncryptStoredData = this.EncryptStoredData,
251+
//// Currently Data Encryption is not supported.
252+
EncryptStoredData = false,
212253
ReplicationFrequencyInSeconds = replicationFrequencyInSeconds,
213254
RecoveryPoints = this.RecoveryPoints,
214255
ApplicationConsistentSnapshotFrequencyInHours = this.ApplicationConsistentSnapshotFrequencyInHours,
@@ -233,12 +274,13 @@ private void EnterpriseToEnterpriseProtectionProfileObject()
233274
this.ReplicationProvider));
234275
}
235276

236-
PSRecoveryServicesClientHelper.ValidateReplicationStartTime(this.ReplicationStartTime);
277+
PSRecoveryServicesClient.ValidateReplicationStartTime(this.ReplicationStartTime);
237278

238-
ushort replicationFrequencyInSeconds = PSRecoveryServicesClientHelper.ConvertReplicationFrequencyToUshort(this.ReplicationFrequencyInSeconds);
279+
ushort replicationFrequencyInSeconds = PSRecoveryServicesClient.ConvertReplicationFrequencyToUshort(this.ReplicationFrequencyInSeconds);
239280

240281
ASRProtectionProfile protectionProfile = new ASRProtectionProfile()
241282
{
283+
Name = this.Name,
242284
ReplicationProvider = this.ReplicationProvider,
243285
HyperVReplicaAzureProviderSettingsObject = null,
244286
HyperVReplicaProviderSettingsObject = new HyperVReplicaProviderSettings()

0 commit comments

Comments
 (0)