Commit 064f576f authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

pithos: change resource usage retrieval

Replace ``astakosclient.get_info()`` with ``astakosclient.get_quotas()``
parent f1495806
......@@ -44,7 +44,6 @@ from django.core.files.uploadhandler import FileUploadHandler
from django.core.files.uploadedfile import UploadedFile
from snf_django.lib.api.parsedate import parse_http_date_safe, parse_http_date
from snf_django.lib.astakos import user_for_token
from snf_django.lib import api
from snf_django.lib.api import faults, utils
......@@ -63,6 +62,7 @@ from pithos.api.settings import (BACKEND_DB_MODULE, BACKEND_DB_CONNECTION,
RADOS_POOL_MAPS, TRANSLATE_UUIDS,
PUBLIC_URL_SECURITY,
PUBLIC_URL_ALPHABET)
from pithos.api.resources import resources
from pithos.backends.base import (NotAllowedError, QuotaError, ItemNotExists,
VersionNotExists)
from astakosclient import AstakosClient
......@@ -1043,11 +1043,10 @@ def update_response_headers(request, response):
def get_pithos_usage(token):
"""Get Pithos Usage from astakos."""
astakos = AstakosClient(ASTAKOS_URL, retry=2, use_pool=True, logger=logger)
user_info = user_for_token(astakos, token, usage=True)
usage = user_info.get("usage", [])
for u in usage:
if u.get('name') == 'pithos.diskspace':
return u
quotas = astakos.get_quotas(token)['system']
pithos_resources = [r['name'] for r in resources]
map(quotas.pop, filter(lambda k: k not in pithos_resources, quotas.keys()))
return quotas.popitem()[-1] # assume only one resource
def api_method(http_method=None, user_required=True, logger=None,
......
......@@ -301,7 +301,7 @@ class ModularBackend(BaseBackend):
meta.update({'name': account, 'count': count, 'bytes': bytes})
if self.using_external_quotaholder:
external_quota = external_quota or {}
meta['bytes'] = external_quota.get('currValue', 0)
meta['bytes'] = external_quota.get('usage', 0)
meta.update({'modified': modified})
return meta
......@@ -359,7 +359,7 @@ class ModularBackend(BaseBackend):
policy = self._get_policy(node, is_account_policy=True)
if self.using_external_quotaholder:
external_quota = external_quota or {}
policy['quota'] = external_quota.get('maxValue', 0)
policy['quota'] = external_quota.get('limit', 0)
return policy
@backend_method
......
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