commit 6cc50d6a7e6c84bed5c067e6b27de234698c904f
Author: Giorgos Korfiatis <gkorf@grnet.gr>
Date:   Mon Apr 8 15:25:37 2013 +0300

    Cleanup obsolete quota code

diff --git a/snf-astakos-app/astakos/quotaholder/callpoint.py b/snf-astakos-app/astakos/quotaholder/callpoint.py
index 17b12e8..2a2333b 100644
--- a/snf-astakos-app/astakos/quotaholder/callpoint.py
+++ b/snf-astakos-app/astakos/quotaholder/callpoint.py
@@ -46,8 +46,6 @@ from astakos.quotaholder.commission import (
 from astakos.quotaholder.utils.newname import newname
 from astakos.quotaholder.api import QH_PRACTICALLY_INFINITE
 
-from django.db.models import Q, Count
-from django.db.models import Q
 from .models import (Holding,
                      Commission, Provision, ProvisionLog,
                      now,
@@ -57,117 +55,6 @@ from .models import (Holding,
 
 class QuotaholderDjangoDBCallpoint(object):
 
-    def _init_holding(self,
-                      holder, resource, limit,
-                      imported_min, imported_max,
-                      flags):
-        try:
-            h = db_get_holding(holder=holder, resource=resource,
-                               for_update=True)
-        except Holding.DoesNotExist:
-            h = Holding(holder=holder, resource=resource)
-
-        h.limit = limit
-        h.flags = flags
-        h.imported_min = imported_min
-        h.imported_max = imported_max
-        h.save()
-
-    def init_holding(self, context=None, init_holding=[]):
-        rejected = []
-        append = rejected.append
-
-        for idx, sfh in enumerate(init_holding):
-            (holder, resource, limit,
-             imported_min, imported_max,
-             flags) = sfh
-
-            self._init_holding(holder, resource, limit,
-                               imported_min, imported_max,
-                               flags)
-        if rejected:
-            raise QuotaholderError(rejected)
-        return rejected
-
-    def reset_holding(self, context=None, reset_holding=[]):
-        rejected = []
-        append = rejected.append
-
-        for idx, tpl in enumerate(reset_holding):
-            (holder, source, resource,
-             imported_min, imported_max) = tpl
-
-            try:
-                h = db_get_holding(holder=holder,
-                                   source=source,
-                                   resource=resource,
-                                   for_update=True)
-                h.imported_min = imported_min
-                h.imported_max = imported_max
-                h.save()
-            except Holding.DoesNotExist:
-                append(idx)
-                continue
-
-        if rejected:
-            raise QuotaholderError(rejected)
-        return rejected
-
-    def _check_pending(self, holding):
-        ps = Provision.objects.filter(holding=holding)
-        return ps.count()
-
-    def release_holding(self, context=None, release_holding=[]):
-        rejected = []
-        append = rejected.append
-
-        for idx, (holder, source, resource) in enumerate(release_holding):
-            try:
-                h = db_get_holding(holder=holder,
-                                   source=source,
-                                   resource=resource,
-                                   for_update=True)
-            except Holding.DoesNotExist:
-                append(idx)
-                continue
-
-            if self._check_pending(h):
-                append(idx)
-                continue
-
-            if h.imported_max > 0:
-                append(idx)
-                continue
-
-            h.delete()
-
-        if rejected:
-            raise QuotaholderError(rejected)
-        return rejected
-
-    def list_resources(self, context=None, holder=None):
-        holdings = Holding.objects.filter(holder=holder)
-        resources = [h.resource for h in holdings]
-        return resources
-
-    def list_holdings(self, context=None, list_holdings=[]):
-        rejected = []
-        reject = rejected.append
-        holdings_list = []
-        append = holdings_list.append
-
-        for holder in list_holdings:
-            holdings = list(Holding.objects.filter(holder=holder))
-            if not holdings:
-                reject(holder)
-                continue
-
-            append([(holder, h.source, h.resource,
-                     h.imported_min, h.imported_max)
-                    for h in holdings])
-
-        return holdings_list, rejected
-
     def get_holder_quota(self, holders=None, sources=None, resources=None):
         holdings = Holding.objects.filter(holder__in=holders)
 
@@ -185,28 +72,6 @@ class QuotaholderDjangoDBCallpoint(object):
 
         return quotas
 
-    def get_quota(self, context=None, get_quota=[]):
-        quotas = []
-        append = quotas.append
-
-        holders = set(holder for holder, r in get_quota)
-        hs = Holding.objects.filter(holder__in=holders)
-        holdings = {}
-        for h in hs:
-            holdings[(h.holder, h.source, h.resource)] = h
-
-        for holder, source, resource in get_quota:
-            try:
-                h = holdings[(holder, source, resource)]
-            except:
-                continue
-
-            append((h.holder, h.source, h.resource, h.limit,
-                    h.imported_min, h.imported_max,
-                    h.flags))
-
-        return quotas
-
     def set_holder_quota(self, quotas):
         holders = quotas.keys()
         hs = Holding.objects.filter(holder__in=holders).select_for_update()
@@ -227,89 +92,6 @@ class QuotaholderDjangoDBCallpoint(object):
                     h.limit = limit
                     h.save()
 
-    def set_quota(self, context=None, set_quota=[]):
-        rejected = []
-        append = rejected.append
-
-        q_holdings = Q()
-        holders = []
-        for (holder, source, resource, _, _) in set_quota:
-            holders.append(holder)
-
-        hs = Holding.objects.filter(holder__in=holders).select_for_update()
-        holdings = {}
-        for h in hs:
-            holdings[(h.holder, h.source, h.resource)] = h
-
-        for (holder, source, resource,
-             limit,
-             flags) in set_quota:
-
-            try:
-                h = holdings[(holder, source, resource)]
-                h.flags = flags
-            except KeyError:
-                h = Holding(holder=holder,
-                            source=source,
-                            resource=resource,
-                            flags=flags)
-
-            h.limit = limit
-            h.save()
-            holdings[(holder, source, resource)] = h
-
-        if rejected:
-            raise QuotaholderError(rejected)
-        return rejected
-
-    def add_quota(self,
-                  context=None,
-                  sub_quota=[], add_quota=[]):
-        rejected = []
-        append = rejected.append
-
-        sources = sub_quota + add_quota
-        q_holdings = Q()
-        holders = []
-        for (holder, resource, _) in sources:
-            holders.append(holder)
-
-        hs = Holding.objects.filter(holder__in=holders).select_for_update()
-        holdings = {}
-        for h in hs:
-            holdings[(h.holder, h.resource)] = h
-
-        for removing, source in [(True, sub_quota), (False, add_quota)]:
-            for (holder, resource,
-                 limit,
-                 ) in source:
-
-                try:
-                    h = holdings[(holder, resource)]
-                    current_limit = h.limit
-                except KeyError:
-                    if removing:
-                        append((holder, resource))
-                        continue
-
-                    h = Holding(holder=holder, resource=resource, flags=0)
-                    current_limit = 0
-
-                h.limit = (current_limit - limit if removing else
-                           current_limit + limit)
-
-                if h.limit < 0:
-                    append((holder, resource))
-                    continue
-
-                h.save()
-                holdings[(holder, resource)] = h
-
-        if rejected:
-            raise QuotaholderError(rejected)
-
-        return rejected
-
     def issue_commission(self,
                          context=None,
                          clientkey=None,
@@ -524,76 +306,5 @@ class QuotaholderDjangoDBCallpoint(object):
         failed = list(set(failed_ac + failed_re))
         return accepted, rejected, failed
 
-    def get_timeline(self, context=None, after="", before="Z", get_timeline=[]):
-        holder_set = set()
-        e_add = holder_set.add
-        resource_set = set()
-        r_add = resource_set.add
-
-        for holder, resource in get_timeline:
-            if holder not in holder_set:
-                e_add(holder)
-
-            r_add((holder, resource))
-
-        chunk_size = 65536
-        nr = 0
-        timeline = []
-        append = timeline.append
-        filterlogs = ProvisionLog.objects.filter
-        if holder_set:
-            q_holder = Q(source__in=holder_set) | Q(target__in=holder_set)
-        else:
-            q_holder = Q()
-
-        while 1:
-            logs = filterlogs(q_holder,
-                              issue_time__gt=after,
-                              issue_time__lte=before,
-                              reason__startswith='ACCEPT:')
-
-            logs = logs.order_by('issue_time')
-            #logs = logs.values()
-            logs = logs[:chunk_size]
-            nr += len(logs)
-            if not logs:
-                break
-            for g in logs:
-                if ((g.source, g.resource) not in resource_set
-                    or (g.target, g.resource) not in resource_set):
-                    continue
-
-                o = {
-                    'serial':                   g.serial,
-                    'source':                   g.source,
-                    'target':                   g.target,
-                    'resource':                 g.resource,
-                    'name':                     g.name,
-                    'quantity':                 g.delta_quantity,
-                    'source_allocated':         g.source_allocated(),
-                    'source_allocated_through': g.source_allocated_through(),
-                    'source_inbound':           g.source_inbound(),
-                    'source_inbound_through':   g.source_inbound_through(),
-                    'source_outbound':          g.source_outbound(),
-                    'source_outbound_through':  g.source_outbound_through(),
-                    'target_allocated':         g.target_allocated(),
-                    'target_allocated_through': g.target_allocated_through(),
-                    'target_inbound':           g.target_inbound(),
-                    'target_inbound_through':   g.target_inbound_through(),
-                    'target_outbound':          g.target_outbound(),
-                    'target_outbound_through':  g.target_outbound_through(),
-                    'issue_time':               g.issue_time,
-                    'log_time':                 g.log_time,
-                    'reason':                   g.reason,
-                }
-
-                append(o)
-
-            after = g.issue_time
-            if after >= before:
-                break
-
-        return timeline
-
 
 API_Callpoint = QuotaholderDjangoDBCallpoint
