Merge pull request #317 from spulec/ec2-security-group-tag-filtering
Add support to tag filtering to Security Groups
This commit is contained in:
commit
c0e80de4d3
@ -92,7 +92,9 @@ from .utils import (
|
|||||||
filter_reservations,
|
filter_reservations,
|
||||||
random_network_acl_id,
|
random_network_acl_id,
|
||||||
random_network_acl_subnet_association_id,
|
random_network_acl_subnet_association_id,
|
||||||
random_vpn_gateway_id)
|
random_vpn_gateway_id,
|
||||||
|
is_tag_filter,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def validate_resource_ids(resource_ids):
|
def validate_resource_ids(resource_ids):
|
||||||
@ -1113,6 +1115,9 @@ class SecurityGroup(TaggedEC2Resource):
|
|||||||
for ingress in self.ingress_rules:
|
for ingress in self.ingress_rules:
|
||||||
if getattr(ingress, ingress_attr) in filter_value:
|
if getattr(ingress, ingress_attr) in filter_value:
|
||||||
return True
|
return True
|
||||||
|
elif is_tag_filter(key):
|
||||||
|
tag_value = self.get_filter_value(key)
|
||||||
|
return tag_value in filter_value
|
||||||
else:
|
else:
|
||||||
attr_name = to_attr(key)
|
attr_name = to_attr(key)
|
||||||
return getattr(self, attr_name) in filter_value
|
return getattr(self, attr_name) in filter_value
|
||||||
|
@ -248,3 +248,13 @@ def test_security_group_tagging():
|
|||||||
group = conn.get_all_security_groups("test-sg")[0]
|
group = conn.get_all_security_groups("test-sg")[0]
|
||||||
group.tags.should.have.length_of(1)
|
group.tags.should.have.length_of(1)
|
||||||
group.tags["Test"].should.equal("Tag")
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user