-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1971 from JordonPhillips/ec2-pagination
Default ec2 page size to 1000
- Loading branch information
Showing
6 changed files
with
124 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"type": "bugfix", | ||
"category": "ec2", | ||
"description": "Sets MaxResults to default value of 1000." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). You | ||
# may not use this file except in compliance with the License. A copy of | ||
# the License is located at | ||
# | ||
# http://aws.amazon.com/apache2.0/ | ||
# | ||
# or in the "license" file accompanying this file. This file is | ||
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF | ||
# ANY KIND, either express or implied. See the License for the specific | ||
# language governing permissions and limitations under the License. | ||
DEFAULT_MAX_RESULTS = 1000 | ||
|
||
|
||
def set_max_results_default(parsed_args, parsed_globals, **kwargs): | ||
""" | ||
In order to have EC2 return results you can paginate you need to inject | ||
the `MaxItems` parameter. In the CLI we should be setting this by default | ||
to avoid users having to wait exceedingly long times for the full results. | ||
""" | ||
|
||
# The check for page size validates that the operation is a pagination | ||
# operation. | ||
if parsed_globals.paginate and hasattr(parsed_args, 'page_size') and \ | ||
parsed_args.page_size is None and parsed_args.max_results is None: | ||
parsed_args.page_size = DEFAULT_MAX_RESULTS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). You | ||
# may not use this file except in compliance with the License. A copy of | ||
# the License is located at | ||
# | ||
# http://aws.amazon.com/apache2.0/ | ||
# | ||
# or in the "license" file accompanying this file. This file is | ||
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF | ||
# ANY KIND, either express or implied. See the License for the specific | ||
# language governing permissions and limitations under the License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). You | ||
# may not use this file except in compliance with the License. A copy of | ||
# the License is located at | ||
# | ||
# http://aws.amazon.com/apache2.0/ | ||
# | ||
# or in the "license" file accompanying this file. This file is | ||
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF | ||
# ANY KIND, either express or implied. See the License for the specific | ||
# language governing permissions and limitations under the License. | ||
import mock | ||
|
||
from awscli.customizations.ec2.paginate import set_max_results_default | ||
from awscli.customizations.ec2.paginate import DEFAULT_MAX_RESULTS | ||
from awscli.testutils import unittest | ||
|
||
|
||
class TestSetMaxResult(unittest.TestCase): | ||
def setUp(self): | ||
self.parsed_args = mock.Mock() | ||
self.parsed_globals = mock.Mock() | ||
|
||
self.parsed_args.max_results = None | ||
self.parsed_args.page_size = None | ||
self.parsed_globals.paginate = True | ||
|
||
def test_default_is_set(self): | ||
set_max_results_default(self.parsed_args, self.parsed_globals) | ||
self.assertEqual(self.parsed_args.page_size, DEFAULT_MAX_RESULTS) | ||
|
||
def test_page_size_isnt_overwritten(self): | ||
page_size = DEFAULT_MAX_RESULTS - 10 | ||
self.parsed_args.page_size = page_size | ||
set_max_results_default(self.parsed_args, self.parsed_globals) | ||
self.assertEqual(self.parsed_args.page_size, page_size) | ||
|
||
def test_max_results_isnt_overwritten(self): | ||
max_results = DEFAULT_MAX_RESULTS - 10 | ||
self.parsed_args.max_results = max_results | ||
set_max_results_default(self.parsed_args, self.parsed_globals) | ||
self.assertEqual(self.parsed_args.max_results, max_results) | ||
self.assertEqual(self.parsed_args.page_size, None) | ||
|
||
def test_no_paginate_disables_default(self): | ||
self.parsed_globals.paginate = False | ||
set_max_results_default(self.parsed_args, self.parsed_globals) | ||
self.assertEqual(self.parsed_args.page_size, None) | ||
|
||
def test_only_applies_if_page_size_is_present(self): | ||
del self.parsed_args.page_size | ||
set_max_results_default(self.parsed_args, self.parsed_globals) | ||
self.assertFalse(hasattr(self.parsed_args, 'page_size')) |