Skip to content

Commit b379fd8

Browse files
committed
Added cmdlet to delete Node configuration
1 parent e375c18 commit b379fd8

File tree

4 files changed

+84
-1
lines changed

4 files changed

+84
-1
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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 Microsoft.Azure.Commands.Automation.Properties;
16+
using System.Management.Automation;
17+
using System.Security.Permissions;
18+
19+
namespace Microsoft.Azure.Commands.Automation.Cmdlet
20+
{
21+
/// <summary>
22+
/// Remove a DSC configuration
23+
/// </summary>
24+
[Cmdlet(VerbsCommon.Remove, "AzureRmAutomationDscNodeConfiguration")]
25+
public class RemoveAzureAutomationDscNodeConfiguration : AzureAutomationBaseCmdlet
26+
{
27+
/// <summary>
28+
/// Gets or sets the Configuration name.
29+
/// </summary>
30+
[Parameter(Position = 2, Mandatory = true, ValueFromPipelineByPropertyName = true,
31+
HelpMessage = "The Node configuration name.")]
32+
[Alias("NodeConfigurationName")]
33+
[ValidateNotNullOrEmpty]
34+
public string Name { get; set; }
35+
36+
[Parameter(Position = 3, HelpMessage = "Force confirmation of the removal of the configuration")]
37+
public SwitchParameter Force { get; set; }
38+
39+
/// <summary>
40+
/// Execute this cmdlet.
41+
/// </summary>
42+
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
43+
protected override void AutomationProcessRecord()
44+
{
45+
ConfirmAction(
46+
Force.IsPresent,
47+
string.Format(Resources.RemovingAzureAutomationResourceWarning, "DSC NodeConfiguration"),
48+
string.Format(Resources.RemoveAzureAutomationResourceDescription, "DSC NodeConfiguration"),
49+
Name,
50+
() => this.AutomationClient.DeleteNodeConfiguration(
51+
this.ResourceGroupName,
52+
this.AutomationAccountName,
53+
this.Name));
54+
}
55+
}
56+
}

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

Lines changed: 2 additions & 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, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
66+
<Reference Include="Microsoft.Azure.Management.Automation, Version=0.9.0.0, Culture=neutral, 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>
@@ -164,6 +164,7 @@
164164
<Compile Include="Cmdlet\RemoveAzureAutomationConnectionType.cs" />
165165
<Compile Include="Cmdlet\RemoveAzureAutomationConnection.cs" />
166166
<Compile Include="Cmdlet\RemoveAzureAutomationCredential.cs" />
167+
<Compile Include="Cmdlet\RemoveAzureAutomationDscNodeConfiguration.cs" />
167168
<Compile Include="Cmdlet\RemoveAzureAutomationModule.cs" />
168169
<Compile Include="Cmdlet\RemoveAzureAutomationRunbook.cs" />
169170
<Compile Include="Cmdlet\RemoveAzureAutomationSchedule.cs" />

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,30 @@ public Model.NodeConfiguration CreateNodeConfiguration(
12851285
}
12861286
}
12871287

1288+
public void DeleteNodeConfiguration(string resourceGroupName, string automationAccountName, string name)
1289+
{
1290+
Requires.Argument("ResourceGroupName", resourceGroupName).NotNull();
1291+
Requires.Argument("AutomationAccountName", automationAccountName).NotNull();
1292+
Requires.Argument("NodeConfigurationname", name).NotNull();
1293+
1294+
using (var request = new RequestSettings(this.automationManagementClient))
1295+
{
1296+
try
1297+
{
1298+
this.automationManagementClient.NodeConfigurations.Delete(resourceGroupName, automationAccountName, name);
1299+
}
1300+
catch (CloudException cloudException)
1301+
{
1302+
if (cloudException.Response.StatusCode == HttpStatusCode.NotFound)
1303+
{
1304+
throw new ResourceNotFoundException(
1305+
typeof(Model.NodeConfiguration),
1306+
string.Format(CultureInfo.CurrentCulture, Resources.NodeConfigurationNotFound, name));
1307+
}
1308+
throw;
1309+
}
1310+
}
1311+
}
12881312
#endregion
12891313

12901314
#region dsc reports

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ public interface IAutomationClient
6262
IEnumerable<NodeConfiguration> ListNodeConfigurations(string resourceGroupName, string automationAccountName, string rollupStatus);
6363

6464
NodeConfiguration CreateNodeConfiguration(string resourceGroupName, string automationAccountName, string sourcePath, string nodeConfiguraionName, bool overWrite);
65+
66+
void DeleteNodeConfiguration(string resourceGroupName, string automationAccountName, string name);
6567
#endregion
6668

6769
#region Configurations

0 commit comments

Comments
 (0)