#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.Linq;
using System.Management.Automation;
using SolidFire.Core;
using SolidFire.Core.Helpers;
using SolidFire.Element.Api;
using SolidFire.Exceptions;
#endregion
namespace SolidFire.Volume.New
{
[Cmdlet(VerbsCommon.New, "SFQoSPolicy", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
public class NewSFQoSPolicy : SFCmdlet
{
#region Private Data
///
/// Member for saving the optional minimum iops setting. Implemented
/// as a nullable to help decide if the setting needs to be sent
/// to the api call as JSON data.
///
private int? minIOPS;
///
/// Member for saving the optional maximum iops setting. Implemented
/// as a nullable to help decide if the setting needs to be sent
/// to the api call as JSON data.
///
private int? maxIOPS;
///
/// Member for saving the optional burst iops setting. Implemented
/// as a nullable to help decide if the setting needs to be sent
/// to the api call as JSON data.
///
private int? burstIOPS;
///
/// Member for saving the optional burst iops setting. Implemented
/// as a nullable to help decide if the setting needs to be sent
/// to the api call as JSON data.
///
private int? burstTime;
#endregion
#region Parameters
[Parameter(Position = 0, Mandatory = true, HelpMessage = "The name of the QoS policy.")]
public string Name { get; set; }
///
/// Minimum iops to set for the volume.
///
[Parameter(Mandatory = false, Position = 8,
HelpMessage = "The desired minimum 4KB IOPS to guarantee")]
public int MinIOPS
{
get { return minIOPS.HasValue ? minIOPS.Value : 0; }
set { minIOPS = value; }
}
///
/// Maximum iops to set for the volume.
///
[Parameter(Mandatory = false, Position = 9,
HelpMessage = "The desired maximum 4KB IOPS to guarantee")]
public int MaxIOPS
{
get { return maxIOPS ?? 0; }
set { maxIOPS = value; }
}
///
/// Burst iops to set for the volume.
///
[Parameter(Mandatory = false, Position = 10,
HelpMessage = "The maximum 4KB IOPS allowed for a short time")]
public int BurstIOPS
{
get { return burstIOPS ?? 0; }
set { burstIOPS = value; }
}
///
/// Burst iops to set for the volume.
///
[Parameter(Mandatory = false, Position = 11,
HelpMessage = "The time to allow a burst of maximum 4KB IOPS")]
public int BurstTime
{
get { return burstTime ?? 0; }
set { burstTime = value; }
}
#endregion
#region Cmdlet Overrides
protected override void BeginProcessing()
{
base.BeginProcessing();
CheckConnection();
}
protected override void ProcessRecord()
{
base.ProcessRecord();
var request = new CreateQoSPolicyRequest
{
Name = Name
};
if (minIOPS.HasValue || maxIOPS.HasValue || burstIOPS.HasValue || burstTime.HasValue)
{
request.Qos = new QoS
{
BurstIOPS = burstIOPS,
MaxIOPS = maxIOPS,
MinIOPS = minIOPS,
BurstTime = burstTime
};
}
else
{
var errorRecord =
new ErrorRecord(new ParameterException("Missing at least one QoS value. Please supply MinIOPS, MaxIOPS, BurstIOPS, or BurstTime"), "ParameterError", ErrorCategory.InvalidOperation, this);
SolidFireUtilities.HandleError(errorRecord, this);
}
WriteObject(SendRequest("CreateQoSPolicy", request).Select(r => r.Result.QosPolicy));
}
#endregion
}
}