Skip to content

Commit e33f51b

Browse files
committed
Merge pull request #8 from AsrOneSdk/neha-dev
Create Protection Profile cmdlet and Protection Profile model
2 parents 6bee28e + d9e027e commit e33f51b

13 files changed

+713
-199
lines changed

setup/azurecmdfiles.wxi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,9 +1114,15 @@
11141114
<Component Id="cmp12C6E2ACC51F95C3303F6486917E8E75" Guid="*">
11151115
<File Id="filDB5B05710501E18F7BB630DA75A91B03" KeyPath="yes" Source="$(var.sourceDir)\ServiceManagement\Azure\Network\Newtonsoft.Json.dll" />
11161116
</Component>
1117+
<Component Id="cmpE36FC5D85FACEDF16450AC56F0C159BE" Guid="*">
1118+
<File Id="filF9245A77CC3210597C7BCB3777FFEEC3" KeyPath="yes" Source="$(var.sourceDir)\ServiceManagement\Azure\Network\System.Net.Http.Extensions.dll" />
1119+
</Component>
11171120
<Component Id="cmp87E83CA66DD51C9A6D61F1AC91FF683B" Guid="*">
11181121
<File Id="filB81C05773E93D768A10E3A660379BBC7" KeyPath="yes" Source="$(var.sourceDir)\ServiceManagement\Azure\Network\System.Net.Http.Formatting.dll" />
11191122
</Component>
1123+
<Component Id="cmp4F4E2D906EB5F067FB54ACDE2DA1F2DE" Guid="*">
1124+
<File Id="fil32D7BA9A1417F592C027C83F08BCB27A" KeyPath="yes" Source="$(var.sourceDir)\ServiceManagement\Azure\Network\System.Net.Http.Primitives.dll" />
1125+
</Component>
11201126
<Component Id="cmpCC09A82900E1A278F48DB77993C40967" Guid="*">
11211127
<File Id="filA9139A091A1470B6463953C84F7B1BF9" KeyPath="yes" Source="$(var.sourceDir)\ServiceManagement\Azure\Network\System.Spatial.dll" />
11221128
</Component>
@@ -2341,7 +2347,9 @@
23412347
<ComponentRef Id="cmpB382FB922425C1C446A732BD66BBEEE0" />
23422348
<ComponentRef Id="cmp9C36EDC63632529B78C870EF3695F0D3" />
23432349
<ComponentRef Id="cmp12C6E2ACC51F95C3303F6486917E8E75" />
2350+
<ComponentRef Id="cmpE36FC5D85FACEDF16450AC56F0C159BE" />
23442351
<ComponentRef Id="cmp87E83CA66DD51C9A6D61F1AC91FF683B" />
2352+
<ComponentRef Id="cmp4F4E2D906EB5F067FB54ACDE2DA1F2DE" />
23452353
<ComponentRef Id="cmpCC09A82900E1A278F48DB77993C40967" />
23462354
<ComponentRef Id="cmpCA80C6C0F5670291AF2F3560D36B1EA3" />
23472355
<ComponentRef Id="cmp1E1EACEE941A7D7B9B2649BB3AC9ABC3" />

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@
7171
<SpecificVersion>False</SpecificVersion>
7272
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Common.1.4.0\lib\net45\Microsoft.WindowsAzure.Common.NetFramework.dll</HintPath>
7373
</Reference>
74+
<Reference Include="Microsoft.WindowsAzure.Management.Storage">
75+
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.Storage.3.1.0\lib\net40\Microsoft.WindowsAzure.Management.Storage.dll</HintPath>
76+
</Reference>
7477
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
7578
<SpecificVersion>False</SpecificVersion>
7679
<HintPath>..\..\..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll</HintPath>
@@ -119,6 +122,8 @@
119122
<DependentUpon>Resources.resx</DependentUpon>
120123
</Compile>
121124
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesCloudServiceClient.cs" />
125+
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesProtectionProfileClient.cs" />
126+
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesClientHelper.cs" />
122127
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesStorageClient.cs" />
123128
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesStorageMappingClient.cs" />
124129
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesNetworkMappingClient.cs" />
@@ -137,6 +142,7 @@
137142
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesVMClient.cs" />
138143
<Compile Include="RecoveryServicesCmdletBase.cs" />
139144
<Compile Include="Properties\AssemblyInfo.cs" />
145+
<Compile Include="Service\CreateAzureSiteRecoveryProtectionProfileObject.cs" />
140146
<Compile Include="Service\CreateAzureSiteRecoveryVault.cs" />
141147
<Compile Include="Service\GetAzureSiteRecoveryStorage.cs" />
142148
<Compile Include="Service\GetAzureSiteRecoveryStorageMapping.cs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using System.Collections.Generic;
17+
using Microsoft.WindowsAzure;
18+
using Microsoft.WindowsAzure.Commands.Common;
19+
using Microsoft.WindowsAzure.Commands.Common.Models;
20+
using Microsoft.WindowsAzure.Management.Storage;
21+
using Microsoft.WindowsAzure.Management.Storage.Models;
22+
23+
namespace Microsoft.Azure.Commands.RecoveryServices
24+
{
25+
/// <summary>
26+
/// Recovery Services Client Helper Methods class
27+
/// </summary>
28+
public class PSRecoveryServicesClientHelper
29+
{
30+
/// <summary>
31+
/// Validates whether the subscription belongs to the currently logged account or not.
32+
/// </summary>
33+
/// <param name="azureSubscriptionId">Azure Subscription ID</param>
34+
public static void ValidateSubscriptionAccountAssociation(string azureSubscriptionId)
35+
{
36+
bool associatedSubscription = false;
37+
ProfileClient pc = new ProfileClient();
38+
List<AzureSubscription> subscriptions =
39+
pc.RefreshSubscriptions(AzureSession.CurrentContext.Environment);
40+
41+
foreach (AzureSubscription sub in subscriptions)
42+
{
43+
if (azureSubscriptionId.Equals(sub.Id.ToString(), StringComparison.OrdinalIgnoreCase))
44+
{
45+
associatedSubscription = true;
46+
break;
47+
}
48+
}
49+
50+
if (!associatedSubscription)
51+
{
52+
throw new InvalidOperationException(
53+
string.Format(
54+
Properties.Resources.SubscriptionIsNotAssociatedWithTheAccount,
55+
azureSubscriptionId));
56+
}
57+
}
58+
59+
/// <summary>
60+
/// Validates whether the storage belongs to the currently logged account or not.
61+
/// </summary>
62+
/// <param name="azureStorageAccount">Storage Account details</param>
63+
public static void ValidateStorageAccountAssociation(string azureStorageAccount)
64+
{
65+
bool associatedAccount = false;
66+
67+
SubscriptionCloudCredentials creds
68+
= AzureSession.AuthenticationFactory.GetSubscriptionCloudCredentials(AzureSession.CurrentContext);
69+
StorageManagementClient storageManagementClient = new StorageManagementClient(creds);
70+
71+
StorageAccountListResponse storageAccounts = storageManagementClient.StorageAccounts.List();
72+
foreach (StorageAccount storage in storageAccounts)
73+
{
74+
if (azureStorageAccount.Equals(storage.Name, StringComparison.OrdinalIgnoreCase))
75+
{
76+
associatedAccount = true;
77+
break;
78+
}
79+
}
80+
81+
if (!associatedAccount)
82+
{
83+
throw new InvalidOperationException(
84+
string.Format(
85+
Properties.Resources.StorageIsNotAssociatedWithTheAccount,
86+
azureStorageAccount));
87+
}
88+
}
89+
}
90+
}

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

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -293,35 +293,6 @@ public JobResponse NewAzureSiteRecoveryAzureNetworkMapping(
293293
.Create(networkMappingInput, this.GetRequestHeaders());
294294
}
295295

296-
/// <summary>
297-
/// Validates whether the subscription belongs to the currently logged account or not.
298-
/// </summary>
299-
/// <param name="azureSubscriptionId">Azure Subscription ID</param>
300-
public void ValidateSubscriptionAccountAssociation(string azureSubscriptionId)
301-
{
302-
bool associatedSubscription = false;
303-
ProfileClient pc = new ProfileClient();
304-
List<AzureSubscription> subscriptions =
305-
pc.RefreshSubscriptions(AzureSession.CurrentContext.Environment);
306-
307-
foreach (AzureSubscription sub in subscriptions)
308-
{
309-
if (azureSubscriptionId.Equals(sub.Id.ToString(), StringComparison.OrdinalIgnoreCase))
310-
{
311-
associatedSubscription = true;
312-
break;
313-
}
314-
}
315-
316-
if (!associatedSubscription)
317-
{
318-
throw new InvalidOperationException(
319-
string.Format(
320-
Properties.Resources.SubscriptionIsNotAssociatedWithTheAccount,
321-
azureSubscriptionId));
322-
}
323-
}
324-
325296
/// <summary>
326297
/// Validates whether the Azure VM Network is associated with the subscription or not.
327298
/// </summary>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using Microsoft.WindowsAzure;
17+
using Microsoft.WindowsAzure.Management.SiteRecovery;
18+
using Microsoft.WindowsAzure.Management.SiteRecovery.Models;
19+
20+
namespace Microsoft.Azure.Commands.RecoveryServices
21+
{
22+
/// <summary>
23+
/// Recovery services convenience client.
24+
/// </summary>
25+
public partial class PSRecoveryServicesClient
26+
{
27+
/// <summary>
28+
/// Gets Azure Site Recovery Protection Profile.
29+
/// </summary>
30+
/// <returns>Protection Profile list response</returns>
31+
public ProtectionProfileListResponse GetAzureSiteRecoveryProtectionProfile()
32+
{
33+
return this.GetSiteRecoveryClient().ProtectionProfile.List(this.GetRequestHeaders());
34+
}
35+
36+
/// <summary>
37+
/// Gets Azure Site Recovery Protection Profile given the ID.
38+
/// </summary>
39+
/// <param name="protectionProfileId">Protection Profile ID</param>
40+
/// <returns>Protection Profile response</returns>
41+
public ProtectionProfileResponse GetAzureSiteRecoveryProtectionProfile(
42+
string protectionProfileId)
43+
{
44+
return this.GetSiteRecoveryClient().ProtectionProfile.Get(
45+
protectionProfileId,
46+
this.GetRequestHeaders());
47+
}
48+
49+
/// <summary>
50+
/// Updates Azure Site Recovery Protection Profile given the ID.
51+
/// </summary>
52+
/// <param name="updateProtectionProfileInput">Protection Profile Input</param>
53+
/// <param name="protectionProfileId">Protection Profile ID</param>
54+
/// <returns>Job response</returns>
55+
public JobResponse UpdateAzureSiteRecoveryProtectionProfile(
56+
UpdateProtectionProfileInput updateProtectionProfileInput,
57+
string protectionProfileId)
58+
{
59+
return this.GetSiteRecoveryClient().ProtectionProfile.Update(
60+
updateProtectionProfileInput,
61+
protectionProfileId,
62+
this.GetRequestHeaders());
63+
}
64+
65+
/// <summary>
66+
/// Creates and Associates Azure Site Recovery Protection Profile.
67+
/// </summary>
68+
/// <param name="createAndAssociateProtectionProfileInput">Protection Profile Input</param>
69+
/// <returns>Job response</returns>
70+
public JobResponse StartCreateAndAssociateAzureSiteRecoveryProtectionProfileJob(
71+
CreateAndAssociateProtectionProfileInput createAndAssociateProtectionProfileInput)
72+
{
73+
return this.GetSiteRecoveryClient().ProtectionProfile.CreateAndAssociate(
74+
createAndAssociateProtectionProfileInput,
75+
this.GetRequestHeaders());
76+
}
77+
78+
/// <summary>
79+
/// Deletes and Dissociates Azure Site Recovery Protection Profile.
80+
/// </summary>
81+
/// <param name="protectionProfileId">Protection Profile ID</param>
82+
/// <param name="protectionProfileAssociationInput">Protection Profile Association Input</param>
83+
/// <returns>Job response</returns>
84+
public JobResponse StartDeleteAndDissociateAzureSiteRecoveryProtectionProfileJob(
85+
string protectionProfileId,
86+
ProtectionProfileAssociationInput protectionProfileAssociationInput)
87+
{
88+
return this.GetSiteRecoveryClient().ProtectionProfile.DissociateAndDelete(
89+
protectionProfileId,
90+
protectionProfileAssociationInput,
91+
this.GetRequestHeaders());
92+
}
93+
}
94+
}

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
@@ -203,6 +203,9 @@ ClientRequestId: {3}</value>
203203
<data name="VaultCredentialGenerationUnSupported" xml:space="preserve">
204204
<value>Cannot generate vault credentials for this vault. Download it from the Azure Portal.</value>
205205
</data>
206+
<data name="StorageIsNotAssociatedWithTheAccount" xml:space="preserve">
207+
<value>Storage account {0} is not associated with the account</value>
208+
</data>
206209
<data name="VaultCreationSuccessMessage" xml:space="preserve">
207210
<value>Vault has been created</value>
208211
</data>

0 commit comments

Comments
 (0)