Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alibabacloud: use NextToken and MaxResults to list instance types #25387

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 21 additions & 4 deletions pkg/alibabacloud/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,30 @@ func (c *Client) GetVPCs(ctx context.Context) (ipamTypes.VirtualNetworkMap, erro

// GetInstanceTypes returns all the known ECS instance types in the configured region
func (c *Client) GetInstanceTypes(ctx context.Context) ([]ecs.InstanceType, error) {
var result []ecs.InstanceType
req := ecs.CreateDescribeInstanceTypesRequest()
resp, err := c.ecsClient.DescribeInstanceTypes(req)
if err != nil {
return nil, err
// When there are many instance types, some instance limits can not be queried,
// so use NextToken and MaxResults for paging query.
// MaxResults is the number of entries on each page, the maximum value of this parameter is 100.
// Ref: https://www.alibabacloud.com/help/en/elastic-compute-service/latest/describeinstancetypes
req.MaxResults = requests.NewInteger(100)
haozhangami marked this conversation as resolved.
Show resolved Hide resolved
for {
resp, err := c.ecsClient.DescribeInstanceTypes(req)
if err != nil {
return nil, err
}

for _, v := range resp.InstanceTypes.InstanceType {
result = append(result, v)
}

if resp.NextToken == "" {
break
}
req.NextToken = resp.NextToken
}

return resp.InstanceTypes.InstanceType, nil
return result, nil
}

// GetSecurityGroups return all sg
Expand Down