#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.Management.Automation; using SolidFire.Core.Validation; using SolidFire.Core; using SolidFire.Element.Api; using System.Linq; #endregion namespace SolidFire.Volume.New { /// /// New-SFCloneMultiple is used to create a clone of a group of specified volumes. A consistent set of characteristics can be /// assigned to a group of multiple volume when they are cloned together. /// If groupSnapshotID is going to be used to clone the volumes in a group snapshot, the group snapshot must be created first /// using the CreateGroupSnapshot API method or the SolidFire Element WebUI. Using groupSnapshotID is optional when /// cloning multiple volumes. /// [Cmdlet(VerbsCommon.New, "SFCloneMultiple", ConfirmImpact = ConfirmImpact.None)] public class NewSFCloneMultiple : SFCmdlet { #region Private Data private Int64? newAccountID = null; private Int64? groupSnapshotID = null; #endregion #region Parameters /// /// Unique SFCloneVolume for each volume to include in the clone. If optional parameters are not specified, the values will be inherited from the source volumes. /// [Parameter(Mandatory = true, Position = 0, ParameterSetName = "CloneVolume", HelpMessage = "Unique SFCloneVolume for each volume to include in the clone. If optional parameters are not specified, the values will be inherited from the source volumes.")] public CloneMultipleVolumeParams[] Volume { get; set; } /// /// Unique ID for each volume to include in the clone /// [Parameter(Mandatory = true, Position = 0, ValueFromPipeline=true, ParameterSetName = "CloneVolumeID", HelpMessage = "Unique ID for each volume to include in the clone. Default values will be inherited from the source volumes.")] [ValidatePattern(SolidFireValidations.Numeric)] public Int64[] VolumeID { get; set; } /// /// New default access method for the new volumes if not overridden by information passed in the volume's array. /// [Parameter(Mandatory = false, Position = 2, HelpMessage = "New default access method for the new volumes if not overridden by information passed in the Volumes array.")] [ValidatePattern(SolidFireValidations.UpperAndLowerCase)] [ValidateSet("readOnly", "readWrite", "locked", "replicationTarget", IgnoreCase = true)] public string Access { get; set; } /// /// /// [Parameter(Mandatory = false, Position = 3, HelpMessage = "ID of the group snapshot to use as a basis for the clone.")] [ValidatePattern(SolidFireValidations.Numeric)] public Int64 GroupSnapshotID { get { return groupSnapshotID.Value; } set { groupSnapshotID = value; } } /// /// /// [Parameter(Mandatory = false, Position = 4, HelpMessage = "New account ID for the volumes if not overridden by information passed in the Volumes array.")] [ValidatePattern(SolidFireValidations.Numeric)] public Int64 NewAccountID { get { return newAccountID.Value; } set { newAccountID = value; } } #endregion #region Cmdlet Overrides protected override void BeginProcessing() { base.BeginProcessing(); CheckConnection(); } /// /// /// protected override void ProcessRecord() { base.ProcessRecord(); var request = new CloneMultipleVolumesRequest(); request.Access = Access; request.GroupSnapshotID = groupSnapshotID; request.NewAccountID = newAccountID; if (ParameterSetName == "CloneVolume") { request.Volumes = Volume; } if (ParameterSetName == "CloneVolumeID") { request.Volumes = VolumeID.Select(v => new CloneMultipleVolumeParams() {VolumeID = v}).ToArray(); } var objsFromAPI = SendRequest("CloneMultipleVolumes", request); foreach (var obj in objsFromAPI) { WriteObject(obj.Result); } } #endregion } }