Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Allow paging of instance status results. Closes #447.
Browse files Browse the repository at this point in the history
The results of the get_all_instance_status method (DescribeInstanceStatus)
can be paged on the server side.  Previously boto did not provide any way
to access the next_token value or to pass it to subsequent calls to get
the next page of results.  This commit fixes that problem.

Requested-by: Anonymous
Signed-off-by: Mitch Garnaat <mitch@garnaat.com>
  • Loading branch information
garnaat committed Dec 23, 2011
1 parent b27a1ea commit 44aa8ce
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
31 changes: 23 additions & 8 deletions boto/ec2/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,29 +463,44 @@ def get_all_instances(self, instance_ids=None, filters=None):
self.build_filter_params(params, filters)
return self.get_list('DescribeInstances', params,
[('item', Reservation)], verb='POST')
def get_all_instance_status(self, instance_ids=None, filters=None):

def get_all_instance_status(self, instance_ids=None,
max_results=None, next_token=None,
filters=None):
"""
Retrieve all the instances in your account scheduled for maintenance.
:type instance_ids: list
:param instance_ids: A list of strings of instance IDs
:type max_results: int
:param max_results: The maximum number of paginated instance
items per response.
:type next_token: str
:param next_token: A string specifying the next paginated set
of results to return.
:type filters: dict
:param filters: Optional filters that can be used to limit
the results returned. Filters are provided
in the form of a dictionary consisting of
filter names as the key and filter values
as the value. The set of allowable filter
names/values is dependent on the request
being performed. Check the EC2 API guide
for details.
the results returned. Filters are provided
in the form of a dictionary consisting of
filter names as the key and filter values
as the value. The set of allowable filter
names/values is dependent on the request
being performed. Check the EC2 API guide
for details.
:rtype: list
:return: A list of instances that have maintenance scheduled.
"""
params = {}
if instance_ids:
self.build_list_params(params, instance_ids, 'InstanceId')
if max_results:
params['MaxResults'] = max_results
if next_token:
params['NextToken'] = next_token
if filters:
self.build_filter_params(params, filters)
return self.get_object('DescribeInstanceStatus', params,
Expand Down
16 changes: 15 additions & 1 deletion boto/ec2/instancestatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,22 @@ def endElement(self, name, value, connection):
setattr(self, name, value)

class InstanceStatusSet(list):
"""
A list object that contains the results of a call to
DescribeInstanceStatus request. Each element of the
list will be an InstanceStatus object.
:ivar next_token: If the response was truncated by
the EC2 service, the next_token attribute of the
object will contain the string that needs to be
passed in to the next request to retrieve the next
set of results.
"""

def __init__(self, connection=None):
self.connection = connection
list.__init__(self)
self.connection = connection
self.next_token = None

def startElement(self, name, attrs, connection):
if name == 'item':
Expand All @@ -129,5 +141,7 @@ def startElement(self, name, attrs, connection):
return None

def endElement(self, name, value, connection):
if name == 'NextToken':
self.next_token = value
setattr(self, name, value)

0 comments on commit 44aa8ce

Please sign in to comment.