Commit c44e6eda authored by Giorgos Korfiatis's avatar Giorgos Korfiatis
Browse files

In sync_users log quotas computed by astakos

parent 4fdba47a
......@@ -98,6 +98,15 @@ def qh_get_holdings(users, resources):
result = get_holding(payload)
return result
def quota_limits_per_user_from_get(lst):
quotas = {}
for holder, resource, q, c, il, el, imp, exp, ret, rel, flags in lst:
userquotas = quotas.get(holder, {})
userquotas[resource] = QuotaValues(quantity=q, capacity=c,
import_limit=il, export_limit=el)
quotas[holder] = userquotas
return quotas
def qh_get_quota(users, resources):
c = get_client()
if not c:
......@@ -114,7 +123,7 @@ def qh_get_quota(users, resources):
def qh_get_quota_limits(users, resources):
result = qh_get_quota(users, resources)
return result
return quota_limits_per_user_from_get(result)
def create_entity(payload):
c = get_client()
......@@ -198,6 +207,25 @@ def register_quotas(users):
flags=0))
return set_quota(payload)
def send_quotas(userquotas):
if not userquotas:
return
payload = []
append = payload.append
for holder, quotas in userquotas.iteritems():
for resource, q in quotas.iteritems():
append( SetQuotaPayload(
holder=holder,
resource=resource,
key=ENTITY_KEY,
quantity=q.quantity,
capacity=q.capacity,
import_limit=q.import_limit,
export_limit=q.export_limit,
flags=0))
return set_quota(payload)
def register_services(services):
payload = list(CreateEntityPayload(
entity=service,
......
......@@ -72,7 +72,7 @@ from astakos.im.settings import (
PROJECT_MEMBER_JOIN_POLICIES, PROJECT_MEMBER_LEAVE_POLICIES)
from astakos.im import settings as astakos_settings
from astakos.im.endpoints.qh import (
register_users, register_quotas, qh_check_users, qh_get_quota_limits,
register_users, send_quotas, qh_check_users, qh_get_quota_limits,
register_services, register_resources, qh_add_quota, QuotaLimits,
qh_query_serials, qh_ack_serials,
QuotaValues, add_quota_values)
......@@ -2211,19 +2211,26 @@ def sync_projects(sync=True, retries=3, retry_wait=1.0):
retries=retries,
retry_wait=retry_wait)
def all_users_quotas(users):
quotas = {}
for user in users:
quotas[user.uuid] = user.all_quotas()
return quotas
def _sync_users(users, sync):
sync_finish_serials()
existing, nonexisting = qh_check_users(users)
resources = get_resource_names()
quotas = qh_get_quota_limits(existing, resources)
registered_quotas = qh_get_quota_limits(existing, resources)
astakos_quotas = all_users_quotas(users)
if sync:
r = register_users(nonexisting)
r = register_quotas(users)
r = send_quotas(astakos_quotas)
# TODO: some proper reporting
return (existing, nonexisting, quotas)
return (existing, nonexisting, registered_quotas, astakos_quotas)
def sync_users(users, sync=True, retries=3, retry_wait=1.0):
return lock_sync(_sync_users,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment