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