Skip to content

Commit 0d3cd53

Browse files
committed
Added flag IgnoreNodeMappings
1 parent cb1c81e commit 0d3cd53

File tree

6 files changed

+43
-11
lines changed

6 files changed

+43
-11
lines changed

src/ResourceManager/Automation/Commands.Automation/Cmdlet/RemoveAzureAutomationDscNodeConfiguration.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,17 @@ public class RemoveAzureAutomationDscNodeConfiguration : AzureAutomationBaseCmdl
2828
/// Gets or sets the Configuration name.
2929
/// </summary>
3030
[Parameter(Position = 2, Mandatory = true, ValueFromPipelineByPropertyName = true,
31-
HelpMessage = "The Node configuration name.")]
31+
HelpMessage = "The node configuration name.")]
3232
[Alias("NodeConfigurationName")]
3333
[ValidateNotNullOrEmpty]
3434
public string Name { get; set; }
3535

36-
[Parameter(Position = 3, HelpMessage = "Force confirmation of the removal of the Node configuration")]
36+
[Parameter(Position = 3, HelpMessage = "Force confirmation of the removal of the node configuration")]
3737
public SwitchParameter Force { get; set; }
3838

39+
[Parameter(Position = 4, HelpMessage = "Delete even if the node configuration is mapped to a node")]
40+
public SwitchParameter IgnoreNodeMappings { get; set; }
41+
3942
/// <summary>
4043
/// Execute this cmdlet.
4144
/// </summary>
@@ -44,13 +47,14 @@ protected override void AutomationProcessRecord()
4447
{
4548
ConfirmAction(
4649
Force.IsPresent,
47-
string.Format(Resources.RemovingAzureAutomationResourceWarning, "DSC NodeConfiguration"),
48-
string.Format(Resources.RemoveAzureAutomationResourceDescription, "DSC NodeConfiguration"),
50+
string.Format(Resources.RemovingAzureAutomationResourceWarning, "DSC node configuration"),
51+
string.Format(Resources.RemoveAzureAutomationResourceDescription, "DSC node configuration"),
4952
Name,
5053
() => this.AutomationClient.DeleteNodeConfiguration(
5154
this.ResourceGroupName,
5255
this.AutomationAccountName,
53-
this.Name));
56+
this.Name,
57+
IgnoreNodeMappings.IsPresent));
5458
}
5559
}
5660
}

src/ResourceManager/Automation/Commands.Automation/Commands.Automation.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
<HintPath>..\..\..\packages\Microsoft.Azure.Common.Authentication.1.4.0-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
6464
<Private>True</Private>
6565
</Reference>
66-
<Reference Include="Microsoft.Azure.Management.Automation, Version=0.9.0.0, Culture=neutral, processorArchitecture=MSIL">
66+
<Reference Include="Microsoft.Azure.Management.Automation, Version=0.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
6767
<SpecificVersion>False</SpecificVersion>
6868
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Automation.0.50.2-prerelease\lib\portable-net45+wp8+wpa81+win\Microsoft.Azure.Management.Automation.dll</HintPath>
6969
</Reference>

src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientDSC.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ public Model.DscNode GetDscNodeById(
591591

592592
IEnumerable<AutomationManagement.Models.DscNode> dscNodes;
593593

594-
if (!String.IsNullOrEmpty(status))
594+
if (!string.IsNullOrEmpty(status))
595595
{
596596
dscNodes = AutomationManagementClient.ContinuationTokenHandler(
597597
skipToken =>
@@ -1285,17 +1285,31 @@ public Model.NodeConfiguration CreateNodeConfiguration(
12851285
}
12861286
}
12871287

1288-
public void DeleteNodeConfiguration(string resourceGroupName, string automationAccountName, string name)
1288+
public void DeleteNodeConfiguration(string resourceGroupName, string automationAccountName, string name, bool ignoreNodeMappings)
12891289
{
12901290
Requires.Argument("ResourceGroupName", resourceGroupName).NotNull();
12911291
Requires.Argument("AutomationAccountName", automationAccountName).NotNull();
1292-
Requires.Argument("NodeConfigurationname", name).NotNull();
1292+
Requires.Argument("NodeConfigurationName", name).NotNull();
12931293

12941294
using (var request = new RequestSettings(this.automationManagementClient))
12951295
{
12961296
try
12971297
{
1298-
this.automationManagementClient.NodeConfigurations.Delete(resourceGroupName, automationAccountName, name);
1298+
if (ignoreNodeMappings)
1299+
{
1300+
this.automationManagementClient.NodeConfigurations.Delete(resourceGroupName, automationAccountName,
1301+
name);
1302+
}
1303+
else
1304+
{
1305+
var nodeList = this.ListDscNodesByNodeConfiguration(resourceGroupName, automationAccountName, name, null);
1306+
if (nodeList.Any())
1307+
{
1308+
throw new ResourceNotFoundException(
1309+
typeof(Model.NodeConfiguration),
1310+
string.Format(CultureInfo.CurrentCulture, Resources.CannotDeleteNodeConfiguration, name));
1311+
}
1312+
}
12991313
}
13001314
catch (CloudException cloudException)
13011315
{
@@ -1309,6 +1323,7 @@ public void DeleteNodeConfiguration(string resourceGroupName, string automationA
13091323
}
13101324
}
13111325
}
1326+
13121327
#endregion
13131328

13141329
#region dsc reports

src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public interface IAutomationClient
6363

6464
NodeConfiguration CreateNodeConfiguration(string resourceGroupName, string automationAccountName, string sourcePath, string nodeConfiguraionName, bool overWrite);
6565

66-
void DeleteNodeConfiguration(string resourceGroupName, string automationAccountName, string name);
66+
void DeleteNodeConfiguration(string resourceGroupName, string automationAccountName, string name, bool ignoreNodeMappings);
6767
#endregion
6868

6969
#region Configurations

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

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

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,10 @@
388388
<value>The Dsc Configuration was not found. Configuration name {0}.</value>
389389
<comment>Automation</comment>
390390
</data>
391+
<data name="CannotDeleteNodeConfiguration" xml:space="preserve">
392+
<value>The Node configuration is mapped a node. Specify IgnoreNodeMappings to delete the node configuration {0}.</value>
393+
<comment>Automation</comment>
394+
</data>
391395
<data name="WebhookNotFound" xml:space="preserve">
392396
<value>The Webhook with Name: {0} was not found.</value>
393397
<comment>Automation</comment>

0 commit comments

Comments
 (0)