Revision 5aac5dc4

b/snf-astakos-app/astakos/im/endpoints/qh.py
98 98
    result = get_holding(payload)
99 99
    return result
100 100

  
101
def quota_limits_per_user_from_get(lst):
102
    quotas = {}
103
    for holder, resource, q, c, il, el, imp, exp, ret, rel, flags in lst:
104
        userquotas = quotas.get(holder, {})
105
        userquotas[resource] = QuotaValues(quantity=q, capacity=c,
106
                                           import_limit=il, export_limit=el)
107
        quotas[holder] = userquotas
108
    return quotas
109

  
101 110
def qh_get_quota(users, resources):
102 111
    c = get_client()
103 112
    if not c:
......
114 123

  
115 124
def qh_get_quota_limits(users, resources):
116 125
    result = qh_get_quota(users, resources)
117
    return result
126
    return quota_limits_per_user_from_get(result)
118 127

  
119 128
def create_entity(payload):
120 129
    c = get_client()
......
198 207
                    flags=0))
199 208
    return set_quota(payload)
200 209

  
210
def send_quotas(userquotas):
211
    if not userquotas:
212
        return
213

  
214
    payload = []
215
    append = payload.append
216
    for holder, quotas in userquotas.iteritems():
217
        for resource, q in quotas.iteritems():
218
            append( SetQuotaPayload(
219
                    holder=holder,
220
                    resource=resource,
221
                    key=ENTITY_KEY,
222
                    quantity=q.quantity,
223
                    capacity=q.capacity,
224
                    import_limit=q.import_limit,
225
                    export_limit=q.export_limit,
226
                    flags=0))
227
    return set_quota(payload)
228

  
201 229
def register_services(services):
202 230
    payload = list(CreateEntityPayload(
203 231
                    entity=service,
b/snf-astakos-app/astakos/im/models.py
72 72
    PROJECT_MEMBER_JOIN_POLICIES, PROJECT_MEMBER_LEAVE_POLICIES)
73 73
from astakos.im import settings as astakos_settings
74 74
from astakos.im.endpoints.qh import (
75
    register_users, register_quotas, qh_check_users, qh_get_quota_limits,
75
    register_users, send_quotas, qh_check_users, qh_get_quota_limits,
76 76
    register_services, register_resources, qh_add_quota, QuotaLimits,
77 77
    qh_query_serials, qh_ack_serials,
78 78
    QuotaValues, add_quota_values)
......
2211 2211
                     retries=retries,
2212 2212
                     retry_wait=retry_wait)
2213 2213

  
2214

  
2215
def all_users_quotas(users):
2216
    quotas = {}
2217
    for user in users:
2218
        quotas[user.uuid] = user.all_quotas()
2219
    return quotas
2220

  
2214 2221
def _sync_users(users, sync):
2215 2222
    sync_finish_serials()
2216 2223

  
2217 2224
    existing, nonexisting = qh_check_users(users)
2218 2225
    resources = get_resource_names()
2219
    quotas = qh_get_quota_limits(existing, resources)
2226
    registered_quotas = qh_get_quota_limits(existing, resources)
2227
    astakos_quotas = all_users_quotas(users)
2220 2228

  
2221 2229
    if sync:
2222 2230
        r = register_users(nonexisting)
2223
        r = register_quotas(users)
2231
        r = send_quotas(astakos_quotas)
2224 2232

  
2225
    # TODO: some proper reporting
2226
    return (existing, nonexisting, quotas)
2233
    return (existing, nonexisting, registered_quotas, astakos_quotas)
2227 2234

  
2228 2235
def sync_users(users, sync=True, retries=3, retry_wait=1.0):
2229 2236
    return lock_sync(_sync_users,

Also available in: Unified diff