From 862bd35e28955a3903859a19ffbf3eb166b9de41 Mon Sep 17 00:00:00 2001 From: pragrawa Date: Wed, 17 Jun 2015 14:54:15 +0530 Subject: [PATCH 1/5] ProtectionPolicy changes --- .../AzureBackupCmdletHelpMessage.cs | 3 +- .../GetAzureBackupProtectionPolicy.cs | 5 +- .../NewAzureBackupProtectionPolicy.cs | 49 +++- .../RemoveAzureBackupProtectionPolicy.cs | 6 +- .../SetAzureBackupProtectionPolicy.cs | 66 ++--- .../Commands.AzureBackup.csproj | 9 +- .../Library/ProtectionPolicyHelper.cs | 234 ++++++++++++++++++ .../Models/AzureBackupEnums.cs | 26 ++ .../Models/ProtectionPolicy.cs | 6 +- 9 files changed, 332 insertions(+), 72 deletions(-) create mode 100644 src/ResourceManager/AzureBackup/Commands.AzureBackup/Library/ProtectionPolicyHelper.cs diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupCmdletHelpMessage.cs b/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupCmdletHelpMessage.cs index 9bac64b6af95..38cf1cb69e10 100644 --- a/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupCmdletHelpMessage.cs +++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupCmdletHelpMessage.cs @@ -46,6 +46,7 @@ internal static class AzureBackupCmdletHelpMessage public const string ScheduleRunTimes = "Times of day for running backup."; public const string RetentionType = "Unit of retention for the recovery point."; public const string RententionDuration = "Duration of retention for the recovery point in units specified by RetentionType."; - public const string PolicyInstanceId = "ProtectionPolicy InstanceId"; + public const string PolicyNewName = "Policy new name"; + public const string AzureBackupPolicy = "Azure Backup protection policy"; } } diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/GetAzureBackupProtectionPolicy.cs b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/GetAzureBackupProtectionPolicy.cs index 6da99d9b3a33..d51235f89b7e 100644 --- a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/GetAzureBackupProtectionPolicy.cs +++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/GetAzureBackupProtectionPolicy.cs @@ -25,7 +25,7 @@ namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets /// Get list of protection policies /// [Cmdlet(VerbsCommon.Get, "AzureBackupProtectionPolicy"), OutputType(typeof(AzureBackupProtectionPolicy), typeof(List))] - public class GetAzureBackupProtectionPolicy : AzureBackupPolicyCmdletBase + public class GetAzureBackupProtectionPolicy : AzureBackupVaultCmdletBase { [Parameter(Position = 3, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.PolicyName)] [ValidateNotNullOrEmpty] @@ -53,7 +53,8 @@ public override void ExecuteCmdlet() } WriteDebug("Converting response"); - WriteAzureBackupProtectionPolicy(policyObjects); + ProtectionPolicyHelper.WriteAzureBackupProtectionPolicy(this, ResourceGroupName, ResourceName, Location, policyObjects); + }); } } diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/NewAzureBackupProtectionPolicy.cs b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/NewAzureBackupProtectionPolicy.cs index 6a5be3176f75..94f35a8c0a0e 100644 --- a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/NewAzureBackupProtectionPolicy.cs +++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/NewAzureBackupProtectionPolicy.cs @@ -24,9 +24,12 @@ namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets /// /// Create new protection policy /// - [Cmdlet(VerbsCommon.Add, "AzureBackupProtectionPolicy"), OutputType(typeof(AzureBackupProtectionPolicy))] - public class NewAzureBackupProtectionPolicy : AzureBackupPolicyCmdletBase - { + [Cmdlet(VerbsCommon.New, "AzureBackupProtectionPolicy", DefaultParameterSetName = DailyScheduleParamSet), OutputType(typeof(AzureBackupProtectionPolicy))] + public class NewAzureBackupProtectionPolicy : AzureBackupVaultCmdletBase + { + protected const string WeeklyScheduleParamSet = "WeeklyScheduleParamSet"; + protected const string DailyScheduleParamSet = "DailyScheduleParamSet"; + [Parameter(Position = 3, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.PolicyName)] [ValidateNotNullOrEmpty] public string Name { get; set; } @@ -39,9 +42,11 @@ public class NewAzureBackupProtectionPolicy : AzureBackupPolicyCmdletBase [ValidateSet("Full")] public string BackupType { get; set; } - [Parameter(Position = 6, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleType, ValueFromPipelineByPropertyName = true)] - [ValidateSet("Daily", "Weekly")] - public string ScheduleType { get; set; } + [Parameter(ParameterSetName = DailyScheduleParamSet, Position = 7, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleType)] + public SwitchParameter Daily { get; set; } + + [Parameter(ParameterSetName = WeeklyScheduleParamSet, Position = 6, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleType)] + public SwitchParameter Weekly { get; set; } [Parameter(Position = 7, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleRunTimes, ValueFromPipelineByPropertyName = true)] public DateTime ScheduleRunTimes { get; set; } @@ -51,10 +56,9 @@ public class NewAzureBackupProtectionPolicy : AzureBackupPolicyCmdletBase public string RetentionType { get; set; } [Parameter(Position = 9, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.RententionDuration, ValueFromPipelineByPropertyName = true)] - [ValidateRange(1,30)] public int RetentionDuration { get; set; } - [Parameter(Position = 10, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleRunDays, ValueFromPipelineByPropertyName = true)] + [Parameter(ParameterSetName = WeeklyScheduleParamSet, Position = 10, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleRunDays, ValueFromPipelineByPropertyName = true)] [ValidateSet("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", IgnoreCase = true)] public string[] ScheduleRunDays { get; set; } @@ -66,8 +70,14 @@ public override void ExecuteCmdlet() { WriteDebug("Making client call"); - var backupSchedule = GetBackupSchedule(BackupType, ScheduleType, ScheduleRunTimes, - RetentionType, RetentionDuration, ScheduleRunDays); + var ScheduleType = GetScheduelType(ScheduleRunDays); + + var backupSchedule = ProtectionPolicyHelper.GetBackupSchedule(this,BackupType, ScheduleType, ScheduleRunTimes, + RetentionType, RetentionDuration, ScheduleRunDays); + + + //var backupSchedule = GetBackupSchedule(BackupType, ScheduleType, ScheduleRunTimes, + // RetentionType, RetentionDuration, ScheduleRunDays); var addProtectionPolicyRequest = new AddProtectionPolicyRequest(); addProtectionPolicyRequest.PolicyName = this.Name; @@ -76,7 +86,7 @@ public override void ExecuteCmdlet() var operationId = AzureBackupClient.ProtectionPolicy.AddAsync(addProtectionPolicyRequest, GetCustomRequestHeaders(), CmdletCancellationToken).Result; - WriteVerbose("Protection policy created successfully"); + WriteDebug("Protection policy created successfully"); var policyListResponse = AzureBackupClient.ProtectionPolicy.ListAsync(GetCustomRequestHeaders(), CmdletCancellationToken).Result; @@ -86,9 +96,22 @@ public override void ExecuteCmdlet() policyObjects = policyListResponse.ProtectionPolicies.Where(x => x.Name.Equals(Name, System.StringComparison.InvariantCultureIgnoreCase)); WriteDebug("Converting response"); - WriteAzureBackupProtectionPolicy(policyObjects); + ProtectionPolicyHelper.WriteAzureBackupProtectionPolicy(this, ResourceGroupName, ResourceName, Location, policyObjects); }); - } + } + + private string GetScheduelType(string[] ScheduleRunDays) + { + WriteDebug("ParameterSetName = " + this.ParameterSetName.ToString()); + if (this.ParameterSetName == WeeklyScheduleParamSet || (ScheduleRunDays != null && ScheduleRunDays.Length > 0)) + { + return ScheduleType.Weekly.ToString(); + } + else + { + return ScheduleType.Daily.ToString(); + } + } } } diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/RemoveAzureBackupProtectionPolicy.cs b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/RemoveAzureBackupProtectionPolicy.cs index 74ed22c56106..07c425d3000c 100644 --- a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/RemoveAzureBackupProtectionPolicy.cs +++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/RemoveAzureBackupProtectionPolicy.cs @@ -27,10 +27,6 @@ namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets [Cmdlet(VerbsCommon.Remove, "AzureBackupProtectionPolicy")] public class RemoveAzureBackupProtectionPolicy : AzureBackupPolicyCmdletBase { - [Parameter(Position = 3, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.PolicyName)] - [ValidateNotNullOrEmpty] - public string Name { get; set; } - public override void ExecuteCmdlet() { base.ExecuteCmdlet(); @@ -44,7 +40,7 @@ public override void ExecuteCmdlet() WriteDebug("Received policy response"); IEnumerable policyObjects = null; - policyObjects = policyListResponse.ProtectionPolicies.Objects.Where(x => x.Name.Equals(Name, System.StringComparison.InvariantCultureIgnoreCase)); + policyObjects = policyListResponse.ProtectionPolicies.Objects.Where(x => x.Name.Equals(ProtectionPolicy.Name, System.StringComparison.InvariantCultureIgnoreCase)); if (policyObjects.Count() != 0) { diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/SetAzureBackupProtectionPolicy.cs b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/SetAzureBackupProtectionPolicy.cs index dcddd784dbc2..acc4ee8dfd14 100644 --- a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/SetAzureBackupProtectionPolicy.cs +++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/SetAzureBackupProtectionPolicy.cs @@ -27,37 +27,10 @@ namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets [Cmdlet(VerbsCommon.Set, "AzureBackupProtectionPolicy"), OutputType(typeof(AzureBackupProtectionPolicy))] public class SetAzureBackupProtectionPolicy : AzureBackupPolicyCmdletBase { - [Parameter(Position = 3, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.PolicyName, ValueFromPipelineByPropertyName = true)] + + [Parameter(Position = 3, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.PolicyNewName, ValueFromPipelineByPropertyName = true)] [ValidateNotNullOrEmpty] - public string Name { get; set; } - - [Parameter(Position = 4, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.PolicyInstanceId, ValueFromPipelineByPropertyName = true)] - [ValidateNotNullOrEmpty] - public string InstanceId { get; set; } - - [Parameter(Position = 5, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.BackupType, ValueFromPipelineByPropertyName = true)] - [ValidateSet("Full")] - public string BackupType { get; set; } - - [Parameter(Position = 6, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleType, ValueFromPipelineByPropertyName = true)] - [ValidateSet("Daily", "Weekly")] - public string ScheduleType { get; set; } - - [Parameter(Position = 7, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleRunTimes, ValueFromPipelineByPropertyName = true)] - public DateTime ScheduleRunTimes { get; set; } - - [Parameter(Position = 8, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.RetentionType, ValueFromPipelineByPropertyName = true)] - [ValidateSet("Days", IgnoreCase = true)] - public string RetentionType { get; set; } - - [Parameter(Position = 9, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.RententionDuration, ValueFromPipelineByPropertyName = true)] - [ValidateRange(1, 30)] - public int RetentionDuration { get; set; } - - [Parameter(Position = 10, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleRunDays, ValueFromPipelineByPropertyName = true)] - [ValidateSet("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", IgnoreCase = true)] - public string[] ScheduleRunDays { get; set; } - + public string NewName { get; set; } public override void ExecuteCmdlet() { @@ -66,45 +39,50 @@ public override void ExecuteCmdlet() ExecutionBlock(() => { WriteDebug("Making client call"); + AzureBackupProtectionPolicy policy = ProtectionPolicy; + ProtectionPolicyHelper.ValidateAzureBackupPolicyRequest(this, policy); - var backupSchedule = GetBackupSchedule(BackupType, ScheduleType, ScheduleRunTimes, - RetentionType, RetentionDuration, ScheduleRunDays); - - var updateProtectionPolicyRequest = new UpdateProtectionPolicyRequest(); - updateProtectionPolicyRequest.PolicyName = this.Name; - updateProtectionPolicyRequest.Schedule = backupSchedule; + var backupSchedule = ProtectionPolicyHelper.GetBackupSchedule(this, policy.BackupType, policy.ScheduleType, policy.ScheduleRunTimes, + policy.RetentionType, policy.RetentionDuration, policy.ScheduleRunDays.ToArray()); + var policyListResponse = AzureBackupClient.ProtectionPolicy.ListAsync(GetCustomRequestHeaders(), CmdletCancellationToken).Result; - + + NewName = (string.IsNullOrEmpty(NewName) ? policy.Name: NewName); + var updateProtectionPolicyRequest = new UpdateProtectionPolicyRequest(); + updateProtectionPolicyRequest.PolicyName = this.NewName; + updateProtectionPolicyRequest.Schedule = backupSchedule; + WriteDebug("Got the protectionPolicy List"); IEnumerable policyObjects = null; - policyObjects = policyListResponse.ProtectionPolicies.Objects.Where(x => x.InstanceId.Equals(this.InstanceId, System.StringComparison.InvariantCultureIgnoreCase)); + policyObjects = policyListResponse.ProtectionPolicies.Objects.Where(x => x.Name.Equals(policy.Name, System.StringComparison.InvariantCultureIgnoreCase)); - WriteDebug("Got the protectionPolicy with InstanceId" + InstanceId); + WriteDebug("Got the protectionPolicy with Name" + this.ProtectionPolicy.Name); if (policyObjects.Count() != 0) { - var operationId = AzureBackupClient.ProtectionPolicy.UpdateAsync(this.InstanceId, updateProtectionPolicyRequest, GetCustomRequestHeaders(), CmdletCancellationToken).Result; + var operationId = AzureBackupClient.ProtectionPolicy.UpdateAsync(ProtectionPolicy.InstanceId, updateProtectionPolicyRequest, GetCustomRequestHeaders(), CmdletCancellationToken).Result; } else { - var exception = new Exception("Protection Policy Not Found with InstanceId" + this.InstanceId); + var exception = new Exception("Protection Policy Not Found with Name" + ProtectionPolicy.Name); var errorRecord = new ErrorRecord(exception, string.Empty, ErrorCategory.InvalidData, null); WriteError(errorRecord); } - WriteVerbose("Protection Policy successfully updated"); + WriteDebug("Protection Policy successfully updated"); var policyListResponse_afterUpdate = AzureBackupClient.ProtectionPolicy.ListAsync(GetCustomRequestHeaders(), CmdletCancellationToken).Result; WriteDebug("Received policy response"); - policyObjects = policyListResponse_afterUpdate.ProtectionPolicies.Where(x => x.Name.Equals(Name, System.StringComparison.InvariantCultureIgnoreCase)); + policyObjects = policyListResponse_afterUpdate.ProtectionPolicies.Where(x => x.Name.Equals(NewName, System.StringComparison.InvariantCultureIgnoreCase)); WriteDebug("Converting response"); - WriteAzureBackupProtectionPolicy(policyObjects); + ProtectionPolicyHelper.WriteAzureBackupProtectionPolicy(this, policy.ResourceGroupName, policy.ResourceName, policy.Location, policyObjects); + }); } } diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Commands.AzureBackup.csproj b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Commands.AzureBackup.csproj index 52245d2a87f4..500bb4055ca3 100644 --- a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Commands.AzureBackup.csproj +++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Commands.AzureBackup.csproj @@ -86,7 +86,7 @@ ..\..\..\packages\Microsoft.WindowsAzure.Management.4.1.1\lib\net40\Microsoft.WindowsAzure.Management.dll - ..\..\..\..\..\..\azure-sdk-for-net\src\ResourceManagement\AzureBackup\BackupServicesManagment\bin\Net40-Debug\Microsoft.WindowsAzure.Management.BackupServicesManagment.dll + ..\..\..\..\..\..\Git4\dummy\azure-sdk-for-net\src\ResourceManagement\AzureBackup\BackupServicesManagment\bin\Net45-Debug\Microsoft.WindowsAzure.Management.BackupServicesManagment.dll False @@ -136,21 +136,22 @@ + + + - - Code - + diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Library/ProtectionPolicyHelper.cs b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Library/ProtectionPolicyHelper.cs new file mode 100644 index 000000000000..4a722d56942b --- /dev/null +++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Library/ProtectionPolicyHelper.cs @@ -0,0 +1,234 @@ +// ---------------------------------------------------------------------------------- +// +// 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.Management.Automation; +using System.Collections.Generic; +using System.Xml; +using Microsoft.WindowsAzure.Commands.Utilities.Common; +using Microsoft.Azure.Common.Authentication; +using Microsoft.Azure.Common.Authentication.Models; +using System.Threading; +using Hyak.Common; +using Microsoft.Azure.Commands.AzureBackup.Properties; +using System.Net; +using Microsoft.Azure.Management.BackupServices.Models; +using Microsoft.Azure.Commands.AzureBackup.Cmdlets; + +namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets +{ + public class ProtectionPolicyHelper + { + public const int MinRetentionInDays = 7; + public const int MaxRetentionInDays = 30; + public const int MinRetentionInWeeks = 1; + public const int MaxRetentionInWeeks = 4; + + public static void WriteAzureBackupProtectionPolicy(AzureBackupCmdletBase azureBackupCmd, string ResourceGroupName, + string ResourceName, string Location, ProtectionPolicyInfo sourcePolicy) + { + azureBackupCmd.WriteObject(new AzureBackupProtectionPolicy(ResourceGroupName, ResourceName, Location, sourcePolicy)); + } + + public static void WriteAzureBackupProtectionPolicy(AzureBackupCmdletBase azureBackupCmd, string ResourceGroupName, + string ResourceName, string Location, IEnumerable sourcePolicyList) + { + List targetList = new List(); + + foreach (var sourcePolicy in sourcePolicyList) + { + targetList.Add(new AzureBackupProtectionPolicy(ResourceGroupName, + ResourceName, Location, sourcePolicy)); + } + + azureBackupCmd.WriteObject(targetList, true); + } + + public static BackupSchedule GetBackupSchedule(AzureBackupCmdletBase azureBackupCmd, string backupType, string scheduleType, DateTime scheduleStartTime, + string retentionType, int retentionDuration, string[] scheduleRunDays) + { + var backupSchedule = new BackupSchedule(); + + backupSchedule.BackupType = backupType; + backupSchedule.RetentionPolicy = GetRetentionPolicy(azureBackupCmd, retentionType, retentionDuration); + + scheduleType = GetScheduleType(scheduleType, scheduleRunDays); + backupSchedule.ScheduleRun = scheduleType; + + if (string.Compare(scheduleType, ScheduleType.Weekly.ToString(), true) == 0) + { + backupSchedule.ScheduleRunDays = GetScheduleRunDays(azureBackupCmd, scheduleRunDays); + } + + DateTime scheduleRunTime = GetScheduleRunTime(scheduleStartTime); + + backupSchedule.ScheduleRunTimes = new List { scheduleRunTime }; + + azureBackupCmd.WriteDebug("Exiting GetBackupSchedule"); + return backupSchedule; + } + + public static void ValidateAzureBackupPolicyRequest(AzureBackupCmdletBase azureBackupCmd, AzureBackupProtectionPolicy policy) + { + + //ValidateWorkloadType(azureBackupCmd, policy.WorkloadType); + ValidateBackupType(azureBackupCmd, policy.BackupType); + ValidateScheduleType(azureBackupCmd, policy.ScheduleType); + ValidateScheduleRunDays(azureBackupCmd, policy.ScheduleRunDays); + ValidateRetentionType(azureBackupCmd, policy.RetentionType); + } + + private static void ValidateWorkloadType(AzureBackupCmdletBase azureBackupCmd, string workloadType) + { + WorkloadType item = (WorkloadType)Enum.Parse(typeof(WorkloadType), workloadType, true); + + if (item != WorkloadType.VM) + { + var exception = new Exception("Invalid value for param WorkloadType, Valid values are VM."); + var errorRecord = new ErrorRecord(exception, string.Empty, ErrorCategory.InvalidData, null); + azureBackupCmd.WriteError(errorRecord); + } + } + + private static void ValidateBackupType(AzureBackupCmdletBase azureBackupCmd, string backupType) + { + BackupType item = (BackupType)Enum.Parse(typeof(BackupType), backupType, true); + + if (item != BackupType.Full) + { + var exception = new Exception("Invalid value for param BackupType, Valid values are Full."); + var errorRecord = new ErrorRecord(exception, string.Empty, ErrorCategory.InvalidData, null); + azureBackupCmd.WriteError(errorRecord); + } + } + + private static void ValidateScheduleType(AzureBackupCmdletBase azureBackupCmd, string scheduleType) + { + ScheduleType item = (ScheduleType)Enum.Parse(typeof(ScheduleType), scheduleType, true); + + if (!(item == ScheduleType.Daily || item == ScheduleType.Weekly)) + { + var exception = new Exception("Invalid value for param ScheduleType, Valid values are Daily, Weekly."); + var errorRecord = new ErrorRecord(exception, string.Empty, ErrorCategory.InvalidData, null); + azureBackupCmd.WriteError(errorRecord); + } + } + + private static void ValidateRetentionType(AzureBackupCmdletBase azureBackupCmd, string retentionType) + { + RetentionType item = (RetentionType)Enum.Parse(typeof(RetentionType), retentionType, true); + + if (!(item == RetentionType.Days || item == RetentionType.Weeks)) + { + var exception = new Exception("Invalid value for param RetentionType, Valid values are Days, Weeks."); + var errorRecord = new ErrorRecord(exception, string.Empty, ErrorCategory.InvalidData, null); + azureBackupCmd.WriteError(errorRecord); + } + } + + private static void ValidateScheduleRunDays(AzureBackupCmdletBase azureBackupCmd, List scheduleRunDays) + { + foreach (string scheduleRunDay in scheduleRunDays) + { + DayOfWeek item = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), scheduleRunDay, true); + + if (!(item == DayOfWeek.Sunday || item == DayOfWeek.Monday || item == DayOfWeek.Tuesday || + item == DayOfWeek.Wednesday || item == DayOfWeek.Thursday || item == DayOfWeek.Friday || item == DayOfWeek.Saturday)) + { + var exception = new Exception("Invalid value for param ScheduleRunDays, " + + "Valid values are Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday"); + var errorRecord = new ErrorRecord(exception, string.Empty, ErrorCategory.InvalidData, null); + azureBackupCmd.WriteError(errorRecord); + } + } + } + private static RetentionPolicy GetRetentionPolicy(AzureBackupCmdletBase azureBackupCmd, string retentionType, int retentionDuration) + { + ValidateRetentionRange(azureBackupCmd, retentionType, retentionDuration); + var retentionPolicy = new RetentionPolicy + { + RetentionType = (RetentionDurationType)Enum.Parse(typeof(RetentionDurationType), retentionType, true), + RetentionDuration = retentionDuration + }; + + return retentionPolicy; + } + + private static void ValidateRetentionRange(AzureBackupCmdletBase azureBackupCmd, string retentionType, int retentionDuration) + { + if(retentionType == RetentionDurationType.Days.ToString() && (retentionDuration < MinRetentionInDays + || retentionDuration > MaxRetentionInDays)) + { + var exception = new Exception("For Retention in days , valid values of retention duration are 7 to 30."); + var errorRecord = new ErrorRecord(exception, string.Empty, ErrorCategory.InvalidData, null); + azureBackupCmd.WriteError(errorRecord); + } + + if (retentionType == RetentionDurationType.Weeks.ToString() && (retentionDuration < MinRetentionInWeeks + || retentionDuration > MaxRetentionInWeeks)) + { + var exception = new Exception("For Retention in weeks , valid values of retention duration are 1 to 4."); + var errorRecord = new ErrorRecord(exception, string.Empty, ErrorCategory.InvalidData, null); + azureBackupCmd.WriteError(errorRecord); + } + + } + + private static string GetScheduleType(string scheduleType, string[] scheduleRunDays) + { + if (scheduleType == ScheduleType.Daily.ToString() && scheduleRunDays != null && scheduleRunDays.Length > 0) + { + return ScheduleType.Weekly.ToString(); + } + + else + { + return Enum.Parse(typeof(ScheduleType), scheduleType, true).ToString(); + } + } + + private static IList GetScheduleRunDays(AzureBackupCmdletBase azureBackupCmd, string[] scheduleRunDays) + { + if (scheduleRunDays == null || scheduleRunDays.Length <= 0) + { + var exception = new Exception("For weekly scheduletype , ScheduleRunDays should not be empty."); + var errorRecord = new ErrorRecord(exception, string.Empty, ErrorCategory.InvalidData, null); + azureBackupCmd.WriteError(errorRecord); + } + + IList ListofWeekDays = new List(); + + foreach (var dayOfWeek in scheduleRunDays) + { + azureBackupCmd.WriteDebug("dayOfWeek" + dayOfWeek.ToString()); + DayOfWeek item = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), dayOfWeek, true); + azureBackupCmd.WriteDebug("Item" + item.ToString()); + if (!ListofWeekDays.Contains(item)) + { + ListofWeekDays.Add(item); + } + } + + return ListofWeekDays; + } + + private static DateTime GetScheduleRunTime(DateTime scheduleStartTime) + { + scheduleStartTime = scheduleStartTime.ToUniversalTime(); + DateTime scheduleRunTime = new DateTime(scheduleStartTime.Year, scheduleStartTime.Month, + scheduleStartTime.Day, scheduleStartTime.Hour, scheduleStartTime.Minute - (scheduleStartTime.Minute % 30), 0); + return scheduleRunTime; + } + } +} diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Models/AzureBackupEnums.cs b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Models/AzureBackupEnums.cs index 54eeb2133599..64a161eadb67 100644 --- a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Models/AzureBackupEnums.cs +++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Models/AzureBackupEnums.cs @@ -92,4 +92,30 @@ public enum AzureBackupVaultStorageType GeoRedundant = 1, LocallyRedundant, } + + public enum ScheduleType + { + Invalid = 0, + Daily = 1, + Weekly = 2 + } + + public enum RetentionType + { + Invalid = 0, + Days = 1, + Weeks = 2 + } + + public enum WorkloadType + { + Invalid = 0, + VM = 1 + } + + public enum BackupType + { + Invalid = 0, + Full = 1 + } } diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Models/ProtectionPolicy.cs b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Models/ProtectionPolicy.cs index 83a9caad93c1..cb0afa42fe91 100644 --- a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Models/ProtectionPolicy.cs +++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Models/ProtectionPolicy.cs @@ -39,7 +39,7 @@ public class AzureBackupProtectionPolicy : AzureBackupVaultContextObject public string ScheduleType { get; set; } - public IList ScheduleRunDays { get; set; } + public List ScheduleRunDays { get; set; } public DateTime ScheduleRunTimes { get; set; } @@ -67,9 +67,9 @@ public AzureBackupProtectionPolicy(string resourceGroupName, string resourceName RetentionDuration = sourcePolicy.Schedule.RetentionPolicy.RetentionDuration; } - private IList ConvertScheduleRunDays(IList weekDaysList) + private List ConvertScheduleRunDays(IList weekDaysList) { - IList scheduelRunDays = new List(); + List scheduelRunDays = new List(); foreach(object item in weekDaysList) { From 1b71ddb24dc9b4b3333aea125e411b6769c58017 Mon Sep 17 00:00:00 2001 From: pragrawa Date: Wed, 17 Jun 2015 18:30:28 +0530 Subject: [PATCH 2/5] ProtectionPolicyChanges2 --- .../AzureBackupCmdletBase.cs | 1 + .../AzureBackupPolicyCmdletBase.cs | 94 ++----------------- .../GetAzureBackupProtectionPolicy.cs | 2 +- .../NewAzureBackupProtectionPolicy.cs | 15 +-- .../SetAzureBackupProtectionPolicy.cs | 85 +++++++++++++++-- ...cyHelper.cs => AzureBackupCmdletHelper.cs} | 80 ++++++++-------- 6 files changed, 143 insertions(+), 134 deletions(-) rename src/ResourceManager/AzureBackup/Commands.AzureBackup/Library/{ProtectionPolicyHelper.cs => AzureBackupCmdletHelper.cs} (72%) diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupCmdletBase.cs b/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupCmdletBase.cs index b73ff2db7947..eef1713302e3 100644 --- a/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupCmdletBase.cs +++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupCmdletBase.cs @@ -97,6 +97,7 @@ public void InitializeAzureBackupCmdlet(string rgName, string rName, string loca WriteDebug(string.Format("Initialized AzureBackup Cmdlet, ClientRequestId: {0}, ResourceGroupName: {1}, ResourceName : {2}", this.clientRequestId, resourceGroupName, resourceName)); CmdletCancellationToken = cancellationTokenSource.Token; + AzureBackupCmdletHelper cmdHelper = new AzureBackupCmdletHelper(this); } protected void ExecutionBlock(Action execAction) diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupPolicyCmdletBase.cs b/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupPolicyCmdletBase.cs index e41024298aa2..c2e4c6a3486d 100644 --- a/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupPolicyCmdletBase.cs +++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupPolicyCmdletBase.cs @@ -27,96 +27,22 @@ namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets { - public abstract class AzureBackupPolicyCmdletBase : AzureBackupVaultCmdletBase + public abstract class AzureBackupPolicyCmdletBase : AzureBackupCmdletBase { + // ToDO: + // Correct Help message and other attributes related to paameters + [Parameter(Position = 0, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.AzureBackupPolicy, ValueFromPipeline = true)] + [ValidateNotNullOrEmpty] + public AzureBackupProtectionPolicy ProtectionPolicy { get; set; } + public override void ExecuteCmdlet() { base.ExecuteCmdlet(); - WriteDebug(String.Format("Cmdlet called for ResourceGroupName: {0}, ResourceName: {1}, Location: {2}", ResourceGroupName, ResourceName, Location)); - } - - public void WriteAzureBackupProtectionPolicy(ProtectionPolicyInfo sourcePolicy) - { - this.WriteObject(new AzureBackupProtectionPolicy(ResourceGroupName, ResourceName, Location, sourcePolicy)); - } - - public void WriteAzureBackupProtectionPolicy(IEnumerable sourcePolicyList) - { - List targetList = new List(); - - foreach (var sourcePolicy in sourcePolicyList) - { - targetList.Add(new AzureBackupProtectionPolicy(ResourceGroupName, ResourceName, Location, sourcePolicy)); - } - - this.WriteObject(targetList, true); - } - - public BackupSchedule GetBackupSchedule(string backupType, string scheduleType, DateTime scheduleStartTime, - string retentionType, int retentionDuration, string[] scheduleRunDays = null) - { - var backupSchedule = new BackupSchedule(); - - backupSchedule.BackupType = backupType; - backupSchedule.RetentionPolicy = GetRetentionPolicy(retentionType, retentionDuration); - //Enum.Parse(ScheduleRunType, this.ScheduleType), - backupSchedule.ScheduleRun = scheduleType; - if (string.Compare(scheduleType, "Weekly", true) == 0) - { - backupSchedule.ScheduleRunDays = GetScheduleRunDays(scheduleRunDays); - } - - DateTime scheduleRunTime = GetScheduleRunTime(scheduleStartTime); + WriteDebug(String.Format("Cmdlet called for ResourceGroupName: {0}, ResourceName: {1}, Location: {2}", ProtectionPolicy.ResourceGroupName, ProtectionPolicy.ResourceName, ProtectionPolicy.Location)); - backupSchedule.ScheduleRunTimes = new List { scheduleRunTime }; - - WriteDebug("Exiting GetBackupSchedule"); - return backupSchedule; - } - - private RetentionPolicy GetRetentionPolicy(string retentionType, int retentionDuration) - { - var retentionPolicy = new RetentionPolicy - { - RetentionType = (RetentionDurationType)Enum.Parse(typeof(RetentionDurationType), retentionType, true), - RetentionDuration = retentionDuration - }; - - return retentionPolicy; - } - - private IList GetScheduleRunDays(string[] scheduleRunDays) - { - if (scheduleRunDays == null || scheduleRunDays.Length <= 0) - { - var exception = new Exception("For weekly scheduletype , ScheduleRunDays param is required."); - var errorRecord = new ErrorRecord(exception, string.Empty, ErrorCategory.InvalidData, null); - WriteError(errorRecord); - } - - IList ListofWeekDays = new List(); - - foreach (var dayOfWeek in scheduleRunDays) - { - WriteDebug("dayOfWeek" + dayOfWeek.ToString()); - DayOfWeek item = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), dayOfWeek, true); - WriteDebug("Item" + item.ToString()); - if (!ListofWeekDays.Contains(item)) - { - ListofWeekDays.Add(item); - } - } - - return ListofWeekDays; - } - - private DateTime GetScheduleRunTime(DateTime scheduleStartTime) - { - scheduleStartTime = scheduleStartTime.ToUniversalTime(); - DateTime scheduleRunTime = new DateTime(scheduleStartTime.Year, scheduleStartTime.Month, - scheduleStartTime.Day, scheduleStartTime.Hour, scheduleStartTime.Minute - (scheduleStartTime.Minute % 30), 0); - return scheduleRunTime; + InitializeAzureBackupCmdlet(ProtectionPolicy.ResourceGroupName, ProtectionPolicy.ResourceName, ProtectionPolicy.Location); } + } } \ No newline at end of file diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/GetAzureBackupProtectionPolicy.cs b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/GetAzureBackupProtectionPolicy.cs index d51235f89b7e..54626ebc5dc9 100644 --- a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/GetAzureBackupProtectionPolicy.cs +++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/GetAzureBackupProtectionPolicy.cs @@ -53,7 +53,7 @@ public override void ExecuteCmdlet() } WriteDebug("Converting response"); - ProtectionPolicyHelper.WriteAzureBackupProtectionPolicy(this, ResourceGroupName, ResourceName, Location, policyObjects); + AzureBackupCmdletHelper.WriteAzureBackupProtectionPolicy(ResourceGroupName, ResourceName, Location, policyObjects); }); } diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/NewAzureBackupProtectionPolicy.cs b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/NewAzureBackupProtectionPolicy.cs index 94f35a8c0a0e..e940ccb460d1 100644 --- a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/NewAzureBackupProtectionPolicy.cs +++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/NewAzureBackupProtectionPolicy.cs @@ -24,11 +24,12 @@ namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets /// /// Create new protection policy /// - [Cmdlet(VerbsCommon.New, "AzureBackupProtectionPolicy", DefaultParameterSetName = DailyScheduleParamSet), OutputType(typeof(AzureBackupProtectionPolicy))] + [Cmdlet(VerbsCommon.New, "AzureBackupProtectionPolicy", DefaultParameterSetName = NoScheduleParamSet), OutputType(typeof(AzureBackupProtectionPolicy))] public class NewAzureBackupProtectionPolicy : AzureBackupVaultCmdletBase { protected const string WeeklyScheduleParamSet = "WeeklyScheduleParamSet"; protected const string DailyScheduleParamSet = "DailyScheduleParamSet"; + protected const string NoScheduleParamSet = "DailyScheduleParamSet"; [Parameter(Position = 3, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.PolicyName)] [ValidateNotNullOrEmpty] @@ -59,6 +60,7 @@ public class NewAzureBackupProtectionPolicy : AzureBackupVaultCmdletBase public int RetentionDuration { get; set; } [Parameter(ParameterSetName = WeeklyScheduleParamSet, Position = 10, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleRunDays, ValueFromPipelineByPropertyName = true)] + [Parameter(ParameterSetName = NoScheduleParamSet, Position = 10, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleRunDays, ValueFromPipelineByPropertyName = true)] [ValidateSet("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", IgnoreCase = true)] public string[] ScheduleRunDays { get; set; } @@ -72,7 +74,7 @@ public override void ExecuteCmdlet() var ScheduleType = GetScheduelType(ScheduleRunDays); - var backupSchedule = ProtectionPolicyHelper.GetBackupSchedule(this,BackupType, ScheduleType, ScheduleRunTimes, + var backupSchedule = AzureBackupCmdletHelper.FillBackupSchedule(BackupType, ScheduleType, ScheduleRunTimes, RetentionType, RetentionDuration, ScheduleRunDays); @@ -96,21 +98,22 @@ public override void ExecuteCmdlet() policyObjects = policyListResponse.ProtectionPolicies.Where(x => x.Name.Equals(Name, System.StringComparison.InvariantCultureIgnoreCase)); WriteDebug("Converting response"); - ProtectionPolicyHelper.WriteAzureBackupProtectionPolicy(this, ResourceGroupName, ResourceName, Location, policyObjects); + AzureBackupCmdletHelper.WriteAzureBackupProtectionPolicy(ResourceGroupName, ResourceName, Location, policyObjects); }); } private string GetScheduelType(string[] ScheduleRunDays) { WriteDebug("ParameterSetName = " + this.ParameterSetName.ToString()); - if (this.ParameterSetName == WeeklyScheduleParamSet || (ScheduleRunDays != null && ScheduleRunDays.Length > 0)) + + if (ScheduleRunDays != null && ScheduleRunDays.Length > 0) { return ScheduleType.Weekly.ToString(); } - else + else { return ScheduleType.Daily.ToString(); - } + } } } } diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/SetAzureBackupProtectionPolicy.cs b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/SetAzureBackupProtectionPolicy.cs index acc4ee8dfd14..735c4403fa42 100644 --- a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/SetAzureBackupProtectionPolicy.cs +++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/SetAzureBackupProtectionPolicy.cs @@ -24,14 +24,41 @@ namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets /// /// Update existing protection policy /// - [Cmdlet(VerbsCommon.Set, "AzureBackupProtectionPolicy"), OutputType(typeof(AzureBackupProtectionPolicy))] + [Cmdlet(VerbsCommon.Set, "AzureBackupProtectionPolicy", DefaultParameterSetName = NoScheduleParamSet), OutputType(typeof(AzureBackupProtectionPolicy))] public class SetAzureBackupProtectionPolicy : AzureBackupPolicyCmdletBase { - + protected const string WeeklyScheduleParamSet = "WeeklyScheduleParamSet"; + protected const string DailyScheduleParamSet = "DailyScheduleParamSet"; + protected const string NoScheduleParamSet = "NoScheduleParamSet"; + [Parameter(Position = 3, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.PolicyNewName, ValueFromPipelineByPropertyName = true)] [ValidateNotNullOrEmpty] public string NewName { get; set; } + [Parameter(Position = 5, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.BackupType, ValueFromPipelineByPropertyName = true)] + [ValidateSet("Full")] + public string BackupType { get; set; } + + [Parameter(ParameterSetName = DailyScheduleParamSet, Position = 7, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleType)] + public SwitchParameter Daily { get; set; } + + [Parameter(ParameterSetName = WeeklyScheduleParamSet, Position = 6, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleType)] + public SwitchParameter Weekly { get; set; } + + [Parameter(Position = 7, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleRunTimes, ValueFromPipelineByPropertyName = true)] + public DateTime ScheduleRunTimes { get; set; } + + [Parameter(Position = 8, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.RetentionType, ValueFromPipelineByPropertyName = true)] + [ValidateSet("Days", IgnoreCase = true)] + public string RetentionType { get; set; } + + [Parameter(Position = 9, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.RententionDuration, ValueFromPipelineByPropertyName = true)] + public int RetentionDuration { get; set; } + + [Parameter(ParameterSetName = WeeklyScheduleParamSet, Position = 10, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleRunDays, ValueFromPipelineByPropertyName = true)] + [ValidateSet("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", IgnoreCase = true)] + public string[] ScheduleRunDays { get; set; } + public override void ExecuteCmdlet() { base.ExecuteCmdlet(); @@ -39,11 +66,15 @@ public override void ExecuteCmdlet() ExecutionBlock(() => { WriteDebug("Making client call"); + AzureBackupProtectionPolicy policy = ProtectionPolicy; - ProtectionPolicyHelper.ValidateAzureBackupPolicyRequest(this, policy); - var backupSchedule = ProtectionPolicyHelper.GetBackupSchedule(this, policy.BackupType, policy.ScheduleType, policy.ScheduleRunTimes, - policy.RetentionType, policy.RetentionDuration, policy.ScheduleRunDays.ToArray()); + FillRemainingValuesForSetPolicyRequest(policy); + + AzureBackupCmdletHelper.ValidateAzureBackupPolicyRequest(policy); + + var backupSchedule = AzureBackupCmdletHelper.FillBackupSchedule(BackupType, policy.ScheduleType, ScheduleRunTimes, + RetentionType, RetentionDuration, policy.ScheduleRunDays.ToArray()); var policyListResponse = AzureBackupClient.ProtectionPolicy.ListAsync(GetCustomRequestHeaders(), CmdletCancellationToken).Result; @@ -81,10 +112,52 @@ public override void ExecuteCmdlet() policyObjects = policyListResponse_afterUpdate.ProtectionPolicies.Where(x => x.Name.Equals(NewName, System.StringComparison.InvariantCultureIgnoreCase)); WriteDebug("Converting response"); - ProtectionPolicyHelper.WriteAzureBackupProtectionPolicy(this, policy.ResourceGroupName, policy.ResourceName, policy.Location, policyObjects); + AzureBackupCmdletHelper.WriteAzureBackupProtectionPolicy(policy.ResourceGroupName, policy.ResourceName, policy.Location, policyObjects); }); } + + private void FillRemainingValuesForSetPolicyRequest(AzureBackupProtectionPolicy policy) + { + if(string.IsNullOrEmpty(BackupType)) + { + BackupType = policy.BackupType; + } + + if (ScheduleRunTimes == null) + { + ScheduleRunTimes = policy.ScheduleRunTimes; + } + + if (string.IsNullOrEmpty(RetentionType)) + { + RetentionType = policy.RetentionType; + } + + if (RetentionDuration == 0) + { + RetentionDuration = policy.RetentionDuration; + } + + if (string.IsNullOrEmpty(BackupType)) + { + BackupType = policy.BackupType; + } + + if (this.ParameterSetName != NoScheduleParamSet ) + { + if (ScheduleRunDays != null && ScheduleRunDays.Length > 0) + { + policy.ScheduleType = ScheduleType.Weekly.ToString(); + policy.ScheduleRunDays = ScheduleRunDays.ToList(); + } + else + { + policy.ScheduleType = ScheduleType.Daily.ToString(); + } + + } + } } } diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Library/ProtectionPolicyHelper.cs b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Library/AzureBackupCmdletHelper.cs similarity index 72% rename from src/ResourceManager/AzureBackup/Commands.AzureBackup/Library/ProtectionPolicyHelper.cs rename to src/ResourceManager/AzureBackup/Commands.AzureBackup/Library/AzureBackupCmdletHelper.cs index 4a722d56942b..94f77f06b691 100644 --- a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Library/ProtectionPolicyHelper.cs +++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Library/AzureBackupCmdletHelper.cs @@ -28,20 +28,26 @@ namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets { - public class ProtectionPolicyHelper + public class AzureBackupCmdletHelper { public const int MinRetentionInDays = 7; public const int MaxRetentionInDays = 30; public const int MinRetentionInWeeks = 1; public const int MaxRetentionInWeeks = 4; + public static AzureBackupCmdletBase azureBackupCmdletBase; - public static void WriteAzureBackupProtectionPolicy(AzureBackupCmdletBase azureBackupCmd, string ResourceGroupName, + public AzureBackupCmdletHelper(AzureBackupCmdletBase azureBackupCmd) + { + azureBackupCmdletBase = azureBackupCmd; + } + + public static void WriteAzureBackupProtectionPolicy(string ResourceGroupName, string ResourceName, string Location, ProtectionPolicyInfo sourcePolicy) { - azureBackupCmd.WriteObject(new AzureBackupProtectionPolicy(ResourceGroupName, ResourceName, Location, sourcePolicy)); + azureBackupCmdletBase.WriteObject(new AzureBackupProtectionPolicy(ResourceGroupName, ResourceName, Location, sourcePolicy)); } - public static void WriteAzureBackupProtectionPolicy(AzureBackupCmdletBase azureBackupCmd, string ResourceGroupName, + public static void WriteAzureBackupProtectionPolicy(string ResourceGroupName, string ResourceName, string Location, IEnumerable sourcePolicyList) { List targetList = new List(); @@ -52,44 +58,44 @@ public static void WriteAzureBackupProtectionPolicy(AzureBackupCmdletBase azureB ResourceName, Location, sourcePolicy)); } - azureBackupCmd.WriteObject(targetList, true); + azureBackupCmdletBase.WriteObject(targetList, true); } - public static BackupSchedule GetBackupSchedule(AzureBackupCmdletBase azureBackupCmd, string backupType, string scheduleType, DateTime scheduleStartTime, + public static BackupSchedule FillBackupSchedule(string backupType, string scheduleType, DateTime scheduleStartTime, string retentionType, int retentionDuration, string[] scheduleRunDays) { var backupSchedule = new BackupSchedule(); backupSchedule.BackupType = backupType; - backupSchedule.RetentionPolicy = GetRetentionPolicy(azureBackupCmd, retentionType, retentionDuration); + backupSchedule.RetentionPolicy = FillRetentionPolicy(retentionType, retentionDuration); - scheduleType = GetScheduleType(scheduleType, scheduleRunDays); + scheduleType = FillScheduleType(scheduleType, scheduleRunDays); backupSchedule.ScheduleRun = scheduleType; if (string.Compare(scheduleType, ScheduleType.Weekly.ToString(), true) == 0) { - backupSchedule.ScheduleRunDays = GetScheduleRunDays(azureBackupCmd, scheduleRunDays); + backupSchedule.ScheduleRunDays = ParseScheduleRunDays(scheduleRunDays); } - DateTime scheduleRunTime = GetScheduleRunTime(scheduleStartTime); + DateTime scheduleRunTime = ParseScheduleRunTime(scheduleStartTime); backupSchedule.ScheduleRunTimes = new List { scheduleRunTime }; - azureBackupCmd.WriteDebug("Exiting GetBackupSchedule"); + azureBackupCmdletBase.WriteDebug("Exiting GetBackupSchedule"); return backupSchedule; } - public static void ValidateAzureBackupPolicyRequest(AzureBackupCmdletBase azureBackupCmd, AzureBackupProtectionPolicy policy) + public static void ValidateAzureBackupPolicyRequest(AzureBackupProtectionPolicy policy) { //ValidateWorkloadType(azureBackupCmd, policy.WorkloadType); - ValidateBackupType(azureBackupCmd, policy.BackupType); - ValidateScheduleType(azureBackupCmd, policy.ScheduleType); - ValidateScheduleRunDays(azureBackupCmd, policy.ScheduleRunDays); - ValidateRetentionType(azureBackupCmd, policy.RetentionType); + ValidateBackupType(policy.BackupType); + ValidateScheduleType(policy.ScheduleType); + ValidateScheduleRunDays(policy.ScheduleRunDays); + ValidateRetentionType(policy.RetentionType); } - private static void ValidateWorkloadType(AzureBackupCmdletBase azureBackupCmd, string workloadType) + private static void ValidateWorkloadType(string workloadType) { WorkloadType item = (WorkloadType)Enum.Parse(typeof(WorkloadType), workloadType, true); @@ -97,11 +103,11 @@ private static void ValidateWorkloadType(AzureBackupCmdletBase azureBackupCmd, s { var exception = new Exception("Invalid value for param WorkloadType, Valid values are VM."); var errorRecord = new ErrorRecord(exception, string.Empty, ErrorCategory.InvalidData, null); - azureBackupCmd.WriteError(errorRecord); + azureBackupCmdletBase.WriteError(errorRecord); } } - private static void ValidateBackupType(AzureBackupCmdletBase azureBackupCmd, string backupType) + private static void ValidateBackupType(string backupType) { BackupType item = (BackupType)Enum.Parse(typeof(BackupType), backupType, true); @@ -109,11 +115,11 @@ private static void ValidateBackupType(AzureBackupCmdletBase azureBackupCmd, str { var exception = new Exception("Invalid value for param BackupType, Valid values are Full."); var errorRecord = new ErrorRecord(exception, string.Empty, ErrorCategory.InvalidData, null); - azureBackupCmd.WriteError(errorRecord); + azureBackupCmdletBase.WriteError(errorRecord); } } - private static void ValidateScheduleType(AzureBackupCmdletBase azureBackupCmd, string scheduleType) + private static void ValidateScheduleType(string scheduleType) { ScheduleType item = (ScheduleType)Enum.Parse(typeof(ScheduleType), scheduleType, true); @@ -121,11 +127,11 @@ private static void ValidateScheduleType(AzureBackupCmdletBase azureBackupCmd, s { var exception = new Exception("Invalid value for param ScheduleType, Valid values are Daily, Weekly."); var errorRecord = new ErrorRecord(exception, string.Empty, ErrorCategory.InvalidData, null); - azureBackupCmd.WriteError(errorRecord); + azureBackupCmdletBase.WriteError(errorRecord); } } - private static void ValidateRetentionType(AzureBackupCmdletBase azureBackupCmd, string retentionType) + private static void ValidateRetentionType(string retentionType) { RetentionType item = (RetentionType)Enum.Parse(typeof(RetentionType), retentionType, true); @@ -133,11 +139,11 @@ private static void ValidateRetentionType(AzureBackupCmdletBase azureBackupCmd, { var exception = new Exception("Invalid value for param RetentionType, Valid values are Days, Weeks."); var errorRecord = new ErrorRecord(exception, string.Empty, ErrorCategory.InvalidData, null); - azureBackupCmd.WriteError(errorRecord); + azureBackupCmdletBase.WriteError(errorRecord); } } - private static void ValidateScheduleRunDays(AzureBackupCmdletBase azureBackupCmd, List scheduleRunDays) + private static void ValidateScheduleRunDays(List scheduleRunDays) { foreach (string scheduleRunDay in scheduleRunDays) { @@ -149,13 +155,13 @@ private static void ValidateScheduleRunDays(AzureBackupCmdletBase azureBackupCmd var exception = new Exception("Invalid value for param ScheduleRunDays, " + "Valid values are Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday"); var errorRecord = new ErrorRecord(exception, string.Empty, ErrorCategory.InvalidData, null); - azureBackupCmd.WriteError(errorRecord); + azureBackupCmdletBase.WriteError(errorRecord); } } } - private static RetentionPolicy GetRetentionPolicy(AzureBackupCmdletBase azureBackupCmd, string retentionType, int retentionDuration) + private static RetentionPolicy FillRetentionPolicy(string retentionType, int retentionDuration) { - ValidateRetentionRange(azureBackupCmd, retentionType, retentionDuration); + ValidateRetentionRange(retentionType, retentionDuration); var retentionPolicy = new RetentionPolicy { RetentionType = (RetentionDurationType)Enum.Parse(typeof(RetentionDurationType), retentionType, true), @@ -165,14 +171,14 @@ private static RetentionPolicy GetRetentionPolicy(AzureBackupCmdletBase azureBac return retentionPolicy; } - private static void ValidateRetentionRange(AzureBackupCmdletBase azureBackupCmd, string retentionType, int retentionDuration) + private static void ValidateRetentionRange(string retentionType, int retentionDuration) { if(retentionType == RetentionDurationType.Days.ToString() && (retentionDuration < MinRetentionInDays || retentionDuration > MaxRetentionInDays)) { var exception = new Exception("For Retention in days , valid values of retention duration are 7 to 30."); var errorRecord = new ErrorRecord(exception, string.Empty, ErrorCategory.InvalidData, null); - azureBackupCmd.WriteError(errorRecord); + azureBackupCmdletBase.WriteError(errorRecord); } if (retentionType == RetentionDurationType.Weeks.ToString() && (retentionDuration < MinRetentionInWeeks @@ -180,12 +186,12 @@ private static void ValidateRetentionRange(AzureBackupCmdletBase azureBackupCmd, { var exception = new Exception("For Retention in weeks , valid values of retention duration are 1 to 4."); var errorRecord = new ErrorRecord(exception, string.Empty, ErrorCategory.InvalidData, null); - azureBackupCmd.WriteError(errorRecord); + azureBackupCmdletBase.WriteError(errorRecord); } } - private static string GetScheduleType(string scheduleType, string[] scheduleRunDays) + private static string FillScheduleType(string scheduleType, string[] scheduleRunDays) { if (scheduleType == ScheduleType.Daily.ToString() && scheduleRunDays != null && scheduleRunDays.Length > 0) { @@ -198,22 +204,22 @@ private static string GetScheduleType(string scheduleType, string[] scheduleRunD } } - private static IList GetScheduleRunDays(AzureBackupCmdletBase azureBackupCmd, string[] scheduleRunDays) + private static IList ParseScheduleRunDays(string[] scheduleRunDays) { if (scheduleRunDays == null || scheduleRunDays.Length <= 0) { var exception = new Exception("For weekly scheduletype , ScheduleRunDays should not be empty."); var errorRecord = new ErrorRecord(exception, string.Empty, ErrorCategory.InvalidData, null); - azureBackupCmd.WriteError(errorRecord); + azureBackupCmdletBase.WriteError(errorRecord); } IList ListofWeekDays = new List(); foreach (var dayOfWeek in scheduleRunDays) { - azureBackupCmd.WriteDebug("dayOfWeek" + dayOfWeek.ToString()); + azureBackupCmdletBase.WriteDebug("dayOfWeek" + dayOfWeek.ToString()); DayOfWeek item = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), dayOfWeek, true); - azureBackupCmd.WriteDebug("Item" + item.ToString()); + azureBackupCmdletBase.WriteDebug("Item" + item.ToString()); if (!ListofWeekDays.Contains(item)) { ListofWeekDays.Add(item); @@ -223,7 +229,7 @@ private static IList GetScheduleRunDays(AzureBackupCmdletBase azureBa return ListofWeekDays; } - private static DateTime GetScheduleRunTime(DateTime scheduleStartTime) + private static DateTime ParseScheduleRunTime(DateTime scheduleStartTime) { scheduleStartTime = scheduleStartTime.ToUniversalTime(); DateTime scheduleRunTime = new DateTime(scheduleStartTime.Year, scheduleStartTime.Month, From 09407d44cc034ec26e6265f2131b95dd86fed424 Mon Sep 17 00:00:00 2001 From: pragrawa Date: Wed, 17 Jun 2015 23:18:30 +0530 Subject: [PATCH 3/5] ProtectionPolicy Changes 3 --- .../AzureBackupCmdletBase.cs | 10 +- .../AzureBackupCmdletHelpMessage.cs | 3 +- .../AzureBackupPolicyCmdletBase.cs | 3 +- .../GetAzureBackupProtectionPolicy.cs | 17 +-- .../NewAzureBackupProtectionPolicy.cs | 38 ++---- .../RemoveAzureBackupProtectionPolicy.cs | 21 ++- .../SetAzureBackupProtectionPolicy.cs | 62 ++++----- .../Commands.AzureBackup.csproj | 2 +- .../Library/AzureBackupCmdletHelper.cs | 122 ++++++------------ 9 files changed, 105 insertions(+), 173 deletions(-) diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupCmdletBase.cs b/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupCmdletBase.cs index eef1713302e3..83bbee619a1b 100644 --- a/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupCmdletBase.cs +++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupCmdletBase.cs @@ -60,12 +60,14 @@ public abstract class AzureBackupCmdletBase : AzurePSCmdlet /// Cancellation Token Source /// private CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); - protected CancellationToken CmdletCancellationToken; + internal CancellationToken CmdletCancellationToken; + + protected AzureBackupCmdletHelper azureBackupCmdletHelper; /// /// Get Azure backup client. /// - protected BackupServicesManagementClient AzureBackupClient + internal BackupServicesManagementClient AzureBackupClient { get { @@ -97,7 +99,7 @@ public void InitializeAzureBackupCmdlet(string rgName, string rName, string loca WriteDebug(string.Format("Initialized AzureBackup Cmdlet, ClientRequestId: {0}, ResourceGroupName: {1}, ResourceName : {2}", this.clientRequestId, resourceGroupName, resourceName)); CmdletCancellationToken = cancellationTokenSource.Token; - AzureBackupCmdletHelper cmdHelper = new AzureBackupCmdletHelper(this); + azureBackupCmdletHelper = new AzureBackupCmdletHelper(this); } protected void ExecutionBlock(Action execAction) @@ -170,7 +172,7 @@ private void HandleException(Exception exception) } } - protected CustomRequestHeaders GetCustomRequestHeaders() + internal CustomRequestHeaders GetCustomRequestHeaders() { var hdrs = new CustomRequestHeaders() { diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupCmdletHelpMessage.cs b/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupCmdletHelpMessage.cs index 38cf1cb69e10..c03a9df587d7 100644 --- a/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupCmdletHelpMessage.cs +++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupCmdletHelpMessage.cs @@ -41,7 +41,8 @@ internal static class AzureBackupCmdletHelpMessage public const string Comments = "Comments for for removing protection"; public const string WorkloadType = "Workload type for which the policy is defined."; public const string BackupType = "Type of backup."; - public const string ScheduleType = "Type of schedule."; + public const string DailyScheduleType = "Switch parameter for daily backup schedule."; + public const string WeeklyScheduleType = "Switch parameter for weekly backup schedule."; public const string ScheduleRunDays = "Days of week for running backup, required for weekly schedule."; public const string ScheduleRunTimes = "Times of day for running backup."; public const string RetentionType = "Unit of retention for the recovery point."; diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupPolicyCmdletBase.cs b/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupPolicyCmdletBase.cs index c2e4c6a3486d..ae374269b6aa 100644 --- a/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupPolicyCmdletBase.cs +++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/AzureBackupPolicyCmdletBase.cs @@ -39,7 +39,8 @@ public override void ExecuteCmdlet() { base.ExecuteCmdlet(); - WriteDebug(String.Format("Cmdlet called for ResourceGroupName: {0}, ResourceName: {1}, Location: {2}", ProtectionPolicy.ResourceGroupName, ProtectionPolicy.ResourceName, ProtectionPolicy.Location)); + WriteDebug(String.Format("Cmdlet called for ResourceGroupName: {0}, ResourceName: {1}, Location: {2}", + ProtectionPolicy.ResourceGroupName, ProtectionPolicy.ResourceName, ProtectionPolicy.Location)); InitializeAzureBackupCmdlet(ProtectionPolicy.ResourceGroupName, ProtectionPolicy.ResourceName, ProtectionPolicy.Location); } diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/GetAzureBackupProtectionPolicy.cs b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/GetAzureBackupProtectionPolicy.cs index 54626ebc5dc9..513dc2c16660 100644 --- a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/GetAzureBackupProtectionPolicy.cs +++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/GetAzureBackupProtectionPolicy.cs @@ -39,22 +39,23 @@ public override void ExecuteCmdlet() { WriteDebug("Making client call"); - var policyListResponse = AzureBackupClient.ProtectionPolicy.ListAsync(GetCustomRequestHeaders(), CmdletCancellationToken).Result; - - WriteDebug("Received policy response"); IEnumerable policyObjects = null; if (Name != null) { - policyObjects = policyListResponse.ProtectionPolicies.Objects.Where(x => x.Name.Equals(Name, System.StringComparison.InvariantCultureIgnoreCase)); + AzureBackupProtectionPolicy policyInfo = azureBackupCmdletHelper.GetAzureBackupProtectionPolicyByName(Name, ResourceGroupName, ResourceName, Location); + WriteDebug("Converting response"); + WriteObject(policyInfo); } else { + var policyListResponse = AzureBackupClient.ProtectionPolicy.ListAsync(GetCustomRequestHeaders(), CmdletCancellationToken).Result; + + WriteDebug("Received policy response"); policyObjects = policyListResponse.ProtectionPolicies.Objects; - } - WriteDebug("Converting response"); - AzureBackupCmdletHelper.WriteAzureBackupProtectionPolicy(ResourceGroupName, ResourceName, Location, policyObjects); - + WriteDebug("Converting response"); + azureBackupCmdletHelper.WriteAzureBackupProtectionPolicy(ResourceGroupName, ResourceName, Location, policyObjects); + } }); } } diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/NewAzureBackupProtectionPolicy.cs b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/NewAzureBackupProtectionPolicy.cs index e940ccb460d1..b0c6396f5e35 100644 --- a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/NewAzureBackupProtectionPolicy.cs +++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/NewAzureBackupProtectionPolicy.cs @@ -36,31 +36,32 @@ public class NewAzureBackupProtectionPolicy : AzureBackupVaultCmdletBase public string Name { get; set; } [Parameter(Position = 4, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.WorkloadType, ValueFromPipelineByPropertyName = true)] - [ValidateSet("VM")] + [ValidateSet("VM", IgnoreCase = true)] public string WorkloadType { get; set; } [Parameter(Position = 5, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.BackupType, ValueFromPipelineByPropertyName = true)] - [ValidateSet("Full")] + [ValidateSet("Full", IgnoreCase = true)] public string BackupType { get; set; } - [Parameter(ParameterSetName = DailyScheduleParamSet, Position = 7, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleType)] + [Parameter(ParameterSetName = DailyScheduleParamSet, Position = 6, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.DailyScheduleType)] public SwitchParameter Daily { get; set; } - [Parameter(ParameterSetName = WeeklyScheduleParamSet, Position = 6, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleType)] + [Parameter(ParameterSetName = WeeklyScheduleParamSet, Position = 7, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.WeeklyScheduleType)] public SwitchParameter Weekly { get; set; } - [Parameter(Position = 7, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleRunTimes, ValueFromPipelineByPropertyName = true)] + [Parameter(Position = 8, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleRunTimes, ValueFromPipelineByPropertyName = true)] public DateTime ScheduleRunTimes { get; set; } - [Parameter(Position = 8, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.RetentionType, ValueFromPipelineByPropertyName = true)] + [Parameter(Position = 9, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.RetentionType, ValueFromPipelineByPropertyName = true)] [ValidateSet("Days", IgnoreCase = true)] public string RetentionType { get; set; } - [Parameter(Position = 9, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.RententionDuration, ValueFromPipelineByPropertyName = true)] + [Parameter(Position = 10, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.RententionDuration, ValueFromPipelineByPropertyName = true)] public int RetentionDuration { get; set; } - [Parameter(ParameterSetName = WeeklyScheduleParamSet, Position = 10, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleRunDays, ValueFromPipelineByPropertyName = true)] - [Parameter(ParameterSetName = NoScheduleParamSet, Position = 10, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleRunDays, ValueFromPipelineByPropertyName = true)] + [Parameter(ParameterSetName = WeeklyScheduleParamSet, Position = 11, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleRunDays, ValueFromPipelineByPropertyName = true)] + [Parameter(ParameterSetName = NoScheduleParamSet, Position = 11, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleRunDays, ValueFromPipelineByPropertyName = true)] + [AllowEmptyCollection] [ValidateSet("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", IgnoreCase = true)] public string[] ScheduleRunDays { get; set; } @@ -74,31 +75,20 @@ public override void ExecuteCmdlet() var ScheduleType = GetScheduelType(ScheduleRunDays); - var backupSchedule = AzureBackupCmdletHelper.FillBackupSchedule(BackupType, ScheduleType, ScheduleRunTimes, + var backupSchedule = azureBackupCmdletHelper.FillBackupSchedule(BackupType, ScheduleType, ScheduleRunTimes, RetentionType, RetentionDuration, ScheduleRunDays); - - //var backupSchedule = GetBackupSchedule(BackupType, ScheduleType, ScheduleRunTimes, - // RetentionType, RetentionDuration, ScheduleRunDays); - var addProtectionPolicyRequest = new AddProtectionPolicyRequest(); addProtectionPolicyRequest.PolicyName = this.Name; addProtectionPolicyRequest.Schedule = backupSchedule; - addProtectionPolicyRequest.WorkloadType = this.WorkloadType; + addProtectionPolicyRequest.WorkloadType = Enum.Parse(typeof(WorkloadType), this.WorkloadType, true).ToString(); var operationId = AzureBackupClient.ProtectionPolicy.AddAsync(addProtectionPolicyRequest, GetCustomRequestHeaders(), CmdletCancellationToken).Result; - WriteDebug("Protection policy created successfully"); - - var policyListResponse = AzureBackupClient.ProtectionPolicy.ListAsync(GetCustomRequestHeaders(), CmdletCancellationToken).Result; - - WriteDebug("Received policy response"); - - IEnumerable policyObjects = null; - policyObjects = policyListResponse.ProtectionPolicies.Where(x => x.Name.Equals(Name, System.StringComparison.InvariantCultureIgnoreCase)); + AzureBackupProtectionPolicy policyInfo = azureBackupCmdletHelper.GetAzureBackupProtectionPolicyByName(Name, ResourceGroupName, ResourceName, Location); WriteDebug("Converting response"); - AzureBackupCmdletHelper.WriteAzureBackupProtectionPolicy(ResourceGroupName, ResourceName, Location, policyObjects); + WriteObject(policyInfo); }); } diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/RemoveAzureBackupProtectionPolicy.cs b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/RemoveAzureBackupProtectionPolicy.cs index 07c425d3000c..b0fd31d5fe59 100644 --- a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/RemoveAzureBackupProtectionPolicy.cs +++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/RemoveAzureBackupProtectionPolicy.cs @@ -35,25 +35,20 @@ public override void ExecuteCmdlet() { WriteDebug("Making client call"); - var policyListResponse = AzureBackupClient.ProtectionPolicy.ListAsync(GetCustomRequestHeaders(), CmdletCancellationToken).Result; - - WriteDebug("Received policy response"); - IEnumerable policyObjects = null; - - policyObjects = policyListResponse.ProtectionPolicies.Objects.Where(x => x.Name.Equals(ProtectionPolicy.Name, System.StringComparison.InvariantCultureIgnoreCase)); - - if (policyObjects.Count() != 0) + AzureBackupProtectionPolicy policyInfo = azureBackupCmdletHelper.GetAzureBackupProtectionPolicyByName(ProtectionPolicy.Name, + ProtectionPolicy.ResourceGroupName, ProtectionPolicy.ResourceName, ProtectionPolicy.Location); + + if (policyInfo != null) { - ProtectionPolicyInfo protectionPolicyInfo = policyObjects.ElementAt(0); - var policyRemoveResponse = AzureBackupClient.ProtectionPolicy.DeleteAsync(protectionPolicyInfo.InstanceId, GetCustomRequestHeaders(), CmdletCancellationToken).Result; + var policyRemoveResponse = AzureBackupClient.ProtectionPolicy.DeleteAsync(policyInfo.InstanceId, GetCustomRequestHeaders(), CmdletCancellationToken).Result; + + WriteDebug("Converting response"); + WriteVerbose("Successfully deleted policy"); } else { WriteVerbose("Policy Not Found"); } - - WriteDebug("Converting response"); - WriteVerbose("Successfully deleted policy"); }); } } diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/SetAzureBackupProtectionPolicy.cs b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/SetAzureBackupProtectionPolicy.cs index 735c4403fa42..4f772724e10b 100644 --- a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/SetAzureBackupProtectionPolicy.cs +++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/SetAzureBackupProtectionPolicy.cs @@ -31,31 +31,31 @@ public class SetAzureBackupProtectionPolicy : AzureBackupPolicyCmdletBase protected const string DailyScheduleParamSet = "DailyScheduleParamSet"; protected const string NoScheduleParamSet = "NoScheduleParamSet"; - [Parameter(Position = 3, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.PolicyNewName, ValueFromPipelineByPropertyName = true)] + [Parameter(Position = 1, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.PolicyNewName)] [ValidateNotNullOrEmpty] public string NewName { get; set; } - [Parameter(Position = 5, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.BackupType, ValueFromPipelineByPropertyName = true)] - [ValidateSet("Full")] + [Parameter(Position = 2, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.BackupType)] + [ValidateSet("Full", IgnoreCase = true)] public string BackupType { get; set; } - [Parameter(ParameterSetName = DailyScheduleParamSet, Position = 7, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleType)] + [Parameter(ParameterSetName = DailyScheduleParamSet, Position = 3, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.DailyScheduleType)] public SwitchParameter Daily { get; set; } - [Parameter(ParameterSetName = WeeklyScheduleParamSet, Position = 6, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleType)] + [Parameter(ParameterSetName = WeeklyScheduleParamSet, Position = 4, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.WeeklyScheduleType)] public SwitchParameter Weekly { get; set; } - [Parameter(Position = 7, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleRunTimes, ValueFromPipelineByPropertyName = true)] + [Parameter(Position = 5, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleRunTimes)] public DateTime ScheduleRunTimes { get; set; } - [Parameter(Position = 8, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.RetentionType, ValueFromPipelineByPropertyName = true)] + [Parameter(Position = 6, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.RetentionType)] [ValidateSet("Days", IgnoreCase = true)] public string RetentionType { get; set; } - [Parameter(Position = 9, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.RententionDuration, ValueFromPipelineByPropertyName = true)] + [Parameter(Position = 7, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.RententionDuration)] public int RetentionDuration { get; set; } - [Parameter(ParameterSetName = WeeklyScheduleParamSet, Position = 10, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleRunDays, ValueFromPipelineByPropertyName = true)] + [Parameter(ParameterSetName = WeeklyScheduleParamSet, Position = 8, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleRunDays)] [ValidateSet("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", IgnoreCase = true)] public string[] ScheduleRunDays { get; set; } @@ -66,53 +66,38 @@ public override void ExecuteCmdlet() ExecutionBlock(() => { WriteDebug("Making client call"); - - AzureBackupProtectionPolicy policy = ProtectionPolicy; - - FillRemainingValuesForSetPolicyRequest(policy); - AzureBackupCmdletHelper.ValidateAzureBackupPolicyRequest(policy); + AzureBackupProtectionPolicy policyInfo = azureBackupCmdletHelper.GetAzureBackupProtectionPolicyByName(ProtectionPolicy.Name, + ProtectionPolicy.ResourceGroupName, ProtectionPolicy.ResourceName, ProtectionPolicy.Location); + + FillRemainingValuesForSetPolicyRequest(policyInfo); - var backupSchedule = AzureBackupCmdletHelper.FillBackupSchedule(BackupType, policy.ScheduleType, ScheduleRunTimes, - RetentionType, RetentionDuration, policy.ScheduleRunDays.ToArray()); - - - var policyListResponse = AzureBackupClient.ProtectionPolicy.ListAsync(GetCustomRequestHeaders(), CmdletCancellationToken).Result; + var backupSchedule = azureBackupCmdletHelper.FillBackupSchedule(BackupType, policyInfo.ScheduleType, ScheduleRunTimes, + RetentionType, RetentionDuration, policyInfo.ScheduleRunDays.ToArray()); - NewName = (string.IsNullOrEmpty(NewName) ? policy.Name: NewName); + NewName = (string.IsNullOrEmpty(NewName) ? policyInfo.Name : NewName); var updateProtectionPolicyRequest = new UpdateProtectionPolicyRequest(); updateProtectionPolicyRequest.PolicyName = this.NewName; updateProtectionPolicyRequest.Schedule = backupSchedule; - WriteDebug("Got the protectionPolicy List"); - - IEnumerable policyObjects = null; - - policyObjects = policyListResponse.ProtectionPolicies.Objects.Where(x => x.Name.Equals(policy.Name, System.StringComparison.InvariantCultureIgnoreCase)); - - WriteDebug("Got the protectionPolicy with Name" + this.ProtectionPolicy.Name); - - if (policyObjects.Count() != 0) + if (policyInfo != null) { - var operationId = AzureBackupClient.ProtectionPolicy.UpdateAsync(ProtectionPolicy.InstanceId, updateProtectionPolicyRequest, GetCustomRequestHeaders(), CmdletCancellationToken).Result; + var operationId = AzureBackupClient.ProtectionPolicy.UpdateAsync(policyInfo.InstanceId, updateProtectionPolicyRequest, GetCustomRequestHeaders(), CmdletCancellationToken).Result; } else { var exception = new Exception("Protection Policy Not Found with Name" + ProtectionPolicy.Name); var errorRecord = new ErrorRecord(exception, string.Empty, ErrorCategory.InvalidData, null); - WriteError(errorRecord); + WriteError(errorRecord); + return; } WriteDebug("Protection Policy successfully updated"); - var policyListResponse_afterUpdate = AzureBackupClient.ProtectionPolicy.ListAsync(GetCustomRequestHeaders(), CmdletCancellationToken).Result; - - WriteDebug("Received policy response"); - - policyObjects = policyListResponse_afterUpdate.ProtectionPolicies.Where(x => x.Name.Equals(NewName, System.StringComparison.InvariantCultureIgnoreCase)); - + AzureBackupProtectionPolicy updatedPolicyInfo = azureBackupCmdletHelper.GetAzureBackupProtectionPolicyByName(NewName, + ProtectionPolicy.ResourceGroupName, ProtectionPolicy.ResourceName, ProtectionPolicy.Location); WriteDebug("Converting response"); - AzureBackupCmdletHelper.WriteAzureBackupProtectionPolicy(policy.ResourceGroupName, policy.ResourceName, policy.Location, policyObjects); + WriteObject(updatedPolicyInfo); }); } @@ -154,6 +139,7 @@ private void FillRemainingValuesForSetPolicyRequest(AzureBackupProtectionPolicy else { policy.ScheduleType = ScheduleType.Daily.ToString(); + policy.ScheduleRunDays = new List(); } } diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Commands.AzureBackup.csproj b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Commands.AzureBackup.csproj index 500bb4055ca3..6da6d473fb74 100644 --- a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Commands.AzureBackup.csproj +++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Commands.AzureBackup.csproj @@ -151,7 +151,7 @@ - + diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Library/AzureBackupCmdletHelper.cs b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Library/AzureBackupCmdletHelper.cs index 94f77f06b691..8cade17c75f6 100644 --- a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Library/AzureBackupCmdletHelper.cs +++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Library/AzureBackupCmdletHelper.cs @@ -25,6 +25,7 @@ using System.Net; using Microsoft.Azure.Management.BackupServices.Models; using Microsoft.Azure.Commands.AzureBackup.Cmdlets; +using System.Linq; namespace Microsoft.Azure.Commands.AzureBackup.Cmdlets { @@ -34,20 +35,20 @@ public class AzureBackupCmdletHelper public const int MaxRetentionInDays = 30; public const int MinRetentionInWeeks = 1; public const int MaxRetentionInWeeks = 4; - public static AzureBackupCmdletBase azureBackupCmdletBase; + public AzureBackupCmdletBase azureBackupCmdletBase {get; set;} public AzureBackupCmdletHelper(AzureBackupCmdletBase azureBackupCmd) { azureBackupCmdletBase = azureBackupCmd; } - public static void WriteAzureBackupProtectionPolicy(string ResourceGroupName, + public void WriteAzureBackupProtectionPolicy(string ResourceGroupName, string ResourceName, string Location, ProtectionPolicyInfo sourcePolicy) { azureBackupCmdletBase.WriteObject(new AzureBackupProtectionPolicy(ResourceGroupName, ResourceName, Location, sourcePolicy)); } - public static void WriteAzureBackupProtectionPolicy(string ResourceGroupName, + public void WriteAzureBackupProtectionPolicy(string ResourceGroupName, string ResourceName, string Location, IEnumerable sourcePolicyList) { List targetList = new List(); @@ -61,7 +62,33 @@ public static void WriteAzureBackupProtectionPolicy(string ResourceGroupName, azureBackupCmdletBase.WriteObject(targetList, true); } - public static BackupSchedule FillBackupSchedule(string backupType, string scheduleType, DateTime scheduleStartTime, + public AzureBackupProtectionPolicy GetAzureBackupProtectionPolicyByName(string policyName, string ResourceGroupName, + string ResourceName, string Location) + { + var policyListResponse = azureBackupCmdletBase.AzureBackupClient.ProtectionPolicy.ListAsync(azureBackupCmdletBase.GetCustomRequestHeaders(), azureBackupCmdletBase.CmdletCancellationToken).Result; + + azureBackupCmdletBase.WriteDebug("Got the protectionPolicy List"); + + IEnumerable policyObjects = null; + + policyObjects = policyListResponse.ProtectionPolicies.Objects.Where(x => x.Name.Equals(policyName, System.StringComparison.InvariantCultureIgnoreCase)); + + azureBackupCmdletBase.WriteDebug("Got the protectionPolicy with Name" + policyName); + + IEnumerator enumerator = policyObjects.GetEnumerator(); + enumerator.MoveNext(); + + ProtectionPolicyInfo protectionPolicyInfo = enumerator.Current; + + if (protectionPolicyInfo == null) + { + return null; + } + + return new AzureBackupProtectionPolicy(ResourceGroupName, ResourceName, Location, protectionPolicyInfo); + } + + public BackupSchedule FillBackupSchedule(string backupType, string scheduleType, DateTime scheduleStartTime, string retentionType, int retentionDuration, string[] scheduleRunDays) { var backupSchedule = new BackupSchedule(); @@ -85,81 +112,7 @@ public static BackupSchedule FillBackupSchedule(string backupType, string schedu return backupSchedule; } - public static void ValidateAzureBackupPolicyRequest(AzureBackupProtectionPolicy policy) - { - - //ValidateWorkloadType(azureBackupCmd, policy.WorkloadType); - ValidateBackupType(policy.BackupType); - ValidateScheduleType(policy.ScheduleType); - ValidateScheduleRunDays(policy.ScheduleRunDays); - ValidateRetentionType(policy.RetentionType); - } - - private static void ValidateWorkloadType(string workloadType) - { - WorkloadType item = (WorkloadType)Enum.Parse(typeof(WorkloadType), workloadType, true); - - if (item != WorkloadType.VM) - { - var exception = new Exception("Invalid value for param WorkloadType, Valid values are VM."); - var errorRecord = new ErrorRecord(exception, string.Empty, ErrorCategory.InvalidData, null); - azureBackupCmdletBase.WriteError(errorRecord); - } - } - - private static void ValidateBackupType(string backupType) - { - BackupType item = (BackupType)Enum.Parse(typeof(BackupType), backupType, true); - - if (item != BackupType.Full) - { - var exception = new Exception("Invalid value for param BackupType, Valid values are Full."); - var errorRecord = new ErrorRecord(exception, string.Empty, ErrorCategory.InvalidData, null); - azureBackupCmdletBase.WriteError(errorRecord); - } - } - - private static void ValidateScheduleType(string scheduleType) - { - ScheduleType item = (ScheduleType)Enum.Parse(typeof(ScheduleType), scheduleType, true); - - if (!(item == ScheduleType.Daily || item == ScheduleType.Weekly)) - { - var exception = new Exception("Invalid value for param ScheduleType, Valid values are Daily, Weekly."); - var errorRecord = new ErrorRecord(exception, string.Empty, ErrorCategory.InvalidData, null); - azureBackupCmdletBase.WriteError(errorRecord); - } - } - - private static void ValidateRetentionType(string retentionType) - { - RetentionType item = (RetentionType)Enum.Parse(typeof(RetentionType), retentionType, true); - - if (!(item == RetentionType.Days || item == RetentionType.Weeks)) - { - var exception = new Exception("Invalid value for param RetentionType, Valid values are Days, Weeks."); - var errorRecord = new ErrorRecord(exception, string.Empty, ErrorCategory.InvalidData, null); - azureBackupCmdletBase.WriteError(errorRecord); - } - } - - private static void ValidateScheduleRunDays(List scheduleRunDays) - { - foreach (string scheduleRunDay in scheduleRunDays) - { - DayOfWeek item = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), scheduleRunDay, true); - - if (!(item == DayOfWeek.Sunday || item == DayOfWeek.Monday || item == DayOfWeek.Tuesday || - item == DayOfWeek.Wednesday || item == DayOfWeek.Thursday || item == DayOfWeek.Friday || item == DayOfWeek.Saturday)) - { - var exception = new Exception("Invalid value for param ScheduleRunDays, " + - "Valid values are Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday"); - var errorRecord = new ErrorRecord(exception, string.Empty, ErrorCategory.InvalidData, null); - azureBackupCmdletBase.WriteError(errorRecord); - } - } - } - private static RetentionPolicy FillRetentionPolicy(string retentionType, int retentionDuration) + private RetentionPolicy FillRetentionPolicy(string retentionType, int retentionDuration) { ValidateRetentionRange(retentionType, retentionDuration); var retentionPolicy = new RetentionPolicy @@ -171,7 +124,7 @@ private static RetentionPolicy FillRetentionPolicy(string retentionType, int ret return retentionPolicy; } - private static void ValidateRetentionRange(string retentionType, int retentionDuration) + private void ValidateRetentionRange(string retentionType, int retentionDuration) { if(retentionType == RetentionDurationType.Days.ToString() && (retentionDuration < MinRetentionInDays || retentionDuration > MaxRetentionInDays)) @@ -179,6 +132,7 @@ private static void ValidateRetentionRange(string retentionType, int retentionDu var exception = new Exception("For Retention in days , valid values of retention duration are 7 to 30."); var errorRecord = new ErrorRecord(exception, string.Empty, ErrorCategory.InvalidData, null); azureBackupCmdletBase.WriteError(errorRecord); + throw exception; } if (retentionType == RetentionDurationType.Weeks.ToString() && (retentionDuration < MinRetentionInWeeks @@ -187,11 +141,12 @@ private static void ValidateRetentionRange(string retentionType, int retentionDu var exception = new Exception("For Retention in weeks , valid values of retention duration are 1 to 4."); var errorRecord = new ErrorRecord(exception, string.Empty, ErrorCategory.InvalidData, null); azureBackupCmdletBase.WriteError(errorRecord); + throw exception; } } - private static string FillScheduleType(string scheduleType, string[] scheduleRunDays) + private string FillScheduleType(string scheduleType, string[] scheduleRunDays) { if (scheduleType == ScheduleType.Daily.ToString() && scheduleRunDays != null && scheduleRunDays.Length > 0) { @@ -204,13 +159,14 @@ private static string FillScheduleType(string scheduleType, string[] scheduleRun } } - private static IList ParseScheduleRunDays(string[] scheduleRunDays) + private IList ParseScheduleRunDays(string[] scheduleRunDays) { if (scheduleRunDays == null || scheduleRunDays.Length <= 0) { var exception = new Exception("For weekly scheduletype , ScheduleRunDays should not be empty."); var errorRecord = new ErrorRecord(exception, string.Empty, ErrorCategory.InvalidData, null); azureBackupCmdletBase.WriteError(errorRecord); + throw exception; } IList ListofWeekDays = new List(); @@ -229,7 +185,7 @@ private static IList ParseScheduleRunDays(string[] scheduleRunDays) return ListofWeekDays; } - private static DateTime ParseScheduleRunTime(DateTime scheduleStartTime) + private DateTime ParseScheduleRunTime(DateTime scheduleStartTime) { scheduleStartTime = scheduleStartTime.ToUniversalTime(); DateTime scheduleRunTime = new DateTime(scheduleStartTime.Year, scheduleStartTime.Month, From 0b907cd6ec7bef32ec32a09751f75b700dca1d6e Mon Sep 17 00:00:00 2001 From: pragrawa Date: Wed, 17 Jun 2015 23:27:35 +0530 Subject: [PATCH 4/5] Making param BackupType case insensitive --- .../Commands.AzureBackup/Library/AzureBackupCmdletHelper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Library/AzureBackupCmdletHelper.cs b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Library/AzureBackupCmdletHelper.cs index 8cade17c75f6..afaadbf62c66 100644 --- a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Library/AzureBackupCmdletHelper.cs +++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Library/AzureBackupCmdletHelper.cs @@ -93,7 +93,7 @@ public BackupSchedule FillBackupSchedule(string backupType, string scheduleType, { var backupSchedule = new BackupSchedule(); - backupSchedule.BackupType = backupType; + backupSchedule.BackupType = Enum.Parse(typeof(BackupType), backupType, true).ToString(); backupSchedule.RetentionPolicy = FillRetentionPolicy(retentionType, retentionDuration); scheduleType = FillScheduleType(scheduleType, scheduleRunDays); From fa9ece2b9232e6d99e2743679551308f7d6484a5 Mon Sep 17 00:00:00 2001 From: pragrawa Date: Wed, 17 Jun 2015 23:50:56 +0530 Subject: [PATCH 5/5] merge Conflict2 --- .../AzureBackup/Commands.AzureBackup/Commands.AzureBackup.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Commands.AzureBackup.csproj b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Commands.AzureBackup.csproj index b36222267916..dceba4b35f53 100644 --- a/src/ResourceManager/AzureBackup/Commands.AzureBackup/Commands.AzureBackup.csproj +++ b/src/ResourceManager/AzureBackup/Commands.AzureBackup/Commands.AzureBackup.csproj @@ -153,6 +153,7 @@ +