Пример #1
0
    def reservation_rollback(self, context, reservations, project_id):
        with _session_for_write():
            usages = self._get_quota_usages(context, project_id)
            usages = self._dict_with_usage_id(usages)
            for reservation in reservations:
                if reservation.allocated_id:
                    reservation.quota.allocated -= reservation.delta
                else:
                    usage = usages[reservation.usage_id]
                    if reservation.delta >= 0:
                        usage.reserved -= reservation.delta

                query = model_query(context, models.Reservation)
                query = query.filter_by(uuid=reservation.uuid)
                count = query.delete()
                if count != 1:
                    raise exception.ReservationNotFound(uuid=reservation.uuid)
Пример #2
0
    def reservation_commit(self, context, reservations, project_id):
        with _session_for_write():
            usages = self._get_quota_usages(context, project_id)
            usages = self._dict_with_usage_id(usages)

            for reservation in reservations:
                # Allocated reservations will have already been bumped
                if not reservation.allocated_id:
                    usage = usages[reservation.usage_id]
                    if reservation.delta >= 0:
                        usage.reserved -= reservation.delta
                    usage.in_use += reservation.delta

                query = model_query(context, models.Reservation)
                query = query.filter_by(uuid=reservation.uuid)
                count = query.delete()
                if count != 1:
                    raise exception.ReservationNotFound(uuid=reservation.uuid)
Пример #3
0
    def reservation_expire(self, context):
        with _session_for_write() as session:
            current_time = timeutils.utcnow()
            results = model_query(context, models.Reservation).\
                filter(models.Reservation.expire < current_time).\
                all()

            if results:
                for reservation in results:
                    if reservation.delta >= 0:
                        if reservation.allocated_id:
                            reservation.quota.allocated -= reservation.delta
                            reservation.quota.save(session=session)
                        else:
                            reservation.usage.reserved -= reservation.delta
                            reservation.usage.save(session=session)

                    query = model_query(context, models.Reservation)
                    query = query.filter_by(uuid=reservation.uuid)
                    count = query.delete()
                    if count != 1:
                        uuid = reservation.uuid
                        raise exception.ReservationNotFound(uuid=uuid)