def reservations_by_recurring_allocation(self): """Find reservations that target a recurring allocation """ allocation_id = self.recurring_allocation_id allocation = Session.query(Allocation).get(allocation_id) if not allocation: return None reservation_tokens = [each.reservation_token for each in allocation.reserved_slots] return Session.query(Reservation).filter( Reservation.token.in_(reservation_tokens))
def generate_reservations(self, resource, start, end): query = Session.query(Allocation) query = query.filter(Allocation._start >= start) query = query.filter(Allocation._end <= end) query = query.filter(Allocation.mirror_of == resource.string_uuid()) query = query.order_by(Allocation._start) email = '*****@*****.**' scheduler = resource.scheduler() allocations = query.all() Session.expunge_all() for allocation in allocations: if allocation.partly_available: start = allocation.start total = (allocation.end - allocation.start).seconds / 60 if total > allocation.raster: start_minute = random.randrange( 0, total - allocation.raster, allocation.raster ) end_minute = random.randrange( start_minute + allocation.raster, total, allocation.raster ) else: start_minute = 0 end_minute = total start = start + timedelta(start_minute * 60) end = start + timedelta(end_minute * 60) else: start, end = allocation.start, allocation.display_end if not allocation.approve_manually: limit = allocation.quota for i in range(0, random.randrange(0, limit + 1)): try: print('r @', start, end) token = scheduler.reserve(email, dates=(start, end)) if not allocation.approve_manually: scheduler.approve_reservations(token) except ReservationError: break Session.expire_on_commit = False transaction.commit()
def generate_reservations(self, resource, start, end): query = Session.query(Allocation) query = query.filter(Allocation._start >= start) query = query.filter(Allocation._end <= end) query = query.filter(Allocation.mirror_of == resource.string_uuid()) query = query.order_by(Allocation._start) email = '*****@*****.**' scheduler = resource.scheduler() allocations = query.all() Session.expunge_all() for allocation in allocations: if allocation.partly_available: start = allocation.start total = (allocation.end - allocation.start).seconds / 60 if total > allocation.raster: start_minute = random.randrange(0, total - allocation.raster, allocation.raster) end_minute = random.randrange( start_minute + allocation.raster, total, allocation.raster) else: start_minute = 0 end_minute = total start = start + timedelta(start_minute * 60) end = start + timedelta(end_minute * 60) else: start, end = allocation.start, allocation.display_end if not allocation.approve_manually: limit = allocation.quota for i in range(0, random.randrange(0, limit + 1)): try: print('r @', start, end) token = scheduler.reserve(email, dates=(start, end)) if not allocation.approve_manually: scheduler.approve_reservations(token) except ReservationError: break Session.expire_on_commit = False transaction.commit()
def all_allocations(self): query = super(ReservationList, self).all_allocations() if query: return query if self.recurring_allocation_id: return Session.query(Allocation).filter_by( id=self.recurring_allocation_id) return None
def allocation(self): if self.allocation_id: return Session.query(Allocation).get(self.allocation_id) return None
def tearDown(self): endInteraction() super(IntegrationTestCase, self).tearDown() Session.remove()