Merge pull request #592 from aiell0/hotifx/add-additional-instance-filters-issue-581

Added ec2 describe-instances filter: 'architecture'
This commit is contained in:
Steve Pulec 2016-04-23 19:40:15 -04:00
commit 224e92ba17
2 changed files with 16 additions and 6 deletions

View File

@ -361,15 +361,15 @@ filter_dict_attribute_mapping = {
'group-id': 'security_groups',
'instance.group-id': 'security_groups',
'instance-type': 'instance_type',
'private-ip-address' : 'private_ip',
'ip-address' : 'public_ip',
'availability-zone' :'placement'
'private-ip-address': 'private_ip',
'ip-address': 'public_ip',
'availability-zone': 'placement',
'architecture': 'architecture'
}
def passes_filter_dict(instance, filter_dict):
for filter_name, filter_values in filter_dict.items():
if filter_name in filter_dict_attribute_mapping:
instance_attr = filter_dict_attribute_mapping[filter_name]
instance_value = get_object_value(instance, instance_attr)
@ -381,7 +381,7 @@ def passes_filter_dict(instance, filter_dict):
return False
else:
raise NotImplementedError(
"Filter dicts have not been implemented in Moto for '%s' yet. Feel free to open an issue at https://github.com/spulec/moto/issues",
"Filter dicts have not been implemented in Moto for '%s' yet. Feel free to open an issue at https://github.com/spulec/moto/issues" %
filter_name)
return True

View File

@ -278,6 +278,17 @@ def test_get_instances_filtering_by_vpc_id():
reservations2[0].instances[0].id.should.equal(instance2.id)
@mock_ec2
def test_get_instances_filtering_by_architecture():
conn = boto.connect_ec2()
reservation = conn.run_instances('ami-1234abcd', min_count=1)
instance = reservation.instances
reservations = conn.get_all_instances(filters={'architecture': 'x86_64'})
# get_all_instances should return the instance
reservations[0].instances.should.have.length_of(1)
@mock_ec2
def test_get_instances_filtering_by_tag():
conn = boto.connect_ec2()
@ -519,7 +530,6 @@ def test_run_instance_with_security_group_name():
def test_run_instance_with_security_group_id():
conn = boto.connect_ec2('the_key', 'the_secret')
group = conn.create_security_group('group1', "some description")
reservation = conn.run_instances('ami-1234abcd',
security_group_ids=[group.id])
instance = reservation.instances[0]