#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.Validation; using SolidFire.Core; using SolidFire.Element.Api; using System.Management.Automation.Runspaces; using System.Collections; using System.Linq; #endregion namespace SolidFire.Volume.Invoke { /// /// RollbackToGroupSnapshot is used to roll back each individual volume in a snapshot group to a copy of their individual snapshots. /// This will ONLY return a value if SaveCurrentState is true. The returned value with contain the GroupSnapshotID of the newly created /// GroupSnapshot if you need to roll forward to CurrentState. Otherwise, nothing will be returned. /// [Cmdlet(VerbsLifecycle.Invoke, "SFRollbackToGroupSnapshot", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.High)] public class InvokeSFRollbackToGroupSnapshot : SFCmdlet { #region Private Data private Pipeline pipeline; private List processedIDs = new List(); #endregion #region Parameters [Parameter(Position = 0, Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, ValueFromRemainingArguments = false, HelpMessage = "Please enter a GroupSnapshotID for the volume to restore.")] public long GroupSnapshotID { get; set; } [Parameter(Position = 1, Mandatory = false, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, ValueFromRemainingArguments = false, HelpMessage = "Name for the snapshot. If no name is given then the name of the snapshot being rolled back to is used with '- copy' appended to the end of the name.")] public string Name { get; set; } [Parameter(Position = 2, Mandatory = false, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, ValueFromRemainingArguments = false, HelpMessage = "true: The previous active volume image is kept. false: (default) The previous active volume image is deleted.")] public bool SaveCurrentState { get; set; } [Parameter(Position = 3, Mandatory = false, ValueFromPipeline = false, ValueFromPipelineByPropertyName = false, HelpMessage = "Attributes to set")] public Hashtable Attributes { get; set; } #endregion #region Cmdlet Overrides protected override void BeginProcessing() { base.BeginProcessing(); CheckConnection(minVersionNumber: 7.0f); pipeline = Runspace.DefaultRunspace.CreateNestedPipeline(); } protected override void ProcessRecord() { base.ProcessRecord(); var request = new RollbackToGroupSnapshotRequest(); request.GroupSnapshotID = GroupSnapshotID; request.Name = Name; request.SaveCurrentState = SaveCurrentState; request.Attributes = Attributes; var objsFromAPI = SendRequest("RollbackToGroupSnapshot", request); foreach (var obj in objsFromAPI.Where(r => r.Result.GroupSnapshotID.HasValue)) { processedIDs.Add(obj.Result.GroupSnapshotID.Value); } } protected override void EndProcessing() { if (processedIDs.Count > 0) { var command = new Command("Get-SFGroupSnapshot"); command.Parameters.Add("GroupSnapshotID", 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); } base.EndProcessing(); processedIDs.Clear(); pipeline = null; } #endregion } }