1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package elasticinference
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/elasticinference/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Describes information over a provided set of accelerators belonging to an
16// account.
17func (c *Client) DescribeAccelerators(ctx context.Context, params *DescribeAcceleratorsInput, optFns ...func(*Options)) (*DescribeAcceleratorsOutput, error) {
18	if params == nil {
19		params = &DescribeAcceleratorsInput{}
20	}
21
22	result, metadata, err := c.invokeOperation(ctx, "DescribeAccelerators", params, optFns, c.addOperationDescribeAcceleratorsMiddlewares)
23	if err != nil {
24		return nil, err
25	}
26
27	out := result.(*DescribeAcceleratorsOutput)
28	out.ResultMetadata = metadata
29	return out, nil
30}
31
32type DescribeAcceleratorsInput struct {
33
34	// The IDs of the accelerators to describe.
35	AcceleratorIds []string
36
37	// One or more filters. Filter names and values are case-sensitive. Valid filter
38	// names are: accelerator-types: can provide a list of accelerator type names to
39	// filter for. instance-id: can provide a list of EC2 instance ids to filter for.
40	Filters []types.Filter
41
42	// The total number of items to return in the command's output. If the total number
43	// of items available is more than the value specified, a NextToken is provided in
44	// the command's output. To resume pagination, provide the NextToken value in the
45	// starting-token argument of a subsequent command. Do not use the NextToken
46	// response element directly outside of the AWS CLI.
47	MaxResults int32
48
49	// A token to specify where to start paginating. This is the NextToken from a
50	// previously truncated response.
51	NextToken *string
52
53	noSmithyDocumentSerde
54}
55
56type DescribeAcceleratorsOutput struct {
57
58	// The details of the Elastic Inference Accelerators.
59	AcceleratorSet []types.ElasticInferenceAccelerator
60
61	// A token to specify where to start paginating. This is the NextToken from a
62	// previously truncated response.
63	NextToken *string
64
65	// Metadata pertaining to the operation's result.
66	ResultMetadata middleware.Metadata
67
68	noSmithyDocumentSerde
69}
70
71func (c *Client) addOperationDescribeAcceleratorsMiddlewares(stack *middleware.Stack, options Options) (err error) {
72	err = stack.Serialize.Add(&awsRestjson1_serializeOpDescribeAccelerators{}, middleware.After)
73	if err != nil {
74		return err
75	}
76	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpDescribeAccelerators{}, middleware.After)
77	if err != nil {
78		return err
79	}
80	if err = addSetLoggerMiddleware(stack, options); err != nil {
81		return err
82	}
83	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
84		return err
85	}
86	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
87		return err
88	}
89	if err = addResolveEndpointMiddleware(stack, options); err != nil {
90		return err
91	}
92	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
93		return err
94	}
95	if err = addRetryMiddlewares(stack, options); err != nil {
96		return err
97	}
98	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
99		return err
100	}
101	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
102		return err
103	}
104	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
105		return err
106	}
107	if err = addClientUserAgent(stack); err != nil {
108		return err
109	}
110	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
111		return err
112	}
113	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
114		return err
115	}
116	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opDescribeAccelerators(options.Region), middleware.Before); err != nil {
117		return err
118	}
119	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
120		return err
121	}
122	if err = addResponseErrorMiddleware(stack); err != nil {
123		return err
124	}
125	if err = addRequestResponseLogging(stack, options); err != nil {
126		return err
127	}
128	return nil
129}
130
131// DescribeAcceleratorsAPIClient is a client that implements the
132// DescribeAccelerators operation.
133type DescribeAcceleratorsAPIClient interface {
134	DescribeAccelerators(context.Context, *DescribeAcceleratorsInput, ...func(*Options)) (*DescribeAcceleratorsOutput, error)
135}
136
137var _ DescribeAcceleratorsAPIClient = (*Client)(nil)
138
139// DescribeAcceleratorsPaginatorOptions is the paginator options for
140// DescribeAccelerators
141type DescribeAcceleratorsPaginatorOptions struct {
142	// The total number of items to return in the command's output. If the total number
143	// of items available is more than the value specified, a NextToken is provided in
144	// the command's output. To resume pagination, provide the NextToken value in the
145	// starting-token argument of a subsequent command. Do not use the NextToken
146	// response element directly outside of the AWS CLI.
147	Limit int32
148
149	// Set to true if pagination should stop if the service returns a pagination token
150	// that matches the most recent token provided to the service.
151	StopOnDuplicateToken bool
152}
153
154// DescribeAcceleratorsPaginator is a paginator for DescribeAccelerators
155type DescribeAcceleratorsPaginator struct {
156	options   DescribeAcceleratorsPaginatorOptions
157	client    DescribeAcceleratorsAPIClient
158	params    *DescribeAcceleratorsInput
159	nextToken *string
160	firstPage bool
161}
162
163// NewDescribeAcceleratorsPaginator returns a new DescribeAcceleratorsPaginator
164func NewDescribeAcceleratorsPaginator(client DescribeAcceleratorsAPIClient, params *DescribeAcceleratorsInput, optFns ...func(*DescribeAcceleratorsPaginatorOptions)) *DescribeAcceleratorsPaginator {
165	if params == nil {
166		params = &DescribeAcceleratorsInput{}
167	}
168
169	options := DescribeAcceleratorsPaginatorOptions{}
170	if params.MaxResults != 0 {
171		options.Limit = params.MaxResults
172	}
173
174	for _, fn := range optFns {
175		fn(&options)
176	}
177
178	return &DescribeAcceleratorsPaginator{
179		options:   options,
180		client:    client,
181		params:    params,
182		firstPage: true,
183	}
184}
185
186// HasMorePages returns a boolean indicating whether more pages are available
187func (p *DescribeAcceleratorsPaginator) HasMorePages() bool {
188	return p.firstPage || p.nextToken != nil
189}
190
191// NextPage retrieves the next DescribeAccelerators page.
192func (p *DescribeAcceleratorsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*DescribeAcceleratorsOutput, error) {
193	if !p.HasMorePages() {
194		return nil, fmt.Errorf("no more pages available")
195	}
196
197	params := *p.params
198	params.NextToken = p.nextToken
199
200	params.MaxResults = p.options.Limit
201
202	result, err := p.client.DescribeAccelerators(ctx, &params, optFns...)
203	if err != nil {
204		return nil, err
205	}
206	p.firstPage = false
207
208	prevToken := p.nextToken
209	p.nextToken = result.NextToken
210
211	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
212		p.nextToken = nil
213	}
214
215	return result, nil
216}
217
218func newServiceMetadataMiddleware_opDescribeAccelerators(region string) *awsmiddleware.RegisterServiceMetadata {
219	return &awsmiddleware.RegisterServiceMetadata{
220		Region:        region,
221		ServiceID:     ServiceID,
222		SigningName:   "elastic-inference",
223		OperationName: "DescribeAccelerators",
224	}
225}
226