Statistics
| Branch: | Tag: | Revision:

root / api / urls.py @ a31ff6cb

History | View | Annotate | Download (2.6 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
virtual_machine_group_handler = Resource(VirtualMachineGroupHandler, auth)
27

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

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

    
54
version_handler = Resource(VersionHandler)
55

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