#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.Helpers;
using SolidFire.Core.Objects;
using SolidFire.Core.Validation;
using SolidFire.Core;
using SolidFire.Element.Api;
using ElementVolume = SolidFire.Element.Api.Volume;
#endregion
namespace SolidFire.Volume.Get
{
///
/// ListActiveVolumes is used to return the list of active volumes currently in the system.
/// The list of volumes is returned sorted in VolumeID order and can be returned in multiple parts (pages).
///
[Cmdlet(VerbsCommon.Get, "SFDeletedVolume", DefaultParameterSetName = "VolumeId")]
public class GetSFDeletedVolume : SFCmdlet
{
#region Private Data
///
///
///
private Int64[] volumeId;
private string[] volumeName;
#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")]
[ValidateNotNullOrEmpty]
[ValidatePattern(SolidFireValidations.Numeric)]
public Int64[] VolumeID
{
get
{
return volumeId;
}
set
{
volumeId = value;
}
}
[Parameter(Position = 0, ParameterSetName = "Name", Mandatory = false, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, ValueFromRemainingArguments = false, HelpMessage = "Please enter a volume name or list of volume names")]
[ValidateNotNullOrEmpty]
[ValidatePattern(SolidFireValidations.UpperAndLowerCase)]
public String[] Name
{
get
{
return volumeName;
}
set
{
volumeName = value;
}
}
#endregion
#region Cmdlet Overrides
protected override void BeginProcessing()
{
base.BeginProcessing();
CheckConnection();
}
///
///
///
protected override void ProcessRecord()
{
base.ProcessRecord();
var objsFromAPI = SendRequest("ListDeletedVolumes", new ListDeletedVolumesRequest());
foreach (var obj in objsFromAPI)
{
switch (ParameterSetName)
{
case "VolumeId":
FilterByVolumeId(obj);
break;
case "Name":
FilterByName(obj);
break;
default:
throw new ArgumentException("Invalid parameter set.");
}
}
}
private void FilterByName(SFWrapper objFromApi)
{
const WildcardOptions options = WildcardOptions.IgnoreCase |
WildcardOptions.Compiled;
foreach (var volName in volumeName)
{
var matchedVolumes = new List();
foreach (var vol in objFromApi.Result.Volumes)
{
var wildcard = new WildcardPattern(volName, options);
if (wildcard.IsMatch(vol.Name))
{
if (!matchedVolumes.Contains(vol))
{
matchedVolumes.Add(vol);
}
}
}
if (matchedVolumes.Count > 0)
{
WriteObject(matchedVolumes, true);
}
}
}
private void FilterByVolumeId(SFWrapper objFromApi)
{
// If there were no parameter arguments sent in for the Name parameter then we just want to list all volumes.
if (volumeId == null)
{
WriteObject(objFromApi.Result.Volumes, true);
return;
}
foreach (var id in volumeId)
{
foreach (var sfVolumeInfo in objFromApi.Result.Volumes)
{
if (sfVolumeInfo.VolumeID != id) continue;
WriteObject(sfVolumeInfo);
}
}
}
#endregion
}
}