Statistics
| Branch: | Tag: | Revision:

root / docs / quota-api-guide.rst @ c8618788

History | View | Annotate | Download (13.3 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 case of ``NoCapacityError``, ``limit`` and ``usage`` are
262
also included; in case of ``NoQuantityError`` (that is, when attempting to
263
release a value greater than what is registered), the ``available`` quantity
264
is provided.
265

    
266
**Example Successful Response**:
267

    
268
.. code-block:: javascript
269

    
270
  {
271
      "serial": 57
272
  }
273

    
274
**Example Failure Response**:
275

    
276
.. code-block:: javascript
277

    
278
  {
279
      "overLimit": {
280
          "message": "a human-readable error message",
281
          "code": 413,
282
          "data": {
283
              "provision": {
284
                  "holder": "c02f315b-7d84-45bc-a383-552a3f97d2ad",
285
                  "source": "system",
286
                  "resource": "cyclades.vm",
287
                  "quantity": 1
288
              },
289
              "name": "NoCapacityError",
290
              "limit": 2,
291
              "usage": 2
292
          }
293
      }
294
  }
295

    
296
Get Pending Commissions
297
.......................
298

    
299
**GET** /astakos/api/commissions
300

    
301
====================  ============================
302
Request Header Name   Value
303
====================  ============================
304
X-Auth-Token          Service authentication token
305
====================  ============================
306

    
307
The service can query the quota system for all *pending* commissions
308
initiated by itself, that is, all commissions that have been issued
309
but not accepted or rejected (see below). The call responds with the list
310
of the serials of all pending commissions.
311

    
312
**Response Codes**:
313

    
314
======  ============================
315
Status  Description
316
======  ============================
317
200     Success
318
401     Unauthorized (Missing token)
319
500     Internal Server Error
320
======  ============================
321

    
322
**Example Successful Response**:
323

    
324
.. code-block:: javascript
325

    
326
  [<serial>, ...]
327

    
328
Get the Description of a Commission
329
...................................
330

    
331
**GET** /astakos/api/commissions/<serial>
332

    
333
====================  ============================
334
Request Header Name   Value
335
====================  ============================
336
X-Auth-Token          Service authentication token
337
====================  ============================
338

    
339
This call allows a service to retrieve information for a pending commission.
340

    
341
**Response Codes**:
342

    
343
======  ============================
344
Status  Description
345
======  ============================
346
200     Success
347
401     Unauthorized (Missing token)
348
404     Commission Not Found
349
500     Internal Server Error
350
======  ============================
351

    
352
**Example Successful Response**:
353

    
354
.. code-block:: javascript
355

    
356
  {
357
      "serial": 57,
358
      "issue_time": "2013-04-08T10:19:15.0373",
359
      "name": "an optional description",
360
      "provisions": [
361
          {
362
              "holder": "c02f315b-7d84-45bc-a383-552a3f97d2ad",
363
              "source": "system",
364
              "resource": "cyclades.vm",
365
              "quantity": 1
366
          },
367
          {
368
              "holder": "c02f315b-7d84-45bc-a383-552a3f97d2ad",
369
              "source": "system",
370
              "resource": "cyclades.ram",
371
              "quantity": 536870912
372
          }
373
      ]
374
  }
375

    
376
Accept or Reject a Commission
377
.............................
378

    
379
**POST** /astakos/api/commissions/<serial>/action
380

    
381
====================  ============================
382
Request Header Name   Value
383
====================  ============================
384
X-Auth-Token          Service authentication token
385
====================  ============================
386

    
387
With this call a service can *accept* or *reject* a pending commission, that
388
is, finalize the registered usage or undo commission issued.
389
The system guarantees that a commission can always be later accepted
390
or rejected, no matter what other commissions have taken place in the meantime.
391

    
392
To accept, include in the request body a field indexed by ``accept``;
393
likewise for rejecting.
394

    
395
**Example Requests**:
396

    
397
.. code-block:: javascript
398

    
399
  {
400
      "accept": ""
401
  }
402

    
403
  {
404
      "reject": ""
405
  }
406

    
407
**Response Codes**:
408

    
409
======  ============================
410
Status  Description
411
======  ============================
412
200     Success
413
401     Unauthorized (Missing token)
414
404     Commission Not Found
415
500     Internal Server Error
416
======  ============================
417

    
418
Accept or Reject Multiple Commissions
419
.....................................
420

    
421
**POST** /astakos/api/commissions/action
422

    
423
====================  ============================
424
Request Header Name   Value
425
====================  ============================
426
X-Auth-Token          Service authentication token
427
====================  ============================
428

    
429
This allows to accept and reject multiple commissions in the same time,
430
by including the list of serials to accept and the list of serials to reject
431
in the request body.
432

    
433
**Example Request**:
434

    
435
.. code-block:: javascript
436

    
437
  {
438
      "accept": [56, 57],
439
      "reject": [56, 58, 59]
440
  }
441

    
442
The response includes the list of serials that have been actually
443
``accepted`` or ``rejected`` and those that ``failed``. The latter
444
consists of a list of pairs. The first element of the pair is a serial
445
that failed, the second element is a cloudFault describing the failure.
446

    
447
**Response Codes**:
448

    
449
======  ============================
450
Status  Description
451
======  ============================
452
200     Success
453
401     Unauthorized (Missing token)
454
500     Internal Server Error
455
======  ============================
456

    
457
**Example Successful Response**:
458

    
459
.. code-block:: javascript
460

    
461
  { "accepted": [57],
462
    "rejected": [59],
463
    "failed": [
464
        [56, {
465
                 "badRequest": {
466
                     "message": "cannot both accept and reject serial 56",
467
                     "code": 400
468
                     }
469
                 }
470
        ],
471
        [58, {
472
                 "itemNotFound": {
473
                     "message": "serial 58 does not exist",
474
                     "code": 404
475
                     }
476
                 }
477
        ]
478
    ]
479
  }