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 specified Scheduled Instances or all your Scheduled Instances. 16func (c *Client) DescribeScheduledInstances(ctx context.Context, params *DescribeScheduledInstancesInput, optFns ...func(*Options)) (*DescribeScheduledInstancesOutput, error) { 17 if params == nil { 18 params = &DescribeScheduledInstancesInput{} 19 } 20 21 result, metadata, err := c.invokeOperation(ctx, "DescribeScheduledInstances", params, optFns, addOperationDescribeScheduledInstancesMiddlewares) 22 if err != nil { 23 return nil, err 24 } 25 26 out := result.(*DescribeScheduledInstancesOutput) 27 out.ResultMetadata = metadata 28 return out, nil 29} 30 31// Contains the parameters for DescribeScheduledInstances. 32type DescribeScheduledInstancesInput struct { 33 34 // Checks whether you have the required permissions for the action, without 35 // actually making the request, and provides an error response. If you have the 36 // required permissions, the error response is DryRunOperation. Otherwise, it is 37 // UnauthorizedOperation. 38 DryRun bool 39 40 // The filters. 41 // 42 // * availability-zone - The Availability Zone (for example, 43 // us-west-2a). 44 // 45 // * instance-type - The instance type (for example, c4.large). 46 // 47 // * 48 // network-platform - The network platform (EC2-Classic or EC2-VPC). 49 // 50 // * platform - 51 // The platform (Linux/UNIX or Windows). 52 Filters []types.Filter 53 54 // The maximum number of results to return in a single call. This value can be 55 // between 5 and 300. The default value is 100. To retrieve the remaining results, 56 // make another call with the returned NextToken value. 57 MaxResults int32 58 59 // The token for the next set of results. 60 NextToken *string 61 62 // The Scheduled Instance IDs. 63 ScheduledInstanceIds []string 64 65 // The time period for the first schedule to start. 66 SlotStartTimeRange *types.SlotStartTimeRangeRequest 67} 68 69// Contains the output of DescribeScheduledInstances. 70type DescribeScheduledInstancesOutput struct { 71 72 // The token required to retrieve the next set of results. This value is null when 73 // there are no more results to return. 74 NextToken *string 75 76 // Information about the Scheduled Instances. 77 ScheduledInstanceSet []types.ScheduledInstance 78 79 // Metadata pertaining to the operation's result. 80 ResultMetadata middleware.Metadata 81} 82 83func addOperationDescribeScheduledInstancesMiddlewares(stack *middleware.Stack, options Options) (err error) { 84 err = stack.Serialize.Add(&awsEc2query_serializeOpDescribeScheduledInstances{}, middleware.After) 85 if err != nil { 86 return err 87 } 88 err = stack.Deserialize.Add(&awsEc2query_deserializeOpDescribeScheduledInstances{}, middleware.After) 89 if err != nil { 90 return err 91 } 92 if err = addSetLoggerMiddleware(stack, options); err != nil { 93 return err 94 } 95 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 96 return err 97 } 98 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 99 return err 100 } 101 if err = addResolveEndpointMiddleware(stack, options); err != nil { 102 return err 103 } 104 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 105 return err 106 } 107 if err = addRetryMiddlewares(stack, options); err != nil { 108 return err 109 } 110 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 111 return err 112 } 113 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 114 return err 115 } 116 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 117 return err 118 } 119 if err = addClientUserAgent(stack); err != nil { 120 return err 121 } 122 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 123 return err 124 } 125 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 126 return err 127 } 128 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opDescribeScheduledInstances(options.Region), middleware.Before); err != nil { 129 return err 130 } 131 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 132 return err 133 } 134 if err = addResponseErrorMiddleware(stack); err != nil { 135 return err 136 } 137 if err = addRequestResponseLogging(stack, options); err != nil { 138 return err 139 } 140 return nil 141} 142 143// DescribeScheduledInstancesAPIClient is a client that implements the 144// DescribeScheduledInstances operation. 145type DescribeScheduledInstancesAPIClient interface { 146 DescribeScheduledInstances(context.Context, *DescribeScheduledInstancesInput, ...func(*Options)) (*DescribeScheduledInstancesOutput, error) 147} 148 149var _ DescribeScheduledInstancesAPIClient = (*Client)(nil) 150 151// DescribeScheduledInstancesPaginatorOptions is the paginator options for 152// DescribeScheduledInstances 153type DescribeScheduledInstancesPaginatorOptions struct { 154 // The maximum number of results to return in a single call. This value can be 155 // between 5 and 300. The default value is 100. To retrieve the remaining results, 156 // make another call with the returned NextToken value. 157 Limit int32 158 159 // Set to true if pagination should stop if the service returns a pagination token 160 // that matches the most recent token provided to the service. 161 StopOnDuplicateToken bool 162} 163 164// DescribeScheduledInstancesPaginator is a paginator for 165// DescribeScheduledInstances 166type DescribeScheduledInstancesPaginator struct { 167 options DescribeScheduledInstancesPaginatorOptions 168 client DescribeScheduledInstancesAPIClient 169 params *DescribeScheduledInstancesInput 170 nextToken *string 171 firstPage bool 172} 173 174// NewDescribeScheduledInstancesPaginator returns a new 175// DescribeScheduledInstancesPaginator 176func NewDescribeScheduledInstancesPaginator(client DescribeScheduledInstancesAPIClient, params *DescribeScheduledInstancesInput, optFns ...func(*DescribeScheduledInstancesPaginatorOptions)) *DescribeScheduledInstancesPaginator { 177 options := DescribeScheduledInstancesPaginatorOptions{} 178 if params.MaxResults != 0 { 179 options.Limit = params.MaxResults 180 } 181 182 for _, fn := range optFns { 183 fn(&options) 184 } 185 186 if params == nil { 187 params = &DescribeScheduledInstancesInput{} 188 } 189 190 return &DescribeScheduledInstancesPaginator{ 191 options: options, 192 client: client, 193 params: params, 194 firstPage: true, 195 } 196} 197 198// HasMorePages returns a boolean indicating whether more pages are available 199func (p *DescribeScheduledInstancesPaginator) HasMorePages() bool { 200 return p.firstPage || p.nextToken != nil 201} 202 203// NextPage retrieves the next DescribeScheduledInstances page. 204func (p *DescribeScheduledInstancesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*DescribeScheduledInstancesOutput, error) { 205 if !p.HasMorePages() { 206 return nil, fmt.Errorf("no more pages available") 207 } 208 209 params := *p.params 210 params.NextToken = p.nextToken 211 212 params.MaxResults = p.options.Limit 213 214 result, err := p.client.DescribeScheduledInstances(ctx, ¶ms, optFns...) 215 if err != nil { 216 return nil, err 217 } 218 p.firstPage = false 219 220 prevToken := p.nextToken 221 p.nextToken = result.NextToken 222 223 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 224 p.nextToken = nil 225 } 226 227 return result, nil 228} 229 230func newServiceMetadataMiddleware_opDescribeScheduledInstances(region string) *awsmiddleware.RegisterServiceMetadata { 231 return &awsmiddleware.RegisterServiceMetadata{ 232 Region: region, 233 ServiceID: ServiceID, 234 SigningName: "ec2", 235 OperationName: "DescribeScheduledInstances", 236 } 237} 238