#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.Management.Automation; using System.Net; using System.Threading; using System.Threading.Tasks; using Newtonsoft.Json; using SolidFire.Core.Exceptions; using SolidFire.Core.Helpers; using SolidFire.Core.Objects; #endregion namespace SolidFire.Core { [Cmdlet(VerbsLifecycle.Invoke, "SFApi")] public class InvokeSFApi : SFCmdlet { #region Private Data #endregion #region Parameters [Parameter(Position = 0, Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Please enter the API Method to call.")] public string Method { get; set; } [Parameter(Position = 1, Mandatory = false, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Please enter any parameters to be passed into this API Method in the form of a Hashtable.")] public Hashtable Params { get; set; } [Parameter(Position = 2, HelpMessage = "Use this to force the connection to use a different port than it was established with and pass in the desired port number.")] public int? ForcePort { get; set; } #endregion #region Cmdlet Overrides protected override void ProcessRecord() { base.ProcessRecord(); if (SFConnection != null) { foreach (var conn in SFConnection) { _runInvokeSFApi(conn); } } else if (Target != null) { foreach (var target in Target) { var conn = SolidFireUtilities.GetSFConnection(this, target); _runInvokeSFApi(conn); } } } private void _runInvokeSFApi(SFConnection conn) { if (ForcePort.HasValue) // Some CmdLets are using Node connections but need to force a call to the 443 port. Get-SFBootstrapConfig and New-SFCluster are two of them. { WriteVerbose("Altering connection to force use of port 443 due to special needs of " + this.GetType().Name); conn = (SFConnection)conn.Clone(); // This is a temporary connection that is not persisted beyond the scope of this method. conn.SetPort(ForcePort.Value); } WriteVerbose("Running " + this.GetType().Name + " command on connection " + conn.Name + " at " + conn.Uri + " with username " + conn.Credential.UserName); var returnable = conn.Element.InvokeSFApi(Method, Params); WriteObject(returnable, true); } #endregion } }