Skip to content

Commit 489de54

Browse files
committed
Merge pull request #5 from AsrOneSdk/devsri-dev
Vault Credentials Client changes, enumerate vaults, create cloudservice and create vault changes
2 parents ec60110 + c8c2d3e commit 489de54

16 files changed

+1668
-14
lines changed

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
<Prefer32Bit>false</Prefer32Bit>
4848
</PropertyGroup>
4949
<ItemGroup>
50+
<Reference Include="Microsoft.Azure.RecoveryServices">
51+
<HintPath>..\..\..\..\..\hydra-specs-pr\SiteRecovery\SiteRecovery.Tests\bin\Debug\Microsoft.Azure.RecoveryServices.dll</HintPath>
52+
</Reference>
5053
<Reference Include="Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
5154
<SpecificVersion>False</SpecificVersion>
5255
<HintPath>..\..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll</HintPath>
@@ -67,14 +70,14 @@
6770
<SpecificVersion>False</SpecificVersion>
6871
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Common.1.4.0\lib\net45\Microsoft.WindowsAzure.Common.NetFramework.dll</HintPath>
6972
</Reference>
70-
<Reference Include="Microsoft.WindowsAzure.Management.SiteRecovery, Version=0.9.0.0, Culture=neutral, PublicKeyToken=c66ce9294aae1300, processorArchitecture=MSIL">
71-
<SpecificVersion>False</SpecificVersion>
72-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.RecoveryServices.0.2.2-preview\lib\net40\Microsoft.WindowsAzure.Management.SiteRecovery.dll</HintPath>
73-
</Reference>
7473
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
7574
<SpecificVersion>False</SpecificVersion>
7675
<HintPath>..\..\..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll</HintPath>
7776
</Reference>
77+
<Reference Include="Security.Cryptography, Version=1.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
78+
<SpecificVersion>False</SpecificVersion>
79+
<HintPath>lib\Security.Cryptography.dll</HintPath>
80+
</Reference>
7881
<Reference Include="System" />
7982
<Reference Include="System.Core" />
8083
<Reference Include="System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
@@ -103,19 +106,24 @@
103106
<ItemGroup>
104107
<Compile Include="lib\PSStorageObjects.cs" />
105108
<Compile Include="lib\PSNetworkObjects.cs" />
109+
<Compile Include="lib\CertUtils.cs" />
106110
<Compile Include="lib\PSContracts.cs" />
107111
<Compile Include="lib\PSObjects.cs" />
108112
<Compile Include="lib\PSParameterSets.cs" />
109113
<Compile Include="lib\PSRecoveryPlanObjects.cs" />
114+
<Compile Include="lib\Utilities.cs" />
110115
<Compile Include="Properties\Resources.Designer.cs">
111116
<AutoGen>True</AutoGen>
112117
<DesignTime>True</DesignTime>
113118
<DependentUpon>Resources.resx</DependentUpon>
114119
</Compile>
120+
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesCloudServiceClient.cs" />
115121
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesStorageClient.cs" />
116122
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesStorageMappingClient.cs" />
117123
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesNetworkMappingClient.cs" />
118124
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesNetworkClient.cs" />
125+
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesVaultClient.cs" />
126+
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesVaultExtendedInfoClient.cs" />
119127
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesVMGroupClient.cs" />
120128
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesPEClient.cs" />
121129
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesClient.cs">
@@ -128,8 +136,10 @@
128136
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesVMClient.cs" />
129137
<Compile Include="RecoveryServicesCmdletBase.cs" />
130138
<Compile Include="Properties\AssemblyInfo.cs" />
139+
<Compile Include="Service\CreateAzureSiteRecoveryVault.cs" />
131140
<Compile Include="Service\GetAzureSiteRecoveryStorage.cs" />
132141
<Compile Include="Service\GetAzureSiteRecoveryStorageMapping.cs" />
142+
<Compile Include="Service\GetAzureSiteRecoveryVaults.cs" />
133143
<Compile Include="Service\NewAzureSiteRecoveryStorageMapping.cs" />
134144
<Compile Include="Service\RemoveAzureSiteRecoveryStorageMapping.cs" />
135145
<Compile Include="Service\RemoveAzureSiteRecoveryNetworkMapping.cs" />
@@ -138,6 +148,7 @@
138148
<Compile Include="Service\GetAzureSiteRecoveryNetwork.cs" />
139149
<Compile Include="Service\CreateAzureSiteRecoveryRecoveryPlan.cs" />
140150
<Compile Include="Service\GetAzureSiteRecoveryRecoveryPlanFile.cs" />
151+
<Compile Include="Service\GetAzureSiteRecoveryVaultCredential.cs" />
141152
<Compile Include="Service\RemoveAzureSiteRecoveryRecoveryPlan.cs" />
142153
<Compile Include="Service\GetAzureSiteRecoveryProtectionEntity.cs" />
143154
<Compile Include="Service\RestartAzureSiteRecoveryJob.cs" />
@@ -166,6 +177,10 @@
166177
</ProjectReference>
167178
</ItemGroup>
168179
<ItemGroup>
180+
<Content Include="lib\Microsoft.Azure.RecoveryServices.dll" />
181+
<Content Include="lib\Security.Cryptography.dll">
182+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
183+
</Content>
169184
<Content Include="Microsoft.Azure.Commands.RecoveryServices.dll-help.xml">
170185
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
171186
</Content>
@@ -181,6 +196,9 @@
181196
<None Include="MSSharedLibKey.snk" />
182197
<None Include="packages.config" />
183198
</ItemGroup>
199+
<ItemGroup>
200+
<WCFMetadata Include="Service References\" />
201+
</ItemGroup>
184202
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
185203
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
186204
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ public partial class PSRecoveryServicesClient
4747
/// </summary>
4848
public string ClientRequestId { get; set; }
4949

50+
/// <summary>
51+
/// Gets the value of recovery services management client.
52+
/// </summary>
53+
public RecoveryServicesManagementClient GetRecoveryServicesClient
54+
{
55+
get
56+
{
57+
return this.recoveryServicesClient;
58+
}
59+
}
60+
5061
/// <summary>
5162
/// Amount of time to sleep before fetching job details again.
5263
/// </summary>
@@ -184,8 +195,9 @@ public string GenerateAgentAuthenticationHeader(string clientRequestId)
184195
/// <summary>
185196
/// Gets request headers.
186197
/// </summary>
198+
/// <param name="shouldSignRequest">specifies whether to sign the request or not</param>
187199
/// <returns>Custom request headers</returns>
188-
public CustomRequestHeaders GetRequestHeaders()
200+
public CustomRequestHeaders GetRequestHeaders(bool shouldSignRequest = true)
189201
{
190202
this.ClientRequestId = Guid.NewGuid().ToString() + "-" + DateTime.Now.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ssZ") + "-P";
191203

@@ -194,7 +206,7 @@ public CustomRequestHeaders GetRequestHeaders()
194206
// ClientRequestId is a unique ID for every request to Azure Site Recovery.
195207
// It is useful when diagnosing failures in API calls.
196208
ClientRequestId = this.ClientRequestId,
197-
AgentAuthenticationHeader = this.GenerateAgentAuthenticationHeader(this.ClientRequestId)
209+
AgentAuthenticationHeader = shouldSignRequest ? this.GenerateAgentAuthenticationHeader(this.ClientRequestId) : ""
198210
};
199211
}
200212

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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.Azure.Commands.RecoveryServices.SiteRecovery;
18+
using Microsoft.WindowsAzure;
19+
using Microsoft.WindowsAzure.Management.RecoveryServices.Models;
20+
21+
namespace Microsoft.Azure.Commands.RecoveryServices
22+
{
23+
/// <summary>
24+
/// Recovery services convenience client.
25+
/// </summary>
26+
public partial class PSRecoveryServicesClient
27+
{
28+
/// <summary>
29+
/// Method to retrieve cloud services list for the current subscription
30+
/// </summary>
31+
/// <returns>list of cloud services.</returns>
32+
public IEnumerable<CloudService> GetCloudServices()
33+
{
34+
CloudServiceListResponse response = this.GetRecoveryServicesClient.CloudServices.List();
35+
36+
return response.CloudServices;
37+
}
38+
39+
/// <summary>
40+
/// Method to get Cloud Service object for a given vault
41+
/// </summary>
42+
/// <param name="vault">vault object</param>
43+
/// <returns>cloud service object.</returns>
44+
public CloudService GetCloudServiceForVault(ASRVault vault)
45+
{
46+
IEnumerable<CloudService> cloudServiceList = this.GetCloudServices();
47+
CloudService cloudServiceToReturn = null;
48+
49+
foreach (var cloudService in cloudServiceList)
50+
{
51+
Vault selectedVault = null;
52+
if (cloudService.GeoRegion.Equals(vault.Location, StringComparison.InvariantCultureIgnoreCase))
53+
{
54+
foreach (var resource in cloudService.Resources)
55+
{
56+
if (resource.Name.Equals(vault.Name, StringComparison.InvariantCultureIgnoreCase))
57+
{
58+
selectedVault = resource;
59+
break;
60+
}
61+
}
62+
}
63+
64+
if (selectedVault != null)
65+
{
66+
cloudServiceToReturn = cloudService;
67+
break;
68+
}
69+
}
70+
71+
return cloudServiceToReturn;
72+
}
73+
74+
/// <summary>
75+
/// Method to Either find or create the cloud service.
76+
/// </summary>
77+
/// <param name="cloudServiceName">name of the cloud service to be created</param>
78+
/// <param name="cloudServiceInput">cloud service input to create the service.</param>
79+
public void FindOrCreateCloudService(string cloudServiceName, CloudServiceCreateArgs cloudServiceInput)
80+
{
81+
bool cloudServicePresent = this.DoesCloudServiceExits(cloudServiceName);
82+
83+
if (!cloudServicePresent)
84+
{
85+
this.GetRecoveryServicesClient.CloudServices.Create(cloudServiceName, cloudServiceInput);
86+
}
87+
}
88+
89+
/// <summary>
90+
/// Checks whether a cloud service is present or not.
91+
/// </summary>
92+
/// <param name="cloudServiceName">name of the cloud service to be created</param>
93+
/// <returns>returns true in case the cloud service exits and false otherwise.</returns>
94+
private bool DoesCloudServiceExits(string cloudServiceName)
95+
{
96+
IEnumerable<CloudService> cloudServiceList = this.GetCloudServices();
97+
bool cloudServicePresent = false;
98+
99+
foreach (var cloudService in cloudServiceList)
100+
{
101+
if (cloudServiceName.Equals(cloudService.Name, StringComparison.InvariantCultureIgnoreCase))
102+
{
103+
cloudServicePresent = true;
104+
break;
105+
}
106+
}
107+
108+
return cloudServicePresent;
109+
}
110+
}
111+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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 Microsoft.WindowsAzure;
16+
using Microsoft.WindowsAzure.Management.RecoveryServices.Models;
17+
18+
namespace Microsoft.Azure.Commands.RecoveryServices
19+
{
20+
/// <summary>
21+
/// Recovery services convenience client.
22+
/// </summary>
23+
public partial class PSRecoveryServicesClient
24+
{
25+
/// <summary>
26+
/// Method to create Azure Site Recovery Vault
27+
/// </summary>
28+
/// <param name="cloudServiceName">name of the cloud service</param>
29+
/// <param name="vaultName">name of the vault</param>
30+
/// <param name="vaultCreateInput">vault creation input object</param>
31+
/// <returns>creation response object.</returns>
32+
public VaultCreateResponse CreateVault(string cloudServiceName, string vaultName, VaultCreateArgs vaultCreateInput)
33+
{
34+
return this.GetRecoveryServicesClient.Vaults.Create(cloudServiceName, vaultName, vaultCreateInput);
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)