Skip to content

Commit

Permalink
Merge pull request #8 from AsrOneSdk/neha-dev
Browse files Browse the repository at this point in the history
Create Protection Profile cmdlet and Protection Profile model
  • Loading branch information
sanjkuma committed Jan 20, 2015
2 parents 6bee28e + d9e027e commit e33f51b
Show file tree
Hide file tree
Showing 13 changed files with 713 additions and 199 deletions.
8 changes: 8 additions & 0 deletions setup/azurecmdfiles.wxi
Original file line number Diff line number Diff line change
Expand Up @@ -1114,9 +1114,15 @@
<Component Id="cmp12C6E2ACC51F95C3303F6486917E8E75" Guid="*">
<File Id="filDB5B05710501E18F7BB630DA75A91B03" KeyPath="yes" Source="$(var.sourceDir)\ServiceManagement\Azure\Network\Newtonsoft.Json.dll" />
</Component>
<Component Id="cmpE36FC5D85FACEDF16450AC56F0C159BE" Guid="*">
<File Id="filF9245A77CC3210597C7BCB3777FFEEC3" KeyPath="yes" Source="$(var.sourceDir)\ServiceManagement\Azure\Network\System.Net.Http.Extensions.dll" />
</Component>
<Component Id="cmp87E83CA66DD51C9A6D61F1AC91FF683B" Guid="*">
<File Id="filB81C05773E93D768A10E3A660379BBC7" KeyPath="yes" Source="$(var.sourceDir)\ServiceManagement\Azure\Network\System.Net.Http.Formatting.dll" />
</Component>
<Component Id="cmp4F4E2D906EB5F067FB54ACDE2DA1F2DE" Guid="*">
<File Id="fil32D7BA9A1417F592C027C83F08BCB27A" KeyPath="yes" Source="$(var.sourceDir)\ServiceManagement\Azure\Network\System.Net.Http.Primitives.dll" />
</Component>
<Component Id="cmpCC09A82900E1A278F48DB77993C40967" Guid="*">
<File Id="filA9139A091A1470B6463953C84F7B1BF9" KeyPath="yes" Source="$(var.sourceDir)\ServiceManagement\Azure\Network\System.Spatial.dll" />
</Component>
Expand Down Expand Up @@ -2341,7 +2347,9 @@
<ComponentRef Id="cmpB382FB922425C1C446A732BD66BBEEE0" />
<ComponentRef Id="cmp9C36EDC63632529B78C870EF3695F0D3" />
<ComponentRef Id="cmp12C6E2ACC51F95C3303F6486917E8E75" />
<ComponentRef Id="cmpE36FC5D85FACEDF16450AC56F0C159BE" />
<ComponentRef Id="cmp87E83CA66DD51C9A6D61F1AC91FF683B" />
<ComponentRef Id="cmp4F4E2D906EB5F067FB54ACDE2DA1F2DE" />
<ComponentRef Id="cmpCC09A82900E1A278F48DB77993C40967" />
<ComponentRef Id="cmpCA80C6C0F5670291AF2F3560D36B1EA3" />
<ComponentRef Id="cmp1E1EACEE941A7D7B9B2649BB3AC9ABC3" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
<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.Storage">
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Management.Storage.3.1.0\lib\net40\Microsoft.WindowsAzure.Management.Storage.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>
Expand Down Expand Up @@ -119,6 +122,8 @@
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesCloudServiceClient.cs" />
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesProtectionProfileClient.cs" />
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesClientHelper.cs" />
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesStorageClient.cs" />
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesStorageMappingClient.cs" />
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesNetworkMappingClient.cs" />
Expand All @@ -137,6 +142,7 @@
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesVMClient.cs" />
<Compile Include="RecoveryServicesCmdletBase.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Service\CreateAzureSiteRecoveryProtectionProfileObject.cs" />
<Compile Include="Service\CreateAzureSiteRecoveryVault.cs" />
<Compile Include="Service\GetAzureSiteRecoveryStorage.cs" />
<Compile Include="Service\GetAzureSiteRecoveryStorageMapping.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// ----------------------------------------------------------------------------------
//
// 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.WindowsAzure;
using Microsoft.WindowsAzure.Commands.Common;
using Microsoft.WindowsAzure.Commands.Common.Models;
using Microsoft.WindowsAzure.Management.Storage;
using Microsoft.WindowsAzure.Management.Storage.Models;

namespace Microsoft.Azure.Commands.RecoveryServices
{
/// <summary>
/// Recovery Services Client Helper Methods class
/// </summary>
public class PSRecoveryServicesClientHelper
{
/// <summary>
/// Validates whether the subscription belongs to the currently logged account or not.
/// </summary>
/// <param name="azureSubscriptionId">Azure Subscription ID</param>
public static void ValidateSubscriptionAccountAssociation(string azureSubscriptionId)
{
bool associatedSubscription = false;
ProfileClient pc = new ProfileClient();
List<AzureSubscription> subscriptions =
pc.RefreshSubscriptions(AzureSession.CurrentContext.Environment);

foreach (AzureSubscription sub in subscriptions)
{
if (azureSubscriptionId.Equals(sub.Id.ToString(), StringComparison.OrdinalIgnoreCase))
{
associatedSubscription = true;
break;
}
}

if (!associatedSubscription)
{
throw new InvalidOperationException(
string.Format(
Properties.Resources.SubscriptionIsNotAssociatedWithTheAccount,
azureSubscriptionId));
}
}

/// <summary>
/// Validates whether the storage belongs to the currently logged account or not.
/// </summary>
/// <param name="azureStorageAccount">Storage Account details</param>
public static void ValidateStorageAccountAssociation(string azureStorageAccount)
{
bool associatedAccount = false;

SubscriptionCloudCredentials creds
= AzureSession.AuthenticationFactory.GetSubscriptionCloudCredentials(AzureSession.CurrentContext);
StorageManagementClient storageManagementClient = new StorageManagementClient(creds);

StorageAccountListResponse storageAccounts = storageManagementClient.StorageAccounts.List();
foreach (StorageAccount storage in storageAccounts)
{
if (azureStorageAccount.Equals(storage.Name, StringComparison.OrdinalIgnoreCase))
{
associatedAccount = true;
break;
}
}

if (!associatedAccount)
{
throw new InvalidOperationException(
string.Format(
Properties.Resources.StorageIsNotAssociatedWithTheAccount,
azureStorageAccount));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -293,35 +293,6 @@ public partial class PSRecoveryServicesClient
.Create(networkMappingInput, this.GetRequestHeaders());
}

/// <summary>
/// Validates whether the subscription belongs to the currently logged account or not.
/// </summary>
/// <param name="azureSubscriptionId">Azure Subscription ID</param>
public void ValidateSubscriptionAccountAssociation(string azureSubscriptionId)
{
bool associatedSubscription = false;
ProfileClient pc = new ProfileClient();
List<AzureSubscription> subscriptions =
pc.RefreshSubscriptions(AzureSession.CurrentContext.Environment);

foreach (AzureSubscription sub in subscriptions)
{
if (azureSubscriptionId.Equals(sub.Id.ToString(), StringComparison.OrdinalIgnoreCase))
{
associatedSubscription = true;
break;
}
}

if (!associatedSubscription)
{
throw new InvalidOperationException(
string.Format(
Properties.Resources.SubscriptionIsNotAssociatedWithTheAccount,
azureSubscriptionId));
}
}

/// <summary>
/// Validates whether the Azure VM Network is associated with the subscription or not.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// ----------------------------------------------------------------------------------
//
// 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 Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.Management.SiteRecovery;
using Microsoft.WindowsAzure.Management.SiteRecovery.Models;

namespace Microsoft.Azure.Commands.RecoveryServices
{
/// <summary>
/// Recovery services convenience client.
/// </summary>
public partial class PSRecoveryServicesClient
{
/// <summary>
/// Gets Azure Site Recovery Protection Profile.
/// </summary>
/// <returns>Protection Profile list response</returns>
public ProtectionProfileListResponse GetAzureSiteRecoveryProtectionProfile()
{
return this.GetSiteRecoveryClient().ProtectionProfile.List(this.GetRequestHeaders());
}

/// <summary>
/// Gets Azure Site Recovery Protection Profile given the ID.
/// </summary>
/// <param name="protectionProfileId">Protection Profile ID</param>
/// <returns>Protection Profile response</returns>
public ProtectionProfileResponse GetAzureSiteRecoveryProtectionProfile(
string protectionProfileId)
{
return this.GetSiteRecoveryClient().ProtectionProfile.Get(
protectionProfileId,
this.GetRequestHeaders());
}

/// <summary>
/// Updates Azure Site Recovery Protection Profile given the ID.
/// </summary>
/// <param name="updateProtectionProfileInput">Protection Profile Input</param>
/// <param name="protectionProfileId">Protection Profile ID</param>
/// <returns>Job response</returns>
public JobResponse UpdateAzureSiteRecoveryProtectionProfile(
UpdateProtectionProfileInput updateProtectionProfileInput,
string protectionProfileId)
{
return this.GetSiteRecoveryClient().ProtectionProfile.Update(
updateProtectionProfileInput,
protectionProfileId,
this.GetRequestHeaders());
}

/// <summary>
/// Creates and Associates Azure Site Recovery Protection Profile.
/// </summary>
/// <param name="createAndAssociateProtectionProfileInput">Protection Profile Input</param>
/// <returns>Job response</returns>
public JobResponse StartCreateAndAssociateAzureSiteRecoveryProtectionProfileJob(
CreateAndAssociateProtectionProfileInput createAndAssociateProtectionProfileInput)
{
return this.GetSiteRecoveryClient().ProtectionProfile.CreateAndAssociate(
createAndAssociateProtectionProfileInput,
this.GetRequestHeaders());
}

/// <summary>
/// Deletes and Dissociates Azure Site Recovery Protection Profile.
/// </summary>
/// <param name="protectionProfileId">Protection Profile ID</param>
/// <param name="protectionProfileAssociationInput">Protection Profile Association Input</param>
/// <returns>Job response</returns>
public JobResponse StartDeleteAndDissociateAzureSiteRecoveryProtectionProfileJob(
string protectionProfileId,
ProtectionProfileAssociationInput protectionProfileAssociationInput)
{
return this.GetSiteRecoveryClient().ProtectionProfile.DissociateAndDelete(
protectionProfileId,
protectionProfileAssociationInput,
this.GetRequestHeaders());
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ ClientRequestId: {3}</value>
<data name="VaultCredentialGenerationUnSupported" xml:space="preserve">
<value>Cannot generate vault credentials for this vault. Download it from the Azure Portal.</value>
</data>
<data name="StorageIsNotAssociatedWithTheAccount" xml:space="preserve">
<value>Storage account {0} is not associated with the account</value>
</data>
<data name="VaultCreationSuccessMessage" xml:space="preserve">
<value>Vault has been created</value>
</data>
Expand Down
Loading

0 comments on commit e33f51b

Please sign in to comment.