Commit 8d9f3ab6 authored by Kostas Papadimitriou's avatar Kostas Papadimitriou
Browse files

Handle astakos usage response in ui

override the hardcoded quotas if astakos response includes user usage
information.
parent 3d8cde61
......@@ -229,7 +229,12 @@ def machines_console(request):
return template('machines_console', request, context)
def user_quota(request):
get_user(request, settings.ASTAKOS_URL)
try:
get_user(request, settings.ASTAKOS_URL, usage=True)
except TypeError:
# astakos client backwards compatibility
get_user(request, settings.ASTAKOS_URL)
vms_limit_for_user = \
settings.VMS_USER_QUOTA.get(request.user_uniq,
settings.MAX_VMS_PER_USER)
......@@ -237,6 +242,17 @@ def user_quota(request):
networks_limit_for_user = \
settings.NETWORKS_USER_QUOTA.get(request.user_uniq,
settings.MAX_NETWORKS_PER_USER)
if 'usage' in request.user:
quota = dict(zip([q['name'] for q in request.user['usage']],
request.user['usage']))
# TODO: is it ok to use hardcoded resource name ???
if 'cyclades.vm' in quota:
vms_limit_for_user = quota['cyclades.vm']['maxValue']
if 'cyclades.network.private' in quota:
vms_limit_for_user = quota['cyclades.network.private']['maxValue']
return HttpResponse('{"vms_quota":%d, "networks_quota":%d}' % (vms_limit_for_user,
networks_limit_for_user),
mimetype="application/json")
......
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