Statistics
| Branch: | Tag: | Revision:

root / api / urls.py @ 5c812d1b

History | View | Annotate | Download (2.3 kB)

1
# vim: ts=4 sts=4 et ai sw=4 fileencoding=utf-8
2
#
3
# Copyright © 2010 Greek Research and Technology Network
4
#
5

    
6
from django.conf.urls.defaults import *
7
from synnefo.helpers import url_with_format
8
from synnefo.api.resource import Resource
9
from synnefo.api.handlers import *
10
from synnefo.api.authentication import TokenAuthentication
11
from synnefo.api.faults import fault
12

    
13
auth = TokenAuthentication()
14

    
15
def notFound(request):
16
    return fault.itemNotFound.response
17

    
18
limit_handler = Resource(LimitHandler, auth)
19
server_handler = Resource(ServerHandler, auth)
20
server_address_handler = Resource(ServerAddressHandler, auth)
21
server_actions_handler = Resource(ServerActionHandler, auth)
22
server_backup_handler = Resource(ServerBackupHandler, auth)
23
flavor_handler = Resource(FlavorHandler, auth)
24
image_handler = Resource(ImageHandler, auth)
25
shared_ip_group_handler = Resource(SharedIPGroupHandler, auth)
26

    
27
def url_with_format(regex, *args, **kwargs):
28
    if regex[-1] == '$':
29
        regex = regex[:-1]
30
    regex = regex + r'(\.(?P<emitter_format>json|xml))?$'
31
    return url(regex, *args, **kwargs)
32

    
33
v10patterns = patterns('',
34
    url_with_format(r'^limits$', limit_handler),
35
    url_with_format(r'^servers$', server_handler),
36
    url_with_format(r'^servers/(?P<id>[^/]+)$', server_handler),
37
    url_with_format(r'^servers/(?P<id>[^/]+)/action$', server_actions_handler),
38
    url_with_format(r'^servers/(?P<id>[^/]+)/ips$', server_address_handler),
39
    url_with_format(r'^servers/(?P<id>[^/]+)/ips/private$', server_address_handler),
40
    url_with_format(r'^servers/(?P<id>[^/]+)/ips/public/(?P<address>[^/]+)$', server_address_handler),
41
    url_with_format(r'^servers/(?P<id>[^/]+)/backup_schedule', server_backup_handler),
42
    url_with_format(r'^flavors$', flavor_handler),
43
    url_with_format(r'^flavors/(?P<id>[^/]+)$', flavor_handler),
44
    url_with_format(r'^images$', image_handler),
45
    url_with_format(r'^images/(?P<id>[^/]+)$', image_handler),
46
    url_with_format(r'^shared_ip_groups$', shared_ip_group_handler),
47
    url_with_format(r'^shared_ip_groups/(?P<id>[^/]+)$', shared_ip_group_handler),
48
    url(r'^.+', notFound), # catch-all
49
)
50

    
51
version_handler = Resource(VersionHandler)
52

    
53
urlpatterns = patterns('',
54
    url_with_format(r'^(?P<number>[^/]+)/?$', version_handler),
55
    url(r'^$', version_handler),
56
    url(r'^v1.0/', include(v10patterns)),
57
    url(r'^.+', notFound), # catch-all
58
)