Skip to content

Commit 5449bf8

Browse files
committed
added dsc configuration job cmdlets
1 parent faa47c8 commit 5449bf8

10 files changed

+647
-250
lines changed
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;
17+
using System.Collections.Generic;
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 Azure automation compilation job
28+
/// </summary>
29+
[Cmdlet(VerbsCommon.Get, "AzureAutomationDscCompilationJob", DefaultParameterSetName = AutomationCmdletParameterSets.ByAll)]
30+
[OutputType(typeof(DscCompilationJob))]
31+
public class GetAzureAutomationDscCompilationJob : AzureAutomationBaseCmdlet
32+
{
33+
/// <summary>
34+
/// Gets or sets the automation account name.
35+
/// </summary>
36+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The automation account name.")]
37+
[ValidateNotNullOrEmpty]
38+
public string AutomationAccountName { get; set; }
39+
40+
/// <summary>
41+
/// Gets or sets the job id.
42+
/// </summary>
43+
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByJobId, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The dsc compilation job id.")]
44+
[Alias("JobId")]
45+
public Guid Id { get; set; }
46+
47+
/// <summary>
48+
/// Gets or sets the runbook name of the job.
49+
/// </summary>
50+
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByConfigurationName, Mandatory = true, HelpMessage = "The configuration name of the job.")]
51+
[Alias("Name")]
52+
public string ConfigurationName { get; set; }
53+
54+
/// <summary>
55+
/// Gets or sets the status of a job.
56+
/// </summary>
57+
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByConfigurationName, Mandatory = false, HelpMessage = "The configuration name of the job.")]
58+
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByAll, Mandatory = false, HelpMessage = "Filter jobs based on their status.")]
59+
[ValidateSet("Completed", "Failed", "Queued", "Starting", "Resuming", "Running", "Stopped", "Stopping", "Suspended", "Suspending", "Activating")]
60+
public string Status { get; set; }
61+
62+
/// <summary>
63+
/// Gets or sets the start time filter.
64+
/// </summary>
65+
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByConfigurationName, Mandatory = false, HelpMessage = "The configuration name of the job.")]
66+
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByAll, Mandatory = false, HelpMessage = "Filter jobs so that job start time >= StartTime.")]
67+
public DateTimeOffset? StartTime { get; set; }
68+
69+
/// <summary>
70+
/// Gets or sets the end time filter.
71+
/// </summary>
72+
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByConfigurationName, Mandatory = false, HelpMessage = "The configuration name of the job.")]
73+
[Parameter(ParameterSetName = AutomationCmdletParameterSets.ByAll, Mandatory = false, HelpMessage = "Filter jobs so that job end time <= EndTime.")]
74+
public DateTimeOffset? EndTime { get; set; }
75+
76+
/// <summary>
77+
/// Execute this cmdlet.
78+
/// </summary>
79+
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
80+
protected override void AutomationExecuteCmdlet()
81+
{
82+
IEnumerable<DscCompilationJob> jobs;
83+
84+
if (this.Id != null && !Guid.Empty.Equals(this.Id))
85+
{
86+
// ByJobId
87+
jobs = new List<DscCompilationJob> { this.AutomationClient.GetCompilationJob(this.ResourceGroupName, this.AutomationAccountName, this.Id) };
88+
}
89+
else if (this.ConfigurationName != null)
90+
{
91+
// ByConfiguration
92+
jobs = this.AutomationClient.ListCompilationJobsByConfigurationName(this.ResourceGroupName, this.AutomationAccountName, this.ConfigurationName, this.StartTime, this.EndTime, this.Status);
93+
}
94+
else
95+
{
96+
// ByAll
97+
jobs = this.AutomationClient.ListCompilationJobs(this.ResourceGroupName, this.AutomationAccountName, this.StartTime, this.EndTime, this.Status);
98+
}
99+
100+
this.WriteObject(jobs, true);
101+
}
102+
}
103+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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;
17+
using System.Collections.Generic;
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 stream for a compilation job
28+
/// </summary>
29+
[Cmdlet(VerbsCommon.Get, "AzureAutomationDscCompilationJobOutput")]
30+
[OutputType(typeof(JobStream))]
31+
public class GetAzureAutomationDscCompilationJobOutput : AzureAutomationBaseCmdlet
32+
{
33+
/// <summary>
34+
/// Gets or sets the automation account name.
35+
/// </summary>
36+
[Parameter(Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The automation account name.")]
37+
[ValidateNotNullOrEmpty]
38+
public string AutomationAccountName { get; set; }
39+
40+
/// <summary>
41+
/// Gets or sets the job id
42+
/// </summary>
43+
[Alias("JobId")]
44+
[Parameter(Mandatory = true, Position = 2, ValueFromPipelineByPropertyName = true, HelpMessage = "The job Id")]
45+
public Guid Id { get; set; }
46+
47+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The stream type. Defaults to Any.")]
48+
public StreamType Stream { get; set; }
49+
50+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "Retrieves output created after this time")]
51+
public DateTimeOffset? StartTime { get; set; }
52+
53+
/// <summary>
54+
/// Execute this cmdlet.
55+
/// </summary>
56+
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
57+
protected override void AutomationExecuteCmdlet()
58+
{
59+
var ret = this.AutomationClient.GetDscCompilationJobStream(this.ResourceGroupName, this.AutomationAccountName, this.Id, this.StartTime, this.Stream.ToString());
60+
61+
this.GenerateCmdletOutput(ret);
62+
}
63+
}
64+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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.Collections;
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+
/// starts azure automation compilation job
27+
/// </summary>
28+
[Cmdlet(VerbsLifecycle.Start, "AzureAutomationDscCompilationJob", DefaultParameterSetName = AutomationCmdletParameterSets.ByConfigurationName)]
29+
[OutputType(typeof(DscCompilationJob))]
30+
public class StartAzureAutomationDscCompilationJob : AzureAutomationBaseCmdlet
31+
{
32+
/// <summary>
33+
/// Gets or sets the automation account name.
34+
/// </summary>
35+
[Parameter(Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The automation account name.")]
36+
[ValidateNotNullOrEmpty]
37+
public string AutomationAccountName { get; set; }
38+
39+
/// <summary>
40+
/// Gets or sets the configuration name.
41+
/// </summary>
42+
[Parameter(Position = 2, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The configuration name.")]
43+
public string ConfigurationName { get; set; }
44+
45+
/// <summary>
46+
/// Gets or sets the configuration parameters.
47+
/// </summary>
48+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "The configuration parameters.")]
49+
public IDictionary Parameters { get; set; }
50+
51+
/// <summary>
52+
/// Execute this cmdlet.
53+
/// </summary>
54+
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
55+
protected override void AutomationExecuteCmdlet()
56+
{
57+
DscCompilationJob job = null;
58+
59+
job = this.AutomationClient.StartCompilationJob(this.ResourceGroupName, this.AutomationAccountName, this.ConfigurationName, this.Parameters);
60+
61+
this.WriteObject(job);
62+
}
63+
}
64+
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
44
<PropertyGroup>
55
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -116,6 +116,9 @@
116116
</ItemGroup>
117117
<ItemGroup>
118118
<Compile Include="Cmdlet\AzureAutomationBaseCmdlet.cs" />
119+
<Compile Include="Cmdlet\GetAzureAutomationDscCompilationJob.cs" />
120+
<Compile Include="Cmdlet\GetAzureAutomationDscCompilationJobOutput.cs" />
121+
<Compile Include="Cmdlet\StartAzureAutomationDscCompilationJob.cs" />
119122
<Compile Include="Cmdlet\GetAzureAutomationAgentRegistrationInformation.cs" />
120123
<Compile Include="Cmdlet\GetAzureAutomationConfiguration.cs" />
121124
<Compile Include="Cmdlet\ImportAzureAutomationDscConfiguration.cs" />
@@ -143,6 +146,7 @@
143146
<Compile Include="Model\AutomationAccount.cs" />
144147
<Compile Include="Model\DscCompilationJob.cs" />
145148
<Compile Include="Model\Configuration.cs" />
149+
<Compile Include="Model\JobStream.cs" />
146150
<Compile Include="Properties\AssemblyInfo.cs" />
147151
<Compile Include="Properties\Resources.Designer.cs">
148152
<AutoGen>True</AutoGen>

0 commit comments

Comments
 (0)