Merge pull request #317 from spulec/ec2-security-group-tag-filtering

Add support to tag filtering to Security Groups
This commit is contained in:
Steve Pulec 2015-02-24 18:00:51 -05:00
commit c0e80de4d3
2 changed files with 16 additions and 1 deletions

View File

@ -92,7 +92,9 @@ from .utils import (
filter_reservations,
random_network_acl_id,
random_network_acl_subnet_association_id,
random_vpn_gateway_id)
random_vpn_gateway_id,
is_tag_filter,
)
def validate_resource_ids(resource_ids):
@ -1113,6 +1115,9 @@ class SecurityGroup(TaggedEC2Resource):
for ingress in self.ingress_rules:
if getattr(ingress, ingress_attr) in filter_value:
return True
elif is_tag_filter(key):
tag_value = self.get_filter_value(key)
return tag_value in filter_value
else:
attr_name = to_attr(key)
return getattr(self, attr_name) in filter_value

View File

@ -248,3 +248,13 @@ def test_security_group_tagging():
group = conn.get_all_security_groups("test-sg")[0]
group.tags.should.have.length_of(1)
group.tags["Test"].should.equal("Tag")
@mock_ec2
def test_security_group_tag_filtering():
conn = boto.connect_ec2()
sg = conn.create_security_group("test-sg", "Test SG")
sg.add_tag("test-tag", "test-value")
groups = conn.get_all_security_groups(filters={"tag:test-tag": "test-value"})
groups.should.have.length_of(1)