Skip to content

Commit

Permalink
Merge pull request #1813 from mbarrien/pull-request-snapshots
Browse files Browse the repository at this point in the history
Add support for filtering by multiple account IDs to EC2 get_all_snapshots. Fixes #1813, #1554.
  • Loading branch information
danielgtaylor committed Oct 28, 2013
2 parents 46d3ffe + 52bd753 commit 9433fe2
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 6 deletions.
13 changes: 7 additions & 6 deletions boto/ec2/connection.py
Expand Up @@ -2205,17 +2205,17 @@ def get_all_snapshots(self, snapshot_ids=None,
present, only the Snapshots associated with
these snapshot ids will be returned.
:type owner: str
:param owner: If present, only the snapshots owned by the specified user
:type owner: str or list
:param owner: If present, only the snapshots owned by the specified user(s)
will be returned. Valid values are:
* self
* amazon
* AWS Account ID
:type restorable_by: str
:type restorable_by: str or list
:param restorable_by: If present, only the snapshots that are restorable
by the specified account id will be returned.
by the specified account id(s) will be returned.
:type filters: dict
:param filters: Optional filters that can be used to limit
Expand All @@ -2236,10 +2236,11 @@ def get_all_snapshots(self, snapshot_ids=None,
params = {}
if snapshot_ids:
self.build_list_params(params, snapshot_ids, 'SnapshotId')

if owner:
params['Owner'] = owner
self.build_list_params(params, owner, 'Owner')
if restorable_by:
params['RestorableBy'] = restorable_by
self.build_list_params(params, restorable_by, 'RestorableBy')
if filters:
self.build_filter_params(params, filters)
if dry_run:
Expand Down
59 changes: 59 additions & 0 deletions tests/unit/ec2/test_snapshot.py
@@ -0,0 +1,59 @@
from tests.unit import AWSMockServiceTestCase

from boto.ec2.connection import EC2Connection
from boto.ec2.snapshot import Snapshot


class TestDescribeSnapshots(AWSMockServiceTestCase):

connection_class = EC2Connection

def default_body(self):
return """
<DescribeSnapshotsResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-01/">
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
<snapshotSet>
<item>
<snapshotId>snap-1a2b3c4d</snapshotId>
<volumeId>vol-1a2b3c4d</volumeId>
<status>pending</status>
<startTime>YYYY-MM-DDTHH:MM:SS.SSSZ</startTime>
<progress>30%</progress>
<ownerId>111122223333</ownerId>
<volumeSize>15</volumeSize>
<description>Daily Backup</description>
<tagSet>
<item>
<key>Purpose</key>
<value>demo_db_14_backup</value>
</item>
</tagSet>
</item>
</snapshotSet>
</DescribeSnapshotsResponse>
"""

def test_cancel_spot_instance_requests(self):
self.set_http_response(status_code=200)
response = self.service_connection.get_all_snapshots(['snap-1a2b3c4d', 'snap-9f8e7d6c'],
owner=['self', '111122223333'],
restorable_by='999988887777',
filters={'status': 'pending',
'tag-value': '*db_*'})
self.assert_request_parameters({
'Action': 'DescribeSnapshots',
'SnapshotId.1': 'snap-1a2b3c4d',
'SnapshotId.2': 'snap-9f8e7d6c',
'Owner.1': 'self',
'Owner.2': '111122223333',
'RestorableBy.1': '999988887777',
'Filter.1.Name': 'status',
'Filter.1.Value.1': 'pending',
'Filter.2.Name': 'tag-value',
'Filter.2.Value.1': '*db_*'},
ignore_params_values=['AWSAccessKeyId', 'SignatureMethod',
'SignatureVersion', 'Timestamp',
'Version'])
self.assertEqual(len(response), 1)
self.assertIsInstance(response[0], Snapshot)
self.assertEqual(response[0].id, 'snap-1a2b3c4d')

0 comments on commit 9433fe2

Please sign in to comment.