If ec2 filtering exclude all instances for a reservation, remove the reservation from the results.

This commit is contained in:
Steve Pulec 2013-07-08 22:25:25 -04:00
parent 46f9430bdd
commit af31744dbd
2 changed files with 8 additions and 2 deletions

View File

@ -98,10 +98,13 @@ def passes_filter_dict(instance, filter_dict):
def filter_reservations(reservations, filter_dict):
result = []
for reservation in reservations:
new_instances = []
for instance in reservation.instances:
if passes_filter_dict(instance, filter_dict):
new_instances.append(instance)
reservation.instances = new_instances
return reservations
if new_instances:
reservation.instances = new_instances
result.append(reservation)
return result

View File

@ -96,6 +96,9 @@ def test_get_instances_filtering_by_state():
instance_ids = [instance.id for instance in reservations[0].instances]
instance_ids.should.equal([instance2.id])
reservations = conn.get_all_instances([instance2.id], filters={'instance-state-name': 'terminating'})
list(reservations).should.equal([])
# get_all_instances should still return all 3
reservations = conn.get_all_instances()
reservations[0].instances.should.have.length_of(3)