#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;
using System.Collections.Generic;
using System.ComponentModel;
using System.Management.Automation;
using SolidFire.Core.Validation;
using System.Management.Automation.Runspaces;
using SolidFire.Core;
using SolidFire.Element.Api;
#endregion
namespace SolidFire.Volume.New
{
///
/// NewSFVolumeAccessGroup is used to create a new volume access group on
/// the cluster by wrapping the CreateVolumeAccessGroup API method . The
/// new volume access group must be given a name when it is created.
/// Entering initiators and volumes are optional when creating a volume
/// access group. Once the group is created volumes and initiator IQNs
/// can be added. Any initiator IQN that is successfully added to the
/// volume access group is able to access any volume in the group without
/// CHAP authentication.
///
/// VolumeAccessGroup Limits:
/// A volume access group can contain up to sixty-four initiator IQNs
/// An initiator can only belong to only one volume access group
/// A volume access group can contain up to two thousand volumes
/// Each volume access group can belong to a maximum of four other volume access groups
///
[Cmdlet(VerbsCommon.New, "SFVolumeAccessGroup", ConfirmImpact = ConfirmImpact.Medium)]
public class NewSFVolumeAccessGroup : SFCmdlet
{
#region Private Data
private string name;
private string[] initiators;
private Int64[] volumes;
///
/// The ID of the SolidFire Virtual Network ID to associate the volume access group with.
///
private Int64[] virtualNetworkID;
///
/// The ID of the VLAN Virtual Network Tag to associate the volume access group with.
///
private Int64[] virtualNetworkTags;
private List processedIDs = new List();
private Pipeline pipeline;
#endregion
#region Parameters
///
///
///
[Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Name of the volume access group")]
[ValidatePattern(SolidFireValidations.UpperAndLowerCaseAndNumeric)]
public String Name
{
get { return name; }
set { name = value; }
}
///
///
///
[Parameter(Mandatory = false, Position = 1, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, HelpMessage = "List of initiator names (IQNs and WWPNs) to include in the volume access group")]
// Validation Pattern is too restrictive [ValidatePattern(SolidFireValidations.iSCSIInitiator)]
public string[] Initiators
{
get { return initiators; }
set { initiators = value; }
}
///
///
///
[Parameter(Mandatory = false, Position = 2, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, HelpMessage = "List of VolumeIDs to include in the volume access group")]
[ValidatePattern(SolidFireValidations.Numeric)]
public Int64[] VolumeIDs
{
get { return volumes; }
set { volumes = value; }
}
[Parameter(Mandatory = false, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The ID of the SolidFire Virtual Network ID to associate the volume access group with.")]
public Int64[] VirtualNetworkID
{
get { return virtualNetworkID; }
set { virtualNetworkID = value; }
}
[Parameter(Mandatory = false, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The ID of the VLAN Virtual Network Tag to associate the volume access group with.")]
public Int64[] VirtualNetworkTag
{
get { return virtualNetworkTags; }
set { virtualNetworkTags = value; }
}
///
///
///
[Parameter(Mandatory = false, Position = 3, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Hashtable of name/values")]
public Hashtable Attributes { get; set; }
#endregion
#region Cmdlet Overrides
protected override void BeginProcessing()
{
base.BeginProcessing();
pipeline = Runspace.DefaultRunspace.CreateNestedPipeline();
CheckConnection();
}
protected override void EndProcessing()
{
base.EndProcessing();
var command = new Command("Get-SFVolumeAccessGroup");
command.Parameters.Add("VolumeAccessGroupID", processedIDs);
if (SFConnection != null)
{
command.Parameters.Add("SFConnection", SFConnection);
}
else if (Target != null)
{
command.Parameters.Add("Target", Target);
}
pipeline.Commands.Add(command);
WriteObject(pipeline.Invoke(), true);
processedIDs.Clear();
pipeline = null;
}
///
///
///
protected override void ProcessRecord()
{
base.ProcessRecord();
// Assemble the parameters object
var request = new CreateVolumeAccessGroupRequest();
request.Attributes = Attributes;
request.Name = name;
request.Initiators = initiators;
request.Volumes = volumes;
request.VirtualNetworkID = virtualNetworkID;
request.VirtualNetworkTags = virtualNetworkTags;
var objsFromAPI = SendRequest("CreateVolumeAccessGroup", request);
foreach (var obj in objsFromAPI)
{
processedIDs.Add(obj.Result.VolumeAccessGroupID);
}
}
#endregion
}
}