root / api / faults.py @ ed66d976
History | View | Annotate | Download (2.2 kB)
1 | 00b4f1be | Faidon Liambotis | # vim: ts=4 sts=4 et ai sw=4 fileencoding=utf-8
|
---|---|---|---|
2 | 00b4f1be | Faidon Liambotis | #
|
3 | 00b4f1be | Faidon Liambotis | # Copyright © 2010 Greek Research and Technology Network
|
4 | 00b4f1be | Faidon Liambotis | #
|
5 | 00b4f1be | Faidon Liambotis | |
6 | 00b4f1be | Faidon Liambotis | from django.http import HttpResponse |
7 | 00b4f1be | Faidon Liambotis | from django.utils import simplejson |
8 | 00b4f1be | Faidon Liambotis | |
9 | 00b4f1be | Faidon Liambotis | class _fault_factory(object): |
10 | 00b4f1be | Faidon Liambotis | """
|
11 | 00b4f1be | Faidon Liambotis | Openstack API Faults factory
|
12 | 00b4f1be | Faidon Liambotis | """
|
13 | 00b4f1be | Faidon Liambotis | |
14 | 00b4f1be | Faidon Liambotis | faults = { |
15 | 00b4f1be | Faidon Liambotis | 'serviceUnavailable': {
|
16 | 00b4f1be | Faidon Liambotis | 'code': 503, |
17 | 00b4f1be | Faidon Liambotis | 'message': 'Service Unavailable', |
18 | 00b4f1be | Faidon Liambotis | }, |
19 | 00b4f1be | Faidon Liambotis | 'unauthorized': {
|
20 | 00b4f1be | Faidon Liambotis | 'code': 401, |
21 | 00b4f1be | Faidon Liambotis | 'message': 'Unauthorized', |
22 | 00b4f1be | Faidon Liambotis | }, |
23 | 00b4f1be | Faidon Liambotis | 'badRequest': {
|
24 | 00b4f1be | Faidon Liambotis | 'code': 400, |
25 | 00b4f1be | Faidon Liambotis | 'message': 'Bad request', |
26 | 00b4f1be | Faidon Liambotis | }, |
27 | 00b4f1be | Faidon Liambotis | 'overLimit': {
|
28 | 00b4f1be | Faidon Liambotis | 'code': 413, |
29 | 00b4f1be | Faidon Liambotis | 'message': 'Overlimit', |
30 | 00b4f1be | Faidon Liambotis | }, |
31 | 00b4f1be | Faidon Liambotis | 'badMediaType': {
|
32 | 00b4f1be | Faidon Liambotis | 'code': 415, |
33 | 00b4f1be | Faidon Liambotis | 'message': 'Bad media type', |
34 | 00b4f1be | Faidon Liambotis | }, |
35 | 00b4f1be | Faidon Liambotis | 'badMethod': {
|
36 | 00b4f1be | Faidon Liambotis | 'code': 405, |
37 | 00b4f1be | Faidon Liambotis | 'message': 'Bad method', |
38 | 00b4f1be | Faidon Liambotis | }, |
39 | 00b4f1be | Faidon Liambotis | 'itemNotFound': {
|
40 | 00b4f1be | Faidon Liambotis | 'code': 404, |
41 | 00b4f1be | Faidon Liambotis | 'message': 'Not Found', |
42 | 00b4f1be | Faidon Liambotis | }, |
43 | 00b4f1be | Faidon Liambotis | 'buildInProgress': {
|
44 | 00b4f1be | Faidon Liambotis | 'code': 409, |
45 | 00b4f1be | Faidon Liambotis | 'message': 'Build in progress', |
46 | 00b4f1be | Faidon Liambotis | }, |
47 | 00b4f1be | Faidon Liambotis | 'serverCapacityUnavailable': {
|
48 | 00b4f1be | Faidon Liambotis | 'code': 503, |
49 | 00b4f1be | Faidon Liambotis | 'message': 'Server capacity unavailable', |
50 | 00b4f1be | Faidon Liambotis | }, |
51 | 00b4f1be | Faidon Liambotis | 'backupOrResizeInProgress': {
|
52 | 00b4f1be | Faidon Liambotis | 'code': 409, |
53 | 00b4f1be | Faidon Liambotis | 'message': 'Backup or resize in progress', |
54 | 00b4f1be | Faidon Liambotis | }, |
55 | 00b4f1be | Faidon Liambotis | 'resizeNotAllowed': {
|
56 | 00b4f1be | Faidon Liambotis | 'code': 403, |
57 | 00b4f1be | Faidon Liambotis | 'message': 'Resize not allowed', |
58 | 00b4f1be | Faidon Liambotis | }, |
59 | 00b4f1be | Faidon Liambotis | 'notImplemented': {
|
60 | 00b4f1be | Faidon Liambotis | 'code': 501, |
61 | 00b4f1be | Faidon Liambotis | 'message': 'Not Implemented', |
62 | 00b4f1be | Faidon Liambotis | }, |
63 | 00b4f1be | Faidon Liambotis | } |
64 | 00b4f1be | Faidon Liambotis | |
65 | 00b4f1be | Faidon Liambotis | def __getattr__(self, attr): |
66 | 00b4f1be | Faidon Liambotis | try:
|
67 | 00b4f1be | Faidon Liambotis | m = self.faults.get(attr)
|
68 | 00b4f1be | Faidon Liambotis | except TypeError: |
69 | 00b4f1be | Faidon Liambotis | raise AttributeError(attr) |
70 | 00b4f1be | Faidon Liambotis | |
71 | 00b4f1be | Faidon Liambotis | # XXX: piston > 0.2.2 does the serialization for us, but be compatible
|
72 | 00b4f1be | Faidon Liambotis | message = simplejson.dumps({ attr: m }, ensure_ascii=False, indent=4) |
73 | 00b4f1be | Faidon Liambotis | code = m['code']
|
74 | 00b4f1be | Faidon Liambotis | |
75 | 00b4f1be | Faidon Liambotis | return HttpResponse(message, status=code)
|
76 | 00b4f1be | Faidon Liambotis | |
77 | 00b4f1be | Faidon Liambotis | |
78 | 00b4f1be | Faidon Liambotis | fault = _fault_factory() |
79 | 00b4f1be | Faidon Liambotis | noContent = HttpResponse(status=204)
|
80 | 00b4f1be | Faidon Liambotis | accepted = HttpResponse(status=202)
|
81 | ed66d976 | Faidon Liambotis | created = HttpResponse(status=201) |