Commit 4d9d67d5 authored by Giorgos Korfiatis's avatar Giorgos Korfiatis

New call astakos/api/service_quotas

Returns quotas for all resources associated with the service that makes
the call.
parent 09c39976
......@@ -89,6 +89,61 @@ Status Description
}
}
Get Quotas per Service
..........
**GET** /astakos/api/service_quotas
==================== ============================
Request Header Name Value
==================== ============================
X-Auth-Token Service authentication token
==================== ============================
**Normal Response Code**: 200
**Error Response Codes**:
====== ============================
Status Description
====== ============================
401 Unauthorized (Missing token)
500 Internal Server Error
====== ============================
**Example Successful Response**:
.. code-block:: javascript
{
"1a6165d0-5020-4b6d-a4ad-83476632a584": {
"system": {
"cyclades.ram": {
"available": 536870912,
"limit": 1073741824,
"used": 536870912
},
"cyclades.vm": {
"available": 0,
"limit": 2,
"used": 2
}
},
"project:1": {
"cyclades.ram": {
"available": 0,
"limit": 2147483648,
"used": 2147483648
},
"cyclades.vm": {
"available": 3,
"limit": 5,
"used": 2
}
}
}
}
Commissions
-----------
......
......@@ -45,7 +45,8 @@ from astakos.im.api import api_method as generic_api_method
from astakos.im.api.user import user_from_token
from astakos.im.api.service import service_from_token
from astakos.im.quotas import get_user_quotas, get_resources
from astakos.im.quotas import (get_user_quotas, get_resources,
get_service_quotas)
import astakos.quotaholder.exception as qh_exception
from astakos.quotaholder.callpoint import QuotaholderDjangoDBCallpoint
......@@ -59,6 +60,13 @@ def quotas(request, user=None):
return json_response(result)
@api.api_method(http_method='GET', token_required=True, user_required=False)
@service_from_token
def service_quotas(request):
result = get_service_quotas(request.service_instance)
return json_response(result)
@api.api_method(http_method='GET', token_required=False, user_required=False)
def resources(request):
result = get_resources()
......
......@@ -36,6 +36,7 @@ from django.conf.urls.defaults import patterns, url
urlpatterns = patterns(
'astakos.api.quotas',
url(r'^quotas/?$', 'quotas'),
url(r'^service_quotas/?$', 'service_quotas'),
url(r'^resources/?$', 'resources'),
url(r'^commissions/?$', 'commissions'),
url(r'^commissions/action/?$', 'resolve_pending_commissions'),
......
......@@ -95,6 +95,13 @@ def get_user_quotas(user, resources=None, sources=None):
return quotas[user.uuid]
def get_service_quotas(service):
resources = Resource.objects.filter(service=service.name)
resource_names = [r.name for r in resources]
counters = qh.get_resource_quota(resource_names)
return transform_data(counters)
def set_user_quota(quotas):
qh.set_holder_quota(quotas)
......
......@@ -69,6 +69,20 @@ class QuotaholderDjangoDBCallpoint(object):
return quotas
def get_resource_quota(self, resources, sources=None):
holdings = Holding.objects.filter(resource__in=resources)
if sources is not None:
holdings = holdings.filter(source__in=sources)
quotas = {}
for holding in holdings:
key = (holding.holder, holding.source, holding.resource)
value = (holding.limit, holding.imported_min, holding.imported_max)
quotas[key] = value
return quotas
def _get_holdings_for_update(self, holding_keys):
holding_keys = sorted(holding_keys)
holdings = {}
......
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