Skip to content

Commit c080696

Browse files
Merge pull request #3 from balukambala/ignite
Ignite: dsc node report cmdlets & config content
2 parents 5ebac3b + 0b2c8e5 commit c080696

16 files changed

+834
-36
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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.IO;
16+
using System.Collections.Generic;
17+
using System.Globalization;
18+
using System.Management.Automation;
19+
using System.Security.Permissions;
20+
using Microsoft.Azure.Commands.Automation.Common;
21+
using Microsoft.Azure.Commands.Automation.Model;
22+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
23+
24+
namespace Microsoft.Azure.Commands.Automation.Cmdlet
25+
{
26+
/// <summary>
27+
/// Gets configuration script for given configuration name and account name.
28+
/// </summary>
29+
[Cmdlet(VerbsData.Export, "AzureAutomationDscConfiguration", DefaultParameterSetName = AutomationCmdletParameterSets.ByAll)]
30+
[OutputType(typeof(DirectoryInfo))]
31+
public class ExportAzureAutomationDscConfiguration : AzureAutomationBaseCmdlet
32+
{
33+
/// <summary>
34+
/// True to overwrite the existing dsc configuration; false otherwise.
35+
/// </summary>
36+
private bool overwriteExistingFile;
37+
38+
/// <summary>
39+
/// Gets or sets the configfuration name.
40+
/// </summary>
41+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The dsc configuration name.")]
42+
[Alias("ConfigurationName")]
43+
[ValidateNotNullOrEmpty]
44+
public string Name { get; set; }
45+
46+
/// <summary>
47+
/// Gets or sets the configuration version type
48+
/// </summary>
49+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "Returns the draft or the published configuration version only. If not set, return published.")]
50+
[ValidateSet(Constants.Published, Constants.Draft)]
51+
public string Slot { get; set; }
52+
53+
/// <summary>
54+
/// Gets or sets the output folder for the configuration script.
55+
/// </summary>
56+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The folder where configuration script to be placed.")]
57+
public string OutputFolder { get; set; }
58+
59+
/// <summary>
60+
/// Gets or sets switch parameter to confirm overwriting of existing configuration script.
61+
/// </summary>
62+
[Parameter(Mandatory = false, HelpMessage = "Forces the command to run without asking for user confirmation and overwrites an existing configuration with same name.")]
63+
public SwitchParameter Force
64+
{
65+
get { return this.overwriteExistingFile; }
66+
set { this.overwriteExistingFile = value; }
67+
}
68+
69+
/// <summary>
70+
/// Execute this cmdlet.
71+
/// </summary>
72+
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
73+
public override void ExecuteCmdlet()
74+
{
75+
bool? isDraft = this.IsDraft();
76+
77+
var ret = this.AutomationClient.GetConfigurationContent(this.ResourceGroupName, this.AutomationAccountName, this.Name, isDraft, OutputFolder, this.Force);
78+
79+
this.WriteObject(ret, true);
80+
}
81+
82+
/// <summary>
83+
/// Returns null if Slot is not provided; otherwise returns true if Slot is Draft.
84+
/// </summary>
85+
/// <returns>
86+
/// The <see cref="bool"/>.
87+
/// </returns>
88+
private bool? IsDraft()
89+
{
90+
bool? isDraft = null;
91+
92+
if (this.Slot != null)
93+
{
94+
isDraft = (0 == string.Compare(this.Slot, Constants.Draft, CultureInfo.InvariantCulture,
95+
CompareOptions.OrdinalIgnoreCase));
96+
}
97+
98+
return isDraft;
99+
}
100+
}
101+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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.IO;
17+
using System.Collections.Generic;
18+
using System.Globalization;
19+
using System.Management.Automation;
20+
using System.Security.Permissions;
21+
using Microsoft.Azure.Commands.Automation.Common;
22+
using Microsoft.Azure.Commands.Automation.Model;
23+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
24+
25+
namespace Microsoft.Azure.Commands.Automation.Cmdlet
26+
{
27+
/// <summary>
28+
/// Gets node report for a given node and report id
29+
/// </summary>
30+
[Cmdlet(VerbsData.Export, "AzureAutomationDscNodeReportContent", DefaultParameterSetName = AutomationCmdletParameterSets.ByAll)]
31+
[OutputType(typeof(DirectoryInfo))]
32+
public class ExportAzureAutomationDscNodeReportContent : AzureAutomationBaseCmdlet
33+
{
34+
/// <summary>
35+
/// True to overwrite the existing node report; false otherwise.
36+
/// </summary>
37+
private bool overwriteExistingFile;
38+
39+
/// <summary>
40+
/// Gets or sets the node id.
41+
/// </summary>
42+
[Parameter(Mandatory = true, ParameterSetName = AutomationCmdletParameterSets.ByAll, ValueFromPipelineByPropertyName = true, HelpMessage = "The dsc node id.")]
43+
public Guid NodeId { get; set; }
44+
45+
/// <summary>
46+
/// Gets or sets the report id.
47+
/// </summary>
48+
[Parameter(Mandatory = true, ParameterSetName = AutomationCmdletParameterSets.ByAll, ValueFromPipelineByPropertyName = true, HelpMessage = "The dsc node report id.")]
49+
public Guid ReportId { get; set; }
50+
51+
/// <summary>
52+
/// Gets or sets the output folder for the configuration script.
53+
/// </summary>
54+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The folder where node report to be placed.")]
55+
public string OutputFolder { get; set; }
56+
57+
/// <summary>
58+
/// Gets or sets switch parameter to confirm overwriting of existing node report.
59+
/// </summary>
60+
[Parameter(Mandatory = false, HelpMessage = "Forces the command to run without asking for user confirmation and overwrites an existing node report with same name.")]
61+
public SwitchParameter Force
62+
{
63+
get { return this.overwriteExistingFile; }
64+
set { this.overwriteExistingFile = value; }
65+
}
66+
67+
/// <summary>
68+
/// Execute this cmdlet.
69+
/// </summary>
70+
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
71+
public override void ExecuteCmdlet()
72+
{
73+
var ret = this.AutomationClient.GetDscNodeReportContent(this.ResourceGroupName, this.AutomationAccountName, this.NodeId, this.ReportId, OutputFolder, overwriteExistingFile);
74+
75+
this.WriteObject(ret, true);
76+
}
77+
}
78+
}

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public class GetAzureAutomationDscCompilationJobOutput : AzureAutomationBaseCmdl
3838
public Guid Id { get; set; }
3939

4040
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The stream type.")]
41-
[ValidateSet("Output", "Warning", "Error", "Debug", "Verbose", "Any")]
42-
public StreamType Stream { get; set; }
41+
[ValidateSet("Warning", "Error", "Debug", "Verbose", "Any")]
42+
public CompilationJobStreamType Stream { get; set; }
4343

4444
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "Retrieves output created after this time")]
4545
public DateTimeOffset? StartTime { get; set; }
@@ -50,11 +50,6 @@ public class GetAzureAutomationDscCompilationJobOutput : AzureAutomationBaseCmdl
5050
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
5151
protected override void AutomationExecuteCmdlet()
5252
{
53-
if (Stream.Equals(StreamType.Progress))
54-
{
55-
Stream = StreamType.Any;
56-
}
57-
5853
var ret = this.AutomationClient.GetDscCompilationJobStream(this.ResourceGroupName, this.AutomationAccountName, this.Id, this.StartTime, this.Stream.ToString());
5954

6055
this.GenerateCmdletOutput(ret);

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public class GetAzureAutomationDscNode : AzureAutomationBaseCmdlet
4242
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByName, Mandatory = false, HelpMessage = "Filter dsc nodes based on their status.")]
4343
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByNodeConfiguration, Mandatory = false, HelpMessage = "Filter dsc nodes based on their status.")]
4444
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByAll, Mandatory = false, HelpMessage = "Filter dsc nodes based on their status.")]
45-
[ValidateSet("Compliant", "NotCompliant", "Failed", "Pending", "Received", "Unresponsive")]
46-
public string Status { get; set; }
45+
[ValidateSet("Any", "Compliant", "NotCompliant", "Failed", "Pending", "Received", "Unresponsive")]
46+
public DscNodeStatus Status { get; set; }
4747

4848
/// <summary>
4949
/// Gets or sets the node name.
@@ -74,6 +74,12 @@ public override void ExecuteCmdlet()
7474
{
7575
IEnumerable<DscNode> ret = null;
7676

77+
var nodeStatus = this.Status.ToString();
78+
if (nodeStatus.Equals(DscNodeStatus.Any))
79+
{
80+
nodeStatus = string.Empty;
81+
}
82+
7783
if (this.ParameterSetName == AutomationCmdletParameterSets.ById)
7884
{
7985
ret = new List<DscNode>
@@ -87,28 +93,28 @@ public override void ExecuteCmdlet()
8793
this.ResourceGroupName,
8894
this.AutomationAccountName,
8995
this.Name,
90-
this.Status);
96+
nodeStatus);
9197
}
9298
else if (this.ParameterSetName == AutomationCmdletParameterSets.ByNodeConfiguration)
9399
{
94100
ret = this.AutomationClient.ListDscNodesByNodeConfiguration(
95101
this.ResourceGroupName,
96102
this.AutomationAccountName,
97103
this.NodeConfigurationName,
98-
this.Status);
104+
nodeStatus);
99105
}
100106
else if (this.ParameterSetName == AutomationCmdletParameterSets.ByConfiguration)
101107
{
102108
ret = this.AutomationClient.ListDscNodesByConfiguration(
103109
this.ResourceGroupName,
104110
this.AutomationAccountName,
105111
this.ConfigurationName,
106-
this.Status);
112+
nodeStatus);
107113
}
108114
else
109115
{
110116
// ByAll
111-
ret = this.AutomationClient.ListDscNodes(this.ResourceGroupName, this.AutomationAccountName, this.Status);
117+
ret = this.AutomationClient.ListDscNodes(this.ResourceGroupName, this.AutomationAccountName, nodeStatus);
112118
}
113119

114120
this.GenerateCmdletOutput(ret);
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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.Collections.Generic;
17+
using System.Management.Automation;
18+
using System.Security.Permissions;
19+
using Microsoft.Azure.Commands.Automation.Common;
20+
using Microsoft.Azure.Commands.Automation.Model;
21+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
22+
23+
namespace Microsoft.Azure.Commands.Automation.Cmdlet
24+
{
25+
/// <summary>
26+
/// Gets azure automation dsc node report.
27+
/// </summary>
28+
[Cmdlet(VerbsCommon.Get, "AzureAutomationDscNodeReport", DefaultParameterSetName = AutomationCmdletParameterSets.ByAll)]
29+
[OutputType(typeof(DscNode))]
30+
public class GetAzureAutomationDscNodeReport : AzureAutomationBaseCmdlet
31+
{
32+
/// <summary>
33+
/// True to get latest the dsc report; false otherwise.
34+
/// </summary>
35+
private bool latestReport;
36+
37+
/// <summary>
38+
/// Gets or sets the node id.
39+
/// </summary>
40+
[Parameter(Mandatory = true, ParameterSetName = AutomationCmdletParameterSets.ByLatest, ValueFromPipelineByPropertyName = true, HelpMessage = "The dsc node id.")]
41+
[Parameter(Mandatory = true, ParameterSetName = AutomationCmdletParameterSets.ByAll, ValueFromPipelineByPropertyName = true, HelpMessage = "The dsc node id.")]
42+
[Parameter(Mandatory = true, ParameterSetName = AutomationCmdletParameterSets.ById, ValueFromPipelineByPropertyName = true, HelpMessage = "The dsc node id.")]
43+
public Guid NodeId { get; set; }
44+
45+
/// <summary>
46+
/// Gets or sets the switch parameter to get latest dsc report
47+
/// </summary>
48+
[Parameter(Mandatory = false, ParameterSetName = AutomationCmdletParameterSets.ByLatest, HelpMessage = "Get Latest Dsc report.")]
49+
public SwitchParameter Latest
50+
{
51+
get { return this.latestReport; }
52+
set { this.latestReport = value; }
53+
}
54+
55+
/// <summary>
56+
/// Gets or sets the node report id.
57+
/// </summary>
58+
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ById, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The dsc node report id.")]
59+
[Alias("ReportId")]
60+
public Guid Id { get; set; }
61+
62+
[Parameter(Mandatory = false, ParameterSetName = AutomationCmdletParameterSets.ByAll, ValueFromPipelineByPropertyName = true, HelpMessage = "Retrieves all reports created after this time")]
63+
public DateTimeOffset? StartTime { get; set; }
64+
65+
[Parameter(Mandatory = false, ParameterSetName = AutomationCmdletParameterSets.ByAll, ValueFromPipelineByPropertyName = true, HelpMessage = "Retrieves all reports received before this time")]
66+
public DateTimeOffset? EndTime { get; set; }
67+
68+
/// <summary>
69+
/// Execute this cmdlet.
70+
/// </summary>
71+
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
72+
public override void ExecuteCmdlet()
73+
{
74+
IEnumerable<DscNodeReport> ret = null;
75+
76+
if (this.ParameterSetName == AutomationCmdletParameterSets.ByLatest)
77+
{
78+
ret = new List<DscNodeReport>
79+
{
80+
this.AutomationClient.GetLatestDscNodeReport(this.ResourceGroupName, this.AutomationAccountName, this.NodeId)
81+
};
82+
}
83+
else if (this.ParameterSetName == AutomationCmdletParameterSets.ById)
84+
{
85+
ret = new List<DscNodeReport>
86+
{
87+
this.AutomationClient.GetDscNodeReportByReportId(this.ResourceGroupName, this.AutomationAccountName, this.NodeId, this.Id)
88+
};
89+
}
90+
else
91+
{
92+
ret = this.AutomationClient.ListDscNodeReports(
93+
this.ResourceGroupName,
94+
this.AutomationAccountName,
95+
this.NodeId,
96+
this.StartTime,
97+
this.EndTime);
98+
}
99+
100+
this.GenerateCmdletOutput(ret);
101+
}
102+
}
103+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class StartAzureAutomationDscCompilationJob : AzureAutomationBaseCmdlet
3333
/// Gets or sets the configuration name.
3434
/// </summary>
3535
[Parameter(Position = 2, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The configuration name.")]
36+
[Alias("Name")]
3637
public string ConfigurationName { get; set; }
3738

3839
/// <summary>

0 commit comments

Comments
 (0)