Skip to content

Commit 7edfeee

Browse files
unknownunknown
unknown
authored and
unknown
committed
Add Force parameter to Remove-AzureAvailabilitySet
1 parent 621ea0b commit 7edfeee

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/AvailabilitySetTests.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ function Test-AvailabilitySet
4343
Assert-AreEqual $aset.PlatformUpdateDomainCount $nonDefaultUD;
4444
Assert-AreEqual $aset.PlatformFaultDomainCount $nonDefaultFD;
4545

46-
Remove-AzureAvailabilitySet -ResourceGroupName $rgname -Name $asetName;
46+
Assert-ThrowsContains { Remove-AzureAvailabilitySet -ResourceGroupName $rgname -Name $asetName; } "This cmdlet will remove the specified availability set. Do you want to continue?"
47+
48+
Remove-AzureAvailabilitySet -ResourceGroupName $rgname -Name $asetName -Force;
4749

4850
$asets = Get-AzureAvailabilitySet -ResourceGroupName $rgname;
4951
Assert-AreEqual $asets $null;

src/ResourceManager/Compute/Commands.Compute/AvailabilitySets/RemoveAzureAvailabilitySetCommand.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,23 @@ public class RemoveAzureAvailabilitySetCommand : AvailabilitySetBaseCmdlet
3737
[ValidateNotNullOrEmpty]
3838
public string Name { get; set; }
3939

40+
[Parameter(
41+
Position = 2,
42+
HelpMessage = "To force the removal.")]
43+
[ValidateNotNullOrEmpty]
44+
public SwitchParameter Force { get; set; }
45+
4046
public override void ExecuteCmdlet()
4147
{
4248
base.ExecuteCmdlet();
4349

44-
var op = this.AvailabilitySetClient.Delete(this.ResourceGroupName, this.Name);
45-
46-
WriteObject(op);
50+
if (this.Force.IsPresent
51+
|| this.ShouldContinue(Properties.Resources.AvailabilitySetRemovalConfirmation,
52+
Properties.Resources.AvailabilitySetRemovalCaption))
53+
{
54+
var op = this.AvailabilitySetClient.Delete(this.ResourceGroupName, this.Name);
55+
WriteObject(op);
56+
}
4757
}
4858
}
4959
}

src/ResourceManager/Compute/Commands.Compute/Properties/Resources.Designer.cs

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

src/ResourceManager/Compute/Commands.Compute/Properties/Resources.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@
117117
<resheader name="writer">
118118
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119119
</resheader>
120+
<data name="AvailabilitySetRemovalCaption" xml:space="preserve">
121+
<value>Availability set removal operation</value>
122+
</data>
123+
<data name="AvailabilitySetRemovalConfirmation" xml:space="preserve">
124+
<value>This cmdlet will remove the specified availability set. Do you want to continue?</value>
125+
</data>
120126
<data name="BothWindowsAndLinuxConfigurationsSpecified" xml:space="preserve">
121127
<value>Cannot specify both Windows and Linux configurations.</value>
122128
</data>

0 commit comments

Comments
 (0)