root / docs / quota-api-guide.rst @ 164e64d5
History | View | Annotate | Download (13.2 kB)
1 |
Resources |
---|---|
2 |
--------- |
3 |
|
4 |
Synnefo services offer *resources* to their users. Each type of resource is |
5 |
registered in Astakos with a unique name. By convention, these names start |
6 |
with the service name, e.g. ``cyclades.vm`` is a resource representing the |
7 |
virtual machines offered by Cyclades. |
8 |
|
9 |
|
10 |
Get Resource List |
11 |
................. |
12 |
|
13 |
**GET** /astakos/api/resources |
14 |
|
15 |
This call returns a description for each resource available in the system. |
16 |
The response consists of a dictionary, indexed by the resource name, which |
17 |
contains a number of attributes for each resource. |
18 |
|
19 |
**Response Codes**: |
20 |
|
21 |
====== ===================== |
22 |
Status Description |
23 |
====== ===================== |
24 |
200 Success |
25 |
500 Internal Server Error |
26 |
====== ===================== |
27 |
|
28 |
**Example Successful Response**: |
29 |
|
30 |
.. code-block:: javascript |
31 |
|
32 |
{ |
33 |
"cyclades.vm": { |
34 |
"unit": null, |
35 |
"description": "Number of virtual machines", |
36 |
"service": "cyclades", |
37 |
"allow_in_projects": true |
38 |
}, |
39 |
"cyclades.ram": { |
40 |
"unit": "bytes", |
41 |
"description": "Virtual machine memory", |
42 |
"service": "cyclades", |
43 |
"allow_in_projects": true |
44 |
} |
45 |
} |
46 |
|
47 |
Quotas |
48 |
------ |
49 |
|
50 |
The system specifies user quotas for each available resource. Resources |
51 |
can be allocated from various sources. By default, users get resources |
52 |
from a single source, called ``system``. For each combination of user, |
53 |
source, and resource, the quota system keeps track of the maximum allowed |
54 |
value (limit) and the current actual usage. The former is controlled by |
55 |
the policy defined in Astakos; the latter is updated by the services that |
56 |
actually implement the resource each time an allocation or deallocation |
57 |
takes place. |
58 |
|
59 |
Get Quotas |
60 |
.......... |
61 |
|
62 |
**GET** /astakos/api/quotas |
63 |
|
64 |
==================== ========================= |
65 |
Request Header Name Value |
66 |
==================== ========================= |
67 |
X-Auth-Token User authentication token |
68 |
==================== ========================= |
69 |
|
70 |
A user can query their resources with this call. It returns in a nested |
71 |
dictionary structure, for each source and resource, three indicators. |
72 |
``limit`` and ``usage`` are as explained above. ``pending`` is related to the |
73 |
commissioning system explained below. Roughly, if ``pending`` is non zero, |
74 |
this indicates that some resource allocation process has started but not |
75 |
finished properly. |
76 |
|
77 |
**Response Codes**: |
78 |
|
79 |
====== ============================ |
80 |
Status Description |
81 |
====== ============================ |
82 |
200 Success |
83 |
401 Unauthorized (Missing token) |
84 |
500 Internal Server Error |
85 |
====== ============================ |
86 |
|
87 |
**Example Successful Response**: |
88 |
|
89 |
.. code-block:: javascript |
90 |
|
91 |
{ |
92 |
"system": { |
93 |
"cyclades.ram": { |
94 |
"usage": 536870912, |
95 |
"limit": 1073741824, |
96 |
"pending": 0 |
97 |
|
98 |
}, |
99 |
"cyclades.vm": { |
100 |
"usage": 2, |
101 |
"limit": 2, |
102 |
"pending": 0 |
103 |
} |
104 |
}, |
105 |
"project:1": { |
106 |
"cyclades.ram": { |
107 |
"usage": 2147483648, |
108 |
"limit": 2147483648, |
109 |
"pending": 0 |
110 |
}, |
111 |
"cyclades.vm": { |
112 |
"usage": 2, |
113 |
"limit": 5, |
114 |
"pending": 1 |
115 |
} |
116 |
} |
117 |
} |
118 |
|
119 |
Get Quotas per Service |
120 |
...................... |
121 |
|
122 |
**GET** /astakos/api/service_quotas |
123 |
|
124 |
==================== ============================ |
125 |
Request Header Name Value |
126 |
==================== ============================ |
127 |
X-Auth-Token Service authentication token |
128 |
==================== ============================ |
129 |
|
130 |
A service can query the quotas for all resources related to it. By default, |
131 |
it returns the quotas for all users, in the format explained above, indexed |
132 |
by the user identifier (UUID). |
133 |
|
134 |
Use the GET parameter ``?user=<uuid>`` to query for a single user. |
135 |
|
136 |
|
137 |
**Response Codes**: |
138 |
|
139 |
====== ============================ |
140 |
Status Description |
141 |
====== ============================ |
142 |
200 Success |
143 |
401 Unauthorized (Missing token) |
144 |
500 Internal Server Error |
145 |
====== ============================ |
146 |
|
147 |
**Example Successful Response**: |
148 |
|
149 |
.. code-block:: javascript |
150 |
|
151 |
{ |
152 |
"1a6165d0-5020-4b6d-a4ad-83476632a584": { |
153 |
"system": { |
154 |
"cyclades.ram": { |
155 |
"usage": 536870912, |
156 |
"limit": 1073741824, |
157 |
"pending": 0 |
158 |
}, |
159 |
"cyclades.vm": { |
160 |
"usage": 2, |
161 |
"limit": 2, |
162 |
"pending": 0 |
163 |
} |
164 |
}, |
165 |
"project:1": { |
166 |
"cyclades.ram": { |
167 |
"usage": 2147483648, |
168 |
"limit": 2147483648, |
169 |
"pending": 0 |
170 |
}, |
171 |
"cyclades.vm": { |
172 |
"usage": 2, |
173 |
"limit": 5, |
174 |
"pending": 1 |
175 |
} |
176 |
} |
177 |
} |
178 |
} |
179 |
|
180 |
Commissions |
181 |
----------- |
182 |
|
183 |
When a resource allocation is about to take place, the service that performs |
184 |
this operation can query the quota system to find out whether the planned |
185 |
allocation would surpass some defined limits. If this is not the case, the |
186 |
quota system registers this pending allocation. Upon the actual allocation |
187 |
of resources, the service informs the quota system to definitely update the |
188 |
usage. |
189 |
|
190 |
Thus, changing quotas consists of two steps: in the first, the service |
191 |
issues a *commission*, indicating which extra resources will be given to |
192 |
particular users; in the second, it finalizes the commission by *accepting* |
193 |
it (or *rejecting*, if the allocation did not actually take place). |
194 |
|
195 |
Issue Commission |
196 |
................ |
197 |
|
198 |
**POST** /astakos/api/commissions |
199 |
|
200 |
==================== ============================ |
201 |
Request Header Name Value |
202 |
==================== ============================ |
203 |
X-Auth-Token Service authentication token |
204 |
==================== ============================ |
205 |
|
206 |
A service issues a commission by providing a list of *provisions*, i.e. |
207 |
the intended allocation for a particular user (in general, ``holder``), |
208 |
``source``, and ``resource`` combination. |
209 |
|
210 |
The request body consists of a JSON dict (as in the example below), which |
211 |
apart from the provisions list can also contain the following optional |
212 |
fields: |
213 |
|
214 |
* ``name``: An optional description of the operation |
215 |
* ``force``: Succeed even if a limit is surpassed |
216 |
* ``auto_accept``: Perform the two steps at once |
217 |
|
218 |
**Example Request**: |
219 |
|
220 |
.. code-block:: javascript |
221 |
|
222 |
{ |
223 |
"force": false, |
224 |
"auto_accept": false, |
225 |
"name": "an optional description", |
226 |
"provisions": [ |
227 |
{ |
228 |
"holder": "c02f315b-7d84-45bc-a383-552a3f97d2ad", |
229 |
"source": "system", |
230 |
"resource": "cyclades.vm", |
231 |
"quantity": 1 |
232 |
}, |
233 |
{ |
234 |
"holder": "c02f315b-7d84-45bc-a383-552a3f97d2ad", |
235 |
"source": "system", |
236 |
"resource": "cyclades.ram", |
237 |
"quantity": 536870912 |
238 |
} |
239 |
] |
240 |
} |
241 |
|
242 |
**Response Codes**: |
243 |
|
244 |
====== ======================================================= |
245 |
Status Description |
246 |
====== ======================================================= |
247 |
201 Success |
248 |
400 Commission failed due to invalid input data |
249 |
401 Unauthorized (Missing token) |
250 |
404 Cannot find one of the target holdings |
251 |
413 A quantity fell below zero in one of the holdings |
252 |
413 A quantity exceeded the capacity in one of the holdings |
253 |
500 Internal Server Error |
254 |
====== ======================================================= |
255 |
|
256 |
On a successful commission, the call responds with a ``serial``, an identifier |
257 |
for the commission. On failure, in the case of ``overLimit`` (413) or |
258 |
``itemNotFound`` (404), the returned cloudFault contains an extra field |
259 |
``data`` with additional application-specific information. It contains at |
260 |
least the ``provision`` that is to blame and the actual ``name`` of the |
261 |
exception raised. In the case of ``overLimit``, ``limit`` and ``usage`` are |
262 |
also included. |
263 |
|
264 |
**Example Successful Response**: |
265 |
|
266 |
.. code-block:: javascript |
267 |
|
268 |
{ |
269 |
"serial": 57 |
270 |
} |
271 |
|
272 |
**Example Failure Response**: |
273 |
|
274 |
.. code-block:: javascript |
275 |
|
276 |
{ |
277 |
"overLimit": { |
278 |
"message": "a human-readable error message", |
279 |
"code": 413, |
280 |
"data": { |
281 |
"provision": { |
282 |
"holder": "c02f315b-7d84-45bc-a383-552a3f97d2ad", |
283 |
"source": "system", |
284 |
"resource": "cyclades.vm", |
285 |
"quantity": 1 |
286 |
}, |
287 |
"name": "NoCapacityError", |
288 |
"limit": 2, |
289 |
"usage": 2 |
290 |
} |
291 |
} |
292 |
} |
293 |
|
294 |
Get Pending Commissions |
295 |
....................... |
296 |
|
297 |
**GET** /astakos/api/commissions |
298 |
|
299 |
==================== ============================ |
300 |
Request Header Name Value |
301 |
==================== ============================ |
302 |
X-Auth-Token Service authentication token |
303 |
==================== ============================ |
304 |
|
305 |
The service can query the quota system for all *pending* commissions |
306 |
initiated by itself, that is, all commissions that have been issued |
307 |
but not accepted or rejected (see below). The call responds with the list |
308 |
of the serials of all pending commissions. |
309 |
|
310 |
**Response Codes**: |
311 |
|
312 |
====== ============================ |
313 |
Status Description |
314 |
====== ============================ |
315 |
200 Success |
316 |
401 Unauthorized (Missing token) |
317 |
500 Internal Server Error |
318 |
====== ============================ |
319 |
|
320 |
**Example Successful Response**: |
321 |
|
322 |
.. code-block:: javascript |
323 |
|
324 |
[<serial>, ...] |
325 |
|
326 |
Get the Description of a Commission |
327 |
................................... |
328 |
|
329 |
**GET** /astakos/api/commissions/<serial> |
330 |
|
331 |
==================== ============================ |
332 |
Request Header Name Value |
333 |
==================== ============================ |
334 |
X-Auth-Token Service authentication token |
335 |
==================== ============================ |
336 |
|
337 |
This call allows a service to retrieve information for a pending commission. |
338 |
|
339 |
**Response Codes**: |
340 |
|
341 |
====== ============================ |
342 |
Status Description |
343 |
====== ============================ |
344 |
200 Success |
345 |
401 Unauthorized (Missing token) |
346 |
404 Commission Not Found |
347 |
500 Internal Server Error |
348 |
====== ============================ |
349 |
|
350 |
**Example Successful Response**: |
351 |
|
352 |
.. code-block:: javascript |
353 |
|
354 |
{ |
355 |
"serial": 57, |
356 |
"issue_time": "2013-04-08T10:19:15.0373+00:00", |
357 |
"name": "an optional description", |
358 |
"provisions": [ |
359 |
{ |
360 |
"holder": "c02f315b-7d84-45bc-a383-552a3f97d2ad", |
361 |
"source": "system", |
362 |
"resource": "cyclades.vm", |
363 |
"quantity": 1 |
364 |
}, |
365 |
{ |
366 |
"holder": "c02f315b-7d84-45bc-a383-552a3f97d2ad", |
367 |
"source": "system", |
368 |
"resource": "cyclades.ram", |
369 |
"quantity": 536870912 |
370 |
} |
371 |
] |
372 |
} |
373 |
|
374 |
Accept or Reject a Commission |
375 |
............................. |
376 |
|
377 |
**POST** /astakos/api/commissions/<serial>/action |
378 |
|
379 |
==================== ============================ |
380 |
Request Header Name Value |
381 |
==================== ============================ |
382 |
X-Auth-Token Service authentication token |
383 |
==================== ============================ |
384 |
|
385 |
With this call a service can *accept* or *reject* a pending commission, that |
386 |
is, finalize the registered usage or undo commission issued. |
387 |
The system guarantees that a commission can always be later accepted |
388 |
or rejected, no matter what other commissions have taken place in the meantime. |
389 |
|
390 |
To accept, include in the request body a field indexed by ``accept``; |
391 |
likewise for rejecting. |
392 |
|
393 |
**Example Requests**: |
394 |
|
395 |
.. code-block:: javascript |
396 |
|
397 |
{ |
398 |
"accept": "" |
399 |
} |
400 |
|
401 |
{ |
402 |
"reject": "" |
403 |
} |
404 |
|
405 |
**Response Codes**: |
406 |
|
407 |
====== ============================ |
408 |
Status Description |
409 |
====== ============================ |
410 |
200 Success |
411 |
401 Unauthorized (Missing token) |
412 |
404 Commission Not Found |
413 |
500 Internal Server Error |
414 |
====== ============================ |
415 |
|
416 |
Accept or Reject Multiple Commissions |
417 |
..................................... |
418 |
|
419 |
**POST** /astakos/api/commissions/action |
420 |
|
421 |
==================== ============================ |
422 |
Request Header Name Value |
423 |
==================== ============================ |
424 |
X-Auth-Token Service authentication token |
425 |
==================== ============================ |
426 |
|
427 |
This allows to accept and reject multiple commissions in the same time, |
428 |
by including the list of serials to accept and the list of serials to reject |
429 |
in the request body. |
430 |
|
431 |
**Example Request**: |
432 |
|
433 |
.. code-block:: javascript |
434 |
|
435 |
{ |
436 |
"accept": [56, 57], |
437 |
"reject": [56, 58, 59] |
438 |
} |
439 |
|
440 |
The response includes the list of serials that have been actually |
441 |
``accepted`` or ``rejected`` and those that ``failed``. The latter |
442 |
consists of a list of pairs. The first element of the pair is a serial |
443 |
that failed, the second element is a cloudFault describing the failure. |
444 |
|
445 |
**Response Codes**: |
446 |
|
447 |
====== ============================ |
448 |
Status Description |
449 |
====== ============================ |
450 |
200 Success |
451 |
401 Unauthorized (Missing token) |
452 |
500 Internal Server Error |
453 |
====== ============================ |
454 |
|
455 |
**Example Successful Response**: |
456 |
|
457 |
.. code-block:: javascript |
458 |
|
459 |
{ "accepted": [57], |
460 |
"rejected": [59], |
461 |
"failed": [ |
462 |
[56, { |
463 |
"badRequest": { |
464 |
"message": "cannot both accept and reject serial 56", |
465 |
"code": 400 |
466 |
} |
467 |
} |
468 |
], |
469 |
[58, { |
470 |
"itemNotFound": { |
471 |
"message": "serial 58 does not exist", |
472 |
"code": 404 |
473 |
} |
474 |
} |
475 |
] |
476 |
] |
477 |
} |