urls.py 3.35 KB
Newer Older
Giorgos Verigakis's avatar
Giorgos Verigakis committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Copyright 2011 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
#
#   1. Redistributions of source code must retain the above
#      copyright notice, this list of conditions and the following
#      disclaimer.
#
#   2. Redistributions in binary form must reproduce the above
#      copyright notice, this list of conditions and the following
#      disclaimer in the documentation and/or other materials
#      provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.

34
from django.conf.urls.defaults import patterns, include
Giorgos Verigakis's avatar
Giorgos Verigakis committed
35
from django.http import HttpResponseNotAllowed
Giorgos Verigakis's avatar
Giorgos Verigakis committed
36

Giorgos Verigakis's avatar
Giorgos Verigakis committed
37
38
39
40
41
from synnefo.plankton import views


def demux(request):
    if request.method == 'GET':
42
        return views.list_images(request)
Giorgos Verigakis's avatar
Giorgos Verigakis committed
43
44
45
46
47
    elif request.method == 'POST':
        return views.add_image(request)
    else:
        return HttpResponseNotAllowed(['GET', 'POST'])

48

Giorgos Verigakis's avatar
Giorgos Verigakis committed
49
def demux_image(request, image_id):
50
    if request.method == "GET":
Giorgos Verigakis's avatar
Giorgos Verigakis committed
51
        return views.get_image(request, image_id)
52
    elif request.method == "HEAD":
Giorgos Verigakis's avatar
Giorgos Verigakis committed
53
        return views.get_image_meta(request, image_id)
54
    elif request.method == "PUT":
Giorgos Verigakis's avatar
Giorgos Verigakis committed
55
        return views.update_image(request, image_id)
56
57
    elif request.method == "DELETE":
        return views.delete_image(request, image_id)
Giorgos Verigakis's avatar
Giorgos Verigakis committed
58
    else:
59
        return HttpResponseNotAllowed(["GET", "HEAD", "PUT", "DELETE"])
Giorgos Verigakis's avatar
Giorgos Verigakis committed
60

61

Giorgos Verigakis's avatar
Giorgos Verigakis committed
62
63
64
65
66
67
68
69
def demux_image_members(request, image_id):
    if request.method == 'GET':
        return views.list_image_members(request, image_id)
    elif request.method == 'PUT':
        return views.update_image_members(request, image_id)
    else:
        return HttpResponseNotAllowed(['GET', 'PUT'])

70

Giorgos Verigakis's avatar
Giorgos Verigakis committed
71
72
73
74
75
76
77
78
79
def demux_members(request, image_id, member):
    if request.method == 'DELETE':
        return views.remove_image_member(request, image_id, member)
    elif request.method == 'PUT':
        return views.add_image_member(request, image_id, member)
    else:
        return HttpResponseNotAllowed(['DELETE', 'PUT'])


80
image_v1_patterns = patterns(
Christos Stavrakakis's avatar
Christos Stavrakakis committed
81
    '',
Giorgos Verigakis's avatar
Giorgos Verigakis committed
82
    (r'^images/$', demux),
83
    (r'^images/detail$', views.list_images, {'detail': True}),
Giorgos Verigakis's avatar
Giorgos Verigakis committed
84
85
    (r'^images/([\w-]+)$', demux_image),
    (r'^images/([\w-]+)/members$', demux_image_members),
86
    (r'^images/([\w-]+)/members/([\w@._-]+)$', demux_members),
87
88
89
90
91
    (r'^shared-images/([\w@._-]+)$', views.list_shared_images),
)

urlpatterns = patterns(
    '',
92
    (r'^v1.0/', include(image_v1_patterns)),
Giorgos Verigakis's avatar
Giorgos Verigakis committed
93
)