Statistics
| Branch: | Tag: | Revision:

root / api / urls.py @ c3e8f508

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.api.emitter import Resource, url_with_format
8
from synnefo.api.handlers import *
9
from synnefo.api.authentication import TokenAuthentication
10
from synnefo.api.faults import fault
11

    
12
auth = TokenAuthentication()
13

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

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

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

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

    
50
version_handler = Resource(VersionHandler)
51

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