Statistics
| Branch: | Tag: | Revision:

root / snf-quotaholder-app / quotaholder_django / quotaholder_app / callpoint.py @ 351b8bf0

History | View | Annotate | Download (27.3 kB)

1
# Copyright 2012 GRNET S.A. All rights reserved.
2
#
3
# Redistribution and use in source and binary forms, with or
4
# without modification, are permitted provided that the following
5
# conditions are met:
6
#
7
#   1. Redistributions of source code must retain the above
8
#      copyright notice, this list of conditions and the following
9
#      disclaimer.
10
#
11
#   2. Redistributions in binary form must reproduce the above
12
#      copyright notice, this list of conditions and the following
13
#      disclaimer in the documentation and/or other materials
14
#      provided with the distribution.
15
#
16
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
# POSSIBILITY OF SUCH DAMAGE.
28
#
29
# The views and conclusions contained in the software and
30
# documentation are those of the authors and should not be
31
# interpreted as representing official policies, either expressed
32
# or implied, of GRNET S.A.
33

    
34
from synnefo.lib.quotaholder.api import (
35
                            QuotaholderAPI,
36
                            InvalidKeyError, NoEntityError,
37
                            NoQuantityError, NoCapacityError,
38
                            ExportLimitError, ImportLimitError,
39
                            DuplicateError)
40

    
41
from synnefo.lib.commissioning import \
42
    Callpoint, CorruptedError, InvalidDataError
43
from synnefo.lib.commissioning.utils.newname import newname
44

    
45
from django.db.models import Q
46
from django.db import transaction, IntegrityError
47
from .models import (Holder, Entity, Policy, Holding,
48
                     Commission, Provision, ProvisionLog, now)
49

    
50

    
51
class QuotaholderDjangoDBCallpoint(Callpoint):
52

    
53
    api_spec = QuotaholderAPI()
54

    
55
    http_exc_lookup = {
56
        CorruptedError:   550,
57
        InvalidDataError: 400,
58
        InvalidKeyError:  401,
59
        NoEntityError:    404,
60
        NoQuantityError:  413,
61
        NoCapacityError:  413,
62
    }
63

    
64
    def init_connection(self, connection):
65
        if connection is not None:
66
            raise ValueError("Cannot specify connection args with %s" %
67
                             type(self).__name__)
68
        pass
69

    
70
    def commit(self):
71
        transaction.commit()
72

    
73
    def rollback(self):
74
        transaction.rollback()
75

    
76
    def do_make_call(self, call_name, data):
77
        call_fn = getattr(self, call_name, None)
78
        if not call_fn:
79
            m = "cannot find call '%s'" % (call_name,)
80
            raise CorruptedError(m)
81

    
82
        return call_fn(**data)
83

    
84
    def create_entity(self, context={}, create_entity=()):
85
        rejected = []
86
        append = rejected.append
87

    
88
        for idx, (entity, owner, key, ownerkey) in enumerate(create_entity):
89
            try:
90
                owner = Entity.objects.get(entity=owner, key=ownerkey)
91
            except Entity.DoesNotExist:
92
                append(idx)
93
                continue
94

    
95
            try:
96
                e = Entity.objects.get(entity=entity)
97
                append(idx)
98
            except Entity.DoesNotExist:
99
                e = Entity.objects.create(entity=entity,
100
                                          owner=owner,
101
                                          key=key)
102
        return rejected
103

    
104
    def set_entity_key(self, context={}, set_entity_key=()):
105
        rejected = []
106
        append = rejected.append
107

    
108
        for entity, key, newkey in set_entity_key:
109
            try:
110
                e = Entity.objects.get(entity=entity, key=key)
111
            except Entity.DoesNotExist:
112
                append(entity)
113
                continue
114

    
115
            e.key = newkey
116
            e.save()
117

    
118
        return rejected
119

    
120
    def list_entities(self, context={}, entity=None, key=None):
121
        try:
122
            e = Entity.objects.get(entity=entity, key=key)
123
        except Entity.DoesNotExist:
124
            m = "Entity '%s' does not exist" % (entity,)
125
            raise NoEntityError(m)
126

    
127
        children = e.entities.all()
128
        entities = [e.entity for e in children]
129
        return entities
130

    
131
    def get_entity(self, context={}, get_entity=()):
132
        entities = []
133
        append = entities.append
134

    
135
        for entity, key in get_entity:
136
            try:
137
                e = Entity.objects.get(entity=entity, key=key)
138
            except Entity.DoesNotExist:
139
                continue
140

    
141
            append((entity, e.owner.entity))
142

    
143
        return entities
144

    
145
    def get_limits(self, context={}, get_limits=()):
146
        limits = []
147
        append = limits.append
148

    
149
        for policy in get_limits:
150
            try:
151
                p = Policy.objects.get(policy=policy)
152
            except Policy.DoesNotExist:
153
                continue
154

    
155
            append((policy, p.quantity, p.capacity,
156
                    p.import_limit, p.export_limit))
157

    
158
        return limits
159

    
160
    def set_limits(self, context={}, set_limits=()):
161

    
162
        for (   policy, quantity, capacity,
163
                import_limit, export_limit  ) in set_limits:
164

    
165
                try:
166
                    policy = Policy.objects.get(policy=policy)
167
                except Policy.DoesNotExist:
168
                    Policy.objects.create(  policy=policy,
169
                                            quantity=quantity,
170
                                            capacity=capacity,
171
                                            import_limit=import_limit,
172
                                            export_limit=export_limit   )
173
                else:
174
                    policy.quantity = quantity
175
                    policy.capacity = capacity
176
                    policy.export_limit = export_limit
177
                    policy.import_limit = import_limit
178
                    policy.save()
179

    
180
        return ()
181

    
182
    def get_holding(self, context={}, get_holding=()):
183
        holdings = []
184
        append = holdings.append
185

    
186
        for entity, resource, key in get_holding:
187
            try:
188
                h = Holding.objects.get(entity=entity, resource=resource)
189
            except Holding.DoesNotExist:
190
                continue
191

    
192
            if h.entity.key != key:
193
                continue
194

    
195
            append((h.entity.entity, h.resource, h.policy.policy,
196
                    h.imported, h.exported,
197
                    h.returned, h.released, h.flags))
198

    
199
        return holdings
200

    
201
    def _set_holding(self, entity, resource, policy, flags):
202
        try:
203
            h = Holding.objects.get(entity=entity, resource=resource)
204
            h.policy = p
205
            h.flags = flags
206
            h.save()
207
        except Holding.DoesNotExist:
208
            h = Holding.objects.create( entity=e, resource=resource,
209
                                        policy=p, flags=flags      )
210
        return h
211

    
212
    def set_holding(self, context={}, set_holding=()):
213
        rejected = []
214
        append = rejected.append
215

    
216
        for entity, resource, key, policy, flags in set_holding:
217
            try:
218
                e = Entity.objects.get(entity=entity, key=key)
219
            except Entity.DoesNotExist:
220
                append((entity, resource, policy))
221
                continue
222

    
223
            if e.key != key:
224
                append((entity, resource, policy))
225
                continue
226

    
227
            try:
228
                p = Policy.objects.get(policy=policy)
229
            except Policy.DoesNotExist:
230
                append((entity, resource, policy))
231
                continue
232

    
233
            try:
234
                h = Holding.objects.get(entity=entity, resource=resource)
235
                h.policy = p
236
                h.flags = flags
237
                h.save()
238
            except Holding.DoesNotExist:
239
                h = Holding.objects.create( entity=e, resource=resource,
240
                                            policy=p, flags=flags      )
241

    
242
        return rejected
243

    
244
    def _init_holding(self, entity, resource, policy,
245
                          imported, exported, returned, released,
246
                          flags):
247
        try:
248
            h = Holding.objects.get(entity=entity, resource=resource)
249
        except Holding.DoesNotExist:
250
            h = Holding(entity=entity, resource=resource)
251

    
252
        h.policy = policy
253
        h.flags = flags
254
        h.imported=imported
255
        h.importing=imported
256
        h.exported=exported
257
        h.exporting=exported
258
        h.returned=returned
259
        h.returning=returned
260
        h.released=released
261
        h.releasing=released
262
        h.save()
263

    
264
    def init_holding(self, context={}, init_holding=()):
265
        rejected = []
266
        append = rejected.append
267

    
268
        for idx, sfh in enumerate(init_holding):
269
            (entity, resource, key, policy,
270
             imported, exported, returned, released,
271
             flags) = sfh
272
            try:
273
                e = Entity.objects.get(entity=entity, key=key)
274
            except Entity.DoesNotExist:
275
                append(idx)
276
                continue
277

    
278
            if e.key != key:
279
                append(idx)
280
                continue
281

    
282
            try:
283
                p = Policy.objects.get(policy=policy)
284
            except Policy.DoesNotExist:
285
                append(idx)
286
                continue
287

    
288
            self._init_holding(e, resource, p,
289
                                   imported, exported,
290
                                   returned, released,
291
                                   flags)
292
        return rejected
293

    
294
    def _check_pending(self, entity=None):
295
        serials = []
296
        try:
297
            cs = Commission.objects.filter(entity=entity)
298
            serials = [c.serial for c in cs]
299
        except Commission.DoesNotExist:
300
            pass
301

    
302
        try:
303
            ps = Provision.objects.filter(entity=entity)
304
            serials += [p.serial.serial for p in ps]
305
        except Provision.DoesNotExist:
306
            pass
307
        return serials
308

    
309
    def _actual_quantity(self, holding):
310
        hp = holding.policy
311
        return hp.quantity + (holding.imported + holding.returned -
312
                              holding.exported - holding.released)
313

    
314
    def _new_policy_name(self):
315
        return newname('policy_')
316

    
317
    def _increase_resource(self, entity, resource, amount):
318
        try:
319
            h = Holding.objects.get(entity=entity, resource=resource)
320
        except Holding.DoesNotExist:
321
            h = Holding(entity=entity, resource=resource)
322
            p = Policy.objects.create(policy=self._new_policy_name(),
323
                                      quantity=0)
324
            h.policy = p
325
        h.imported += amount
326
        h.save()
327

    
328
    def release_holding(self, context={}, release_holding=()):
329
        rejected = []
330
        append = rejected.append
331

    
332
        for idx, (entity, resource, key) in enumerate(release_holding):
333
            try:
334
                h = Holding.objects.get(entity=entity, resource=resource)
335
            except Holding.DoesNotExist:
336
                append(idx)
337
                continue
338

    
339
            if h.entity.key != key:
340
                append(idx)
341
                continue
342

    
343
            if self._check_pending(entity):
344
                append(idx)
345
                continue
346

    
347
            q = self._actual_quantity(h)
348
            owner = h.entity.owner
349
            self._increase_resource(owner, resource, q)
350
            h.delete()
351

    
352
        return rejected
353

    
354
    def list_resources(self, context={}, entity=None, key=None):
355
        try:
356
            e = Entity.objects.get(entity=entity)
357
        except Entity.DoesNotExist:
358
            m = "No such entity '%s'" % (entity,)
359
            raise NoEntityError(m)
360

    
361
        if e.key != key:
362
            m = "Invalid key for entity '%s'" % (entity,)
363
            raise InvalidKeyError(m)
364

    
365
        holdings = e.holding_set.filter(entity=entity)
366
        resources = [h.resource for h in holdings]
367
        return resources
368

    
369
    def get_quota(self, context={}, get_quota=()):
370
        quotas = []
371
        append = quotas.append
372

    
373
        for entity, resource, key in get_quota:
374
            try:
375
                h = Holding.objects.get(entity=entity, resource=resource)
376
            except Holding.DoesNotExist:
377
                continue
378

    
379
            if h.entity.key != key:
380
                continue
381

    
382
            p = h.policy
383

    
384
            append((h.entity.entity, h.resource, p.quantity, p.capacity,
385
                    p.import_limit, p.export_limit,
386
                    h.imported, h.exported,
387
                    h.returned, h.released,
388
                    h.flags))
389

    
390
        return quotas
391

    
392
    def set_quota(self, context={}, set_quota=()):
393
        rejected = []
394
        append = rejected.append
395

    
396
        for (   entity, resource, key,
397
                quantity, capacity,
398
                import_limit, export_limit, flags  ) in set_quota:
399

    
400
                p = None
401

    
402
                try:
403
                    h = Holding.objects.get(entity=entity, resource=resource)
404
                    if h.entity.key != key:
405
                        append((entity, resource))
406
                        continue
407
                    p = h.policy
408

    
409
                except Holding.DoesNotExist:
410
                    try:
411
                        e = Entity.objects.get(entity=entity)
412
                    except Entity.DoesNotExist:
413
                        append((entity, resource))
414
                        continue
415

    
416
                    if e.key != key:
417
                        append((entity, resource))
418
                        continue
419

    
420
                    h = None
421

    
422
                policy = newname('policy_')
423
                newp = Policy   (
424
                            policy=policy,
425
                            quantity=quantity,
426
                            capacity=capacity,
427
                            import_limit=import_limit,
428
                            export_limit=export_limit
429
                )
430

    
431
                if h is None:
432
                    h = Holding(entity=e, resource=resource,
433
                                policy=newp, flags=flags)
434
                else:
435
                    h.policy = newp
436
                    h.flags = flags
437

    
438
                h.save()
439
                newp.save()
440

    
441
                if p is not None and p.holding_set.count() == 0:
442
                    p.delete()
443

    
444
        return rejected
445

    
446
    def issue_commission(self,  context     =   {},
447
                                clientkey   =   None,
448
                                target      =   None,
449
                                key         =   None,
450
                                name        =   None,
451
                                provisions  =   ()  ):
452

    
453
        try:
454
            t = Entity.objects.get(entity=target)
455
        except Entity.DoesNotExist:
456
            m = "No target entity '%s'" % (target,)
457
            raise NoEntityError(m)
458
        else:
459
            if t.key != key:
460
                m = "Invalid key for target entity '%s'" % (target,)
461
                raise InvalidKeyError(m)
462

    
463
        create = Commission.objects.create
464
        commission = create(entity_id=target, clientkey=clientkey, name=name)
465
        serial = commission.serial
466

    
467
        checked = []
468
        for entity, resource, quantity in provisions:
469

    
470
            ent_res = entity, resource
471
            if ent_res in checked:
472
                m = "Duplicate provision for %s.%s" % ent_res
473
                raise DuplicateError(m)
474
            checked.append(ent_res)
475

    
476
            try:
477
                e = Entity.objects.get(entity=entity)
478
            except Entity.DoesNotExist:
479
                m = "No source entity '%s'" % (entity,)
480
                raise NoEntityError(m)
481

    
482
            release = 0
483
            if quantity < 0:
484
                release = 1
485

    
486
            try:
487
                h = Holding.objects.get(entity=entity, resource=resource)
488
            except Holding.DoesNotExist:
489
                m = ("There is not enough quantity "
490
                     "to allocate from in %s.%s" % (entity, resource))
491
                raise NoQuantityError(m)
492

    
493
            hp = h.policy
494

    
495
            if (hp.export_limit is not None and
496
                h.exporting + quantity > hp.export_limit):
497
                    m = ("Export limit reached for %s.%s" % (entity, resource))
498
                    raise ExportLimitError(m)
499

    
500
            if hp.quantity is not None:
501
                available = (+ hp.quantity + h.imported + h.returned
502
                             - h.exporting - h.releasing)
503

    
504
                if available - quantity < 0:
505
                    m = ("There is not enough quantity "
506
                         "to allocate from in %s.%s" % (entity, resource))
507
                    raise NoQuantityError(m)
508

    
509
            try:
510
                th = Holding.objects.get(entity=target, resource=resource)
511
            except Holding.DoesNotExist:
512
                m = ("There is not enough capacity "
513
                     "to allocate into in %s.%s" % (target, resource))
514
                raise NoCapacityError(m)
515

    
516
            tp = th.policy
517

    
518
            if (tp.import_limit is not None and
519
                th.importing + quantity > tp.import_limit):
520
                    m = ("Import limit reached for %s.%s" % (target, resource))
521
                    raise ImportLimitError(m)
522

    
523
            if tp.capacity is not None:
524
                capacity = (+ tp.capacity + th.exported + th.released
525
                            - th.importing - th.returning)
526

    
527
                if capacity - quantity < 0:
528
                        m = ("There is not enough capacity "
529
                             "to allocate into in %s.%s" % (target, resource))
530
                        raise NoCapacityError(m)
531

    
532
            Provision.objects.create(   serial      =   commission,
533
                                        entity      =   e,
534
                                        resource    =   resource,
535
                                        quantity    =   quantity   )
536
            if release:
537
                h.returning -= quantity
538
                th.releasing -= quantity
539
            else:
540
                h.exporting += quantity
541
                th.importing += quantity
542

    
543
            h.save()
544
            th.save()
545

    
546
        return serial
547

    
548
    def _log_provision(self, commission, s_holding, t_holding,
549
                             provision, log_time, reason):
550

    
551
        s_entity = s_holding.entity
552
        s_policy = s_holding.policy
553
        t_entity = t_holding.entity
554
        t_policy = t_holding.policy
555

    
556
        ProvisionLog.objects.create(
557
                        serial              =   commission.serial,
558
                        name                =   commission.name,
559
                        source              =   s_entity.entity,
560
                        target              =   t_entity.entity,
561
                        resource            =   provision.resource,
562
                        source_quantity     =   s_policy.quantity,
563
                        source_capacity     =   s_policy.capacity,
564
                        source_import_limit =   s_policy.import_limit,
565
                        source_export_limit =   s_policy.export_limit,
566
                        source_imported     =   s_holding.imported,
567
                        source_exported     =   s_holding.exported,
568
                        source_returned     =   s_holding.returned,
569
                        source_released     =   s_holding.released,
570
                        target_quantity     =   t_policy.quantity,
571
                        target_capacity     =   t_policy.capacity,
572
                        target_import_limit =   t_policy.import_limit,
573
                        target_export_limit =   t_policy.export_limit,
574
                        target_imported     =   t_holding.imported,
575
                        target_exported     =   t_holding.exported,
576
                        target_returned     =   t_holding.returned,
577
                        target_released     =   t_holding.released,
578
                        delta_quantity      =   provision.quantity,
579
                        issue_time          =   commission.issue_time,
580
                        log_time            =   log_time,
581
                        reason              =   reason)
582

    
583
    def accept_commission(self, context={}, clientkey=None,
584
                                serials=(), reason=''):
585
        log_time = now()
586

    
587
        for serial in serials:
588
            try:
589
                c = Commission.objects.get(clientkey=clientkey, serial=serial)
590
            except Commission.DoesNotExist:
591
                return
592

    
593
            t = c.entity
594

    
595
            provisions = Provision.objects.filter(serial=serial)
596
            for pv in provisions:
597
                try:
598
                    h = Holding.objects.get(entity=pv.entity.entity,
599
                                            resource=pv.resource    )
600
                    th = Holding.objects.get(entity=t, resource=pv.resource)
601
                except Holding.DoesNotExist:
602
                    m = "Corrupted provision"
603
                    raise CorruptedError(m)
604

    
605
                quantity = pv.quantity
606
                release = 0
607
                if quantity < 0:
608
                    release = 1
609

    
610
                if release:
611
                    h.returned -= quantity
612
                    th.released -= quantity
613
                else:
614
                    h.exported += quantity
615
                    th.imported += quantity
616

    
617
                reason = 'ACCEPT:' + reason[-121:]
618
                self._log_provision(c, h, th, pv, log_time, reason)
619
                h.save()
620
                th.save()
621
                pv.delete()
622
            c.delete()
623

    
624
        return
625

    
626
    def reject_commission(self, context={}, clientkey=None,
627
                                serials=(), reason=''):
628
        log_time = now()
629

    
630
        for serial in serials:
631
            try:
632
                c = Commission.objects.get(clientkey=clientkey, serial=serial)
633
            except Commission.DoesNotExist:
634
                return
635

    
636
            t = c.entity
637

    
638
            provisions = Provision.objects.filter(serial=serial)
639
            for pv in provisions:
640
                try:
641
                    h = Holding.objects.get(entity=pv.entity.entity,
642
                                            resource=pv.resource)
643
                    th = Holding.objects.get(entity=t, resource=pv.resource)
644
                except Holding.DoesNotExist:
645
                    m = "Corrupted provision"
646
                    raise CorruptedError(m)
647

    
648
                quantity = pv.quantity
649
                release = 0
650
                if quantity < 0:
651
                    release = 1
652

    
653
                if release:
654
                    h.returning += quantity
655
                    th.releasing += quantity
656
                else:
657
                    h.exporting -= quantity
658
                    th.importing -= quantity
659

    
660
                reason = 'REJECT:' + reason[-121:]
661
                self._log_provision(c, h, th, pv, log_time, reason)
662
                h.save()
663
                th.save()
664
                pv.delete()
665
            c.delete()
666

    
667
        return
668

    
669
    def get_pending_commissions(self, context={}, clientkey=None):
670
        pending = Commission.objects.filter(clientkey=clientkey)\
671
                                    .values_list('serial', flat=True)
672
        return pending
673

    
674
    def resolve_pending_commissions(self,   context={}, clientkey=None,
675
                                            max_serial=None, accept_set=()  ):
676
        accept_set = set(accept_set)
677
        pending = self.get_pending_commissions(context=context, clientkey=clientkey)
678
        pending = sorted(pending)
679

    
680
        accept = self.accept_commission
681
        reject = self.reject_commission
682

    
683
        for serial in pending:
684
            if serial > max_serial:
685
                break
686

    
687
            if serial in accept_set:
688
                accept(context=context, clientkey=clientkey, serials=[serial])
689
            else:
690
                reject(context=context, clientkey=clientkey, serials=[serial])
691

    
692
        return
693

    
694
    def release_entity(self, context={}, release_entity=()):
695
        rejected = []
696
        append = rejected.append
697
        for entity, key in release_entity:
698
            try:
699
                e = Entity.objects.get(entity=entity, key=key)
700
            except Entity.DoesNotExist:
701
                append(entity)
702
                continue
703

    
704
            if e.entities.count() != 0:
705
                append(entity)
706
                continue
707

    
708
            if e.holding_set.count() != 0:
709
                append(entity)
710
                continue
711

    
712
            e.delete()
713

    
714
        return rejected
715

    
716
    def get_timeline(self, context={}, after="", before="Z", get_timeline=()):
717
        entity_set = set()
718
        e_add = entity_set.add
719
        resource_set = set()
720
        r_add = resource_set.add
721

    
722
        for entity, resource, key in get_timeline:
723
            if entity not in entity_set:
724
                try:
725
                    e = Entity.objects.get(entity=entity, key=key)
726
                    e_add(entity)
727
                except Entity.DoesNotExist:
728
                    continue
729

    
730
            r_add((entity, resource))
731

    
732
        chunk_size = 65536
733
        nr = 0
734
        timeline = []
735
        append = timeline.append
736
        filterlogs = ProvisionLog.objects.filter
737
        if entity_set:
738
            q_entity = Q(source__in = entity_set) | Q(target__in = entity_set)
739
        else:
740
            q_entity = Q()
741

    
742
        while 1:
743
            logs = filterlogs(  q_entity,
744
                                issue_time__gt      =   after,
745
                                issue_time__lte     =   before,
746
                                reason__startswith  =   'ACCEPT:'   )
747

    
748
            logs = logs.order_by('issue_time')
749
            #logs = logs.values()
750
            logs = logs[:chunk_size]
751
            nr += len(logs)
752
            if not logs:
753
                break
754
            for g in logs:
755
                if ((g.source, g.resource) not in resource_set
756
                    or (g.target, g.resource) not in resource_set):
757
                        continue
758

    
759
                o = {
760
                    'serial'                    :   g.serial,
761
                    'source'                    :   g.source,
762
                    'target'                    :   g.target,
763
                    'resource'                  :   g.resource,
764
                    'name'                      :   g.name,
765
                    'quantity'                  :   g.delta_quantity,
766
                    'source_allocated'          :   g.source_allocated(),
767
                    'source_allocated_through'  :   g.source_allocated_through(),
768
                    'source_inbound'            :   g.source_inbound(),
769
                    'source_inbound_through'    :   g.source_inbound_through(),
770
                    'source_outbound'           :   g.source_outbound(),
771
                    'source_outbound_through'   :   g.source_outbound_through(),
772
                    'target_allocated'          :   g.target_allocated(),
773
                    'target_allocated_through'  :   g.target_allocated_through(),
774
                    'target_inbound'            :   g.target_inbound(),
775
                    'target_inbound_through'    :   g.target_inbound_through(),
776
                    'target_outbound'           :   g.target_outbound(),
777
                    'target_outbound_through'   :   g.target_outbound_through(),
778
                    'issue_time'                :   g.issue_time,
779
                    'log_time'                  :   g.log_time,
780
                    'reason'                    :   g.reason,
781
                }
782

    
783
                append(o)
784

    
785
            after = g.issue_time
786
            if after >= before:
787
                break
788

    
789
        return timeline
790

    
791

    
792
API_Callpoint = QuotaholderDjangoDBCallpoint
793