-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from AsrOneSdk/neha-dev
Create Protection Profile cmdlet and Protection Profile model
- Loading branch information
Showing
13 changed files
with
713 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
...ices/Commands.RecoveryServices/PSRecoveryServicesClient/PSRecoveryServicesClientHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
...ds.RecoveryServices/PSRecoveryServicesClient/PSRecoveryServicesProtectionProfileClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...iceManagement/RecoveryServices/Commands.RecoveryServices/Properties/Resources.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.