Commit c584ec5e authored by Giorgos Korfiatis's avatar Giorgos Korfiatis

astakos: Get service related project quota

Add API call for a service to request the project quota for its own
resources.
parent 403d89cc
......@@ -213,6 +213,10 @@ class AstakosClient(object):
def api_service_quotas(self):
return join_urls(self.account_prefix, "service_quotas")
@property
def api_service_project_quotas(self):
return join_urls(self.account_prefix, "service_project_quotas")
@property
def api_commissions(self):
return join_urls(self.account_prefix, "commissions")
......@@ -558,6 +562,24 @@ class AstakosClient(object):
query += "?user=" + user
return self._call_astakos(query)
# ----------------------------------
# do a GET to ``API_SERVICE_PROJECT_QUOTAS``
def service_get_project_quotas(self, project=None):
"""Get all project quotas for resources associated with the service
Keyword arguments:
project -- optionally, the uuid of a specific project
In case of success return a dict of dicts with current quotas
for all projects, or of a specified project, if project argument is set.
Otherwise raise an AstakosClientException
"""
query = self.api_service_project_quotas
if project is not None:
query += "?project=" + project
return self._call_astakos(query)
# ----------------------------------
# do a POST to ``API_COMMISSIONS``
def _issue_commission(self, request):
......
......@@ -139,6 +139,13 @@ retry=0, use_pool=False, pool_size=8, logger=None\ **)**
quotas of a specific user with argument user=UUID. In case of error it
raises an AstakosClientException exception.
**service_get_project_quotas(**\ project=None\ **)**
It returns all projects' current quotas for the resources
associated with the service (as dict of dicts).
Optionally, one can query the quotas of a specific project with
argument project=UUID. In case of error it raises an
AstakosClientException exception.
**issue_commission_generic(**\ user_provisions, project_provisions, name="", force=False, auto_accept=False\ **)**
Issue a commission. User provisions are specified as a dict from
(user, project, resource) to int; project provisions as a dict from
......
......@@ -42,7 +42,8 @@ from django.core.cache import cache
from astakos.im import settings
from astakos.im import register
from astakos.im.quotas import get_user_quotas, service_get_quotas
from astakos.im.quotas import get_user_quotas, service_get_quotas, \
service_get_project_quotas
import astakos.quotaholder_app.exception as qh_exception
import astakos.quotaholder_app.callpoint as qh
......@@ -82,6 +83,20 @@ def service_quotas(request):
return json_response(result)
@api.api_method(http_method='GET', token_required=True, user_required=False)
@component_from_token
def service_project_quotas(request):
project = request.GET.get('project')
projects = [project] if project is not None else None
result = service_get_project_quotas(request.component_instance,
projects=projects)
if project is not None and result == {}:
raise ItemNotFound("No such project '%s'" % project)
return json_response(result)
@api.api_method(http_method='GET', token_required=False, user_required=False)
def resources(request):
resources = get_visible_resources()
......
......@@ -39,6 +39,7 @@ astakos_account_v1_0 = patterns(
'astakos.api.quotas',
url(r'^quotas/?$', 'quotas', name="astakos-api-quotas"),
url(r'^service_quotas/?$', 'service_quotas'),
url(r'^service_project_quotas/?$', 'service_project_quotas'),
url(r'^resources/?$', 'resources'),
url(r'^commissions/?$', 'commissions'),
url(r'^commissions/action/?$', 'resolve_pending_commissions'),
......
......@@ -165,6 +165,18 @@ def get_projects_quota(projects, resources=None, sources=None):
return mk_project_quota_dict(strip_names(project_counters))
def service_get_project_quotas(component, projects=None):
name_values = Service.objects.filter(
component=component).values_list('name')
service_names = [t for (t,) in name_values]
resources = Resource.objects.filter(service_origin__in=service_names)
resource_names = [r.name for r in resources]
ps = Project.objects.initialized()
if projects is not None:
ps = ps.filter(uuid__in=projects)
return get_projects_quota(ps, resources=resource_names)
def get_project_quota(project, resources=None, sources=None):
quotas = get_projects_quota([project], resources, sources)
return quotas.get(project.uuid, {})
......
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