Skip to content

Commit 4823795

Browse files
committed
Merge pull request #93 from MabOneSdk/csm-pragrawa
LTR Policy changes
2 parents bbaee32 + afefa93 commit 4823795

File tree

7 files changed

+458
-401
lines changed

7 files changed

+458
-401
lines changed

src/ResourceManager/AzureBackup/Commands.AzureBackup.Test/ScenarioTests/AzureBackupPolicyTests.ps1

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ $Location = "SouthEast Asia"
1919
$PolicyName = "Policy10";
2020
$PolicyId = "c87bbada-6e1b-4db2-b76c-9062d28959a4";
2121
$POName = "iaasvmcontainer;dev01testing;dev01testing"
22-
$WorkloadType = "VM"
22+
$Type = "IaasVM"
2323
$RetentionType = "Days"
24-
$ScheduleRunTimes = "2015-06-13T20:30:00"
25-
$ScheduleRunDays = "Monday"
24+
$BackupTime = "2015-06-13T20:30:00"
25+
$DaysOfWeek = "Monday"
2626
$RetentionDuration = 30
2727
$BackupType = "Full"
2828
$ScheduleType = "Daily"
@@ -40,8 +40,8 @@ function Test-GetAzureBackupProtectionPolicyTests
4040
{
4141
Assert-NotNull $protectionPolicy.InstanceId 'InstanceId should not be null'
4242
Assert-NotNull $protectionPolicy.Name 'Name should not be null'
43-
Assert-NotNull $protectionPolicy.WorkloadType 'WorkloadType should not be null'
44-
Assert-NotNull $protectionPolicy.ScheduleRunTimes 'ScheduleRunTimes should not be null'
43+
Assert-NotNull $protectionPolicy.Type 'Type should not be null'
44+
Assert-NotNull $protectionPolicy.BackupTime 'BackupTime should not be null'
4545
Assert-NotNull $protectionPolicy.RetentionPolicyList 'RetentionPolicyList should not be null'
4646
Assert-NotNull $protectionPolicy.ResourceGroupName 'ResourceGroupName should not be null'
4747
Assert-NotNull $protectionPolicy.ResourceName 'ResourceName should not be null'
@@ -56,8 +56,8 @@ function Test-GetAzureBackupProtectionPolicyByNameTests
5656

5757
Assert-NotNull $protectionPolicy.InstanceId 'InstanceId should not be null'
5858
Assert-NotNull $protectionPolicy.Name 'Name should not be null'
59-
Assert-NotNull $protectionPolicy.WorkloadType 'WorkloadType should not be null'
60-
Assert-NotNull $protectionPolicy.ScheduleRunTimes 'ScheduleRunTimes should not be null'
59+
Assert-NotNull $protectionPolicy.Type 'Type should not be null'
60+
Assert-NotNull $protectionPolicy.BackupTime 'BackupTime should not be null'
6161
Assert-NotNull $protectionPolicy.RetentionPolicyList 'RetentionPolicyList should not be null'
6262
Assert-NotNull $protectionPolicy.ResourceGroupName 'ResourceGroupName should not be null'
6363
Assert-NotNull $protectionPolicy.ResourceName 'ResourceName should not be null'
@@ -72,12 +72,12 @@ function Test-NewAzureBackupProtectionPolicyTests
7272
$r2 = New-AzureBackupRetentionPolicyObject -WeeklyRetention -DaysOfWeek "Monday" -Retention 10
7373
$r = ($r1, $r2)
7474

75-
$protectionPolicy = New-AzureBackupProtectionPolicy -vault $vault -Name $PolicyName -WorkloadType $WorkloadType -Daily -RetentionPolicies $r -ScheduleRunTimes $ScheduleRunTimes
75+
$protectionPolicy = New-AzureBackupProtectionPolicy -vault $vault -Name $PolicyName -Type $Type -Daily -RetentionPolicies $r -BackupTime $BackupTime
7676

7777
Assert-NotNull $protectionPolicy.InstanceId 'InstanceId should not be null'
7878
Assert-NotNull $protectionPolicy.Name 'Name should not be null'
79-
Assert-NotNull $protectionPolicy.WorkloadType 'WorkloadType should not be null'
80-
Assert-NotNull $protectionPolicy.ScheduleRunTimes 'ScheduleRunTimes should not be null'
79+
Assert-NotNull $protectionPolicy.Type 'Type should not be null'
80+
Assert-NotNull $protectionPolicy.BackupTime 'BackupTime should not be null'
8181
Assert-NotNull $protectionPolicy.RetentionPolicyList 'RetentionPolicyList should not be null'
8282
Assert-NotNull $protectionPolicy.ResourceGroupName 'ResourceGroupName should not be null'
8383
Assert-NotNull $protectionPolicy.ResourceName 'ResourceName should not be null'

src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/NewAzureBackupProtectionPolicy.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public class NewAzureBackupProtectionPolicy : AzureBackupVaultCmdletBase
3838
public string Name { get; set; }
3939

4040
[Parameter(Position = 2, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.WorkloadType, ValueFromPipelineByPropertyName = true)]
41-
[ValidateSet("VM", IgnoreCase = true)]
42-
public string WorkloadType { get; set; }
41+
[ValidateSet("IaasVM", IgnoreCase = true)]
42+
public string Type { get; set; }
4343

4444
[Parameter(ParameterSetName = DailyScheduleParamSet, Position = 3, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.DailyScheduleType)]
4545
public SwitchParameter Daily { get; set; }
@@ -48,13 +48,13 @@ public class NewAzureBackupProtectionPolicy : AzureBackupVaultCmdletBase
4848
public SwitchParameter Weekly { get; set; }
4949

5050
[Parameter(Position = 5, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleRunTimes, ValueFromPipelineByPropertyName = true)]
51-
public DateTime ScheduleRunTimes { get; set; }
51+
public DateTime BackupTime { get; set; }
5252

5353
[Parameter(ParameterSetName = WeeklyScheduleParamSet, Position = 7, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleRunDays, ValueFromPipelineByPropertyName = true)]
5454
[Parameter(ParameterSetName = NoScheduleParamSet, Position = 7, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleRunDays, ValueFromPipelineByPropertyName = true)]
5555
[AllowEmptyCollection]
5656
[ValidateSet("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", IgnoreCase = true)]
57-
public string[] ScheduleRunDays { get; set; }
57+
public string[] DaysOfWeek { get; set; }
5858

5959
[Parameter(Position = 6, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.RetentionPolicyList)]
6060
public AzureBackupRetentionPolicy[] RetentionPolicies { get; set; }
@@ -69,13 +69,13 @@ public override void ExecuteCmdlet()
6969
ProtectionPolicyHelpers.ValidateProtectionPolicyName(Name);
7070
AzureBackupClient.CheckProtectionPolicyNameAvailability(this.Name);
7171

72-
var ScheduleType = ProtectionPolicyHelpers.GetScheduleType(ScheduleRunDays, this.ParameterSetName,
72+
var ScheduleType = ProtectionPolicyHelpers.GetScheduleType(DaysOfWeek, this.ParameterSetName,
7373
DailyScheduleParamSet, WeeklyScheduleParamSet);
7474

75-
var backupSchedule = ProtectionPolicyHelpers.FillCSMBackupSchedule(ScheduleType, ScheduleRunTimes,
76-
ScheduleRunDays);
75+
var backupSchedule = ProtectionPolicyHelpers.FillCSMBackupSchedule(ScheduleType, BackupTime,
76+
DaysOfWeek);
7777

78-
ProtectionPolicyHelpers.ValidateRetentionPolicy(RetentionPolicies, ScheduleType);
78+
ProtectionPolicyHelpers.ValidateRetentionPolicy(RetentionPolicies, backupSchedule);
7979

8080
AzureBackupProtectionPolicy protectionPolicy = new AzureBackupProtectionPolicy();
8181

@@ -84,9 +84,9 @@ public override void ExecuteCmdlet()
8484
addCSMProtectionPolicyRequest.Properties = new CSMAddProtectionPolicyRequestProperties();
8585
addCSMProtectionPolicyRequest.Properties.PolicyName = this.Name;
8686
addCSMProtectionPolicyRequest.Properties.BackupSchedule = backupSchedule;
87-
addCSMProtectionPolicyRequest.Properties.WorkloadType = Enum.Parse(typeof(WorkloadType), this.WorkloadType, true).ToString();
87+
addCSMProtectionPolicyRequest.Properties.WorkloadType = Enum.Parse(typeof(WorkloadType), this.Type, true).ToString();
8888

89-
addCSMProtectionPolicyRequest.Properties.LtrRetentionPolicy = protectionPolicy.ConvertToCSMRetentionPolicyObject(RetentionPolicies, backupSchedule);
89+
addCSMProtectionPolicyRequest.Properties.LtrRetentionPolicy = ProtectionPolicyHelpers.ConvertToCSMRetentionPolicyObject(RetentionPolicies, backupSchedule);
9090

9191
AzureBackupClient.AddProtectionPolicy(this.Name, addCSMProtectionPolicyRequest);
9292
WriteDebug("Protection policy created successfully");

src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/NewAzureBackupRetentionPolicyObject.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ public class NewAzureBackupRetentionPolicyObject : AzureBackupCmdletBase
6262

6363
[Parameter(ParameterSetName = MonthlyRetentionInDailyFormatParamSet, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.DaysOfMonth)]
6464
[Parameter(ParameterSetName = YearlyRetentionInDailyFormatParamSet, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.DaysOfMonth)]
65-
[ValidateRange(1, 29)]
66-
public List<int> DaysOfMonth { get; set; }
65+
[ValidateSet("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" ,"13" ,"14", "15", "16", "17", "18",
66+
"19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "IsLast", IgnoreCase = true)]
67+
public List<string> DaysOfMonth { get; set; }
6768

6869
[Parameter(ParameterSetName = MonthlyRetentionInWeeklyFormatParamSet, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.WeekNumber)]
6970
[Parameter(ParameterSetName = YearlyRetentionInWeeklyFormatParamSet, Mandatory = true, HelpMessage = AzureBackupCmdletHelpMessage.WeekNumber)]

src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/ProtectionPolicy/SetAzureBackupProtectionPolicy.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ public class SetAzureBackupProtectionPolicy : AzureBackupPolicyCmdletBase
4545
public SwitchParameter Weekly { get; set; }
4646

4747
[Parameter(Position = 4, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleRunTimes)]
48-
public DateTime ScheduleRunTimes { get; set; }
48+
public DateTime BackupTime { get; set; }
4949

5050
[Parameter(Position = 5, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.RetentionPolicyList)]
5151
public AzureBackupRetentionPolicy[] RetentionPolicies { get; set; }
5252

5353
[Parameter(ParameterSetName = WeeklyScheduleParamSet, Position = 6, Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.ScheduleRunDays)]
5454
[ValidateSet("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", IgnoreCase = true)]
55-
public string[] ScheduleRunDays { get; set; }
55+
public string[] DaysOfWeek { get; set; }
5656

5757
public override void ExecuteCmdlet()
5858
{
@@ -74,8 +74,8 @@ public override void ExecuteCmdlet()
7474
// TODO: Make the below function work with AzureBackupProtectionPolicy
7575
FillRemainingValuesForSetPolicyRequest(policyInfo, this.NewName);
7676

77-
var backupSchedule = ProtectionPolicyHelpers.FillCSMBackupSchedule(policyInfo.ScheduleType, ScheduleRunTimes,
78-
policyInfo.ScheduleRunDays.ToArray<string>());
77+
var backupSchedule = ProtectionPolicyHelpers.FillCSMBackupSchedule(policyInfo.ScheduleType, BackupTime,
78+
policyInfo.DaysOfWeek.ToArray<string>());
7979

8080
NewName = (string.IsNullOrEmpty(NewName) ? policyInfo.Name : NewName);
8181
var updateProtectionPolicyRequest = new CSMUpdateProtectionPolicyRequest();
@@ -86,15 +86,15 @@ public override void ExecuteCmdlet()
8686
AzureBackupProtectionPolicy protectionPolicy = new AzureBackupProtectionPolicy();
8787
if (RetentionPolicies != null && RetentionPolicies.Length > 0)
8888
{
89-
updateProtectionPolicyRequest.Properties.LtrRetentionPolicy =
90-
protectionPolicy.ConvertToCSMRetentionPolicyObject(RetentionPolicies, backupSchedule);
91-
ProtectionPolicyHelpers.ValidateRetentionPolicy(RetentionPolicies, backupSchedule.ScheduleRun);
89+
updateProtectionPolicyRequest.Properties.LtrRetentionPolicy =
90+
ProtectionPolicyHelpers.ConvertToCSMRetentionPolicyObject(RetentionPolicies, backupSchedule);
91+
ProtectionPolicyHelpers.ValidateRetentionPolicy(RetentionPolicies, backupSchedule);
9292
}
9393
else
9494
{
9595
updateProtectionPolicyRequest.Properties.LtrRetentionPolicy =
96-
protectionPolicy.ConvertToCSMRetentionPolicyObject(policyInfo.RetentionPolicyList, backupSchedule);
97-
ProtectionPolicyHelpers.ValidateRetentionPolicy(policyInfo.RetentionPolicyList, backupSchedule.ScheduleRun);
96+
ProtectionPolicyHelpers.ConvertToCSMRetentionPolicyObject(policyInfo.RetentionPolicyList, backupSchedule);
97+
ProtectionPolicyHelpers.ValidateRetentionPolicy(policyInfo.RetentionPolicyList, backupSchedule);
9898
}
9999

100100
var operationId = AzureBackupClient.UpdateProtectionPolicy(policyInfo.Name, updateProtectionPolicyRequest);
@@ -122,33 +122,33 @@ private void FillRemainingValuesForSetPolicyRequest(AzureBackupProtectionPolicy
122122
AzureBackupClient.CheckProtectionPolicyNameAvailability(this.NewName);
123123
}
124124

125-
ScheduleRunTimes = (ScheduleRunTimes == DateTime.MinValue) ? policy.ScheduleRunTimes :
126-
ScheduleRunTimes;
125+
BackupTime = (BackupTime == DateTime.MinValue) ? policy.BackupTime :
126+
BackupTime;
127127

128128
WriteDebug("ParameterSetName = " + this.ParameterSetName.ToString());
129129

130130
if (this.ParameterSetName != NoScheduleParamSet )
131131
{
132-
if (ScheduleRunDays != null && ScheduleRunDays.Length > 0 &&
132+
if (DaysOfWeek != null && DaysOfWeek.Length > 0 &&
133133
this.ParameterSetName == WeeklyScheduleParamSet)
134134
{
135135
policy.ScheduleType = ScheduleType.Weekly.ToString();
136-
policy.ScheduleRunDays = ScheduleRunDays.ToList<string>();
136+
policy.DaysOfWeek = DaysOfWeek.ToList<string>();
137137
}
138-
else if (this.ParameterSetName == DailyScheduleParamSet &&
139-
(ScheduleRunDays == null || ScheduleRunDays.Length <= 0))
138+
else if (this.ParameterSetName == DailyScheduleParamSet &&
139+
(DaysOfWeek == null || DaysOfWeek.Length <= 0))
140140
{
141141
policy.ScheduleType = ScheduleType.Daily.ToString();
142-
policy.ScheduleRunDays = new List<string>();
142+
policy.DaysOfWeek = new List<string>();
143143
}
144144
else
145145
{
146-
policy.ScheduleType = ProtectionPolicyHelpers.GetScheduleType(ScheduleRunDays, this.ParameterSetName,
146+
policy.ScheduleType = ProtectionPolicyHelpers.GetScheduleType(DaysOfWeek, this.ParameterSetName,
147147
DailyScheduleParamSet, WeeklyScheduleParamSet);
148148

149149
}
150150
}
151-
else if(ScheduleRunDays != null && ScheduleRunDays.Length > 0)
151+
else if (DaysOfWeek != null && DaysOfWeek.Length > 0)
152152
{
153153
throw new ArgumentException("For Schedule Run Days, weekly switch param is required");
154154
}

0 commit comments

Comments
 (0)