Statistics
| Branch: | Tag: | Revision:

root / api / urls.py @ 2cc9d3a5

History | View | Annotate | Download (2.3 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.conf.urls.defaults import *
7 5c812d1b Faidon Liambotis
from synnefo.helpers import url_with_format
8 5c812d1b Faidon Liambotis
from synnefo.api.resource import Resource
9 00b4f1be Faidon Liambotis
from synnefo.api.handlers import *
10 00b4f1be Faidon Liambotis
from synnefo.api.authentication import TokenAuthentication
11 0be1a55e Faidon Liambotis
from synnefo.api.faults import fault
12 00b4f1be Faidon Liambotis
13 00b4f1be Faidon Liambotis
auth = TokenAuthentication()
14 00b4f1be Faidon Liambotis
15 0be1a55e Faidon Liambotis
def notFound(request):
16 0be1a55e Faidon Liambotis
    return fault.itemNotFound.response
17 0be1a55e Faidon Liambotis
18 beb79c95 Faidon Liambotis
limit_handler = Resource(LimitHandler, auth)
19 00b4f1be Faidon Liambotis
server_handler = Resource(ServerHandler, auth)
20 00b4f1be Faidon Liambotis
server_address_handler = Resource(ServerAddressHandler, auth)
21 00b4f1be Faidon Liambotis
server_actions_handler = Resource(ServerActionHandler, auth)
22 c99adc90 Faidon Liambotis
server_backup_handler = Resource(ServerBackupHandler, auth)
23 427a9220 Faidon Liambotis
flavor_handler = Resource(FlavorHandler, auth)
24 dcc6a862 Faidon Liambotis
image_handler = Resource(ImageHandler, auth)
25 ed66d976 Faidon Liambotis
shared_ip_group_handler = Resource(SharedIPGroupHandler, auth)
26 00b4f1be Faidon Liambotis
27 c3e8f508 Faidon Liambotis
def url_with_format(regex, *args, **kwargs):
28 c3e8f508 Faidon Liambotis
    if regex[-1] == '$':
29 c3e8f508 Faidon Liambotis
        regex = regex[:-1]
30 c3e8f508 Faidon Liambotis
    regex = regex + r'(\.(?P<emitter_format>json|xml))?$'
31 c3e8f508 Faidon Liambotis
    return url(regex, *args, **kwargs)
32 c3e8f508 Faidon Liambotis
33 00b4f1be Faidon Liambotis
v10patterns = patterns('',
34 c3e8f508 Faidon Liambotis
    url_with_format(r'^limits$', limit_handler),
35 c3e8f508 Faidon Liambotis
    url_with_format(r'^servers$', server_handler),
36 c3e8f508 Faidon Liambotis
    url_with_format(r'^servers/(?P<id>[^/]+)$', server_handler),
37 c3e8f508 Faidon Liambotis
    url_with_format(r'^servers/(?P<id>[^/]+)/action$', server_actions_handler),
38 c3e8f508 Faidon Liambotis
    url_with_format(r'^servers/(?P<id>[^/]+)/ips$', server_address_handler),
39 c3e8f508 Faidon Liambotis
    url_with_format(r'^servers/(?P<id>[^/]+)/ips/private$', server_address_handler),
40 c3e8f508 Faidon Liambotis
    url_with_format(r'^servers/(?P<id>[^/]+)/ips/public/(?P<address>[^/]+)$', server_address_handler),
41 c3e8f508 Faidon Liambotis
    url_with_format(r'^servers/(?P<id>[^/]+)/backup_schedule', server_backup_handler),
42 c3e8f508 Faidon Liambotis
    url_with_format(r'^flavors$', flavor_handler),
43 c3e8f508 Faidon Liambotis
    url_with_format(r'^flavors/(?P<id>[^/]+)$', flavor_handler),
44 c3e8f508 Faidon Liambotis
    url_with_format(r'^images$', image_handler),
45 c3e8f508 Faidon Liambotis
    url_with_format(r'^images/(?P<id>[^/]+)$', image_handler),
46 c3e8f508 Faidon Liambotis
    url_with_format(r'^shared_ip_groups$', shared_ip_group_handler),
47 c3e8f508 Faidon Liambotis
    url_with_format(r'^shared_ip_groups/(?P<id>[^/]+)$', shared_ip_group_handler),
48 c3e8f508 Faidon Liambotis
    url(r'^.+', notFound), # catch-all
49 00b4f1be Faidon Liambotis
)
50 00b4f1be Faidon Liambotis
51 00b4f1be Faidon Liambotis
version_handler = Resource(VersionHandler)
52 00b4f1be Faidon Liambotis
53 00b4f1be Faidon Liambotis
urlpatterns = patterns('',
54 c3e8f508 Faidon Liambotis
    url_with_format(r'^(?P<number>[^/]+)/?$', version_handler),
55 04accb0f Faidon Liambotis
    url(r'^$', version_handler),
56 c3e8f508 Faidon Liambotis
    url(r'^v1.0/', include(v10patterns)),
57 c3e8f508 Faidon Liambotis
    url(r'^.+', notFound), # catch-all
58 00b4f1be Faidon Liambotis
)