Statistics
| Branch: | Tag: | Revision:

root / api / urls.py @ b65b1281

History | View | Annotate | Download (4 kB)

1 00b4f1be Faidon Liambotis
# vim: ts=4 sts=4 et ai sw=4 fileencoding=utf-8
2 00b4f1be Faidon Liambotis
#
3 9071888e Constantinos Venetsanopoulos
# 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 a31ff6cb Markos Gogoulos
virtual_machine_group_handler = Resource(VirtualMachineGroupHandler, auth)
27 9071888e Constantinos Venetsanopoulos
disk_handler = Resource(DiskHandler, auth)
28 00b4f1be Faidon Liambotis
29 c3e8f508 Faidon Liambotis
def url_with_format(regex, *args, **kwargs):
30 c3e8f508 Faidon Liambotis
    if regex[-1] == '$':
31 c3e8f508 Faidon Liambotis
        regex = regex[:-1]
32 c3e8f508 Faidon Liambotis
    regex = regex + r'(\.(?P<emitter_format>json|xml))?$'
33 c3e8f508 Faidon Liambotis
    return url(regex, *args, **kwargs)
34 c3e8f508 Faidon Liambotis
35 9071888e Constantinos Venetsanopoulos
# The Rackspace v1.0 Cloud Servers API
36 00b4f1be Faidon Liambotis
v10patterns = patterns('',
37 c3e8f508 Faidon Liambotis
    url_with_format(r'^limits$', limit_handler),
38 c3e8f508 Faidon Liambotis
    url_with_format(r'^servers$', server_handler),
39 c3e8f508 Faidon Liambotis
    url_with_format(r'^servers/(?P<id>[^/]+)$', server_handler),
40 c3e8f508 Faidon Liambotis
    url_with_format(r'^servers/(?P<id>[^/]+)/action$', server_actions_handler),
41 c3e8f508 Faidon Liambotis
    url_with_format(r'^servers/(?P<id>[^/]+)/ips$', server_address_handler),
42 c3e8f508 Faidon Liambotis
    url_with_format(r'^servers/(?P<id>[^/]+)/ips/private$', server_address_handler),
43 c3e8f508 Faidon Liambotis
    url_with_format(r'^servers/(?P<id>[^/]+)/ips/public/(?P<address>[^/]+)$', server_address_handler),
44 c3e8f508 Faidon Liambotis
    url_with_format(r'^servers/(?P<id>[^/]+)/backup_schedule', server_backup_handler),
45 c3e8f508 Faidon Liambotis
    url_with_format(r'^flavors$', flavor_handler),
46 c3e8f508 Faidon Liambotis
    url_with_format(r'^flavors/(?P<id>[^/]+)$', flavor_handler),
47 c3e8f508 Faidon Liambotis
    url_with_format(r'^images$', image_handler),
48 c3e8f508 Faidon Liambotis
    url_with_format(r'^images/(?P<id>[^/]+)$', image_handler),
49 c3e8f508 Faidon Liambotis
    url_with_format(r'^shared_ip_groups$', shared_ip_group_handler),
50 c3e8f508 Faidon Liambotis
    url_with_format(r'^shared_ip_groups/(?P<id>[^/]+)$', shared_ip_group_handler),
51 d7710a26 Markos Gogoulos
    url_with_format(r'^groups$', virtual_machine_group_handler),
52 d7710a26 Markos Gogoulos
    url_with_format(r'^groups/(?P<id>[^/]+)$', virtual_machine_group_handler),
53 c3e8f508 Faidon Liambotis
    url(r'^.+', notFound), # catch-all
54 00b4f1be Faidon Liambotis
)
55 00b4f1be Faidon Liambotis
56 9071888e Constantinos Venetsanopoulos
# The Rackspace v1.0 Cloud Servers API + GRNET v1.0 extension
57 9071888e Constantinos Venetsanopoulos
v10grnet10patterns = patterns('',
58 9071888e Constantinos Venetsanopoulos
    url_with_format(r'^limits$', limit_handler),
59 9071888e Constantinos Venetsanopoulos
    url_with_format(r'^servers$', server_handler),
60 9071888e Constantinos Venetsanopoulos
    url_with_format(r'^servers/(?P<id>[^/]+)$', server_handler),
61 9071888e Constantinos Venetsanopoulos
    url_with_format(r'^servers/(?P<id>[^/]+)/action$', server_actions_handler),
62 9071888e Constantinos Venetsanopoulos
    url_with_format(r'^servers/(?P<id>[^/]+)/ips$', server_address_handler),
63 9071888e Constantinos Venetsanopoulos
    url_with_format(r'^servers/(?P<id>[^/]+)/ips/private$', server_address_handler),
64 9071888e Constantinos Venetsanopoulos
    url_with_format(r'^servers/(?P<id>[^/]+)/ips/public/(?P<address>[^/]+)$', server_address_handler),
65 9071888e Constantinos Venetsanopoulos
    url_with_format(r'^servers/(?P<id>[^/]+)/backup_schedule', server_backup_handler),
66 9071888e Constantinos Venetsanopoulos
    url_with_format(r'^flavors$', flavor_handler),
67 9071888e Constantinos Venetsanopoulos
    url_with_format(r'^flavors/(?P<id>[^/]+)$', flavor_handler),
68 9071888e Constantinos Venetsanopoulos
    url_with_format(r'^images$', image_handler),
69 9071888e Constantinos Venetsanopoulos
    url_with_format(r'^images/(?P<id>[^/]+)$', image_handler),
70 9071888e Constantinos Venetsanopoulos
    url_with_format(r'^shared_ip_groups$', shared_ip_group_handler),
71 9071888e Constantinos Venetsanopoulos
    url_with_format(r'^shared_ip_groups/(?P<id>[^/]+)$', shared_ip_group_handler),
72 9071888e Constantinos Venetsanopoulos
    url_with_format(r'^groups$', virtual_machine_group_handler),
73 9071888e Constantinos Venetsanopoulos
    url_with_format(r'^disks$', disk_handler),
74 9071888e Constantinos Venetsanopoulos
    url_with_format(r'^disks/(?P<id>[^/]+)$', disk_handler),
75 9071888e Constantinos Venetsanopoulos
    url_with_format(r'^groups/(?P<id>[^/]+)$', virtual_machine_group_handler),
76 9071888e Constantinos Venetsanopoulos
    url(r'^.+', notFound), # catch-all
77 9071888e Constantinos Venetsanopoulos
)
78 9071888e Constantinos Venetsanopoulos
79 00b4f1be Faidon Liambotis
version_handler = Resource(VersionHandler)
80 00b4f1be Faidon Liambotis
81 00b4f1be Faidon Liambotis
urlpatterns = patterns('',
82 c3e8f508 Faidon Liambotis
    url_with_format(r'^(?P<number>[^/]+)/?$', version_handler),
83 04accb0f Faidon Liambotis
    url(r'^$', version_handler),
84 c3e8f508 Faidon Liambotis
    url(r'^v1.0/', include(v10patterns)),
85 9071888e Constantinos Venetsanopoulos
    url(r'^v1.0grnet1/', include(v10grnet10patterns)),
86 c3e8f508 Faidon Liambotis
    url(r'^.+', notFound), # catch-all
87 00b4f1be Faidon Liambotis
)