#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.Linq;
using System.Management.Automation;
using SolidFire.Core.Validation;
using SolidFire.Core;
using SolidFire.Element.Api;
#endregion
namespace SolidFire.Drive.Remove
{
///
/// RemoveDrives is used to pro-actively remove drives that are part of the cluster. For example, when reducing cluster capacity or
/// preparing to replace drives at their end-of-life. Using the RemoveDrives method ensures that any data on the drives to be removed
/// is migrated to other drives in the cluster prior to removal. This is an asynchronous method. Depending on the total capacity of the
/// drives being removed, it may take several minutes to migrate all of the data. The GetAsyncResult method can be used to check on
/// the status of the remove operation. When multiple drives are being removed, it is more efficient to remove them in a single
/// RemoveDrives method rather than multiple individual methods with a single drive. This reduces the amount of data balancing that
/// must occur to even out the storage load on the cluster.
/// Drives with a "failed" status can also be removed using RemoveDrives. When a drive with a "failed" status is removed it is not
/// returned to an "available" or “active” status. The drive is unavailable for use in the cluster.
/// Use the ListDrives method to obtain the driveIDs for the drives you want to remove.
///
[Cmdlet(VerbsCommon.Remove, "SFDrive", DefaultParameterSetName = "DriveIDs", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.High)]
public class RemoveSFDrive : SFCmdlet
{
#region Private Data
#endregion
#region Parameters
///
///
///
[Parameter(Position = 0, ParameterSetName = "DriveIDs", Mandatory = false, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, ValueFromRemainingArguments = false, HelpMessage = "Please enter a drive ID or list of drive IDs")]
public Int64[] DriveID { get; set; }
[Parameter(Position = 0, ParameterSetName = "Drives", Mandatory = false, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, ValueFromRemainingArguments = false, HelpMessage = "Please pass in a SFDrive or list of SFDrives")]
public DriveInfo[] Drive { get; set; }
#endregion
#region Cmdlet Overrides
protected override void BeginProcessing()
{
base.BeginProcessing();
CheckConnection();
}
///
///
///
protected override void ProcessRecord()
{
base.ProcessRecord();
if (ParameterSetName == "DriveIDs")
{
Process(DriveID);
}
if (ParameterSetName == "Drives")
{
Process(Drive.Select(drv => drv.DriveID).ToArray());
}
}
private void Process(IEnumerable driveIDs)
{
var request = new RemoveDrivesRequest();
request.Drives = driveIDs.ToArray();
var objsFromAPI = SendRequest("RemoveDrives", request);
foreach (var obj in objsFromAPI)
{
WriteObject(obj.Result, true);
}
}
#endregion
}
}