Revision f557d10a snf-astakos-app/astakos/im/endpoints/qh.py

b/snf-astakos-app/astakos/im/endpoints/qh.py
1
# Copyright 2011-2012 GRNET S.A. All rights reserved.
1
# Copyright 2011, 2012, 2013 GRNET S.A. All rights reserved.
2 2
#
3 3
# Redistribution and use in source and binary forms, with or
4 4
# without modification, are permitted provided that the following
......
109 109
        quotas[holder] = userquotas
110 110
    return quotas
111 111

  
112
def quotas_per_user_from_get(lst):
113
    limits = {}
114
    counters = {}
115
    for holder, resource, q, c, il, el, imp, exp, ret, rel, flags in lst:
116
        userlimits = limits.get(holder, {})
117
        userlimits[resource] = QuotaValues(quantity=q, capacity=c,
118
                                           import_limit=il, export_limit=el)
119
        limits[holder] = userlimits
120

  
121
        usercounters = counters.get(holder, {})
122
        usercounters[resource] = QuotaCounters(imported=imp, exported=exp,
123
                                               returned=ret, released=rel)
124
        counters[holder] = usercounters
125
    return limits, counters
126

  
127

  
112 128
def qh_get_quota(users, resources):
113 129
    c = get_client()
114 130
    if not c:
......
127 143
    result = qh_get_quota(users, resources)
128 144
    return quota_limits_per_user_from_get(result)
129 145

  
146
def qh_get_quotas(users, resources):
147
    result = qh_get_quota(users, resources)
148
    return quotas_per_user_from_get(result)
149

  
130 150
def create_entity(payload):
131 151
    c = get_client()
132 152
    if not c:
......
156 176
QuotaLimits = namedtuple('QuotaLimits', ('holder',
157 177
                                         'resource',
158 178
                                         'capacity',
159
                                        'import_limit',
179
                                         'import_limit',
160 180
                                         'export_limit'))
161 181

  
182
QuotaCounters = namedtuple('QuotaCounters', ('imported',
183
                                             'exported',
184
                                             'returned',
185
                                             'released'))
186

  
187

  
162 188
class QuotaValues(namedtuple('QuotaValues', ('quantity',
163 189
                                             'capacity',
164 190
                                             'import_limit',

Also available in: Unified diff