From b003b741bb1cb1ab14cbfad334ac49dd472a0db3 Mon Sep 17 00:00:00 2001 From: vishak-ms Date: Thu, 7 Apr 2016 17:57:34 +0530 Subject: [PATCH] [Get/Set AzureRmRecoveryServicesvault] Adding Missing Files and some code changes --- .../Vault/GetAzureRmRecoveryServicesVaults.cs | 4 +- .../Vault/SetAzureRmRecoveryServicesVaults.cs | 71 +++++++++++++++++++ 2 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 src/ResourceManager/RecoveryServices/Commands.RecoveryServices/Vault/SetAzureRmRecoveryServicesVaults.cs diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices/Vault/GetAzureRmRecoveryServicesVaults.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices/Vault/GetAzureRmRecoveryServicesVaults.cs index 1e01b1a4fee6..558fdc0e5027 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices/Vault/GetAzureRmRecoveryServicesVaults.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices/Vault/GetAzureRmRecoveryServicesVaults.cs @@ -96,10 +96,10 @@ private void WriteVaults(IList vaults) { foreach (Vault vault in vaults) { - if (0 == string.Compare(this.Name, vault.Name, true)) + if (0 == string.Compare(this.Name, vault.Name, true) || string.IsNullOrEmpty(this.Name)) { ARSVault rsVault = new ARSVault(vault); - GetResourceStorageConfigResponse getStorageResponse = RecoveryServicesClient.GetVaultStorageType(this.ResourceGroupName, vault.Name); + GetResourceStorageConfigResponse getStorageResponse = RecoveryServicesClient.GetVaultStorageType(rsVault.ResouceGroupName, rsVault.Name); rsVault.Properties.BackupStorageRedundancy = getStorageResponse.Properties.StorageType; rsVault.Properties.BackupStorageDeduplication = getStorageResponse.Properties.DedupState; this.WriteObject(new ARSVault(vault)); diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices/Vault/SetAzureRmRecoveryServicesVaults.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices/Vault/SetAzureRmRecoveryServicesVaults.cs new file mode 100644 index 000000000000..e584fbc6a7fb --- /dev/null +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices/Vault/SetAzureRmRecoveryServicesVaults.cs @@ -0,0 +1,71 @@ +// ---------------------------------------------------------------------------------- +// +// 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 System.Linq; +using System.Management.Automation; +using Microsoft.Azure.Management.RecoveryServices.Models; + +namespace Microsoft.Azure.Commands.RecoveryServices +{ + /// + /// Retrieves Azure Recovery Services Vault. + /// + [Cmdlet(VerbsCommon.Set, "AzureRmRecoveryServicesVault")] + public class SetAzureRmRecoveryServicesVaults : RecoveryServicesCmdletBase + { + #region Parameters + /// + /// Gets or sets vault Object. + /// + [Parameter(Mandatory = true, ValueFromPipeline = true)] + [ValidateNotNullOrEmpty] + public ARSVault Vault { get; set; } + /// + /// Gets or sets BackupStorageRedundancy type. + /// + [Parameter(Mandatory = false)] + public string BackupStorageRedundancy { get; set; } + + /// + /// Gets or sets BackupStorageDeduplication type. + /// + [Parameter(Mandatory = false)] + public string BackupStorageDeduplication { get; set; } + #endregion Parameters + + /// + /// ProcessRecord of the command. + /// + public override void ExecuteCmdlet() + { + try + { + if (!(string.IsNullOrEmpty(this.BackupStorageRedundancy) && string.IsNullOrEmpty(this.BackupStorageDeduplication))) + { + UpdateVaultStorageTypeRequest vaultStorageRequest = new UpdateVaultStorageTypeRequest(); + vaultStorageRequest.Properties = new StorageTypeProperties(); + vaultStorageRequest.Properties.StorageModelType = BackupStorageRedundancy; + vaultStorageRequest.Properties.DedupState = BackupStorageDeduplication; + AzureOperationResponse storageResponse = RecoveryServicesClient.UpdateVaultStorageType(this.Vault.ResouceGroupName, this.Vault.Name, vaultStorageRequest); + } + } + catch (Exception exception) + { + this.HandleException(exception); + } + } + } +}