Skip to content

Commit 32a8ada

Browse files
committed
cmdlets for config-content and dsc node reports
1 parent 96afa0d commit 32a8ada

11 files changed

+768
-34
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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")]
30+
[OutputType(typeof(DirectoryInfo))]
31+
public class ExportAzureAutomationDscConfiguration : AzureAutomationBaseCmdlet
32+
{
33+
/// <summary>
34+
/// Gets or sets the configfuration name.
35+
/// </summary>
36+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The dsc configuration name.")]
37+
[Alias("ConfigurationName")]
38+
[ValidateNotNullOrEmpty]
39+
public string Name { get; set; }
40+
41+
/// <summary>
42+
/// Gets or sets the configuration version type
43+
/// </summary>
44+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "Returns the draft or the published configuration version only. If not set, return published.")]
45+
[ValidateSet(Constants.Published, Constants.Draft)]
46+
public string Slot { get; set; }
47+
48+
/// <summary>
49+
/// Gets or sets the output folder for the configuration script.
50+
/// </summary>
51+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The folder where configuration script to be placed.")]
52+
public string OutputFolder { get; set; }
53+
54+
/// <summary>
55+
/// Execute this cmdlet.
56+
/// </summary>
57+
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
58+
public override void ExecuteCmdlet()
59+
{
60+
bool? isDraft = this.IsDraft();
61+
62+
var ret = this.AutomationClient.GetConfigurationContent(this.ResourceGroupName, this.AutomationAccountName, this.Name, isDraft, OutputFolder, true);
63+
64+
this.WriteObject(ret, true);
65+
}
66+
67+
/// <summary>
68+
/// Returns null if Slot is not provided; otherwise returns true if Slot is Draft.
69+
/// </summary>
70+
/// <returns>
71+
/// The <see cref="bool"/>.
72+
/// </returns>
73+
private bool? IsDraft()
74+
{
75+
bool? isDraft = null;
76+
77+
if (this.Slot != null)
78+
{
79+
isDraft = (0 == string.Compare(this.Slot, Constants.Draft, CultureInfo.InvariantCulture,
80+
CompareOptions.OrdinalIgnoreCase));
81+
}
82+
83+
return isDraft;
84+
}
85+
}
86+
}
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")]
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+
}
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/Commands.ResourceManagement.Automation.csproj

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@
6767
<SpecificVersion>False</SpecificVersion>
6868
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.NetFramework.dll</HintPath>
6969
</Reference>
70-
<Reference Include="Microsoft.Azure.Management.Automation, Version=0.9.0.0, Culture=neutral, processorArchitecture=MSIL">
70+
<Reference Include="Microsoft.Azure.Management.Automation, Version=0.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
7171
<SpecificVersion>False</SpecificVersion>
72-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Automation.0.50.0-prerelease\lib\net40\Microsoft.Azure.Management.Automation.dll</HintPath>
72+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Automation.2.0.0.0-prerelease\lib\net40\Microsoft.Azure.Management.Automation.dll</HintPath>
7373
</Reference>
7474
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
7575
<SpecificVersion>False</SpecificVersion>
@@ -117,9 +117,12 @@
117117
</ItemGroup>
118118
<ItemGroup>
119119
<Compile Include="Cmdlet\AzureAutomationBaseCmdlet.cs" />
120+
<Compile Include="Cmdlet\ExportAzureAutomationDscConfiguration.cs" />
121+
<Compile Include="Cmdlet\ExportAzureAutomationDscNodeReportContent.cs" />
120122
<Compile Include="Cmdlet\GetAzureAutomationDscCompilationJob.cs" />
121123
<Compile Include="Cmdlet\GetAzureAutomationDscCompilationJobOutput.cs" />
122124
<Compile Include="Cmdlet\GetAzureAutomationDscNodeConfiguration.cs" />
125+
<Compile Include="Cmdlet\GetAzureAutomationDscNodeReport.cs" />
123126
<Compile Include="Cmdlet\GetAzureAutomationModule.cs" />
124127
<Compile Include="Cmdlet\NewAzureAutomationModule.cs" />
125128
<Compile Include="Cmdlet\RemoveAzureAutomationModule.cs" />
@@ -157,7 +160,9 @@
157160
<Compile Include="Model\AutomationAccount.cs" />
158161
<Compile Include="Model\CompilationJob.cs" />
159162
<Compile Include="Model\Configuration.cs" />
163+
<Compile Include="Model\ConfigurationContent.cs" />
160164
<Compile Include="Model\DscNode.cs" />
165+
<Compile Include="Model\DscNodeReport.cs" />
161166
<Compile Include="Model\DscOnboardingMetaconfig.cs" />
162167
<Compile Include="Model\JobStream.cs" />
163168
<Compile Include="Model\Module.cs" />

0 commit comments

Comments
 (0)