Revision b3fd98ae snf-cyclades-app/synnefo/api/versions.py
b/snf-cyclades-app/synnefo/api/versions.py | ||
---|---|---|
31 | 31 |
# interpreted as representing official policies, either expressed |
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 |
from datetime import datetime |
|
35 | 34 |
from logging import getLogger |
36 | 35 |
|
37 | 36 |
from django.conf import settings |
... | ... | |
39 | 38 |
from django.template.loader import render_to_string |
40 | 39 |
from django.utils import simplejson as json |
41 | 40 |
|
42 |
from synnefo.api.util import api_method, isoformat
|
|
41 |
from snf_django.lib import api
|
|
43 | 42 |
|
44 | 43 |
|
45 | 44 |
log = getLogger('synnefo.api') |
... | ... | |
60 | 59 |
VERSIONS = [VERSION_1_1] |
61 | 60 |
|
62 | 61 |
MEDIA_TYPES = [ |
63 |
{'base': 'application/xml', 'type': 'application/vnd.openstack.compute-v1.1+xml'}, |
|
64 |
{'base': 'application/json', 'type': 'application/vnd.openstack.compute-v1.1+json'} |
|
62 |
{'base': 'application/xml', |
|
63 |
'type': 'application/vnd.openstack.compute-v1.1+xml'}, |
|
64 |
{'base': 'application/json', |
|
65 |
'type': 'application/vnd.openstack.compute-v1.1+json'} |
|
65 | 66 |
] |
66 | 67 |
|
67 | 68 |
DESCRIBED_BY = [ |
68 |
{ |
|
69 |
'rel' : 'describedby', |
|
70 |
'type' : 'application/pdf', |
|
71 |
'href' : 'http://docs.rackspacecloud.com/servers/api/v1.1/cs-devguide-20110125.pdf' |
|
72 |
}, |
|
73 |
{ |
|
74 |
'rel' : 'describedby', |
|
75 |
'type' : 'application/vnd.sun.wadl+xml', |
|
76 |
'href' : 'http://docs.rackspacecloud.com/servers/api/v1.1/application.wadl' |
|
77 |
} |
|
69 |
{'rel': 'describedby', |
|
70 |
'type': 'application/pdf', |
|
71 |
'href': "http://docs.rackspacecloud.com/servers/api/" |
|
72 |
"v1.1/cs-devguide-20110125.pdf"}, |
|
73 |
{'rel': 'describedby', |
|
74 |
'type': 'application/vnd.sun.wadl+xml', |
|
75 |
'href': "http://docs.rackspacecloud.com/servers/api/v1.1/" |
|
76 |
"application.wadl"} |
|
78 | 77 |
] |
79 | 78 |
|
80 |
@api_method('GET', atom_allowed=True) |
|
79 |
|
|
80 |
@api.api_method(http_method='GET', user_required=True, logger=log) |
|
81 | 81 |
def versions_list(request): |
82 | 82 |
# Normal Response Codes: 200, 203 |
83 | 83 |
# Error Response Codes: 400, 413, 500, 503 |
84 | 84 |
|
85 | 85 |
if request.serialization == 'xml': |
86 | 86 |
data = render_to_string('versions_list.xml', {'versions': VERSIONS}) |
87 |
elif request.serialization == 'atom': |
|
88 |
now = isoformat(datetime.now()) |
|
89 |
data = render_to_string('versions_list.atom', {'now': now,'versions': VERSIONS}) |
|
90 | 87 |
else: |
91 | 88 |
data = json.dumps({'versions': {'values': VERSIONS}}) |
92 | 89 |
|
93 | 90 |
return HttpResponse(data) |
94 | 91 |
|
95 |
@api_method('GET', atom_allowed=True) |
|
92 |
|
|
93 |
@api.api_method('GET', user_required=True, logger=log) |
|
96 | 94 |
def version_details(request, api_version): |
97 | 95 |
# Normal Response Codes: 200, 203 |
98 | 96 |
# Error Response Codes: computeFault (400, 500), |
... | ... | |
109 | 107 |
if request.serialization == 'xml': |
110 | 108 |
version['media_types'] = MEDIA_TYPES |
111 | 109 |
data = render_to_string('version_details.xml', {'version': version}) |
112 |
elif request.serialization == 'atom': |
|
113 |
version['media_types'] = MEDIA_TYPES |
|
114 |
now = isoformat(datetime.now()) |
|
115 |
data = render_to_string('version_details.atom', {'now': now,'version': version}) |
|
116 | 110 |
else: |
117 | 111 |
version['media-types'] = MEDIA_TYPES |
118 | 112 |
data = json.dumps({'version': version}) |
Also available in: Unified diff