1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package ec2
4
5import (
6	"context"
7	"fmt"
8	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
9	"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
10	"github.com/aws/aws-sdk-go-v2/service/ec2/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Finds available schedules that meet the specified criteria. You can search for
16// an available schedule no more than 3 months in advance. You must meet the
17// minimum required duration of 1,200 hours per year. For example, the minimum
18// daily schedule is 4 hours, the minimum weekly schedule is 24 hours, and the
19// minimum monthly schedule is 100 hours. After you find a schedule that meets your
20// needs, call PurchaseScheduledInstances to purchase Scheduled Instances with that
21// schedule.
22func (c *Client) DescribeScheduledInstanceAvailability(ctx context.Context, params *DescribeScheduledInstanceAvailabilityInput, optFns ...func(*Options)) (*DescribeScheduledInstanceAvailabilityOutput, error) {
23	if params == nil {
24		params = &DescribeScheduledInstanceAvailabilityInput{}
25	}
26
27	result, metadata, err := c.invokeOperation(ctx, "DescribeScheduledInstanceAvailability", params, optFns, addOperationDescribeScheduledInstanceAvailabilityMiddlewares)
28	if err != nil {
29		return nil, err
30	}
31
32	out := result.(*DescribeScheduledInstanceAvailabilityOutput)
33	out.ResultMetadata = metadata
34	return out, nil
35}
36
37// Contains the parameters for DescribeScheduledInstanceAvailability.
38type DescribeScheduledInstanceAvailabilityInput struct {
39
40	// The time period for the first schedule to start.
41	//
42	// This member is required.
43	FirstSlotStartTimeRange *types.SlotDateTimeRangeRequest
44
45	// The schedule recurrence.
46	//
47	// This member is required.
48	Recurrence *types.ScheduledInstanceRecurrenceRequest
49
50	// Checks whether you have the required permissions for the action, without
51	// actually making the request, and provides an error response. If you have the
52	// required permissions, the error response is DryRunOperation. Otherwise, it is
53	// UnauthorizedOperation.
54	DryRun bool
55
56	// The filters.
57	//
58	// * availability-zone - The Availability Zone (for example,
59	// us-west-2a).
60	//
61	// * instance-type - The instance type (for example, c4.large).
62	//
63	// *
64	// network-platform - The network platform (EC2-Classic or EC2-VPC).
65	//
66	// * platform -
67	// The platform (Linux/UNIX or Windows).
68	Filters []types.Filter
69
70	// The maximum number of results to return in a single call. This value can be
71	// between 5 and 300. The default value is 300. To retrieve the remaining results,
72	// make another call with the returned NextToken value.
73	MaxResults int32
74
75	// The maximum available duration, in hours. This value must be greater than
76	// MinSlotDurationInHours and less than 1,720.
77	MaxSlotDurationInHours int32
78
79	// The minimum available duration, in hours. The minimum required duration is 1,200
80	// hours per year. For example, the minimum daily schedule is 4 hours, the minimum
81	// weekly schedule is 24 hours, and the minimum monthly schedule is 100 hours.
82	MinSlotDurationInHours int32
83
84	// The token for the next set of results.
85	NextToken *string
86}
87
88// Contains the output of DescribeScheduledInstanceAvailability.
89type DescribeScheduledInstanceAvailabilityOutput struct {
90
91	// The token required to retrieve the next set of results. This value is null when
92	// there are no more results to return.
93	NextToken *string
94
95	// Information about the available Scheduled Instances.
96	ScheduledInstanceAvailabilitySet []types.ScheduledInstanceAvailability
97
98	// Metadata pertaining to the operation's result.
99	ResultMetadata middleware.Metadata
100}
101
102func addOperationDescribeScheduledInstanceAvailabilityMiddlewares(stack *middleware.Stack, options Options) (err error) {
103	err = stack.Serialize.Add(&awsEc2query_serializeOpDescribeScheduledInstanceAvailability{}, middleware.After)
104	if err != nil {
105		return err
106	}
107	err = stack.Deserialize.Add(&awsEc2query_deserializeOpDescribeScheduledInstanceAvailability{}, middleware.After)
108	if err != nil {
109		return err
110	}
111	if err = addSetLoggerMiddleware(stack, options); err != nil {
112		return err
113	}
114	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
115		return err
116	}
117	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
118		return err
119	}
120	if err = addResolveEndpointMiddleware(stack, options); err != nil {
121		return err
122	}
123	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
124		return err
125	}
126	if err = addRetryMiddlewares(stack, options); err != nil {
127		return err
128	}
129	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
130		return err
131	}
132	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
133		return err
134	}
135	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
136		return err
137	}
138	if err = addClientUserAgent(stack); err != nil {
139		return err
140	}
141	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
142		return err
143	}
144	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
145		return err
146	}
147	if err = addOpDescribeScheduledInstanceAvailabilityValidationMiddleware(stack); err != nil {
148		return err
149	}
150	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opDescribeScheduledInstanceAvailability(options.Region), middleware.Before); err != nil {
151		return err
152	}
153	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
154		return err
155	}
156	if err = addResponseErrorMiddleware(stack); err != nil {
157		return err
158	}
159	if err = addRequestResponseLogging(stack, options); err != nil {
160		return err
161	}
162	return nil
163}
164
165// DescribeScheduledInstanceAvailabilityAPIClient is a client that implements the
166// DescribeScheduledInstanceAvailability operation.
167type DescribeScheduledInstanceAvailabilityAPIClient interface {
168	DescribeScheduledInstanceAvailability(context.Context, *DescribeScheduledInstanceAvailabilityInput, ...func(*Options)) (*DescribeScheduledInstanceAvailabilityOutput, error)
169}
170
171var _ DescribeScheduledInstanceAvailabilityAPIClient = (*Client)(nil)
172
173// DescribeScheduledInstanceAvailabilityPaginatorOptions is the paginator options
174// for DescribeScheduledInstanceAvailability
175type DescribeScheduledInstanceAvailabilityPaginatorOptions struct {
176	// The maximum number of results to return in a single call. This value can be
177	// between 5 and 300. The default value is 300. To retrieve the remaining results,
178	// make another call with the returned NextToken value.
179	Limit int32
180
181	// Set to true if pagination should stop if the service returns a pagination token
182	// that matches the most recent token provided to the service.
183	StopOnDuplicateToken bool
184}
185
186// DescribeScheduledInstanceAvailabilityPaginator is a paginator for
187// DescribeScheduledInstanceAvailability
188type DescribeScheduledInstanceAvailabilityPaginator struct {
189	options   DescribeScheduledInstanceAvailabilityPaginatorOptions
190	client    DescribeScheduledInstanceAvailabilityAPIClient
191	params    *DescribeScheduledInstanceAvailabilityInput
192	nextToken *string
193	firstPage bool
194}
195
196// NewDescribeScheduledInstanceAvailabilityPaginator returns a new
197// DescribeScheduledInstanceAvailabilityPaginator
198func NewDescribeScheduledInstanceAvailabilityPaginator(client DescribeScheduledInstanceAvailabilityAPIClient, params *DescribeScheduledInstanceAvailabilityInput, optFns ...func(*DescribeScheduledInstanceAvailabilityPaginatorOptions)) *DescribeScheduledInstanceAvailabilityPaginator {
199	if params == nil {
200		params = &DescribeScheduledInstanceAvailabilityInput{}
201	}
202
203	options := DescribeScheduledInstanceAvailabilityPaginatorOptions{}
204	if params.MaxResults != 0 {
205		options.Limit = params.MaxResults
206	}
207
208	for _, fn := range optFns {
209		fn(&options)
210	}
211
212	return &DescribeScheduledInstanceAvailabilityPaginator{
213		options:   options,
214		client:    client,
215		params:    params,
216		firstPage: true,
217	}
218}
219
220// HasMorePages returns a boolean indicating whether more pages are available
221func (p *DescribeScheduledInstanceAvailabilityPaginator) HasMorePages() bool {
222	return p.firstPage || p.nextToken != nil
223}
224
225// NextPage retrieves the next DescribeScheduledInstanceAvailability page.
226func (p *DescribeScheduledInstanceAvailabilityPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*DescribeScheduledInstanceAvailabilityOutput, error) {
227	if !p.HasMorePages() {
228		return nil, fmt.Errorf("no more pages available")
229	}
230
231	params := *p.params
232	params.NextToken = p.nextToken
233
234	params.MaxResults = p.options.Limit
235
236	result, err := p.client.DescribeScheduledInstanceAvailability(ctx, &params, optFns...)
237	if err != nil {
238		return nil, err
239	}
240	p.firstPage = false
241
242	prevToken := p.nextToken
243	p.nextToken = result.NextToken
244
245	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
246		p.nextToken = nil
247	}
248
249	return result, nil
250}
251
252func newServiceMetadataMiddleware_opDescribeScheduledInstanceAvailability(region string) *awsmiddleware.RegisterServiceMetadata {
253	return &awsmiddleware.RegisterServiceMetadata{
254		Region:        region,
255		ServiceID:     ServiceID,
256		SigningName:   "ec2",
257		OperationName: "DescribeScheduledInstanceAvailability",
258	}
259}
260