Revision bb005bc2
b/docs/quota-api-guide.rst | ||
---|---|---|
89 | 89 |
} |
90 | 90 |
} |
91 | 91 |
|
92 |
Get Quotas per Service |
|
93 |
.......... |
|
94 |
|
|
95 |
**GET** /astakos/api/service_quotas |
|
96 |
|
|
97 |
==================== ============================ |
|
98 |
Request Header Name Value |
|
99 |
==================== ============================ |
|
100 |
X-Auth-Token Service authentication token |
|
101 |
==================== ============================ |
|
102 |
|
|
103 |
**Normal Response Code**: 200 |
|
104 |
|
|
105 |
**Error Response Codes**: |
|
106 |
|
|
107 |
====== ============================ |
|
108 |
Status Description |
|
109 |
====== ============================ |
|
110 |
401 Unauthorized (Missing token) |
|
111 |
500 Internal Server Error |
|
112 |
====== ============================ |
|
113 |
|
|
114 |
**Example Successful Response**: |
|
115 |
|
|
116 |
.. code-block:: javascript |
|
117 |
|
|
118 |
{ |
|
119 |
"1a6165d0-5020-4b6d-a4ad-83476632a584": { |
|
120 |
"system": { |
|
121 |
"cyclades.ram": { |
|
122 |
"available": 536870912, |
|
123 |
"limit": 1073741824, |
|
124 |
"used": 536870912 |
|
125 |
}, |
|
126 |
"cyclades.vm": { |
|
127 |
"available": 0, |
|
128 |
"limit": 2, |
|
129 |
"used": 2 |
|
130 |
} |
|
131 |
}, |
|
132 |
"project:1": { |
|
133 |
"cyclades.ram": { |
|
134 |
"available": 0, |
|
135 |
"limit": 2147483648, |
|
136 |
"used": 2147483648 |
|
137 |
}, |
|
138 |
"cyclades.vm": { |
|
139 |
"available": 3, |
|
140 |
"limit": 5, |
|
141 |
"used": 2 |
|
142 |
} |
|
143 |
} |
|
144 |
} |
|
145 |
} |
|
146 |
|
|
92 | 147 |
Commissions |
93 | 148 |
----------- |
94 | 149 |
|
b/snf-astakos-app/astakos/api/quotas.py | ||
---|---|---|
45 | 45 |
from astakos.im.api.user import user_from_token |
46 | 46 |
from astakos.im.api.service import service_from_token |
47 | 47 |
|
48 |
from astakos.im.quotas import get_user_quotas, get_resources |
|
48 |
from astakos.im.quotas import (get_user_quotas, get_resources, |
|
49 |
get_service_quotas) |
|
49 | 50 |
|
50 | 51 |
import astakos.quotaholder.exception as qh_exception |
51 | 52 |
from astakos.quotaholder.callpoint import QuotaholderDjangoDBCallpoint |
... | ... | |
59 | 60 |
return json_response(result) |
60 | 61 |
|
61 | 62 |
|
63 |
@api.api_method(http_method='GET', token_required=True, user_required=False) |
|
64 |
@service_from_token |
|
65 |
def service_quotas(request): |
|
66 |
result = get_service_quotas(request.service_instance) |
|
67 |
return json_response(result) |
|
68 |
|
|
69 |
|
|
62 | 70 |
@api.api_method(http_method='GET', token_required=False, user_required=False) |
63 | 71 |
def resources(request): |
64 | 72 |
result = get_resources() |
b/snf-astakos-app/astakos/api/urls.py | ||
---|---|---|
36 | 36 |
urlpatterns = patterns( |
37 | 37 |
'astakos.api.quotas', |
38 | 38 |
url(r'^quotas/?$', 'quotas'), |
39 |
url(r'^service_quotas/?$', 'service_quotas'), |
|
39 | 40 |
url(r'^resources/?$', 'resources'), |
40 | 41 |
url(r'^commissions/?$', 'commissions'), |
41 | 42 |
url(r'^commissions/action/?$', 'resolve_pending_commissions'), |
b/snf-astakos-app/astakos/im/quotas.py | ||
---|---|---|
95 | 95 |
return quotas[user.uuid] |
96 | 96 |
|
97 | 97 |
|
98 |
def get_service_quotas(service): |
|
99 |
resources = Resource.objects.filter(service=service.name) |
|
100 |
resource_names = [r.name for r in resources] |
|
101 |
counters = qh.get_resource_quota(resource_names) |
|
102 |
return transform_data(counters) |
|
103 |
|
|
104 |
|
|
98 | 105 |
def set_user_quota(quotas): |
99 | 106 |
qh.set_holder_quota(quotas) |
100 | 107 |
|
b/snf-astakos-app/astakos/quotaholder/callpoint.py | ||
---|---|---|
69 | 69 |
|
70 | 70 |
return quotas |
71 | 71 |
|
72 |
def get_resource_quota(self, resources, sources=None): |
|
73 |
holdings = Holding.objects.filter(resource__in=resources) |
|
74 |
|
|
75 |
if sources is not None: |
|
76 |
holdings = holdings.filter(source__in=sources) |
|
77 |
|
|
78 |
quotas = {} |
|
79 |
for holding in holdings: |
|
80 |
key = (holding.holder, holding.source, holding.resource) |
|
81 |
value = (holding.limit, holding.imported_min, holding.imported_max) |
|
82 |
quotas[key] = value |
|
83 |
|
|
84 |
return quotas |
|
85 |
|
|
72 | 86 |
def _get_holdings_for_update(self, holding_keys): |
73 | 87 |
holding_keys = sorted(holding_keys) |
74 | 88 |
holdings = {} |
Also available in: Unified diff