Revision ec6f741b
b/snf-pithos-app/pithos/api/functions.py | ||
---|---|---|
56 | 56 |
get_content_range, socket_read_iterator, SaveToBackendHandler, |
57 | 57 |
object_data_response, put_object_block, hashmap_md5, simple_list_response, |
58 | 58 |
api_method, is_uuid, retrieve_uuid, retrieve_uuids, |
59 |
retrieve_displaynames, get_pithos_usage, Checksum, NoChecksum
|
|
59 |
retrieve_displaynames, Checksum, NoChecksum |
|
60 | 60 |
) |
61 | 61 |
|
62 | 62 |
from pithos.api.settings import (UPDATE_MD5, TRANSLATE_UUIDS, |
... | ... | |
240 | 240 |
return response |
241 | 241 |
|
242 | 242 |
account_meta = [] |
243 |
usage = get_pithos_usage(request.x_auth_token) |
|
244 | 243 |
for x in accounts: |
245 | 244 |
if x == request.user_uniq: |
246 | 245 |
continue |
247 | 246 |
try: |
248 | 247 |
meta = request.backend.get_account_meta( |
249 |
request.user_uniq, x, 'pithos', include_user_defined=False, |
|
250 |
external_quota=usage) |
|
248 |
request.user_uniq, x, 'pithos', include_user_defined=False) |
|
251 | 249 |
groups = request.backend.get_account_groups(request.user_uniq, x) |
252 | 250 |
except NotAllowedError: |
253 | 251 |
raise faults.Forbidden('Not allowed') |
... | ... | |
284 | 282 |
# badRequest (400) |
285 | 283 |
|
286 | 284 |
until = get_int_parameter(request.GET.get('until')) |
287 |
usage = get_pithos_usage(request.x_auth_token) |
|
288 | 285 |
try: |
289 | 286 |
meta = request.backend.get_account_meta( |
290 |
request.user_uniq, v_account, 'pithos', until, |
|
291 |
external_quota=usage) |
|
287 |
request.user_uniq, v_account, 'pithos', until) |
|
292 | 288 |
groups = request.backend.get_account_groups( |
293 | 289 |
request.user_uniq, v_account) |
294 | 290 |
|
... | ... | |
297 | 293 |
groups[k] = retrieve_displaynames( |
298 | 294 |
getattr(request, 'token', None), groups[k]) |
299 | 295 |
policy = request.backend.get_account_policy( |
300 |
request.user_uniq, v_account, external_quota=usage)
|
|
296 |
request.user_uniq, v_account) |
|
301 | 297 |
except NotAllowedError: |
302 | 298 |
raise faults.Forbidden('Not allowed') |
303 | 299 |
|
... | ... | |
365 | 361 |
# badRequest (400) |
366 | 362 |
|
367 | 363 |
until = get_int_parameter(request.GET.get('until')) |
368 |
usage = get_pithos_usage(request.x_auth_token) |
|
369 | 364 |
try: |
370 | 365 |
meta = request.backend.get_account_meta( |
371 |
request.user_uniq, v_account, 'pithos', until, |
|
372 |
external_quota=usage) |
|
366 |
request.user_uniq, v_account, 'pithos', until) |
|
373 | 367 |
groups = request.backend.get_account_groups( |
374 | 368 |
request.user_uniq, v_account) |
375 | 369 |
policy = request.backend.get_account_policy( |
376 |
request.user_uniq, v_account, external_quota=usage)
|
|
370 |
request.user_uniq, v_account) |
|
377 | 371 |
except NotAllowedError: |
378 | 372 |
raise faults.Forbidden('Not allowed') |
379 | 373 |
|
b/snf-pithos-app/pithos/api/test/__init__.py | ||
---|---|---|
239 | 239 |
new_callable=PropertyMock) |
240 | 240 |
mock_api_oauth2_auth.return_value = '/astakos/oauth2/' |
241 | 241 |
|
242 |
mock_service_get_quotas = self.create_patch( |
|
243 |
'astakosclient.AstakosClient.service_get_quotas') |
|
244 |
mock_service_get_quotas.return_value = { |
|
245 |
self.user: { |
|
246 |
"system": { |
|
247 |
"pithos.diskspace": { |
|
248 |
"usage": 0, |
|
249 |
"limit": 1073741824, # 1GB |
|
250 |
"pending": 0}}}} |
|
251 |
|
|
242 | 252 |
def tearDown(self): |
243 | 253 |
#delete additionally created metadata |
244 | 254 |
meta = self.get_account_meta() |
b/snf-pithos-app/pithos/api/util.py | ||
---|---|---|
1068 | 1068 |
response[quote(k)] = quote(v, safe='/=,:@; ') |
1069 | 1069 |
|
1070 | 1070 |
|
1071 |
def get_pithos_usage(token): |
|
1072 |
"""Get Pithos Usage from astakos.""" |
|
1073 |
astakos = AstakosClient(token, ASTAKOS_AUTH_URL, |
|
1074 |
retry=2, use_pool=True, |
|
1075 |
logger=logger) |
|
1076 |
quotas = astakos.get_quotas()['system'] |
|
1077 |
pithos_resources = [r['name'] for r in resources] |
|
1078 |
map(quotas.pop, filter(lambda k: k not in pithos_resources, quotas.keys())) |
|
1079 |
return quotas.popitem()[-1] # assume only one resource |
|
1080 |
|
|
1081 |
|
|
1082 | 1071 |
def api_method(http_method=None, token_required=True, user_required=True, |
1083 | 1072 |
logger=None, format_allowed=False, serializations=None, |
1084 | 1073 |
strict_serlization=False, lock_container_path=False): |
b/snf-pithos-backend/pithos/backends/modular.py | ||
---|---|---|
120 | 120 |
ULTIMATE_ANSWER = 42 |
121 | 121 |
|
122 | 122 |
DEFAULT_SOURCE = 'system' |
123 |
DEFAULT_DISKSPACE_RESOURCE = 'pithos.diskspace' |
|
123 | 124 |
|
124 | 125 |
logger = logging.getLogger(__name__) |
125 | 126 |
|
... | ... | |
339 | 340 |
start, limit = self._list_limits(allowed, marker, limit) |
340 | 341 |
return allowed[start:start + limit] |
341 | 342 |
|
343 |
def _get_account_quotas(self, account): |
|
344 |
"""Get account usage from astakos.""" |
|
345 |
|
|
346 |
quotas = self.astakosclient.service_get_quotas(account)[account] |
|
347 |
return quotas.get(DEFAULT_SOURCE, {}).get(DEFAULT_DISKSPACE_RESOURCE, |
|
348 |
{}) |
|
349 |
|
|
342 | 350 |
@debug_method |
343 | 351 |
@backend_method |
344 |
def get_account_meta( |
|
345 |
self, user, account, domain, until=None, include_user_defined=True, |
|
346 |
external_quota=None): |
|
352 |
def get_account_meta(self, user, account, domain, until=None, |
|
353 |
include_user_defined=True): |
|
347 | 354 |
"""Return a dictionary with the account metadata for the domain.""" |
348 | 355 |
|
349 | 356 |
path, node = self._lookup_account(account, user == account) |
... | ... | |
377 | 384 |
meta.update({'until_timestamp': tstamp}) |
378 | 385 |
meta.update({'name': account, 'count': count, 'bytes': bytes}) |
379 | 386 |
if self.using_external_quotaholder: |
380 |
external_quota = external_quota or {}
|
|
387 |
external_quota = self._get_account_quotas(account)
|
|
381 | 388 |
meta['bytes'] = external_quota.get('usage', 0) |
382 | 389 |
meta.update({'modified': modified}) |
383 | 390 |
return meta |
... | ... | |
424 | 431 |
|
425 | 432 |
@debug_method |
426 | 433 |
@backend_method |
427 |
def get_account_policy(self, user, account, external_quota=None):
|
|
434 |
def get_account_policy(self, user, account): |
|
428 | 435 |
"""Return a dictionary with the account policy.""" |
429 | 436 |
|
430 | 437 |
if user != account: |
... | ... | |
434 | 441 |
path, node = self._lookup_account(account, True) |
435 | 442 |
policy = self._get_policy(node, is_account_policy=True) |
436 | 443 |
if self.using_external_quotaholder: |
437 |
external_quota = external_quota or {}
|
|
444 |
external_quota = self._get_account_quotas(account)
|
|
438 | 445 |
policy['quota'] = external_quota.get('limit', 0) |
439 | 446 |
return policy |
440 | 447 |
|
Also available in: Unified diff