Skip to content

Commit 7d161c2

Browse files
committed
Merge branch 'dev151125' of https://github.com/AsrOneSdk/azure-powershell into SetRSVaultSettings
Conflicts: src/ResourceManager/SiteRecovery/Commands.SiteRecovery/Vault/SetAzureSiteRecoveryVaultSettings.cs
2 parents 0b17685 + 3d7ba2e commit 7d161c2

File tree

47 files changed

+1616
-755
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1616
-755
lines changed

src/ResourceManager/SiteRecovery/Commands.SiteRecovery/Commands.SiteRecovery.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
</Reference>
5454
<Reference Include="Microsoft.Azure.Management.SiteRecovery, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
5555
<HintPath>..\..\..\packages\Microsoft.Azure.Management.SiteRecovery.1.0.2-preview\lib\net40\Microsoft.Azure.Management.SiteRecovery.dll</HintPath>
56+
<SpecificVersion>False</SpecificVersion>
5657
<Private>True</Private>
5758
</Reference>
5859
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory, Version=2.18.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
@@ -125,6 +126,7 @@
125126
<Compile Include="Common\PSSiteRecoveryPolicyClient.cs" />
126127
<Compile Include="Common\PSSiteRecoveryRecoveryServicesProviderClient.cs" />
127128
<Compile Include="Common\PSSiteRecoveryFabricClient.cs" />
129+
<Compile Include="Common\PSSiteRecoveryStorageClassificationClient.cs" />
128130
<Compile Include="Common\PSSiteRecoveryVaultClient.cs" />
129131
<Compile Include="Common\PSSiteRecoveryVaultExtendedInfoClient.cs" />
130132
<Compile Include="Common\PSSiteRecoveryVMClient.cs" />
@@ -167,6 +169,10 @@
167169
<Compile Include="Policy\StartAzureSiteRecoveryPolicyAssociationJob.cs" />
168170
<Compile Include="Policy\StartAzureSiteRecoveryPolicyDissociationJob.cs" />
169171
<Compile Include="Server\GetAzureSiteRecoveryServer.cs" />
172+
<Compile Include="Storage\Classification\GetAzureSiteRecoveryStorageClassification.cs" />
173+
<Compile Include="Storage\Classification\GetAzureSiteRecoveryStorageClassificationMapping.cs" />
174+
<Compile Include="Storage\Classification\NewAzureRmSiteRecoveryStorageClassificationMapping.cs" />
175+
<Compile Include="Storage\Classification\RemoveAzureSiteRecoveryStorageClassificationMapping.cs" />
170176
<Compile Include="Utilities\CertUtils.cs" />
171177
<Compile Include="Utilities\Utilities.cs" />
172178
<Compile Include="Vault\RemoveAzureSiteRecoveryVault.cs" />

src/ResourceManager/SiteRecovery/Commands.SiteRecovery/Common/PSSiteRecoveryFabricClient.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using System;
16+
using System.Collections.Generic;
17+
using System.Threading;
18+
using System.Threading.Tasks;
1619
using Microsoft.Azure.Management.SiteRecovery;
1720
using Microsoft.Azure.Management.SiteRecovery.Models;
1821
using Microsoft.Azure.Portal.RecoveryServices.Models.Common;
@@ -81,4 +84,23 @@ public LongRunningOperationResponse DeleteAzureSiteRecoveryFabric(string fabricN
8184
this.GetRequestHeaders());
8285
}
8386
}
87+
88+
/// <summary>
89+
/// Fabric extensions.
90+
/// </summary>
91+
public static class FabricExtensions
92+
{
93+
/// <summary>
94+
/// Gets ARM Id of fabric from provider's ARM Id.
95+
/// </summary>
96+
/// <param name="provider">Provider ARM Id.</param>
97+
/// <returns>ARM Id of fabric.</returns>
98+
public static string GetFabricId(this ASRServer provider)
99+
{
100+
return provider.ID.GetVaultArmId() + "/" +
101+
string.Format(ARMResourceIdPaths.FabricResourceIdPath,
102+
provider.ID.UnFormatArmId(
103+
ARMResourceIdPaths.RecoveryServicesProviderResourceIdPath));
104+
}
105+
}
84106
}
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Threading;
4+
using System.Threading.Tasks;
5+
using Microsoft.Azure.Management.SiteRecovery;
6+
using Microsoft.Azure.Management.SiteRecovery.Models;
7+
8+
namespace Microsoft.Azure.Commands.SiteRecovery
9+
{
10+
public partial class PSRecoveryServicesClient
11+
{
12+
/// <summary>
13+
/// Gets all storage classifications associated with a vault.
14+
/// </summary>
15+
/// <param name="callback">Callback to execute on the result.</param>
16+
/// <returns>Task object tracking async operation.</returns>
17+
public Task EnumerateStorageClassificationsAsync(Action<IEnumerable<StorageClassification>> callback)
18+
{
19+
CancellationToken cancellationToken = new CancellationToken();
20+
21+
Task backgroundTask = new Task(new Action(() =>
22+
{
23+
Task<StorageClassificationListResponse> storageTask =
24+
this.GetSiteRecoveryClient().StorageClassification.ListAllAsync(
25+
this.GetRequestHeaders(),
26+
cancellationToken);
27+
28+
Task.WaitAll(storageTask);
29+
30+
callback(storageTask.Result.StorageClassifications);
31+
32+
while (!string.IsNullOrEmpty(storageTask.Result.NextLink))
33+
{
34+
storageTask =
35+
this.GetSiteRecoveryClient().StorageClassification.ListNextAsync(
36+
storageTask.Result.NextLink,
37+
this.GetRequestHeaders(),
38+
cancellationToken);
39+
40+
Task.WaitAll(storageTask);
41+
42+
callback(storageTask.Result.StorageClassifications);
43+
}
44+
}));
45+
46+
backgroundTask.Start();
47+
return backgroundTask;
48+
}
49+
50+
/// <summary>
51+
/// Gets all storage classifications associated with a vault.
52+
/// </summary>
53+
/// <param name="callback">Callback to execute on the result.</param>
54+
/// <returns>Task object tracking async operation.</returns>
55+
public Task EnumerateStorageClassificationMappingsAsync(Action<IEnumerable<StorageClassificationMapping>> callback)
56+
{
57+
CancellationToken cancellationToken = new CancellationToken();
58+
59+
Task backgroundTask = new Task(new Action(() =>
60+
{
61+
Task<StorageClassificationMappingListResponse> storageTask =
62+
this.GetSiteRecoveryClient().StorageClassificationMapping.ListAllAsync(
63+
this.GetRequestHeaders(),
64+
cancellationToken);
65+
66+
Task.WaitAll(storageTask);
67+
68+
callback(storageTask.Result.StorageClassificationMappings);
69+
70+
while (!string.IsNullOrEmpty(storageTask.Result.NextLink))
71+
{
72+
storageTask =
73+
this.GetSiteRecoveryClient().StorageClassificationMapping.ListNextAsync(
74+
storageTask.Result.NextLink,
75+
this.GetRequestHeaders(),
76+
cancellationToken);
77+
78+
Task.WaitAll(storageTask);
79+
80+
callback(storageTask.Result.StorageClassificationMappings);
81+
}
82+
}));
83+
84+
backgroundTask.Start();
85+
return backgroundTask;
86+
}
87+
88+
/// <summary>
89+
/// Starts job for unmapping classifications
90+
/// </summary>
91+
/// <param name="fabricName">Fabric name name.</param>
92+
/// <param name="storageClassificationName">Storage classification name.</param>
93+
/// <param name="mappingName">Classification mapping name.</param>
94+
/// <returns>Operation result.</returns>
95+
public LongRunningOperationResponse UnmapStorageClassifications(
96+
string fabricName,
97+
string storageClassificationName,
98+
string mappingName)
99+
{
100+
return this.GetSiteRecoveryClient().StorageClassificationMapping
101+
.BeginUnpairStorageClassification(
102+
fabricName,
103+
storageClassificationName,
104+
mappingName,
105+
customRequestHeaders: this.GetRequestHeaders());
106+
}
107+
108+
/// <summary>
109+
/// Starts job for mapping storage classification.
110+
/// </summary>
111+
/// <param name="primaryClassification">Primary classification.</param>
112+
/// <param name="input">Mapping input.</param>
113+
/// <param name="armName">Optional. ARM name of the mapping.</param>
114+
/// <returns>Operation response.</returns>
115+
public LongRunningOperationResponse MapStorageClassification(
116+
ASRStorageClassification primaryClassification,
117+
StorageClassificationMappingInput input,
118+
string armName)
119+
{
120+
string[] tokens = primaryClassification.Id.UnFormatArmId(
121+
ARMResourceIdPaths.StorageClassificationResourceIdPath);
122+
123+
return this.GetSiteRecoveryClient().StorageClassificationMapping
124+
.BeginPairStorageClassification(
125+
tokens[0],
126+
tokens[1],
127+
armName,
128+
input,
129+
this.GetRequestHeaders());
130+
}
131+
}
132+
133+
/// <summary>
134+
/// Extension methods for Storage classification.
135+
/// </summary>
136+
public static class StorageClassificationExtensions
137+
{
138+
/// <summary>
139+
/// Gets primary storage classification ARM Id.
140+
/// </summary>
141+
/// <param name="mapping">Storage classification mapping input.</param>
142+
/// <returns>ARM Id of the primary storage classification.</returns>
143+
public static string GetPrimaryStorageClassificationId(
144+
this StorageClassificationMapping mapping)
145+
{
146+
string[] tokens = mapping.Id.UnFormatArmId(
147+
ARMResourceIdPaths.StorageClassificationMappingResourceIdPath);
148+
149+
string vaultId = mapping.Id.GetVaultArmId();
150+
151+
return vaultId + "/" + string.Format(
152+
ARMResourceIdPaths.StorageClassificationResourceIdPath,
153+
tokens[0],
154+
tokens[1]);
155+
}
156+
157+
/// <summary>
158+
/// Gets fabric Id from classification ARM Id.
159+
/// </summary>
160+
/// <param name="classification">Storage classification.</param>
161+
/// <returns>ARM Id of the fabric.</returns>
162+
public static string GetFabricId(
163+
this StorageClassification classification)
164+
{
165+
string[] tokens = classification.Id.UnFormatArmId(
166+
ARMResourceIdPaths.StorageClassificationResourceIdPath);
167+
168+
string vaultId = classification.Id.GetVaultArmId();
169+
170+
return vaultId + "/" + string.Format(
171+
ARMResourceIdPaths.FabricResourceIdPath,
172+
tokens[0]);
173+
}
174+
}
175+
}

src/ResourceManager/SiteRecovery/Commands.SiteRecovery/Common/SiteRecoveryCmdletBase.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,30 @@ internal PSRecoveryServicesClient RecoveryServicesClient
6161
}
6262
}
6363

64+
/// <summary>
65+
/// Virtual method to be implemented by Site Recovery cmdlets.
66+
/// </summary>
67+
public virtual void ExecuteSiteRecoveryCmdlet()
68+
{
69+
// Do Nothing
70+
}
71+
72+
/// <summary>
73+
/// Overriding base implementation go execute cmdlet.
74+
/// </summary>
75+
public override void ExecuteCmdlet()
76+
{
77+
try
78+
{
79+
base.ExecuteCmdlet();
80+
ExecuteSiteRecoveryCmdlet();
81+
}
82+
catch (Exception ex)
83+
{
84+
this.HandleException(ex);
85+
}
86+
}
87+
6488
/// <summary>
6589
/// Exception handler.
6690
/// </summary>

src/ResourceManager/SiteRecovery/Commands.SiteRecovery/Job/GetAzureSiteRecoveryJob.cs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -86,30 +86,24 @@ public class GetAzureSiteRecoveryJob : SiteRecoveryCmdletBase
8686
/// <summary>
8787
/// ProcessRecord of the command.
8888
/// </summary>
89-
public override void ExecuteCmdlet()
89+
public override void ExecuteSiteRecoveryCmdlet()
9090
{
91-
try
91+
base.ExecuteSiteRecoveryCmdlet();
92+
switch (this.ParameterSetName)
9293
{
93-
switch (this.ParameterSetName)
94-
{
95-
case ASRParameterSets.ByObject:
96-
this.Name = this.Job.Name;
97-
this.GetByName();
98-
break;
99-
100-
case ASRParameterSets.ByName:
101-
this.GetByName();
102-
break;
103-
104-
case ASRParameterSets.ByParam:
105-
default:
106-
this.GetByParam();
107-
break;
108-
}
109-
}
110-
catch (Exception exception)
111-
{
112-
this.HandleException(exception);
94+
case ASRParameterSets.ByObject:
95+
this.Name = this.Job.Name;
96+
this.GetByName();
97+
break;
98+
99+
case ASRParameterSets.ByName:
100+
this.GetByName();
101+
break;
102+
103+
case ASRParameterSets.ByParam:
104+
default:
105+
this.GetByParam();
106+
break;
113107
}
114108
}
115109

src/ResourceManager/SiteRecovery/Commands.SiteRecovery/Job/RestartAzureSiteRecoveryJob.cs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,20 @@ public class RestartAzureSiteRecoveryJob : SiteRecoveryCmdletBase
4444
/// <summary>
4545
/// ProcessRecord of the command.
4646
/// </summary>
47-
public override void ExecuteCmdlet()
47+
public override void ExecuteSiteRecoveryCmdlet()
4848
{
49-
try
50-
{
51-
switch (this.ParameterSetName)
52-
{
53-
case ASRParameterSets.ByObject:
54-
this.Name = this.Job.Name;
55-
this.RestartByName();
56-
break;
49+
base.ExecuteSiteRecoveryCmdlet();
5750

58-
case ASRParameterSets.ByName:
59-
this.RestartByName();
60-
break;
61-
}
62-
}
63-
catch (Exception exception)
51+
switch (this.ParameterSetName)
6452
{
65-
this.HandleException(exception);
53+
case ASRParameterSets.ByObject:
54+
this.Name = this.Job.Name;
55+
this.RestartByName();
56+
break;
57+
58+
case ASRParameterSets.ByName:
59+
this.RestartByName();
60+
break;
6661
}
6762
}
6863

src/ResourceManager/SiteRecovery/Commands.SiteRecovery/Job/ResumeAzureSiteRecoveryJob.cs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,20 @@ public class ResumeAzureSiteRecoveryJob : SiteRecoveryCmdletBase
5151
/// <summary>
5252
/// ProcessRecord of the command.
5353
/// </summary>
54-
public override void ExecuteCmdlet()
54+
public override void ExecuteSiteRecoveryCmdlet()
5555
{
56-
try
57-
{
58-
switch (this.ParameterSetName)
59-
{
60-
case ASRParameterSets.ByObject:
61-
this.Name = this.Job.Name;
62-
this.ResumesByName();
63-
break;
56+
base.ExecuteSiteRecoveryCmdlet();
6457

65-
case ASRParameterSets.ByName:
66-
this.ResumesByName();
67-
break;
68-
}
69-
}
70-
catch (Exception exception)
58+
switch (this.ParameterSetName)
7159
{
72-
this.HandleException(exception);
60+
case ASRParameterSets.ByObject:
61+
this.Name = this.Job.Name;
62+
this.ResumesByName();
63+
break;
64+
65+
case ASRParameterSets.ByName:
66+
this.ResumesByName();
67+
break;
7368
}
7469
}
7570

0 commit comments

Comments
 (0)