/*******************************************************************************
* 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 utilization for your account. Management account in an organization
/// have access to member accounts. You can filter data by dimensions in a time period.
/// You can use GetDimensionValues
to determine the possible dimension values.
/// Currently, you can group only by SUBSCRIPTION_ID
.
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", "CEReservationUtilization")]
[OutputType("Amazon.CostExplorer.Model.GetReservationUtilizationResponse")]
[AWSCmdlet("Calls the AWS Cost Explorer GetReservationUtilization API operation.", Operation = new[] {"GetReservationUtilization"}, SelectReturnType = typeof(Amazon.CostExplorer.Model.GetReservationUtilizationResponse))]
[AWSCmdletOutput("Amazon.CostExplorer.Model.GetReservationUtilizationResponse",
"This cmdlet returns an Amazon.CostExplorer.Model.GetReservationUtilizationResponse object containing multiple properties. The object can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack."
)]
public partial class GetCEReservationUtilizationCmdlet : AmazonCostExplorerClientCmdlet, IExecutor
{
#region Parameter Filter
///
///
/// Filters utilization data by dimensions. You can filter by the following dimensions:- AZ
- CACHE_ENGINE
- DEPLOYMENT_OPTION
- INSTANCE_TYPE
- LINKED_ACCOUNT
- OPERATING_SYSTEM
- PLATFORM
- REGION
- SERVICE
- SCOPE
- TENANCY
GetReservationUtilization
uses the same Expression
/// object as the other operations, but only AND
is supported among each
/// dimension, and nesting is supported up to only one level deep. If there are multiple
/// values for a dimension, they are OR'd together.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public Amazon.CostExplorer.Model.Expression Filter { get; set; }
#endregion
#region Parameter Granularity
///
///
/// 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
. If both GroupBy
and Granularity
aren't
/// set, GetReservationUtilization
defaults to DAILY
.The GetReservationUtilization
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
///
///
/// Groups only by SUBSCRIPTION_ID
. Metadata is included.
///
///
[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 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
///
///
/// Sets the start and end dates for retrieving Reserved Instance (RI) utilization. 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(Position = 0, ValueFromPipelineByPropertyName = true, ValueFromPipeline = true)]
#else
[System.Management.Automation.Parameter(Position = 0, ValueFromPipelineByPropertyName = true, ValueFromPipeline = 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.GetReservationUtilizationResponse).
/// Specifying the name of a property of type Amazon.CostExplorer.Model.GetReservationUtilizationResponse 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 PassThru
///
/// Changes the cmdlet behavior to return the value passed to the TimePeriod parameter.
/// The -PassThru parameter is deprecated, use -Select '^TimePeriod' instead. This parameter will be removed in a future version.
///
[System.Obsolete("The -PassThru parameter is deprecated, use -Select '^TimePeriod' instead. This parameter will be removed in a future version.")]
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public SwitchParameter PassThru { 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);
#pragma warning disable CS0618, CS0612 //A class member was marked with the Obsolete attribute
if (ParameterWasBound(nameof(this.Select)))
{
context.Select = CreateSelectDelegate(Select) ??
throw new System.ArgumentException("Invalid value for -Select parameter.", nameof(this.Select));
if (this.PassThru.IsPresent)
{
throw new System.ArgumentException("-PassThru cannot be used when -Select is specified.", nameof(this.Select));
}
}
else if (this.PassThru.IsPresent)
{
context.Select = (response, cmdlet) => this.TimePeriod;
}
#pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute
context.Filter = this.Filter;
context.Granularity = this.Granularity;
if (this.GroupBy != null)
{
context.GroupBy = new List(this.GroupBy);
}
context.MaxResult = this.MaxResult;
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;
#pragma warning disable CS0618, CS0612 //A class member was marked with the Obsolete attribute
var useParameterSelect = this.Select.StartsWith("^") || this.PassThru.IsPresent;
#pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute
// create request and set iteration invariants
var request = new Amazon.CostExplorer.Model.GetReservationUtilizationRequest();
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;
}
// 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.GetReservationUtilizationRequest();
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.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.GetReservationUtilizationResponse CallAWSServiceOperation(IAmazonCostExplorer client, Amazon.CostExplorer.Model.GetReservationUtilizationRequest request)
{
Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Cost Explorer", "GetReservationUtilization");
try
{
#if DESKTOP
return client.GetReservationUtilization(request);
#elif CORECLR
return client.GetReservationUtilizationAsync(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 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;
}
}
}