|
| 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 | +} |
0 commit comments