/*******************************************************************************
* Copyright 2012-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
* this file except in compliance with the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file.
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
* *****************************************************************************
*
* AWS Tools for Windows (TM) PowerShell (TM)
*
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Text;
using Amazon.PowerShell.Common;
using Amazon.Runtime;
using Amazon.MemoryDB;
using Amazon.MemoryDB.Model;
namespace Amazon.PowerShell.Cmdlets.MDB
{
///
/// Returns information about reserved nodes for this account, or about a specified reserved
/// node.
///
[Cmdlet("Get", "MDBReservedNode")]
[OutputType("Amazon.MemoryDB.Model.ReservedNode")]
[AWSCmdlet("Calls the Amazon MemoryDB DescribeReservedNodes API operation.", Operation = new[] {"DescribeReservedNodes"}, SelectReturnType = typeof(Amazon.MemoryDB.Model.DescribeReservedNodesResponse))]
[AWSCmdletOutput("Amazon.MemoryDB.Model.ReservedNode or Amazon.MemoryDB.Model.DescribeReservedNodesResponse",
"This cmdlet returns a collection of Amazon.MemoryDB.Model.ReservedNode objects.",
"The service call response (type Amazon.MemoryDB.Model.DescribeReservedNodesResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack."
)]
public partial class GetMDBReservedNodeCmdlet : AmazonMemoryDBClientCmdlet, IExecutor
{
#region Parameter Duration
///
///
/// The duration filter value, specified in years or seconds. Use this parameter to show
/// only reservations for this duration.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String Duration { get; set; }
#endregion
#region Parameter NodeType
///
///
/// The node type filter value. Use this parameter to show only those reservations matching
/// the specified node type. For more information, see Supported
/// node types.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String NodeType { get; set; }
#endregion
#region Parameter OfferingType
///
///
/// The offering type filter value. Use this parameter to show only the available offerings
/// matching the specified offering type. Valid values: "All Upfront"|"Partial Upfront"|
/// "No Upfront"
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String OfferingType { get; set; }
#endregion
#region Parameter ReservationId
///
///
/// The reserved node identifier filter value. Use this parameter to show only the reservation
/// that matches the specified reservation ID.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String ReservationId { get; set; }
#endregion
#region Parameter ReservedNodesOfferingId
///
///
/// The offering identifier filter value. Use this parameter to show only purchased reservations
/// matching the specified offering identifier.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String ReservedNodesOfferingId { get; set; }
#endregion
#region Parameter MaxResult
///
///
/// The maximum number of records to include in the response. If more records exist than
/// the specified MaxRecords value, a marker is included in the response so that the remaining
/// results can be retrieved.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("MaxResults")]
public System.Int32? MaxResult { get; set; }
#endregion
#region Parameter NextToken
///
///
/// An optional marker returned from a prior request. Use this marker for pagination of
/// results from this operation. If this parameter is specified, the response includes
/// only records beyond the marker, up to the value specified by MaxRecords.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String NextToken { get; set; }
#endregion
#region Parameter Select
///
/// Use the -Select parameter to control the cmdlet output. The default value is 'ReservedNodes'.
/// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.MemoryDB.Model.DescribeReservedNodesResponse).
/// Specifying the name of a property of type Amazon.MemoryDB.Model.DescribeReservedNodesResponse will result in that property being returned.
/// Specifying -Select '^ParameterName' will result in the cmdlet returning the selected cmdlet parameter value.
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public string Select { get; set; } = "ReservedNodes";
#endregion
protected override void ProcessRecord()
{
this._AWSSignerType = "v4";
base.ProcessRecord();
var context = new CmdletContext();
// allow for manipulation of parameters prior to loading into context
PreExecutionContextLoad(context);
if (ParameterWasBound(nameof(this.Select)))
{
context.Select = CreateSelectDelegate(Select) ??
throw new System.ArgumentException("Invalid value for -Select parameter.", nameof(this.Select));
}
context.Duration = this.Duration;
context.MaxResult = this.MaxResult;
context.NextToken = this.NextToken;
context.NodeType = this.NodeType;
context.OfferingType = this.OfferingType;
context.ReservationId = this.ReservationId;
context.ReservedNodesOfferingId = this.ReservedNodesOfferingId;
// allow further manipulation of loaded context prior to processing
PostExecutionContextLoad(context);
var output = Execute(context) as CmdletOutput;
ProcessOutput(output);
}
#region IExecutor Members
public object Execute(ExecutorContext context)
{
var cmdletContext = context as CmdletContext;
// create request
var request = new Amazon.MemoryDB.Model.DescribeReservedNodesRequest();
if (cmdletContext.Duration != null)
{
request.Duration = cmdletContext.Duration;
}
if (cmdletContext.MaxResult != null)
{
request.MaxResults = cmdletContext.MaxResult.Value;
}
if (cmdletContext.NextToken != null)
{
request.NextToken = cmdletContext.NextToken;
}
if (cmdletContext.NodeType != null)
{
request.NodeType = cmdletContext.NodeType;
}
if (cmdletContext.OfferingType != null)
{
request.OfferingType = cmdletContext.OfferingType;
}
if (cmdletContext.ReservationId != null)
{
request.ReservationId = cmdletContext.ReservationId;
}
if (cmdletContext.ReservedNodesOfferingId != null)
{
request.ReservedNodesOfferingId = cmdletContext.ReservedNodesOfferingId;
}
CmdletOutput output;
// issue call
var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint);
try
{
var response = CallAWSServiceOperation(client, request);
object pipelineOutput = null;
pipelineOutput = cmdletContext.Select(response, this);
output = new CmdletOutput
{
PipelineOutput = pipelineOutput,
ServiceResponse = response
};
}
catch (Exception e)
{
output = new CmdletOutput { ErrorResponse = e };
}
return output;
}
public ExecutorContext CreateContext()
{
return new CmdletContext();
}
#endregion
#region AWS Service Operation Call
private Amazon.MemoryDB.Model.DescribeReservedNodesResponse CallAWSServiceOperation(IAmazonMemoryDB client, Amazon.MemoryDB.Model.DescribeReservedNodesRequest request)
{
Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon MemoryDB", "DescribeReservedNodes");
try
{
#if DESKTOP
return client.DescribeReservedNodes(request);
#elif CORECLR
return client.DescribeReservedNodesAsync(request).GetAwaiter().GetResult();
#else
#error "Unknown build edition"
#endif
}
catch (AmazonServiceException exc)
{
var webException = exc.InnerException as System.Net.WebException;
if (webException != null)
{
throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException);
}
throw;
}
}
#endregion
internal partial class CmdletContext : ExecutorContext
{
public System.String Duration { get; set; }
public System.Int32? MaxResult { get; set; }
public System.String NextToken { get; set; }
public System.String NodeType { get; set; }
public System.String OfferingType { get; set; }
public System.String ReservationId { get; set; }
public System.String ReservedNodesOfferingId { get; set; }
public System.Func Select { get; set; } =
(response, cmdlet) => response.ReservedNodes;
}
}
}