1 # Copyright (C) 2010 Oregon State University et al.
2 # Copyright (C) 2010 Greek Research and Technology Network
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 from django
.conf
.urls
.defaults
import patterns
, url
20 from haystack
.views
import SearchView
21 from django
.contrib
.auth
.decorators
import login_required
23 from forms
.autocomplete_search_form
import autocomplete_search_form
25 from ganeti_web
.forms
.virtual_machine
import vm_wizard
26 from ganeti_web
.views
.cluster
import (ClusterDetailView
, ClusterListView
,
27 ClusterVMListView
, ClusterJobListView
)
28 from ganeti_web
.views
.general
import AboutView
29 from ganeti_web
.views
.jobs
import JobDetailView
30 from ganeti_web
.views
.node
import (NodeDetailView
, NodePrimaryListView
,
31 NodeSecondaryListView
)
32 from ganeti_web
.views
.virtual_machine
import VMDeleteView
, VMListView
33 from ganeti_web
.views
.vm_template
import (TemplateFromVMInstanceView
,
34 VMInstanceFromTemplateView
,
37 cluster_slug
= '(?P<cluster_slug>[-_A-Za-z0-9]+)'
38 cluster
= 'cluster/%s' % cluster_slug
40 primary_node
= 'primary_node/(?P<primary_node>.+)'
41 secondary_node
= 'secondary_node/(?P<secondary_node>.+)'
43 instance
= '(?P<instance>[^/]+)'
44 host
= '(?P<host>[^/]+)'
46 template
= '(?P<template>[^/]+)'
49 urlpatterns
= patterns(
50 'ganeti_web.views.general',
52 url(r
'^$', 'overview', name
="index"),
55 url(r
'^overview/?$', 'overview', name
="overview"),
56 url(r
'^used_resources/?$', 'used_resources', name
="used_resources"),
58 url(r
'^error/clear/(?P<pk>\d+)/?$', 'clear_ganeti_error',
61 url(r
'clusters/errors', 'get_errors', name
="cluster-errors"),
63 url(r
'^about/?$', AboutView
.as_view(), name
="about"),
67 # Users - overridden from users app to use custom templates
68 urlpatterns
+= patterns(
69 'muddle_users.views.user',
70 url(r
'^accounts/profile/?', 'user_profile', name
='profile',
71 kwargs
={'template': 'ganeti/users/profile.html'}),
75 urlpatterns
+= patterns(
76 'ganeti_web.views.users',
78 url(r
'^user/(?P<user_id>\d+)/key/?$',
82 url(r
'^keys/get/$', 'key_get', name
="key-get"),
84 url(r
'^keys/get/(?P<key_id>\d+)/?$', 'key_get', name
="key-get"),
86 url(r
'^keys/save/$', 'key_save', name
="key-save"),
88 url(r
'^keys/save/(?P<key_id>\d+)/?$', 'key_save', name
="key-save"),
90 url(r
'^keys/delete/(?P<key_id>\d+)/?$', 'key_delete', name
="key-delete"),
94 urlpatterns
+= patterns(
95 'ganeti_web.views.general',
96 url(r
'^keys/(?P<api_key>\w+)/$', 'ssh_keys', name
="key-list"),
100 urlpatterns
+= patterns(
101 'ganeti_web.views.cluster',
103 url(r
'^clusters/?$', ClusterListView
.as_view(), name
="cluster-list"),
105 url(r
'^cluster/add/?$', 'edit', name
="cluster-create"),
107 url(r
'^%s/?$' % cluster
, ClusterDetailView
.as_view(),
108 name
="cluster-detail"),
110 url(r
'^%s/edit/?$' % cluster
, 'edit', name
="cluster-edit"),
112 url(r
'^%s/refresh/?$' % cluster
, 'refresh', name
='cluster-refresh'),
114 url(r
'^%s/redistribute-config/?$' % cluster
, 'redistribute_config',
115 name
="cluster-redistribute-config"),
117 url(r
'^%s/users/?$' % cluster
, 'users', name
="cluster-users"),
119 url(r
'^%s/virtual_machines/?$' % cluster
, ClusterVMListView
.as_view(),
120 name
="cluster-vm-list"),
122 url(r
'^%s/nodes/?$' % cluster
, 'nodes', name
="cluster-nodes"),
124 url(r
'^%s/quota/(?P<user_id>\d+)?/?$' % cluster
, 'quota',
125 name
="cluster-quota"),
127 url(r
'^%s/permissions/?$' % cluster
, 'permissions',
128 name
="cluster-permissions"),
130 url(r
'^%s/permissions/user/(?P<user_id>\d+)/?$' % cluster
, 'permissions',
131 name
="cluster-permissions-user"),
133 url(r
'^%s/permissions/group/(?P<group_id>\d+)/?$' % cluster
, 'permissions',
134 name
="cluster-permissions-group"),
136 url(r
'^(?P<id>\d+)/jobs/status/?$', "job_status",
137 name
="cluster-job-status"),
139 url(r
'^%s/keys/(?P<api_key>\w+)/?$' % cluster
, "ssh_keys",
140 name
="cluster-keys"),
142 url(r
'^%s/object_log/?$' % cluster
,
144 name
="cluster-object_log"),
146 url(r
'%s/jobs/?$' % cluster
, ClusterJobListView
.as_view(),
147 name
="cluster-job-list"),
152 node_prefix
= 'cluster/%s/node/%s' % (cluster_slug
, host
)
153 urlpatterns
+= patterns(
154 'ganeti_web.views.node',
156 url(r
'^%s/?$' % node_prefix
, NodeDetailView
.as_view(), name
="node-detail"),
158 url(r
'^node/(?P<id>\d+)/jobs/status/?$', "job_status",
159 name
="node-job-status"),
161 url(r
'^%s/primary/?$' % node_prefix
, NodePrimaryListView
.as_view(),
162 name
="node-primary-vms"),
164 url(r
'^%s/secondary/?$' % node_prefix
, NodeSecondaryListView
.as_view(),
165 name
="node-secondary-vms"),
167 url(r
'^%s/object_log/?$' % node_prefix
, 'object_log',
168 name
="node-object_log"),
171 url(r
'^%s/role/?$' % node_prefix
, 'role', name
="node-role"),
172 url(r
'^%s/migrate/?$' % node_prefix
, 'migrate', name
="node-migrate"),
173 url(r
'^%s/evacuate/?$' % node_prefix
, 'evacuate', name
="node-evacuate"),
177 urlpatterns
+= patterns(
178 "ganeti_web.forms.virtual_machine",
180 vm_wizard(initial_dict
={0: {'choices': [u
'hostname']}}),
181 name
="instance-create"),
185 vm_prefix
= '%s/%s' % (cluster
, instance
)
186 urlpatterns
+= patterns(
187 'ganeti_web.views.virtual_machine',
189 url(r
'^vms/$', VMListView
.as_view(), name
="virtualmachine-list"),
191 url(r
'^%s/?$' % vm_prefix
, 'detail', name
="instance-detail"),
193 url(r
'^vm/(?P<id>\d+)/jobs/status/?$', 'job_status',
194 name
="instance-job-status"),
196 url(r
'^%s/users/?$' % vm_prefix
, 'users', name
="vm-users"),
198 url(r
'^%s/permissions/?$' % vm_prefix
, 'permissions',
199 name
="vm-permissions"),
201 url(r
'^%s/permissions/user/(?P<user_id>\d+)/?$' % vm_prefix
, 'permissions',
202 name
="vm-permissions-user"),
204 url(r
'^%s/permissions/group/(?P<group_id>\d+)/?$' % vm_prefix
,
205 'permissions', name
="vm-permissions-user"),
207 url(r
'^%s/vnc/?$' % vm_prefix
, 'novnc', name
="instance-vnc"),
209 url(r
'^%s/vnc/popout/?$' % vm_prefix
, 'novnc',
210 {'template': 'ganeti/virtual_machine/vnc_popout.html'},
211 name
="instance-vnc-popout"),
213 url(r
'^%s/vnc_proxy/?$' % vm_prefix
, 'vnc_proxy',
214 name
="instance-vnc-proxy"),
216 url(r
'^%s/shutdown/?$' % vm_prefix
, 'shutdown', name
="instance-shutdown"),
218 url(r
'^%s/shutdown-now/?$' % vm_prefix
, 'shutdown_now',
219 name
="instance-shutdown-now"),
221 url(r
'^%s/startup/?$' % vm_prefix
, 'startup', name
="instance-startup"),
223 url(r
'^%s/reboot/?$' % vm_prefix
, 'reboot', name
="instance-reboot"),
225 url(r
'^%s/migrate/?$' % vm_prefix
, 'migrate', name
="instance-migrate"),
227 url(r
'^%s/replace_disks/?$' % vm_prefix
, 'replace_disks',
228 name
="instance-replace-disks"),
230 url(r
"^%s/delete/?$" % vm_prefix
, VMDeleteView
.as_view(),
231 name
="instance-delete"),
233 url(r
"^%s/reinstall/?$" % vm_prefix
, "reinstall",
234 name
="instance-reinstall"),
236 url(r
"^%s/edit/?$" % vm_prefix
, "modify", name
="instance-modify"),
238 url(r
'^%s/edit/confirm/?$' % vm_prefix
, "modify_confirm",
239 name
="instance-modify-confirm"),
241 url(r
"^%s/rename/?$" % vm_prefix
, "rename", name
="instance-rename"),
243 url(r
"^%s/reparent/?$" % vm_prefix
, "reparent", name
="instance-reparent"),
245 url(r
'^%s/keys/(?P<api_key>\w+)/?$' % vm_prefix
, "ssh_keys",
246 name
="instance-keys"),
248 url(r
'^%s/object_log/?$' % vm_prefix
, 'object_log', name
="vm-object_log"),
251 # VirtualMachineTemplates
252 template_prefix
= '%s/template/%s' % (cluster
, template
)
253 urlpatterns
+= patterns(
254 'ganeti_web.views.vm_template',
256 url(r
'^templates/$', TemplateListView
.as_view(), name
='template-list'),
258 url(r
'^template/create/$',
259 vm_wizard(initial_dict
={0: {'choices': [u
'template_name']}}),
260 name
='template-create'),
262 url(r
'^%s/?$' % template_prefix
, 'detail', name
='template-detail'),
264 url(r
'^%s/delete/?$' % template_prefix
, 'delete', name
='template-delete'),
266 url(r
'^%s/edit/?$' % template_prefix
, vm_wizard(), name
='template-edit'),
268 url(r
'^%s/copy/?$' % template_prefix
, 'copy', name
='template-copy'),
270 url(r
'^%s/vm/?$' % template_prefix
, VMInstanceFromTemplateView
.as_view(),
271 name
='instance-create-from-template'),
273 url(r
'^%s/template/?$' % vm_prefix
, TemplateFromVMInstanceView
.as_view(),
274 name
='template-create-from-instance'),
277 # Virtual Machine Importing
278 urlpatterns
+= patterns(
279 'ganeti_web.views.importing',
281 url(r
'^import/orphans/', 'orphans',
282 name
='import-orphans'),
283 url(r
'^import/missing/', 'missing_ganeti',
284 name
='import-missing'),
285 url(r
'^import/missing_db/', 'missing_db',
286 name
='import-missing_db'),
290 urlpatterns
+= patterns(
291 'ganeti_web.views.importing_nodes',
293 url(r
'^import/node/missing/', 'missing_ganeti',
294 name
='import-nodes-missing'),
296 url(r
'^import/node/missing_db/', 'missing_db',
297 name
='import-nodes-missing_db'),
301 job
= '%s/job/(?P<job_id>\d+)' % cluster
302 urlpatterns
+= patterns(
303 'ganeti_web.views.jobs',
305 url(r
'^%s/status/?' % job
, 'status', name
='job-status'),
307 url(r
'^%s/clear/?' % job
, 'clear', name
='job-clear'),
309 url(r
'^%s/?' % job
, JobDetailView
.as_view(), name
='job-detail'),
313 urlpatterns
+= patterns(
314 'ganeti_web.views.search',
316 url(r
'^search/suggestions.json', 'suggestions', name
='search-suggestions'),
318 url(r
'^search/detail_lookup', 'detail_lookup', name
='search-detail-lookup')
321 urlpatterns
+= patterns(
322 'ganeti_web.views.user_search',
324 url(r
'^search/owners/?$', 'search_owners', name
="owner-search")
327 urlpatterns
+= patterns(
330 login_required(SearchView(form_class
=autocomplete_search_form
)),
334 # The following is used to serve up local static files like images
335 root
= '%s/static' % os
.path
.dirname(os
.path
.realpath(__file__
))
336 urlpatterns
+= patterns(
338 (r
'^static/(?P<path>.*)',
339 'django.views.static.serve',
340 {'document_root': root
})