#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.ComponentModel;
using System.Linq;
using System.Management.Automation;
using SolidFire.Core.Helpers;
using SolidFire.Core.Validation;
using SolidFire.Core;
using SolidFire.Element.Api;
using SFVolume = SolidFire.Element.Api.Volume;
#endregion
namespace SolidFire.Volume.Get
{
///
/// ListVolumeStatsByVolume returns high-level activity measurements for every volume, by volume.
/// Values are cumulative from the creation of the volume
///
[Cmdlet(VerbsCommon.Get, "SFVolumeStats", DefaultParameterSetName = "VolumeID")]
public class GetSFVolumeStats : SFCmdlet
{
#region Private Data
private long[] _volumeID;
#endregion
#region Parameters
[Parameter(Position = 0, ParameterSetName = "VolumeID", Mandatory = false, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, ValueFromRemainingArguments = false, HelpMessage = "Please enter a volume ID or list of volume IDs")]
public long[] VolumeID { get { return _volumeID; } set { _volumeID = value; } }
[Parameter(Position = 0, ParameterSetName = "AccountID", Mandatory = false, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, ValueFromRemainingArguments = false, HelpMessage = "Please enter an AccountID or list of AccountIDs")]
public long[] AccountID { get; set; }
[Parameter(Position = 0, ParameterSetName = "VolumeAccessGroupID", Mandatory = false, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, ValueFromRemainingArguments = false, HelpMessage = "Please enter a volume access group ID or list of volume access group IDs")]
public long[] VolumeAccessGroupID { get; set; }
#endregion
#region Cmdlet Overrides
protected override void BeginProcessing()
{
base.BeginProcessing();
CheckConnection();
}
///
///
///
protected override void ProcessRecord()
{
base.ProcessRecord();
switch (ParameterSetName)
{
case "VolumeID":
_processByVolumeID();
break;
case "AccountID":
_processByAccountID();
break;
case "VolumeAccessGroupID":
_processByAccessGroupID();
break;
}
}
private void _processByVolumeID()
{
if (_volumeID != null && _volumeID.Count() == 1)
{
var request = new GetVolumeStatsRequest()
{
VolumeID = _volumeID.First()
};
var objsFromAPI = SendRequest("GetVolumeStats", request);
WriteObject(objsFromAPI.Select(o => o.Result.VolumeStats), true);
}
else
{
_processByMultipleVolumeID();
}
}
private void _processByMultipleVolumeID()
{
var objsFromApi = SendRequest("ListVolumeStatsByVolume", new ListVolumeStatsByVolumeRequest());
// If there were no parameter arguments sent in for the VolumeID parameter then we just want to list all volume stats (get everything).
if (_volumeID == null)
{
WriteObject(objsFromApi.SelectMany(obj => obj.Result.VolumeStats), true);
return;
}
foreach (var id in _volumeID)
{
foreach (var volumeStat in objsFromApi.SelectMany(obj => obj.Result.VolumeStats))
{
if (id != volumeStat.VolumeID) continue;
WriteObject(volumeStat);
}
}
}
private void _processByAccountID()
{
var objsFromApi = SendRequest("ListVolumeStatsByVolume", new ListVolumeStatsByVolumeRequest());
// If there were no parameter arguments sent in for the AccountID parameter then we just want to list all volume stats (get everything).
if (AccountID == null)
{
WriteObject(objsFromApi.SelectMany(obj => obj.Result.VolumeStats), true);
return;
}
foreach (var id in AccountID)
{
var accountVolStats = objsFromApi.SelectMany(obj => obj.Result.VolumeStats).Where(v => v.AccountID == id);
WriteObject(accountVolStats, true);
}
}
private void _processByAccessGroupID()
{
var objsFromApi = SendRequest("ListVolumeStatsByVolume", new ListVolumeStatsByVolumeRequest());
// If there were no parameter arguments sent in for the VolumeAccessGroupID parameter then we just want to list all volume stats (get everything).
if (VolumeAccessGroupID == null)
{
WriteObject(objsFromApi.SelectMany(obj => obj.Result.VolumeStats), true);
return;
}
foreach (var accessGroupID in VolumeAccessGroupID)
{
var accessGroupVolStats = objsFromApi.SelectMany(obj => obj.Result.VolumeStats).Where(v => v.VolumeAccessGroups.Contains(accessGroupID));
WriteObject(accessGroupVolStats, true);
}
}
#endregion
}
}