Skip to content

Commit ffabeff

Browse files
committed
Remove Protection Policy cmdlet implementation
1 parent 8af7854 commit ffabeff

File tree

7 files changed

+125
-1
lines changed

7 files changed

+125
-1
lines changed

src/ResourceManager/RecoveryServices.Backup/CmdletParameterHelpMessages.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ internal static class Common
3737
public const string Vault = "The Azure Backup vault object which is the parent resource.";
3838
public const string WorkloadType = "Workload type of the resource (for example: AzureVM, WindowsServer).";
3939
public const string BackupManagementType = "Backup Management type of the resource (for example: MAB, DPM).";
40+
public const string ConfirmationMessage = "Don't ask for confirmation.";
4041
}
4142

4243
internal static class Policy
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using System.Linq;
17+
using System.Text;
18+
using System.Threading.Tasks;
19+
using System.Collections.Generic;
20+
using System.Management.Automation;
21+
using Microsoft.Azure.Management.RecoveryServices.Backup.Models;
22+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Helpers;
23+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models;
24+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ProviderModel;
25+
using Microsoft.Azure.Commands.RecoveryServices.Backup.Properties;
26+
27+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets
28+
{
29+
/// <summary>
30+
/// Update existing protection policy
31+
/// </summary>
32+
[Cmdlet(VerbsCommon.Remove, "AzureRmRecoveryServicesProtectionPolicy")]
33+
public class RemoveAzureRmRecoveryServicesProtectionPolicy : RecoveryServicesBackupCmdletBase
34+
{
35+
[Parameter(Position = 1, Mandatory = true, HelpMessage = ParamHelpMsg.Policy.ProtectionPolicy, ValueFromPipeline = true)]
36+
[ValidateNotNullOrEmpty]
37+
public AzureRmRecoveryServicesPolicyBase Policy { get; set; }
38+
39+
[Parameter(Mandatory = false, HelpMessage = ParamHelpMsg.Common.ConfirmationMessage)]
40+
public SwitchParameter Force { get; set; }
41+
42+
public override void ExecuteCmdlet()
43+
{
44+
ConfirmAction(
45+
Force.IsPresent,
46+
string.Format(Resources.RemoveProtectionPolicyWarning, Policy.Name),
47+
Resources.RemoveProtectionPolicyMessage,
48+
Policy.Name, () =>
49+
{
50+
ExecutionBlock(() =>
51+
{
52+
base.ExecuteCmdlet();
53+
54+
WriteDebug(Resources.MakingClientCall);
55+
56+
HydraAdapter.RemoveProtectionPolicy(Policy.Name);
57+
WriteDebug(Resources.ProtectionPolicyDeleted);
58+
});
59+
60+
});
61+
}
62+
}
63+
}

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Cmdlets.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
<Compile Include="Cmdlets\ProtectionPolicy\GetAzureRmRecoveryServicesPolicy.cs" />
8989
<Compile Include="Cmdlets\ProtectionPolicy\GetAzureRmRecoveryServicesSchedulePolicyObject.cs" />
9090
<Compile Include="Cmdlets\ProtectionPolicy\PolicyCmdletHelpers.cs" />
91+
<Compile Include="Cmdlets\ProtectionPolicy\RemoveAzureRmRecoveryServicesPolicy.cs" />
9192
<Compile Include="Cmdlets\ProtectionPolicy\SetAzureRmRecoveryServicesPolicy.cs" />
9293
<Compile Include="Cmdlets\ProtectionPolicy\NewAzureRmRecoveryServicesPolicy.cs" />
9394
<Compile Include="Constants.cs" />

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Helpers/Commands.RecoveryServices.Backup.Helpers.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
<Project>{5ee72c53-1720-4309-b54b-5fb79703195f}</Project>
6666
<Name>Commands.Common</Name>
6767
</ProjectReference>
68-
<ProjectReference Include="Commands.RecoveryServices.Backup.HydraAdapter\Commands.RecoveryServices.Backup.HydraAdapter.csproj">
68+
<ProjectReference Include="..\Commands.RecoveryServices.Backup.HydraAdapter\Commands.RecoveryServices.Backup.HydraAdapter.csproj">
6969
<Project>{b758fec1-35c1-4f93-a954-66dd33f6e0ec}</Project>
7070
<Name>Commands.RecoveryServices.Backup.HydraAdapter</Name>
7171
</ProjectReference>

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.HydraAdapter/BMSAPIs/PolicyAPIs.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,16 @@ public BackUpOperationStatusResponse GetProtectionPolicyOperationStatusByURL(str
6464
BmsAdapter.GetCustomRequestHeaders(),
6565
BmsAdapter.CmdletCancellationToken).Result;
6666
}
67+
68+
public AzureOperationResponse RemoveProtectionPolicy(
69+
string policyName)
70+
{
71+
return BmsAdapter.Client.ProtectionPolicy.DeleteAsync(
72+
BmsAdapter.GetResourceGroupName(),
73+
BmsAdapter.GetResourceName(),
74+
policyName,
75+
BmsAdapter.GetCustomRequestHeaders(),
76+
BmsAdapter.CmdletCancellationToken).Result;
77+
}
6778
}
6879
}

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Models/Properties/Resources.Designer.cs

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Models/Properties/Resources.resx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,4 +326,16 @@ Please contact Microsoft for further assistant.</value>
326326
<data name="EnableProtectionOperationFailed" xml:space="preserve">
327327
<value>Enable Protection OperationFailed with error code {0} , and error Message {1}</value>
328328
</data>
329+
<data name="RemoveProtectionPolicyMessage" xml:space="preserve">
330+
<value>Removing the protection policy</value>
331+
</data>
332+
<data name="RemoveProtectionPolicyWarning" xml:space="preserve">
333+
<value>Are you sure you want to remove the protection policy '{0}'</value>
334+
</data>
335+
<data name="MakingClientCall" xml:space="preserve">
336+
<value>Making client call</value>
337+
</data>
338+
<data name="ProtectionPolicyDeleted" xml:space="preserve">
339+
<value>Successfully deleted policy</value>
340+
</data>
329341
</root>

0 commit comments

Comments
 (0)