17
17
using System . Management . Automation ;
18
18
using Microsoft . Azure . Commands . RecoveryServices . SiteRecovery ;
19
19
using Microsoft . Azure . Portal . RecoveryServices . Models . Common ;
20
+ using Microsoft . WindowsAzure . Commands . Common . Properties ;
20
21
using Microsoft . WindowsAzure . Management . SiteRecovery . Models ;
21
22
using Microsoft . WindowsAzure . Management . Storage . Models ;
22
23
@@ -29,8 +30,20 @@ namespace Microsoft.Azure.Commands.RecoveryServices
29
30
[ OutputType ( typeof ( ASRProtectionProfile ) ) ]
30
31
public class CreateAzureSiteRecoveryProtectionProfileObject : RecoveryServicesCmdletBase
31
32
{
33
+ /// <summary>
34
+ /// Holds Name (if passed) of the protection profile object.
35
+ /// </summary>
36
+ private string targetName = string . Empty ;
37
+
32
38
#region Parameters
33
39
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
+
34
47
/// <summary>
35
48
/// Gets or sets Replication Provider of the Protection Profile.
36
49
/// </summary>
@@ -66,13 +79,6 @@ public class CreateAzureSiteRecoveryProtectionProfileObject : RecoveryServicesCm
66
79
[ ValidateNotNullOrEmpty ]
67
80
public string RecoveryAzureStorageAccount { get ; set ; }
68
81
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
-
76
82
/// <summary>
77
83
/// Gets or sets Replication Frequency of the Protection Profile in seconds.
78
84
/// </summary>
@@ -143,6 +149,12 @@ public class CreateAzureSiteRecoveryProtectionProfileObject : RecoveryServicesCm
143
149
[ DefaultValue ( false ) ]
144
150
public SwitchParameter AllowReplicaDeletion { get ; set ; }
145
151
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
+
146
158
#endregion Parameters
147
159
148
160
/// <summary>
@@ -183,32 +195,61 @@ protected override void StopProcessing()
183
195
/// </summary>
184
196
private void EnterpriseToAzureProtectionProfileObject ( )
185
197
{
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 )
187
202
{
188
203
throw new InvalidOperationException (
189
204
string . Format (
190
205
Properties . Resources . IncorrectReplicationProvider ,
191
206
this . ReplicationProvider ) ) ;
192
207
}
193
208
194
- // Verify whether the subscription is associated with the account or not.
195
- PSRecoveryServicesClientHelper . ValidateSubscriptionAccountAssociation ( this . RecoveryAzureSubscription ) ;
196
-
197
209
// 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 ( ) ) ;
199
214
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 ) ;
201
238
202
- ushort replicationFrequencyInSeconds = PSRecoveryServicesClientHelper . ConvertReplicationFrequencyToUshort ( this . ReplicationFrequencyInSeconds ) ;
239
+ ushort replicationFrequencyInSeconds =
240
+ PSRecoveryServicesClient . ConvertReplicationFrequencyToUshort (
241
+ this . ReplicationFrequencyInSeconds ) ;
203
242
204
243
ASRProtectionProfile protectionProfile = new ASRProtectionProfile ( )
205
244
{
245
+ Name = this . Name ,
206
246
ReplicationProvider = this . ReplicationProvider ,
207
247
HyperVReplicaAzureProviderSettingsObject = new HyperVReplicaAzureProviderSettings ( )
208
248
{
209
249
RecoveryAzureSubscription = this . RecoveryAzureSubscription ,
210
250
RecoveryAzureStorageAccountName = this . RecoveryAzureStorageAccount ,
211
- EncryptStoredData = this . EncryptStoredData ,
251
+ //// Currently Data Encryption is not supported.
252
+ EncryptStoredData = false ,
212
253
ReplicationFrequencyInSeconds = replicationFrequencyInSeconds ,
213
254
RecoveryPoints = this . RecoveryPoints ,
214
255
ApplicationConsistentSnapshotFrequencyInHours = this . ApplicationConsistentSnapshotFrequencyInHours ,
@@ -233,12 +274,13 @@ private void EnterpriseToEnterpriseProtectionProfileObject()
233
274
this . ReplicationProvider ) ) ;
234
275
}
235
276
236
- PSRecoveryServicesClientHelper . ValidateReplicationStartTime ( this . ReplicationStartTime ) ;
277
+ PSRecoveryServicesClient . ValidateReplicationStartTime ( this . ReplicationStartTime ) ;
237
278
238
- ushort replicationFrequencyInSeconds = PSRecoveryServicesClientHelper . ConvertReplicationFrequencyToUshort ( this . ReplicationFrequencyInSeconds ) ;
279
+ ushort replicationFrequencyInSeconds = PSRecoveryServicesClient . ConvertReplicationFrequencyToUshort ( this . ReplicationFrequencyInSeconds ) ;
239
280
240
281
ASRProtectionProfile protectionProfile = new ASRProtectionProfile ( )
241
282
{
283
+ Name = this . Name ,
242
284
ReplicationProvider = this . ReplicationProvider ,
243
285
HyperVReplicaAzureProviderSettingsObject = null ,
244
286
HyperVReplicaProviderSettingsObject = new HyperVReplicaProviderSettings ( )
0 commit comments