Skip to content

Commit 44de337

Browse files
committed
Merge pull request #25 from AsrOneSdk/neha-dev
Adding help content for the cmdlets.
2 parents e368229 + 32418ce commit 44de337

9 files changed

+934
-96
lines changed

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Commands.RecoveryServices.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@
6363
<SpecificVersion>False</SpecificVersion>
6464
<HintPath>..\..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll</HintPath>
6565
</Reference>
66+
<Reference Include="Microsoft.WindowsAzure.Commands.ServiceManagement">
67+
<HintPath>..\..\..\Package\Debug\ServiceManagement\Azure\Compute\Microsoft.WindowsAzure.Commands.ServiceManagement.dll</HintPath>
68+
</Reference>
6669
<Reference Include="Microsoft.WindowsAzure.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
6770
<SpecificVersion>False</SpecificVersion>
6871
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Common.1.4.0\lib\net45\Microsoft.WindowsAzure.Common.dll</HintPath>

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

Lines changed: 805 additions & 51 deletions
Large diffs are not rendered by default.

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

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@
1414

1515
using System;
1616
using System.Collections.Generic;
17+
using System.Collections.ObjectModel;
18+
using System.Management.Automation;
1719
using Microsoft.WindowsAzure;
1820
using Microsoft.WindowsAzure.Commands.Common;
1921
using Microsoft.WindowsAzure.Commands.Common.Models;
22+
using Microsoft.WindowsAzure.Commands.ServiceManagement.Model;
2023
using Microsoft.WindowsAzure.Management.Storage;
2124
using Microsoft.WindowsAzure.Management.Storage.Models;
2225

@@ -78,17 +81,22 @@ public static void ValidateStorageAccountAssociation(string azureStorageAccount)
7881

7982
bool associatedAccount = false;
8083

81-
SubscriptionCloudCredentials creds
82-
= AzureSession.AuthenticationFactory.GetSubscriptionCloudCredentials(AzureSession.CurrentContext);
83-
StorageManagementClient storageManagementClient = new StorageManagementClient(creds);
84-
85-
StorageAccountListResponse storageAccounts = storageManagementClient.StorageAccounts.List();
86-
foreach (StorageAccount storage in storageAccounts)
84+
using (System.Management.Automation.PowerShell powerShellInstance = System.Management.Automation.PowerShell.Create())
8785
{
88-
if (azureStorageAccount.Equals(storage.Name, StringComparison.OrdinalIgnoreCase))
86+
powerShellInstance.AddCommand("Get-AzureStorageAccount");
87+
Collection<PSObject> powershellOutput = powerShellInstance.Invoke();
88+
89+
foreach (var storage in powershellOutput)
8990
{
90-
associatedAccount = true;
91-
break;
91+
if (storage.BaseObject is StorageServicePropertiesOperationContext)
92+
{
93+
StorageServicePropertiesOperationContext storageAccount = (StorageServicePropertiesOperationContext)storage.BaseObject;
94+
if (azureStorageAccount.Equals(storageAccount.StorageAccountName, StringComparison.OrdinalIgnoreCase))
95+
{
96+
associatedAccount = true;
97+
break;
98+
}
99+
}
92100
}
93101
}
94102

@@ -100,5 +108,48 @@ SubscriptionCloudCredentials creds
100108
azureStorageAccount));
101109
}
102110
}
111+
112+
/// <summary>
113+
/// Converts the Parameter set string of Replication Frequency in seconds to UShort.
114+
/// </summary>
115+
/// <param name="replicationFrequencyString">Replication frequency in seconds.</param>
116+
/// <returns>A UShort corresponding to the value.</returns>
117+
public static ushort ConvertReplicationFrequencyToUshort(string replicationFrequencyString)
118+
{
119+
if (replicationFrequencyString == null)
120+
{
121+
return 0;
122+
}
123+
124+
ushort replicationFrequency;
125+
126+
if (!ushort.TryParse(replicationFrequencyString, out replicationFrequency))
127+
{
128+
throw new InvalidOperationException(
129+
string.Format(
130+
Properties.Resources.InvalidReplicationFrequency,
131+
replicationFrequencyString));
132+
}
133+
134+
return replicationFrequency;
135+
}
136+
137+
/// <summary>
138+
/// Validates if the time span object has a valid value.
139+
/// </summary>
140+
/// <param name="timeSpan">Time span object to be validated</param>
141+
public static void ValidateReplicationStartTime(TimeSpan? timeSpan)
142+
{
143+
if (timeSpan == null)
144+
{
145+
return;
146+
}
147+
148+
if (TimeSpan.Compare(timeSpan.Value, new TimeSpan(24, 0, 0)) == 1)
149+
{
150+
throw new InvalidOperationException(
151+
string.Format(Properties.Resources.ReplicationStartTimeInvalid));
152+
}
153+
}
103154
}
104155
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,7 @@ ClientRequestId: {3}</value>
224224
<data name="IncorrectReplicationProvider" xml:space="preserve">
225225
<value>Replication Provider {0} entered invalid for the current set of parameters.</value>
226226
</data>
227+
<data name="InvalidReplicationFrequency" xml:space="preserve">
228+
<value>Replication Frequency {0} is invalid</value>
229+
</data>
227230
</root>

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

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace Microsoft.Azure.Commands.RecoveryServices
2525
/// <summary>
2626
/// Creates Azure Site Recovery Protection Profile object in memory.
2727
/// </summary>
28-
[Cmdlet(VerbsCommon.New, "AzureSiteRecoveryProtectionProfile", DefaultParameterSetName = ASRParameterSets.EnterpriseToEnterprise)]
28+
[Cmdlet(VerbsCommon.New, "AzureSiteRecoveryProtectionProfileObject", DefaultParameterSetName = ASRParameterSets.EnterpriseToEnterprise)]
2929
[OutputType(typeof(ASRProtectionProfile))]
3030
public class CreateAzureSiteRecoveryProtectionProfileObject : RecoveryServicesCmdletBase
3131
{
@@ -50,7 +50,6 @@ public class CreateAzureSiteRecoveryProtectionProfileObject : RecoveryServicesCm
5050
[ValidateSet(
5151
Constants.OnlineReplicationMethod,
5252
Constants.OfflineReplicationMethod)]
53-
[DefaultValue(Constants.OnlineReplicationMethod)]
5453
public string ReplicationMethod { get; set; }
5554

5655
/// <summary>
@@ -80,7 +79,11 @@ public class CreateAzureSiteRecoveryProtectionProfileObject : RecoveryServicesCm
8079
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToEnterprise)]
8180
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToAzure)]
8281
[ValidateNotNullOrEmpty]
83-
public ushort ReplicationFrequencyInSeconds { get; set; }
82+
[ValidateSet(
83+
Constants.Thirty,
84+
Constants.ThreeHundred,
85+
Constants.NineHundred)]
86+
public string ReplicationFrequencyInSeconds { get; set; }
8487

8588
/// <summary>
8689
/// Gets or sets Recovery Points of the Protection Profile.
@@ -112,7 +115,6 @@ public class CreateAzureSiteRecoveryProtectionProfileObject : RecoveryServicesCm
112115
/// </summary>
113116
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToEnterprise)]
114117
[ValidateNotNullOrEmpty]
115-
[DefaultValue(0)]
116118
public ushort ReplicationPort { get; set; }
117119

118120
/// <summary>
@@ -131,7 +133,6 @@ public class CreateAzureSiteRecoveryProtectionProfileObject : RecoveryServicesCm
131133
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToEnterprise)]
132134
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToAzure)]
133135
[ValidateNotNullOrEmpty]
134-
[DefaultValue(null)]
135136
public TimeSpan? ReplicationStartTime { get; set; }
136137

137138
/// <summary>
@@ -151,12 +152,12 @@ public override void ExecuteCmdlet()
151152
{
152153
try
153154
{
154-
switch (this.ReplicationProvider)
155+
switch (this.ParameterSetName)
155156
{
156-
case Constants.HyperVReplica:
157+
case ASRParameterSets.EnterpriseToEnterprise:
157158
this.EnterpriseToEnterpriseProtectionProfileObject();
158159
break;
159-
case Constants.HyperVReplicaAzure:
160+
case ASRParameterSets.EnterpriseToAzure:
160161
this.EnterpriseToAzureProtectionProfileObject();
161162
break;
162163
}
@@ -182,13 +183,23 @@ protected override void StopProcessing()
182183
/// </summary>
183184
private void EnterpriseToAzureProtectionProfileObject()
184185
{
185-
//// Verify whether the storage account is associated with the account or not.
186-
//// PSRecoveryServicesClientHelper.ValidateStorageAccountAssociation(this.RecoveryAzureStorageAccount);
186+
if (string.Compare(this.ReplicationProvider, Constants.HyperVReplicaAzure, StringComparison.OrdinalIgnoreCase) != 0)
187+
{
188+
throw new InvalidOperationException(
189+
string.Format(
190+
Properties.Resources.IncorrectReplicationProvider,
191+
this.ReplicationProvider));
192+
}
187193

188194
// Verify whether the subscription is associated with the account or not.
189195
PSRecoveryServicesClientHelper.ValidateSubscriptionAccountAssociation(this.RecoveryAzureSubscription);
190196

191-
this.ValidateReplicationStartTime(this.ReplicationStartTime);
197+
// Verify whether the storage account is associated with the subscription or not.
198+
//// PSRecoveryServicesClientHelper.ValidateStorageAccountAssociation(this.RecoveryAzureStorageAccount);
199+
200+
PSRecoveryServicesClientHelper.ValidateReplicationStartTime(this.ReplicationStartTime);
201+
202+
ushort replicationFrequencyInSeconds = PSRecoveryServicesClientHelper.ConvertReplicationFrequencyToUshort(this.ReplicationFrequencyInSeconds);
192203

193204
ASRProtectionProfile protectionProfile = new ASRProtectionProfile()
194205
{
@@ -198,7 +209,7 @@ private void EnterpriseToAzureProtectionProfileObject()
198209
RecoveryAzureSubscription = this.RecoveryAzureSubscription,
199210
RecoveryAzureStorageAccountName = this.RecoveryAzureStorageAccount,
200211
EncryptStoredData = this.EncryptStoredData,
201-
ReplicationFrequencyInSeconds = this.ReplicationFrequencyInSeconds,
212+
ReplicationFrequencyInSeconds = replicationFrequencyInSeconds,
202213
RecoveryPoints = this.RecoveryPoints,
203214
ApplicationConsistentSnapshotFrequencyInHours = this.ApplicationConsistentSnapshotFrequencyInHours,
204215
ReplicationStartTime = this.ReplicationStartTime,
@@ -210,29 +221,21 @@ private void EnterpriseToAzureProtectionProfileObject()
210221
}
211222

212223
/// <summary>
213-
/// Validates if the time span object has a valid value.
224+
/// Creates an E2E Protection Profile object
214225
/// </summary>
215-
/// <param name="timeSpan">Time span object to be validated</param>
216-
private void ValidateReplicationStartTime(TimeSpan? timeSpan)
226+
private void EnterpriseToEnterpriseProtectionProfileObject()
217227
{
218-
if (timeSpan == null)
219-
{
220-
return;
221-
}
222-
223-
if (TimeSpan.Compare(timeSpan.Value, new TimeSpan(24, 0, 0)) == 1)
228+
if (string.Compare(this.ReplicationProvider, Constants.HyperVReplica, StringComparison.OrdinalIgnoreCase) != 0)
224229
{
225230
throw new InvalidOperationException(
226-
string.Format(Properties.Resources.ReplicationStartTimeInvalid));
231+
string.Format(
232+
Properties.Resources.IncorrectReplicationProvider,
233+
this.ReplicationProvider));
227234
}
228-
}
229235

230-
/// <summary>
231-
/// Creates an E2E Protection Profile object
232-
/// </summary>
233-
private void EnterpriseToEnterpriseProtectionProfileObject()
234-
{
235-
this.ValidateReplicationStartTime(this.ReplicationStartTime);
236+
PSRecoveryServicesClientHelper.ValidateReplicationStartTime(this.ReplicationStartTime);
237+
238+
ushort replicationFrequencyInSeconds = PSRecoveryServicesClientHelper.ConvertReplicationFrequencyToUshort(this.ReplicationFrequencyInSeconds);
236239

237240
ASRProtectionProfile protectionProfile = new ASRProtectionProfile()
238241
{
@@ -241,7 +244,7 @@ private void EnterpriseToEnterpriseProtectionProfileObject()
241244
HyperVReplicaProviderSettingsObject = new HyperVReplicaProviderSettings()
242245
{
243246
ReplicationMethod = this.ReplicationMethod,
244-
ReplicationFrequencyInSeconds = this.ReplicationFrequencyInSeconds,
247+
ReplicationFrequencyInSeconds = replicationFrequencyInSeconds,
245248
RecoveryPoints = this.RecoveryPoints,
246249
ApplicationConsistentSnapshotFrequencyInHours = this.ApplicationConsistentSnapshotFrequencyInHours,
247250
CompressionEnabled = this.CompressionEnabled,

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public class StartAzureSiteRecoveryProtectionProfileAssociationJob : RecoverySer
3737
/// <summary>
3838
/// Gets or sets Protection Profile object.
3939
/// </summary>
40-
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToEnterprise, Mandatory = true)]
41-
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToAzure, Mandatory = true)]
40+
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToEnterprise, Mandatory = true, ValueFromPipeline = true)]
41+
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToAzure, Mandatory = true, ValueFromPipeline = true)]
4242
[ValidateNotNullOrEmpty]
4343
public ASRProtectionProfile ProtectionProfile { get; set; }
4444

@@ -51,7 +51,7 @@ public class StartAzureSiteRecoveryProtectionProfileAssociationJob : RecoverySer
5151
public ASRProtectionContainer PrimaryProtectionContainer { get; set; }
5252

5353
/// <summary>
54-
/// Gets or sets Protection Container to be applied the Protection Profile settings on.
54+
/// Gets or sets Recovery Protection Container to be applied the Protection Profile settings on.
5555
/// </summary>
5656
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToEnterprise, Mandatory = true)]
5757
[ValidateNotNullOrEmpty]
@@ -121,7 +121,7 @@ HyperVReplicaAzureProtectionProfileInput hyperVReplicaAzureProtectionProfileInpu
121121
var storageAccount = new CustomerStorageAccount();
122122
storageAccount.StorageAccountName = this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.RecoveryAzureStorageAccountName;
123123
storageAccount.SubscriptionId = this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.RecoveryAzureSubscription;
124-
124+
125125
hyperVReplicaAzureProtectionProfileInput.StorageAccounts = new System.Collections.Generic.List<CustomerStorageAccount>();
126126
hyperVReplicaAzureProtectionProfileInput.StorageAccounts.Add(storageAccount);
127127

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public class StartAzureSiteRecoveryProtectionProfileDissociationJob : RecoverySe
3636
/// <summary>
3737
/// Gets or sets Protection Profile object.
3838
/// </summary>
39-
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToEnterprise, Mandatory = true)]
40-
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToAzure, Mandatory = true)]
39+
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToEnterprise, Mandatory = true, ValueFromPipeline = true)]
40+
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToAzure, Mandatory = true, ValueFromPipeline = true)]
4141
[ValidateNotNullOrEmpty]
4242
public ASRProtectionProfile ProtectionProfile { get; set; }
4343

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/lib/PSObjects.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,21 @@ public class Constants
182182
/// Authentication Type as Kerberos.
183183
/// </summary>
184184
public const string AuthenticationTypeKerberos = "Kerberos";
185+
186+
/// <summary>
187+
/// Acceptable values of Replication Frequency in seconds (as per portal).
188+
/// </summary>
189+
public const string Thirty = "30";
190+
191+
/// <summary>
192+
/// Acceptable values of Replication Frequency in seconds (as per portal).
193+
/// </summary>
194+
public const string ThreeHundred = "300";
195+
196+
/// <summary>
197+
/// Acceptable values of Replication Frequency in seconds (as per portal).
198+
/// </summary>
199+
public const string NineHundred = "900";
185200
}
186201

187202
/// <summary>

0 commit comments

Comments
 (0)