fix deep-copy in ec2.models.all_reservations
This commit is contained in:
parent
b5f74d08f3
commit
becf0a1d3d
@ -765,14 +765,12 @@ class InstanceBackend(object):
|
|||||||
associated with the given instance_ids.
|
associated with the given instance_ids.
|
||||||
"""
|
"""
|
||||||
reservations = []
|
reservations = []
|
||||||
for reservation in self.all_reservations(make_copy=True):
|
for reservation in self.all_reservations():
|
||||||
reservation_instance_ids = [
|
reservation_instance_ids = [
|
||||||
instance.id for instance in reservation.instances]
|
instance.id for instance in reservation.instances]
|
||||||
matching_reservation = any(
|
matching_reservation = any(
|
||||||
instance_id in reservation_instance_ids for instance_id in instance_ids)
|
instance_id in reservation_instance_ids for instance_id in instance_ids)
|
||||||
if matching_reservation:
|
if matching_reservation:
|
||||||
# We need to make a copy of the reservation because we have to modify the
|
|
||||||
# instances to limit to those requested
|
|
||||||
reservation.instances = [
|
reservation.instances = [
|
||||||
instance for instance in reservation.instances if instance.id in instance_ids]
|
instance for instance in reservation.instances if instance.id in instance_ids]
|
||||||
reservations.append(reservation)
|
reservations.append(reservation)
|
||||||
@ -786,15 +784,8 @@ class InstanceBackend(object):
|
|||||||
reservations = filter_reservations(reservations, filters)
|
reservations = filter_reservations(reservations, filters)
|
||||||
return reservations
|
return reservations
|
||||||
|
|
||||||
def all_reservations(self, make_copy=False, filters=None):
|
def all_reservations(self, filters=None):
|
||||||
if make_copy:
|
reservations = [copy.copy(reservation) for reservation in self.reservations.values()]
|
||||||
# Return copies so that other functions can modify them with changing
|
|
||||||
# the originals
|
|
||||||
reservations = [copy.deepcopy(reservation)
|
|
||||||
for reservation in self.reservations.values()]
|
|
||||||
else:
|
|
||||||
reservations = [
|
|
||||||
reservation for reservation in self.reservations.values()]
|
|
||||||
if filters is not None:
|
if filters is not None:
|
||||||
reservations = filter_reservations(reservations, filters)
|
reservations = filter_reservations(reservations, filters)
|
||||||
return reservations
|
return reservations
|
||||||
|
@ -16,8 +16,7 @@ class InstanceResponse(BaseResponse):
|
|||||||
reservations = self.ec2_backend.get_reservations_by_instance_ids(
|
reservations = self.ec2_backend.get_reservations_by_instance_ids(
|
||||||
instance_ids, filters=filter_dict)
|
instance_ids, filters=filter_dict)
|
||||||
else:
|
else:
|
||||||
reservations = self.ec2_backend.all_reservations(
|
reservations = self.ec2_backend.all_reservations(filters=filter_dict)
|
||||||
make_copy=True, filters=filter_dict)
|
|
||||||
|
|
||||||
reservation_ids = [reservation.id for reservation in reservations]
|
reservation_ids = [reservation.id for reservation in reservations]
|
||||||
if token:
|
if token:
|
||||||
|
Loading…
Reference in New Issue
Block a user