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// Describes the status of the specified volumes. Volume status provides the result
16// of the checks performed on your volumes to determine events that can impair the
17// performance of your volumes. The performance of a volume can be affected if an
18// issue occurs on the volume's underlying host. If the volume's underlying host
19// experiences a power outage or system issue, after the system is restored, there
20// could be data inconsistencies on the volume. Volume events notify you if this
21// occurs. Volume actions notify you if any action needs to be taken in response to
22// the event. The DescribeVolumeStatus operation provides the following information
23// about the specified volumes: Status: Reflects the current status of the volume.
24// The possible values are ok, impaired , warning, or insufficient-data. If all
25// checks pass, the overall status of the volume is ok. If the check fails, the
26// overall status is impaired. If the status is insufficient-data, then the checks
27// might still be taking place on your volume at the time. We recommend that you
28// retry the request. For more information about volume status, see Monitoring the
29// status of your volumes
30// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/monitoring-volume-status.html)
31// in the Amazon Elastic Compute Cloud User Guide. Events: Reflect the cause of a
32// volume status and might require you to take action. For example, if your volume
33// returns an impaired status, then the volume event might be
34// potential-data-inconsistency. This means that your volume has been affected by
35// an issue with the underlying host, has all I/O operations disabled, and might
36// have inconsistent data. Actions: Reflect the actions you might have to take in
37// response to an event. For example, if the status of the volume is impaired and
38// the volume event shows potential-data-inconsistency, then the action shows
39// enable-volume-io. This means that you may want to enable the I/O operations for
40// the volume by calling the EnableVolumeIO action and then check the volume for
41// data consistency. Volume status is based on the volume status checks, and does
42// not reflect the volume state. Therefore, volume status does not indicate volumes
43// in the error state (for example, when a volume is incapable of accepting I/O.)
44func (c *Client) DescribeVolumeStatus(ctx context.Context, params *DescribeVolumeStatusInput, optFns ...func(*Options)) (*DescribeVolumeStatusOutput, error) {
45	if params == nil {
46		params = &DescribeVolumeStatusInput{}
47	}
48
49	result, metadata, err := c.invokeOperation(ctx, "DescribeVolumeStatus", params, optFns, addOperationDescribeVolumeStatusMiddlewares)
50	if err != nil {
51		return nil, err
52	}
53
54	out := result.(*DescribeVolumeStatusOutput)
55	out.ResultMetadata = metadata
56	return out, nil
57}
58
59type DescribeVolumeStatusInput struct {
60
61	// Checks whether you have the required permissions for the action, without
62	// actually making the request, and provides an error response. If you have the
63	// required permissions, the error response is DryRunOperation. Otherwise, it is
64	// UnauthorizedOperation.
65	DryRun bool
66
67	// The filters.
68	//
69	// * action.code - The action code for the event (for example,
70	// enable-volume-io).
71	//
72	// * action.description - A description of the action.
73	//
74	// *
75	// action.event-id - The event ID associated with the action.
76	//
77	// * availability-zone
78	// - The Availability Zone of the instance.
79	//
80	// * event.description - A description of
81	// the event.
82	//
83	// * event.event-id - The event ID.
84	//
85	// * event.event-type - The event
86	// type (for io-enabled: passed | failed; for io-performance:
87	// io-performance:degraded | io-performance:severely-degraded |
88	// io-performance:stalled).
89	//
90	// * event.not-after - The latest end time for the
91	// event.
92	//
93	// * event.not-before - The earliest start time for the event.
94	//
95	// *
96	// volume-status.details-name - The cause for volume-status.status (io-enabled |
97	// io-performance).
98	//
99	// * volume-status.details-status - The status of
100	// volume-status.details-name (for io-enabled: passed | failed; for io-performance:
101	// normal | degraded | severely-degraded | stalled).
102	//
103	// * volume-status.status - The
104	// status of the volume (ok | impaired | warning | insufficient-data).
105	Filters []types.Filter
106
107	// The maximum number of volume results returned by DescribeVolumeStatus in
108	// paginated output. When this parameter is used, the request only returns
109	// MaxResults results in a single page along with a NextToken response element. The
110	// remaining results of the initial request can be seen by sending another request
111	// with the returned NextToken value. This value can be between 5 and 1,000; if
112	// MaxResults is given a value larger than 1,000, only 1,000 results are returned.
113	// If this parameter is not used, then DescribeVolumeStatus returns all results.
114	// You cannot specify this parameter and the volume IDs parameter in the same
115	// request.
116	MaxResults int32
117
118	// The NextToken value to include in a future DescribeVolumeStatus request. When
119	// the results of the request exceed MaxResults, this value can be used to retrieve
120	// the next page of results. This value is null when there are no more results to
121	// return.
122	NextToken *string
123
124	// The IDs of the volumes. Default: Describes all your volumes.
125	VolumeIds []string
126}
127
128type DescribeVolumeStatusOutput struct {
129
130	// The token to use to retrieve the next page of results. This value is null when
131	// there are no more results to return.
132	NextToken *string
133
134	// Information about the status of the volumes.
135	VolumeStatuses []types.VolumeStatusItem
136
137	// Metadata pertaining to the operation's result.
138	ResultMetadata middleware.Metadata
139}
140
141func addOperationDescribeVolumeStatusMiddlewares(stack *middleware.Stack, options Options) (err error) {
142	err = stack.Serialize.Add(&awsEc2query_serializeOpDescribeVolumeStatus{}, middleware.After)
143	if err != nil {
144		return err
145	}
146	err = stack.Deserialize.Add(&awsEc2query_deserializeOpDescribeVolumeStatus{}, middleware.After)
147	if err != nil {
148		return err
149	}
150	if err = addSetLoggerMiddleware(stack, options); err != nil {
151		return err
152	}
153	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
154		return err
155	}
156	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
157		return err
158	}
159	if err = addResolveEndpointMiddleware(stack, options); err != nil {
160		return err
161	}
162	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
163		return err
164	}
165	if err = addRetryMiddlewares(stack, options); err != nil {
166		return err
167	}
168	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
169		return err
170	}
171	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
172		return err
173	}
174	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
175		return err
176	}
177	if err = addClientUserAgent(stack); err != nil {
178		return err
179	}
180	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
181		return err
182	}
183	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
184		return err
185	}
186	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opDescribeVolumeStatus(options.Region), middleware.Before); err != nil {
187		return err
188	}
189	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
190		return err
191	}
192	if err = addResponseErrorMiddleware(stack); err != nil {
193		return err
194	}
195	if err = addRequestResponseLogging(stack, options); err != nil {
196		return err
197	}
198	return nil
199}
200
201// DescribeVolumeStatusAPIClient is a client that implements the
202// DescribeVolumeStatus operation.
203type DescribeVolumeStatusAPIClient interface {
204	DescribeVolumeStatus(context.Context, *DescribeVolumeStatusInput, ...func(*Options)) (*DescribeVolumeStatusOutput, error)
205}
206
207var _ DescribeVolumeStatusAPIClient = (*Client)(nil)
208
209// DescribeVolumeStatusPaginatorOptions is the paginator options for
210// DescribeVolumeStatus
211type DescribeVolumeStatusPaginatorOptions struct {
212	// The maximum number of volume results returned by DescribeVolumeStatus in
213	// paginated output. When this parameter is used, the request only returns
214	// MaxResults results in a single page along with a NextToken response element. The
215	// remaining results of the initial request can be seen by sending another request
216	// with the returned NextToken value. This value can be between 5 and 1,000; if
217	// MaxResults is given a value larger than 1,000, only 1,000 results are returned.
218	// If this parameter is not used, then DescribeVolumeStatus returns all results.
219	// You cannot specify this parameter and the volume IDs parameter in the same
220	// request.
221	Limit int32
222
223	// Set to true if pagination should stop if the service returns a pagination token
224	// that matches the most recent token provided to the service.
225	StopOnDuplicateToken bool
226}
227
228// DescribeVolumeStatusPaginator is a paginator for DescribeVolumeStatus
229type DescribeVolumeStatusPaginator struct {
230	options   DescribeVolumeStatusPaginatorOptions
231	client    DescribeVolumeStatusAPIClient
232	params    *DescribeVolumeStatusInput
233	nextToken *string
234	firstPage bool
235}
236
237// NewDescribeVolumeStatusPaginator returns a new DescribeVolumeStatusPaginator
238func NewDescribeVolumeStatusPaginator(client DescribeVolumeStatusAPIClient, params *DescribeVolumeStatusInput, optFns ...func(*DescribeVolumeStatusPaginatorOptions)) *DescribeVolumeStatusPaginator {
239	options := DescribeVolumeStatusPaginatorOptions{}
240	if params.MaxResults != 0 {
241		options.Limit = params.MaxResults
242	}
243
244	for _, fn := range optFns {
245		fn(&options)
246	}
247
248	if params == nil {
249		params = &DescribeVolumeStatusInput{}
250	}
251
252	return &DescribeVolumeStatusPaginator{
253		options:   options,
254		client:    client,
255		params:    params,
256		firstPage: true,
257	}
258}
259
260// HasMorePages returns a boolean indicating whether more pages are available
261func (p *DescribeVolumeStatusPaginator) HasMorePages() bool {
262	return p.firstPage || p.nextToken != nil
263}
264
265// NextPage retrieves the next DescribeVolumeStatus page.
266func (p *DescribeVolumeStatusPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*DescribeVolumeStatusOutput, error) {
267	if !p.HasMorePages() {
268		return nil, fmt.Errorf("no more pages available")
269	}
270
271	params := *p.params
272	params.NextToken = p.nextToken
273
274	params.MaxResults = p.options.Limit
275
276	result, err := p.client.DescribeVolumeStatus(ctx, &params, optFns...)
277	if err != nil {
278		return nil, err
279	}
280	p.firstPage = false
281
282	prevToken := p.nextToken
283	p.nextToken = result.NextToken
284
285	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
286		p.nextToken = nil
287	}
288
289	return result, nil
290}
291
292func newServiceMetadataMiddleware_opDescribeVolumeStatus(region string) *awsmiddleware.RegisterServiceMetadata {
293	return &awsmiddleware.RegisterServiceMetadata{
294		Region:        region,
295		ServiceID:     ServiceID,
296		SigningName:   "ec2",
297		OperationName: "DescribeVolumeStatus",
298	}
299}
300