Skip to content

Commit 69bcdcb

Browse files
committed
Merging with parent.
2 parents 8090480 + 489de54 commit 69bcdcb

15 files changed

+1664
-9
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@
7575
<SpecificVersion>False</SpecificVersion>
7676
<HintPath>..\..\..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll</HintPath>
7777
</Reference>
78+
<Reference Include="Security.Cryptography, Version=1.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
79+
<SpecificVersion>False</SpecificVersion>
80+
<HintPath>lib\Security.Cryptography.dll</HintPath>
81+
</Reference>
7882
<Reference Include="System" />
7983
<Reference Include="System.Core" />
8084
<Reference Include="System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
@@ -103,19 +107,24 @@
103107
<ItemGroup>
104108
<Compile Include="lib\PSStorageObjects.cs" />
105109
<Compile Include="lib\PSNetworkObjects.cs" />
110+
<Compile Include="lib\CertUtils.cs" />
106111
<Compile Include="lib\PSContracts.cs" />
107112
<Compile Include="lib\PSObjects.cs" />
108113
<Compile Include="lib\PSParameterSets.cs" />
109114
<Compile Include="lib\PSRecoveryPlanObjects.cs" />
115+
<Compile Include="lib\Utilities.cs" />
110116
<Compile Include="Properties\Resources.Designer.cs">
111117
<AutoGen>True</AutoGen>
112118
<DesignTime>True</DesignTime>
113119
<DependentUpon>Resources.resx</DependentUpon>
114120
</Compile>
121+
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesCloudServiceClient.cs" />
115122
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesStorageClient.cs" />
116123
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesStorageMappingClient.cs" />
117124
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesNetworkMappingClient.cs" />
118125
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesNetworkClient.cs" />
126+
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesVaultClient.cs" />
127+
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesVaultExtendedInfoClient.cs" />
119128
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesVMGroupClient.cs" />
120129
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesPEClient.cs" />
121130
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesClient.cs">
@@ -128,8 +137,10 @@
128137
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesVMClient.cs" />
129138
<Compile Include="RecoveryServicesCmdletBase.cs" />
130139
<Compile Include="Properties\AssemblyInfo.cs" />
140+
<Compile Include="Service\CreateAzureSiteRecoveryVault.cs" />
131141
<Compile Include="Service\GetAzureSiteRecoveryStorage.cs" />
132142
<Compile Include="Service\GetAzureSiteRecoveryStorageMapping.cs" />
143+
<Compile Include="Service\GetAzureSiteRecoveryVaults.cs" />
133144
<Compile Include="Service\NewAzureSiteRecoveryStorageMapping.cs" />
134145
<Compile Include="Service\RemoveAzureSiteRecoveryStorageMapping.cs" />
135146
<Compile Include="Service\RemoveAzureSiteRecoveryNetworkMapping.cs" />
@@ -138,6 +149,7 @@
138149
<Compile Include="Service\GetAzureSiteRecoveryNetwork.cs" />
139150
<Compile Include="Service\CreateAzureSiteRecoveryRecoveryPlan.cs" />
140151
<Compile Include="Service\GetAzureSiteRecoveryRecoveryPlanFile.cs" />
152+
<Compile Include="Service\GetAzureSiteRecoveryVaultCredential.cs" />
141153
<Compile Include="Service\RemoveAzureSiteRecoveryRecoveryPlan.cs" />
142154
<Compile Include="Service\GetAzureSiteRecoveryProtectionEntity.cs" />
143155
<Compile Include="Service\RestartAzureSiteRecoveryJob.cs" />
@@ -166,6 +178,10 @@
166178
</ProjectReference>
167179
</ItemGroup>
168180
<ItemGroup>
181+
<Content Include="lib\Microsoft.Azure.RecoveryServices.dll" />
182+
<Content Include="lib\Security.Cryptography.dll">
183+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
184+
</Content>
169185
<Content Include="Microsoft.Azure.Commands.RecoveryServices.dll-help.xml">
170186
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
171187
</Content>
@@ -181,6 +197,9 @@
181197
<None Include="MSSharedLibKey.snk" />
182198
<None Include="packages.config" />
183199
</ItemGroup>
200+
<ItemGroup>
201+
<WCFMetadata Include="Service References\" />
202+
</ItemGroup>
184203
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
185204
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
186205
<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)