Statistics
| Branch: | Tag: | Revision:

root / snf-cyclades-app / synnefo / api / extensions.py @ ece5581b

History | View | Annotate | Download (2.6 kB)

1 6966e8df Christos Stavrakakis
# Copyright 2011-2013 GRNET S.A. All rights reserved.
2 6966e8df Christos Stavrakakis
#
3 6966e8df Christos Stavrakakis
# Redistribution and use in source and binary forms, with or
4 6966e8df Christos Stavrakakis
# without modification, are permitted provided that the following
5 6966e8df Christos Stavrakakis
# conditions are met:
6 6966e8df Christos Stavrakakis
#
7 6966e8df Christos Stavrakakis
#   1. Redistributions of source code must retain the above
8 6966e8df Christos Stavrakakis
#      copyright notice, this list of conditions and the following
9 6966e8df Christos Stavrakakis
#      disclaimer.
10 6966e8df Christos Stavrakakis
#
11 6966e8df Christos Stavrakakis
#   2. Redistributions in binary form must reproduce the above
12 6966e8df Christos Stavrakakis
#      copyright notice, this list of conditions and the following
13 6966e8df Christos Stavrakakis
#      disclaimer in the documentation and/or other materials
14 6966e8df Christos Stavrakakis
#      provided with the distribution.
15 6966e8df Christos Stavrakakis
#
16 6966e8df Christos Stavrakakis
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 6966e8df Christos Stavrakakis
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 6966e8df Christos Stavrakakis
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 6966e8df Christos Stavrakakis
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 6966e8df Christos Stavrakakis
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 6966e8df Christos Stavrakakis
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 6966e8df Christos Stavrakakis
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 6966e8df Christos Stavrakakis
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 6966e8df Christos Stavrakakis
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 6966e8df Christos Stavrakakis
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 6966e8df Christos Stavrakakis
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 6966e8df Christos Stavrakakis
# POSSIBILITY OF SUCH DAMAGE.
28 6966e8df Christos Stavrakakis
#
29 6966e8df Christos Stavrakakis
# The views and conclusions contained in the software and
30 6966e8df Christos Stavrakakis
# documentation are those of the authors and should not be
31 6966e8df Christos Stavrakakis
# interpreted as representing official policies, either expressed
32 6966e8df Christos Stavrakakis
# or implied, of GRNET S.A.
33 6966e8df Christos Stavrakakis
34 6966e8df Christos Stavrakakis
from django.conf.urls.defaults import patterns
35 6966e8df Christos Stavrakakis
from django.http import HttpResponse
36 6966e8df Christos Stavrakakis
from django.utils import simplejson as json
37 6966e8df Christos Stavrakakis
from snf_django.lib import api
38 6966e8df Christos Stavrakakis
39 6966e8df Christos Stavrakakis
40 6966e8df Christos Stavrakakis
from logging import getLogger
41 6966e8df Christos Stavrakakis
log = getLogger(__name__)
42 6966e8df Christos Stavrakakis
43 6966e8df Christos Stavrakakis
urlpatterns = patterns(
44 6966e8df Christos Stavrakakis
    'synnefo.api.extensions',
45 6966e8df Christos Stavrakakis
    (r'^(?:/|.json|.xml)?$', 'demux'),
46 fe7b1d66 Christos Stavrakakis
    (r'^/([\w-]+)(?:/|.json|.xml)?$', 'demux_extension'),
47 6966e8df Christos Stavrakakis
)
48 6966e8df Christos Stavrakakis
49 6966e8df Christos Stavrakakis
50 6966e8df Christos Stavrakakis
def demux(request):
51 6966e8df Christos Stavrakakis
    if request.method == 'GET':
52 6966e8df Christos Stavrakakis
        return list_extensions(request)
53 6966e8df Christos Stavrakakis
    else:
54 6966e8df Christos Stavrakakis
        return api.api_method_not_allowed(request)
55 6966e8df Christos Stavrakakis
56 6966e8df Christos Stavrakakis
57 fe7b1d66 Christos Stavrakakis
def demux_extension(request, extension_alias):
58 fe7b1d66 Christos Stavrakakis
    if request.method == 'GET':
59 fe7b1d66 Christos Stavrakakis
        return get_extension(request, extension_alias)
60 fe7b1d66 Christos Stavrakakis
    else:
61 fe7b1d66 Christos Stavrakakis
        return api.api_method_not_allowed(request)
62 fe7b1d66 Christos Stavrakakis
63 fe7b1d66 Christos Stavrakakis
64 6966e8df Christos Stavrakakis
@api.api_method(http_method='GET', user_required=True, logger=log)
65 6966e8df Christos Stavrakakis
def list_extensions(request, detail=False):
66 6966e8df Christos Stavrakakis
    # Temporary return empty list. This will return the SNF: extension.
67 6966e8df Christos Stavrakakis
    data = json.dumps(dict(extensions=[]))
68 6966e8df Christos Stavrakakis
    return HttpResponse(data, status=200)
69 fe7b1d66 Christos Stavrakakis
70 fe7b1d66 Christos Stavrakakis
71 fe7b1d66 Christos Stavrakakis
@api.api_method(http_method='GET', user_required=True, logger=log)
72 fe7b1d66 Christos Stavrakakis
def get_extension(request, extension_alias):
73 fe7b1d66 Christos Stavrakakis
    return HttpResponse(status=404)