Revision dccd7fa0
b/astakosclient/astakosclient/__init__.py | ||
---|---|---|
214 | 214 |
return join_urls(self.account_prefix, "service_quotas") |
215 | 215 |
|
216 | 216 |
@property |
217 |
def api_service_project_quotas(self): |
|
218 |
return join_urls(self.account_prefix, "service_project_quotas") |
|
219 |
|
|
220 |
@property |
|
217 | 221 |
def api_commissions(self): |
218 | 222 |
return join_urls(self.account_prefix, "commissions") |
219 | 223 |
|
... | ... | |
559 | 563 |
return self._call_astakos(query) |
560 | 564 |
|
561 | 565 |
# ---------------------------------- |
566 |
# do a GET to ``API_SERVICE_PROJECT_QUOTAS`` |
|
567 |
def service_get_project_quotas(self, project=None): |
|
568 |
"""Get all project quotas for resources associated with the service |
|
569 |
|
|
570 |
Keyword arguments: |
|
571 |
project -- optionally, the uuid of a specific project |
|
572 |
|
|
573 |
In case of success return a dict of dicts with current quotas |
|
574 |
for all projects, or of a specified project, if project argument is set. |
|
575 |
Otherwise raise an AstakosClientException |
|
576 |
|
|
577 |
""" |
|
578 |
query = self.api_service_project_quotas |
|
579 |
if project is not None: |
|
580 |
query += "?project=" + project |
|
581 |
return self._call_astakos(query) |
|
582 |
|
|
583 |
# ---------------------------------- |
|
562 | 584 |
# do a POST to ``API_COMMISSIONS`` |
563 | 585 |
def _issue_commission(self, request): |
564 | 586 |
"""Issue a commission |
b/astakosclient/docs/index.rst | ||
---|---|---|
139 | 139 |
quotas of a specific user with argument user=UUID. In case of error it |
140 | 140 |
raises an AstakosClientException exception. |
141 | 141 |
|
142 |
**service_get_project_quotas(**\ project=None\ **)** |
|
143 |
It returns all projects' current quotas for the resources |
|
144 |
associated with the service (as dict of dicts). |
|
145 |
Optionally, one can query the quotas of a specific project with |
|
146 |
argument project=UUID. In case of error it raises an |
|
147 |
AstakosClientException exception. |
|
148 |
|
|
142 | 149 |
**issue_commission_generic(**\ user_provisions, project_provisions, name="", force=False, auto_accept=False\ **)** |
143 | 150 |
Issue a commission. User provisions are specified as a dict from |
144 | 151 |
(user, project, resource) to int; project provisions as a dict from |
b/snf-astakos-app/astakos/api/quotas.py | ||
---|---|---|
42 | 42 |
|
43 | 43 |
from astakos.im import settings |
44 | 44 |
from astakos.im import register |
45 |
from astakos.im.quotas import get_user_quotas, service_get_quotas |
|
45 |
from astakos.im.quotas import get_user_quotas, service_get_quotas, \ |
|
46 |
service_get_project_quotas |
|
46 | 47 |
|
47 | 48 |
import astakos.quotaholder_app.exception as qh_exception |
48 | 49 |
import astakos.quotaholder_app.callpoint as qh |
... | ... | |
82 | 83 |
return json_response(result) |
83 | 84 |
|
84 | 85 |
|
86 |
@api.api_method(http_method='GET', token_required=True, user_required=False) |
|
87 |
@component_from_token |
|
88 |
def service_project_quotas(request): |
|
89 |
project = request.GET.get('project') |
|
90 |
projects = [project] if project is not None else None |
|
91 |
result = service_get_project_quotas(request.component_instance, |
|
92 |
projects=projects) |
|
93 |
|
|
94 |
if project is not None and result == {}: |
|
95 |
raise ItemNotFound("No such project '%s'" % project) |
|
96 |
|
|
97 |
return json_response(result) |
|
98 |
|
|
99 |
|
|
85 | 100 |
@api.api_method(http_method='GET', token_required=False, user_required=False) |
86 | 101 |
def resources(request): |
87 | 102 |
resources = get_visible_resources() |
b/snf-astakos-app/astakos/api/urls.py | ||
---|---|---|
39 | 39 |
'astakos.api.quotas', |
40 | 40 |
url(r'^quotas/?$', 'quotas', name="astakos-api-quotas"), |
41 | 41 |
url(r'^service_quotas/?$', 'service_quotas'), |
42 |
url(r'^service_project_quotas/?$', 'service_project_quotas'), |
|
42 | 43 |
url(r'^resources/?$', 'resources'), |
43 | 44 |
url(r'^commissions/?$', 'commissions'), |
44 | 45 |
url(r'^commissions/action/?$', 'resolve_pending_commissions'), |
b/snf-astakos-app/astakos/im/quotas.py | ||
---|---|---|
165 | 165 |
return mk_project_quota_dict(strip_names(project_counters)) |
166 | 166 |
|
167 | 167 |
|
168 |
def service_get_project_quotas(component, projects=None): |
|
169 |
name_values = Service.objects.filter( |
|
170 |
component=component).values_list('name') |
|
171 |
service_names = [t for (t,) in name_values] |
|
172 |
resources = Resource.objects.filter(service_origin__in=service_names) |
|
173 |
resource_names = [r.name for r in resources] |
|
174 |
ps = Project.objects.initialized() |
|
175 |
if projects is not None: |
|
176 |
ps = ps.filter(uuid__in=projects) |
|
177 |
return get_projects_quota(ps, resources=resource_names) |
|
178 |
|
|
179 |
|
|
168 | 180 |
def get_project_quota(project, resources=None, sources=None): |
169 | 181 |
quotas = get_projects_quota([project], resources, sources) |
170 | 182 |
return quotas.get(project.uuid, {}) |
Also available in: Unified diff