#region Copyright
/*
* Copyright © 2014-2016 NetApp, Inc. All Rights Reserved.
*
* CONFIDENTIALITY NOTICE: THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION OF
* NETAPP, INC. USE, DISCLOSURE OR REPRODUCTION IS PROHIBITED WITHOUT THE PRIOR
* EXPRESS WRITTEN PERMISSION OF NETAPP, INC.
*/
#endregion
#region Using Directives
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Management.Automation;
using SolidFire.Core.Objects;
using SolidFire.Core.Validation;
using SolidFire.Core;
using SolidFire.Element.Api;
#endregion
namespace SolidFire.Cluster.Get
{
///
/// ListClusterFaults is used to return information about any faults detected on the cluster. Both current faults as well as faults that
/// were previously detected and resolved can be returned. Faults in the system are cached every 30 seconds.
///
[Cmdlet(VerbsCommon.Get, "SFClusterFault", DefaultParameterSetName = "FaultType")]
public class GetSFClusterFault : SFCmdlet
{
#region Private Data
private Dictionary dicParameters = new Dictionary();
private string[] _faultType;
#endregion
#region Parameters
[Parameter(Position = 0, ParameterSetName = "FaultType", Mandatory = false, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, ValueFromRemainingArguments = true, HelpMessage = "Specify the fault type to retrieve faults on.")]
[ValidateNotNullOrEmpty]
[ValidatePattern(SolidFireValidations.UpperAndLowerCase)]
[ValidateSet("all", "current", "resolved", IgnoreCase = true)]
public String[] FaultType
{
get
{
return _faultType;
}
set
{
_faultType = value;
}
}
#endregion
#region Cmdlet Overrides
protected override void BeginProcessing()
{
base.BeginProcessing();
CheckConnection();
}
///
///
///
protected override void ProcessRecord()
{
base.ProcessRecord();
var request = new ListClusterFaultsRequest();
request.FaultTypes = "all";
var objsFromAPI = SendRequest("ListClusterFaults", request);
foreach (var obj in objsFromAPI)
{
switch (ParameterSetName)
{
case "FaultType":
ProcessByFaultType(obj);
break;
default:
throw new ArgumentException("Invalid parameter set.");
}
}
}
private void ProcessByFaultType(SFWrapper objFromApi)
{
// If there were no parameter arguments sent in for the FaultType parameter then we just want to list all faults found (current and resolved).
if (_faultType == null)
{
WriteObject(objFromApi.Result.Faults, true);
return;
}
foreach (var fault in _faultType)
{
var notMatched = new List();
foreach (var clusterFault in objFromApi.Result.Faults)
{
switch (fault.ToLower())
{
case "all":
WriteObject(clusterFault);
break;
case "current":
if (clusterFault.Resolved)
{
notMatched.Add(clusterFault);
}
else
{
WriteObject(clusterFault);
}
break;
case "resolved":
if (!clusterFault.Resolved)
{
notMatched.Add(clusterFault);
}
else
{
WriteObject(clusterFault);
}
break;
}
}
}
}
#endregion
}
}