Skip to content

Commit

Permalink
Merge pull request #5 from AsrOneSdk/devsri-dev
Browse files Browse the repository at this point in the history
Vault Credentials Client changes, enumerate vaults, create cloudservice and create vault changes
  • Loading branch information
devsriMS committed Jan 13, 2015
2 parents ec60110 + c8c2d3e commit 489de54
Show file tree
Hide file tree
Showing 16 changed files with 1,668 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Azure.RecoveryServices">
<HintPath>..\..\..\..\..\hydra-specs-pr\SiteRecovery\SiteRecovery.Tests\bin\Debug\Microsoft.Azure.RecoveryServices.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll</HintPath>
Expand All @@ -67,14 +70,14 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Common.1.4.0\lib\net45\Microsoft.WindowsAzure.Common.NetFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Management.SiteRecovery, Version=0.9.0.0, Culture=neutral, PublicKeyToken=c66ce9294aae1300, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.RecoveryServices.0.2.2-preview\lib\net40\Microsoft.WindowsAzure.Management.SiteRecovery.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Security.Cryptography, Version=1.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>lib\Security.Cryptography.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
Expand Down Expand Up @@ -103,19 +106,24 @@
<ItemGroup>
<Compile Include="lib\PSStorageObjects.cs" />
<Compile Include="lib\PSNetworkObjects.cs" />
<Compile Include="lib\CertUtils.cs" />
<Compile Include="lib\PSContracts.cs" />
<Compile Include="lib\PSObjects.cs" />
<Compile Include="lib\PSParameterSets.cs" />
<Compile Include="lib\PSRecoveryPlanObjects.cs" />
<Compile Include="lib\Utilities.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesCloudServiceClient.cs" />
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesStorageClient.cs" />
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesStorageMappingClient.cs" />
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesNetworkMappingClient.cs" />
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesNetworkClient.cs" />
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesVaultClient.cs" />
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesVaultExtendedInfoClient.cs" />
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesVMGroupClient.cs" />
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesPEClient.cs" />
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesClient.cs">
Expand All @@ -128,8 +136,10 @@
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesVMClient.cs" />
<Compile Include="RecoveryServicesCmdletBase.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Service\CreateAzureSiteRecoveryVault.cs" />
<Compile Include="Service\GetAzureSiteRecoveryStorage.cs" />
<Compile Include="Service\GetAzureSiteRecoveryStorageMapping.cs" />
<Compile Include="Service\GetAzureSiteRecoveryVaults.cs" />
<Compile Include="Service\NewAzureSiteRecoveryStorageMapping.cs" />
<Compile Include="Service\RemoveAzureSiteRecoveryStorageMapping.cs" />
<Compile Include="Service\RemoveAzureSiteRecoveryNetworkMapping.cs" />
Expand All @@ -138,6 +148,7 @@
<Compile Include="Service\GetAzureSiteRecoveryNetwork.cs" />
<Compile Include="Service\CreateAzureSiteRecoveryRecoveryPlan.cs" />
<Compile Include="Service\GetAzureSiteRecoveryRecoveryPlanFile.cs" />
<Compile Include="Service\GetAzureSiteRecoveryVaultCredential.cs" />
<Compile Include="Service\RemoveAzureSiteRecoveryRecoveryPlan.cs" />
<Compile Include="Service\GetAzureSiteRecoveryProtectionEntity.cs" />
<Compile Include="Service\RestartAzureSiteRecoveryJob.cs" />
Expand Down Expand Up @@ -166,6 +177,10 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="lib\Microsoft.Azure.RecoveryServices.dll" />
<Content Include="lib\Security.Cryptography.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Microsoft.Azure.Commands.RecoveryServices.dll-help.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand All @@ -181,6 +196,9 @@
<None Include="MSSharedLibKey.snk" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Service References\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ public partial class PSRecoveryServicesClient
/// </summary>
public string ClientRequestId { get; set; }

/// <summary>
/// Gets the value of recovery services management client.
/// </summary>
public RecoveryServicesManagementClient GetRecoveryServicesClient
{
get
{
return this.recoveryServicesClient;
}
}

/// <summary>
/// Amount of time to sleep before fetching job details again.
/// </summary>
Expand Down Expand Up @@ -184,8 +195,9 @@ public string GenerateAgentAuthenticationHeader(string clientRequestId)
/// <summary>
/// Gets request headers.
/// </summary>
/// <param name="shouldSignRequest">specifies whether to sign the request or not</param>
/// <returns>Custom request headers</returns>
public CustomRequestHeaders GetRequestHeaders()
public CustomRequestHeaders GetRequestHeaders(bool shouldSignRequest = true)
{
this.ClientRequestId = Guid.NewGuid().ToString() + "-" + DateTime.Now.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ssZ") + "-P";

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using Microsoft.Azure.Commands.RecoveryServices.SiteRecovery;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.Management.RecoveryServices.Models;

namespace Microsoft.Azure.Commands.RecoveryServices
{
/// <summary>
/// Recovery services convenience client.
/// </summary>
public partial class PSRecoveryServicesClient
{
/// <summary>
/// Method to retrieve cloud services list for the current subscription
/// </summary>
/// <returns>list of cloud services.</returns>
public IEnumerable<CloudService> GetCloudServices()
{
CloudServiceListResponse response = this.GetRecoveryServicesClient.CloudServices.List();

return response.CloudServices;
}

/// <summary>
/// Method to get Cloud Service object for a given vault
/// </summary>
/// <param name="vault">vault object</param>
/// <returns>cloud service object.</returns>
public CloudService GetCloudServiceForVault(ASRVault vault)
{
IEnumerable<CloudService> cloudServiceList = this.GetCloudServices();
CloudService cloudServiceToReturn = null;

foreach (var cloudService in cloudServiceList)
{
Vault selectedVault = null;
if (cloudService.GeoRegion.Equals(vault.Location, StringComparison.InvariantCultureIgnoreCase))
{
foreach (var resource in cloudService.Resources)
{
if (resource.Name.Equals(vault.Name, StringComparison.InvariantCultureIgnoreCase))
{
selectedVault = resource;
break;
}
}
}

if (selectedVault != null)
{
cloudServiceToReturn = cloudService;
break;
}
}

return cloudServiceToReturn;
}

/// <summary>
/// Method to Either find or create the cloud service.
/// </summary>
/// <param name="cloudServiceName">name of the cloud service to be created</param>
/// <param name="cloudServiceInput">cloud service input to create the service.</param>
public void FindOrCreateCloudService(string cloudServiceName, CloudServiceCreateArgs cloudServiceInput)
{
bool cloudServicePresent = this.DoesCloudServiceExits(cloudServiceName);

if (!cloudServicePresent)
{
this.GetRecoveryServicesClient.CloudServices.Create(cloudServiceName, cloudServiceInput);
}
}

/// <summary>
/// Checks whether a cloud service is present or not.
/// </summary>
/// <param name="cloudServiceName">name of the cloud service to be created</param>
/// <returns>returns true in case the cloud service exits and false otherwise.</returns>
private bool DoesCloudServiceExits(string cloudServiceName)
{
IEnumerable<CloudService> cloudServiceList = this.GetCloudServices();
bool cloudServicePresent = false;

foreach (var cloudService in cloudServiceList)
{
if (cloudServiceName.Equals(cloudService.Name, StringComparison.InvariantCultureIgnoreCase))
{
cloudServicePresent = true;
break;
}
}

return cloudServicePresent;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.Management.RecoveryServices.Models;

namespace Microsoft.Azure.Commands.RecoveryServices
{
/// <summary>
/// Recovery services convenience client.
/// </summary>
public partial class PSRecoveryServicesClient
{
/// <summary>
/// Method to create Azure Site Recovery Vault
/// </summary>
/// <param name="cloudServiceName">name of the cloud service</param>
/// <param name="vaultName">name of the vault</param>
/// <param name="vaultCreateInput">vault creation input object</param>
/// <returns>creation response object.</returns>
public VaultCreateResponse CreateVault(string cloudServiceName, string vaultName, VaultCreateArgs vaultCreateInput)
{
return this.GetRecoveryServicesClient.Vaults.Create(cloudServiceName, vaultName, vaultCreateInput);
}
}
}
Loading

0 comments on commit 489de54

Please sign in to comment.