Skip to content

Commit 4b13641

Browse files
committed
Updating default parameter set
And updating the values for update protection profile cmdlet
1 parent cf27fe9 commit 4b13641

File tree

1 file changed

+96
-21
lines changed

1 file changed

+96
-21
lines changed

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

Lines changed: 96 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace Microsoft.Azure.Commands.RecoveryServices
2525
/// Updates Azure Site Recovery Protection Profile.
2626
/// Protection profile must be associated with the protection container.
2727
/// </summary>
28-
[Cmdlet(VerbsCommon.Set, "AzureSiteRecoveryProtectionProfile", DefaultParameterSetName = ASRParameterSets.EnterpriseToEnterprise)]
28+
[Cmdlet(VerbsCommon.Set, "AzureSiteRecoveryProtectionProfile", DefaultParameterSetName = ASRParameterSets.EnterpriseToAzure)]
2929
[OutputType(typeof(ASRJob))]
3030
public class SetAzureSiteRecoveryProtectionProfile : RecoveryServicesCmdletBase
3131
{
@@ -101,7 +101,7 @@ public class SetAzureSiteRecoveryProtectionProfile : RecoveryServicesCmdletBase
101101
/// </summary>
102102
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToEnterprise)]
103103
[ValidateNotNullOrEmpty]
104-
public int? ReplicationPort { get; set; }
104+
public ushort? ReplicationPort { get; set; }
105105

106106
/// <summary>
107107
/// Gets or sets the Replication Port of the Protection Profile.
@@ -182,21 +182,49 @@ private void EnterpriseToAzureUpdate()
182182

183183
PSRecoveryServicesClient.ValidateReplicationStartTime(this.ReplicationStartTime);
184184

185-
ushort replicationFrequencyInSeconds = PSRecoveryServicesClient.ConvertReplicationFrequencyToUshort(this.ReplicationFrequencyInSeconds);
186-
185+
// The user should always retrieve the protection profile object before passing it on to the update cmdlet.
186+
// Otherwise old data might get updated as new
187+
// How do we prevent the user from modifying the object itself?
187188
HyperVReplicaAzureProtectionProfileInput hyperVReplicaAzureProtectionProfileInput
188189
= new HyperVReplicaAzureProtectionProfileInput()
189190
{
190-
ApplicationConsistentSnapshotFrequencyInHours = this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.ApplicationConsistentSnapshotFrequencyInHours,
191-
ReplicationInterval = this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.ReplicationFrequencyInSeconds,
192-
OnlineReplicationStartTime = this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.ReplicationStartTime,
193-
RecoveryPointHistoryDuration = this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.RecoveryPoints,
194-
EncryptionEnabled = this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.EncryptStoredData
191+
ApplicationConsistentSnapshotFrequencyInHours =
192+
this.ApplicationConsistentSnapshotFrequencyInHours.HasValue
193+
? this.ApplicationConsistentSnapshotFrequencyInHours.GetValueOrDefault()
194+
: this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.ApplicationConsistentSnapshotFrequencyInHours,
195+
OnlineReplicationStartTime =
196+
this.ReplicationStartTime.HasValue
197+
? this.ReplicationStartTime.GetValueOrDefault()
198+
: this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.ReplicationStartTime,
199+
RecoveryPointHistoryDuration =
200+
this.RecoveryPoints.HasValue
201+
? this.RecoveryPoints.GetValueOrDefault()
202+
: this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.RecoveryPoints,
195203
};
196204

205+
ushort replicationFrequencyInSeconds =
206+
PSRecoveryServicesClient.ConvertReplicationFrequencyToUshort(this.ReplicationFrequencyInSeconds);
207+
if (string.IsNullOrEmpty(this.ReplicationFrequencyInSeconds))
208+
{
209+
hyperVReplicaAzureProtectionProfileInput.ReplicationInterval
210+
= this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.ReplicationFrequencyInSeconds;
211+
}
212+
else
213+
{
214+
hyperVReplicaAzureProtectionProfileInput.ReplicationInterval = replicationFrequencyInSeconds;
215+
}
216+
197217
var storageAccount = new CustomerStorageAccount();
198-
storageAccount.StorageAccountName = this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.RecoveryAzureStorageAccountName;
199218
storageAccount.SubscriptionId = this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.RecoveryAzureSubscription;
219+
if (string.IsNullOrEmpty(this.RecoveryAzureStorageAccount))
220+
{
221+
storageAccount.StorageAccountName
222+
= this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.RecoveryAzureStorageAccountName;
223+
}
224+
else
225+
{
226+
storageAccount.StorageAccountName = this.RecoveryAzureStorageAccount;
227+
}
200228

201229
hyperVReplicaAzureProtectionProfileInput.StorageAccounts = new System.Collections.Generic.List<CustomerStorageAccount>();
202230
hyperVReplicaAzureProtectionProfileInput.StorageAccounts.Add(storageAccount);
@@ -225,24 +253,71 @@ private void EnterpriseToEnterpriseUpdate()
225253
this.ProtectionProfile.ReplicationProvider));
226254
}
227255

256+
string replicationMethod = null;
257+
if (string.IsNullOrEmpty(this.ReplicationMethod))
258+
{
259+
replicationMethod
260+
= this.ProtectionProfile.HyperVReplicaProviderSettingsObject.ReplicationMethod;
261+
}
262+
else
263+
{
264+
replicationMethod = this.ReplicationMethod;
265+
}
266+
267+
string authentication = null;
268+
if (string.IsNullOrEmpty(this.Authentication))
269+
{
270+
authentication
271+
= this.ProtectionProfile.HyperVReplicaProviderSettingsObject.Authentication;
272+
}
273+
else
274+
{
275+
authentication = this.Authentication;
276+
}
277+
228278
HyperVReplicaProtectionProfileInput hyperVReplicaProtectionProfileInput
229279
= new HyperVReplicaProtectionProfileInput()
230280
{
231-
OnlineReplicationStartTime = this.ProtectionProfile.HyperVReplicaProviderSettingsObject.ReplicationStartTime,
232-
CompressionEnabled = this.ProtectionProfile.HyperVReplicaProviderSettingsObject.CompressionEnabled,
233-
OnlineReplicationMethod = (string.Compare(this.ProtectionProfile.HyperVReplicaProviderSettingsObject.ReplicationMethod, Constants.OnlineReplicationMethod, StringComparison.OrdinalIgnoreCase) == 1) ? true : false,
234-
RecoveryPoints = this.ProtectionProfile.HyperVReplicaProviderSettingsObject.RecoveryPoints,
235-
ReplicationPort = this.ProtectionProfile.HyperVReplicaProviderSettingsObject.ReplicationPort,
236-
AllowReplicaDeletion = this.ProtectionProfile.HyperVReplicaProviderSettingsObject.AllowReplicaDeletion,
237-
AllowedAuthenticationType = (ushort)((string.Compare(this.ProtectionProfile.HyperVReplicaProviderSettingsObject.Authentication, Constants.AuthenticationTypeKerberos, StringComparison.OrdinalIgnoreCase) == 0) ? 1 : 2),
281+
ApplicationConsistentSnapshotFrequencyInHours =
282+
this.ApplicationConsistentSnapshotFrequencyInHours.HasValue
283+
? this.ApplicationConsistentSnapshotFrequencyInHours.GetValueOrDefault()
284+
: this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.ApplicationConsistentSnapshotFrequencyInHours,
285+
OnlineReplicationStartTime =
286+
this.ReplicationStartTime.HasValue
287+
? this.ReplicationStartTime.GetValueOrDefault()
288+
: this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.ReplicationStartTime,
289+
RecoveryPoints =
290+
this.RecoveryPoints.HasValue
291+
? this.RecoveryPoints.GetValueOrDefault()
292+
: this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.RecoveryPoints,
293+
CompressionEnabled =
294+
this.CompressionEnabled.HasValue
295+
? (bool)this.CompressionEnabled.GetValueOrDefault()
296+
: this.ProtectionProfile.HyperVReplicaProviderSettingsObject.CompressionEnabled,
297+
OnlineReplicationMethod =
298+
(string.Compare(replicationMethod, Constants.OnlineReplicationMethod, StringComparison.OrdinalIgnoreCase) == 0) ? true : false,
299+
ReplicationPort =
300+
this.ReplicationPort.HasValue
301+
? this.ReplicationPort.GetValueOrDefault()
302+
: this.ProtectionProfile.HyperVReplicaProviderSettingsObject.ReplicationPort,
303+
AllowReplicaDeletion =
304+
this.AllowReplicaDeletion.HasValue
305+
? (bool)this.AllowReplicaDeletion.GetValueOrDefault()
306+
: this.ProtectionProfile.HyperVReplicaProviderSettingsObject.AllowReplicaDeletion,
307+
AllowedAuthenticationType = (ushort)((string.Compare(authentication, Constants.AuthenticationTypeKerberos, StringComparison.OrdinalIgnoreCase) == 0) ? 1 : 2),
238308
};
239309

240-
if (this.ApplicationConsistentSnapshotFrequencyInHours.HasValue)
310+
ushort replicationFrequencyInSeconds =
311+
PSRecoveryServicesClient.ConvertReplicationFrequencyToUshort(this.ReplicationFrequencyInSeconds);
312+
if (string.IsNullOrEmpty(this.ReplicationFrequencyInSeconds))
241313
{
242-
hyperVReplicaProtectionProfileInput.ApplicationConsistentSnapshotFrequencyInHours = this.ApplicationConsistentSnapshotFrequencyInHours.Value;
314+
hyperVReplicaProtectionProfileInput.ReplicationFrequencyInSeconds
315+
= this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.ReplicationFrequencyInSeconds;
316+
}
317+
else
318+
{
319+
hyperVReplicaProtectionProfileInput.ReplicationFrequencyInSeconds = replicationFrequencyInSeconds;
243320
}
244-
245-
hyperVReplicaProtectionProfileInput.ReplicationFrequencyInSeconds = PSRecoveryServicesClient.ConvertReplicationFrequencyToUshort(this.ReplicationFrequencyInSeconds);
246321

247322
UpdateProtectionProfileInput updateProtectionProfileInput =
248323
new UpdateProtectionProfileInput(

0 commit comments

Comments
 (0)