/*******************************************************************************
* 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.CostExplorer;
using Amazon.CostExplorer.Model;
namespace Amazon.PowerShell.Cmdlets.CE
{
///
/// Retrieves the reservation coverage for your account, which you can use to see how
/// much of your Amazon Elastic Compute Cloud, Amazon ElastiCache, Amazon Relational Database
/// Service, or Amazon Redshift usage is covered by a reservation. An organization's management
/// account can see the coverage of the associated member accounts. This supports dimensions,
/// Cost Categories, and nested expressions. For any time period, you can filter data
/// about reservation usage by the following dimensions:
///
/// -
/// AZ
///
-
/// CACHE_ENGINE
///
-
/// DATABASE_ENGINE
///
-
/// DEPLOYMENT_OPTION
///
-
/// INSTANCE_TYPE
///
-
/// LINKED_ACCOUNT
///
-
/// OPERATING_SYSTEM
///
-
/// PLATFORM
///
-
/// REGION
///
-
/// SERVICE
///
-
/// TAG
///
-
/// TENANCY
///
/// To determine valid values for a dimension, use the GetDimensionValues
/// operation.
///
In the AWS.Tools.CostExplorer module, this cmdlet automatically pages all available results to the pipeline - parameters related to iteration are only needed if you want to manually control the paginated output. To disable autopagination, use -NoAutoIteration.
///
[Cmdlet("Get", "CEReservationCoverage")]
[OutputType("Amazon.CostExplorer.Model.GetReservationCoverageResponse")]
[AWSCmdlet("Calls the AWS Cost Explorer GetReservationCoverage API operation.", Operation = new[] {"GetReservationCoverage"}, SelectReturnType = typeof(Amazon.CostExplorer.Model.GetReservationCoverageResponse))]
[AWSCmdletOutput("Amazon.CostExplorer.Model.GetReservationCoverageResponse",
"This cmdlet returns an Amazon.CostExplorer.Model.GetReservationCoverageResponse object containing multiple properties. The object can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack."
)]
public partial class GetCEReservationCoverageCmdlet : AmazonCostExplorerClientCmdlet, IExecutor
{
#region Parameter Filter
///
///
/// Filters utilization data by dimensions. You can filter by the following dimensions:- AZ
- CACHE_ENGINE
- DATABASE_ENGINE
- DEPLOYMENT_OPTION
- INSTANCE_TYPE
- LINKED_ACCOUNT
- OPERATING_SYSTEM
- PLATFORM
- REGION
- SERVICE
- TAG
- TENANCY
GetReservationCoverage
uses the same Expression
/// object as the other operations, but only AND
is supported among each
/// dimension. You can nest only one level deep. If there are multiple values for a dimension,
/// they are OR'd together.If you don't provide a SERVICE
filter, Cost Explorer defaults to EC2.Cost category is also supported.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public Amazon.CostExplorer.Model.Expression Filter { get; set; }
#endregion
#region Parameter Granularity
///
///
/// The granularity of the Amazon Web Services cost data for the reservation. Valid values
/// are MONTHLY
and DAILY
.If GroupBy
is set, Granularity
can't be set. If Granularity
/// isn't set, the response object doesn't include Granularity
, either MONTHLY
/// or DAILY
.The GetReservationCoverage
operation supports only DAILY
/// and MONTHLY
granularities.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[AWSConstantClassSource("Amazon.CostExplorer.Granularity")]
public Amazon.CostExplorer.Granularity Granularity { get; set; }
#endregion
#region Parameter GroupBy
///
///
/// You can group the data by the following attributes:- AZ
- CACHE_ENGINE
- DATABASE_ENGINE
- DEPLOYMENT_OPTION
- INSTANCE_TYPE
- INVOICING_ENTITY
- LINKED_ACCOUNT
- OPERATING_SYSTEM
- PLATFORM
- REGION
- TENANCY
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public Amazon.CostExplorer.Model.GroupDefinition[] GroupBy { get; set; }
#endregion
#region Parameter SortBy_Key
///
///
/// The key that's used to sort the data.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String SortBy_Key { get; set; }
#endregion
#region Parameter Metric
///
///
/// The measurement that you want your reservation coverage reported in.Valid values are Hour
, Unit
, and Cost
. You
/// can use multiple values in a request.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("Metrics")]
public System.String[] Metric { get; set; }
#endregion
#region Parameter SortBy_SortOrder
///
///
/// The order that's used to sort the data.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[AWSConstantClassSource("Amazon.CostExplorer.SortOrder")]
public Amazon.CostExplorer.SortOrder SortBy_SortOrder { get; set; }
#endregion
#region Parameter TimePeriod
///
///
/// The start and end dates of the period that you want to retrieve data about reservation
/// coverage for. You can retrieve data for a maximum of 13 months: the last 12 months
/// and the current month. The start date is inclusive, but the end date is exclusive.
/// For example, if start
is 2017-01-01
and end
/// is 2017-05-01
, then the cost and usage data is retrieved from 2017-01-01
/// up to and including 2017-04-30
but not including 2017-05-01
.
///
///
///
#if !MODULAR
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
#else
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true)]
[System.Management.Automation.AllowNull]
#endif
[Amazon.PowerShell.Common.AWSRequiredParameter]
public Amazon.CostExplorer.Model.DateInterval TimePeriod { get; set; }
#endregion
#region Parameter MaxResult
///
///
/// The maximum number of objects that you returned for this request. If more objects
/// are available, in the response, Amazon Web Services provides a NextPageToken value
/// that you can use in a subsequent call to get the next batch of objects.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("MaxResults")]
public System.Int32? MaxResult { get; set; }
#endregion
#region Parameter NextPageToken
///
///
/// The token to retrieve the next set of results. Amazon Web Services provides the token
/// when the response from a previous call has more results than the maximum page size.
///
///
///
Note: In the AWS.Tools.CostExplorer module, this parameter is only used if you are manually controlling output pagination of the service API call.
///
In order to manually control output pagination, use '-NextPageToken $null' for the first call and '-NextPageToken $AWSHistory.LastServiceResponse.NextPageToken' for subsequent calls.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("NextToken")]
public System.String NextPageToken { get; set; }
#endregion
#region Parameter Select
///
/// Use the -Select parameter to control the cmdlet output. The default value is '*'.
/// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.CostExplorer.Model.GetReservationCoverageResponse).
/// Specifying the name of a property of type Amazon.CostExplorer.Model.GetReservationCoverageResponse 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; } = "*";
#endregion
#region Parameter NoAutoIteration
#if MODULAR
///
/// By default the cmdlet will auto-iterate and retrieve all results to the pipeline by performing multiple
/// service calls. If set, the cmdlet will retrieve only the next 'page' of results using the value of NextPageToken
/// as the start point.
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public SwitchParameter NoAutoIteration { get; set; }
#endif
#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.Filter = this.Filter;
context.Granularity = this.Granularity;
if (this.GroupBy != null)
{
context.GroupBy = new List(this.GroupBy);
}
context.MaxResult = this.MaxResult;
if (this.Metric != null)
{
context.Metric = new List(this.Metric);
}
context.NextPageToken = this.NextPageToken;
context.SortBy_Key = this.SortBy_Key;
context.SortBy_SortOrder = this.SortBy_SortOrder;
context.TimePeriod = this.TimePeriod;
#if MODULAR
if (this.TimePeriod == null && ParameterWasBound(nameof(this.TimePeriod)))
{
WriteWarning("You are passing $null as a value for parameter TimePeriod which is marked as required. In case you believe this parameter was incorrectly marked as required, report this by opening an issue at https://github.com/aws/aws-tools-for-powershell/issues.");
}
#endif
// allow further manipulation of loaded context prior to processing
PostExecutionContextLoad(context);
var output = Execute(context) as CmdletOutput;
ProcessOutput(output);
}
#region IExecutor Members
#if MODULAR
public object Execute(ExecutorContext context)
{
var cmdletContext = context as CmdletContext;
var useParameterSelect = this.Select.StartsWith("^");
// create request and set iteration invariants
var request = new Amazon.CostExplorer.Model.GetReservationCoverageRequest();
if (cmdletContext.Filter != null)
{
request.Filter = cmdletContext.Filter;
}
if (cmdletContext.Granularity != null)
{
request.Granularity = cmdletContext.Granularity;
}
if (cmdletContext.GroupBy != null)
{
request.GroupBy = cmdletContext.GroupBy;
}
if (cmdletContext.MaxResult != null)
{
request.MaxResults = cmdletContext.MaxResult.Value;
}
if (cmdletContext.Metric != null)
{
request.Metrics = cmdletContext.Metric;
}
// populate SortBy
var requestSortByIsNull = true;
request.SortBy = new Amazon.CostExplorer.Model.SortDefinition();
System.String requestSortBy_sortBy_Key = null;
if (cmdletContext.SortBy_Key != null)
{
requestSortBy_sortBy_Key = cmdletContext.SortBy_Key;
}
if (requestSortBy_sortBy_Key != null)
{
request.SortBy.Key = requestSortBy_sortBy_Key;
requestSortByIsNull = false;
}
Amazon.CostExplorer.SortOrder requestSortBy_sortBy_SortOrder = null;
if (cmdletContext.SortBy_SortOrder != null)
{
requestSortBy_sortBy_SortOrder = cmdletContext.SortBy_SortOrder;
}
if (requestSortBy_sortBy_SortOrder != null)
{
request.SortBy.SortOrder = requestSortBy_sortBy_SortOrder;
requestSortByIsNull = false;
}
// determine if request.SortBy should be set to null
if (requestSortByIsNull)
{
request.SortBy = null;
}
if (cmdletContext.TimePeriod != null)
{
request.TimePeriod = cmdletContext.TimePeriod;
}
// Initialize loop variant and commence piping
var _nextToken = cmdletContext.NextPageToken;
var _userControllingPaging = this.NoAutoIteration.IsPresent || ParameterWasBound(nameof(this.NextPageToken));
var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint);
do
{
request.NextPageToken = _nextToken;
CmdletOutput output;
try
{
var response = CallAWSServiceOperation(client, request);
object pipelineOutput = null;
if (!useParameterSelect)
{
pipelineOutput = cmdletContext.Select(response, this);
}
output = new CmdletOutput
{
PipelineOutput = pipelineOutput,
ServiceResponse = response
};
_nextToken = response.NextPageToken;
}
catch (Exception e)
{
output = new CmdletOutput { ErrorResponse = e };
}
ProcessOutput(output);
} while (!_userControllingPaging && AutoIterationHelpers.HasValue(_nextToken));
if (useParameterSelect)
{
WriteObject(cmdletContext.Select(null, this));
}
return null;
}
#else
public object Execute(ExecutorContext context)
{
var cmdletContext = context as CmdletContext;
// create request
var request = new Amazon.CostExplorer.Model.GetReservationCoverageRequest();
if (cmdletContext.Filter != null)
{
request.Filter = cmdletContext.Filter;
}
if (cmdletContext.Granularity != null)
{
request.Granularity = cmdletContext.Granularity;
}
if (cmdletContext.GroupBy != null)
{
request.GroupBy = cmdletContext.GroupBy;
}
if (cmdletContext.MaxResult != null)
{
request.MaxResults = cmdletContext.MaxResult.Value;
}
if (cmdletContext.Metric != null)
{
request.Metrics = cmdletContext.Metric;
}
if (cmdletContext.NextPageToken != null)
{
request.NextPageToken = cmdletContext.NextPageToken;
}
// populate SortBy
var requestSortByIsNull = true;
request.SortBy = new Amazon.CostExplorer.Model.SortDefinition();
System.String requestSortBy_sortBy_Key = null;
if (cmdletContext.SortBy_Key != null)
{
requestSortBy_sortBy_Key = cmdletContext.SortBy_Key;
}
if (requestSortBy_sortBy_Key != null)
{
request.SortBy.Key = requestSortBy_sortBy_Key;
requestSortByIsNull = false;
}
Amazon.CostExplorer.SortOrder requestSortBy_sortBy_SortOrder = null;
if (cmdletContext.SortBy_SortOrder != null)
{
requestSortBy_sortBy_SortOrder = cmdletContext.SortBy_SortOrder;
}
if (requestSortBy_sortBy_SortOrder != null)
{
request.SortBy.SortOrder = requestSortBy_sortBy_SortOrder;
requestSortByIsNull = false;
}
// determine if request.SortBy should be set to null
if (requestSortByIsNull)
{
request.SortBy = null;
}
if (cmdletContext.TimePeriod != null)
{
request.TimePeriod = cmdletContext.TimePeriod;
}
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;
}
#endif
public ExecutorContext CreateContext()
{
return new CmdletContext();
}
#endregion
#region AWS Service Operation Call
private Amazon.CostExplorer.Model.GetReservationCoverageResponse CallAWSServiceOperation(IAmazonCostExplorer client, Amazon.CostExplorer.Model.GetReservationCoverageRequest request)
{
Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Cost Explorer", "GetReservationCoverage");
try
{
#if DESKTOP
return client.GetReservationCoverage(request);
#elif CORECLR
return client.GetReservationCoverageAsync(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 Amazon.CostExplorer.Model.Expression Filter { get; set; }
public Amazon.CostExplorer.Granularity Granularity { get; set; }
public List GroupBy { get; set; }
public System.Int32? MaxResult { get; set; }
public List Metric { get; set; }
public System.String NextPageToken { get; set; }
public System.String SortBy_Key { get; set; }
public Amazon.CostExplorer.SortOrder SortBy_SortOrder { get; set; }
public Amazon.CostExplorer.Model.DateInterval TimePeriod { get; set; }
public System.Func Select { get; set; } =
(response, cmdlet) => response;
}
}
}