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

LIBCLOUD-571 subnet-filters for ec2 driver #306

Closed
wants to merge 1 commit into from
Closed
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
21 changes: 20 additions & 1 deletion libcloud/compute/drivers/ec2.py
Expand Up @@ -2459,15 +2459,34 @@ def ex_delete_network(self, vpc):

return element == 'true'

def ex_list_subnets(self):
def ex_list_subnets(self, subnet_ids=None, filters=None):
"""
Return a list of :class:`EC2NetworkSubnet` objects for the
current region.

:param subnet_ids: Return only subnets matching the provided
subnet IDs. If not specified, a list of all
the subnets in the corresponding region
is returned.
:type subnet_ids: ``list``

:param filters: The filters so that the response includes
information for only certain subnets.
:type filters: ``dict``

:rtype: ``list`` of :class:`EC2NetworkSubnet`
"""
params = {'Action': 'DescribeSubnets'}

if subnet_ids:
for subnet_idx, subnet_id in enumerate(subnet_ids):
subnet_idx += 1 # We want 1-based indexes
subnet_key = 'SubnetId.%s' % subnet_idx
params[subnet_key] = subnet_id

if filters:
params.update(self._build_filters(filters))

return self._to_subnets(
self.connection.request(self.path, params=params).object
)
Expand Down