1 # Copyright (C) 2010 Oregon State University et al.
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 from django
.template
.context
import RequestContext
21 from django
.contrib
.auth
.decorators
import login_required
22 from django
.http
import HttpResponse
23 from django
.shortcuts
import get_object_or_404
, render_to_response
25 from ganeti_web
.models
import Job
, Cluster
, VirtualMachine
, Node
26 from ganeti_web
.views
import render_403
27 from django
.utils
.translation
import ugettext
as _
30 def status(request
, cluster_slug
, job_id
):
32 returns the raw info of a job
34 job
= get_object_or_404(Job
, cluster__slug
=cluster_slug
, job_id
=job_id
)
35 return HttpResponse(json
.dumps(job
.info
), mimetype
='application/json')
39 def detail(request
, cluster_slug
, job_id
):
40 job
= get_object_or_404(Job
, cluster__slug
=cluster_slug
, job_id
=job_id
)
43 cluster_admin
= True if user
.is_superuser
else user
.has_perm('admin', job
.cluster
)
45 return render_to_response("job/detail.html",{
47 'cluster_admin':cluster_admin
48 } ,context_instance
=RequestContext(request
))
52 def clear(request
, cluster_slug
, job_id
):
54 Clear a single failed job error message
58 cluster
= get_object_or_404(Cluster
, slug
=cluster_slug
)
59 job
= get_object_or_404(Job
, cluster__slug
=cluster_slug
, job_id
=job_id
)
62 # if not a superuser, check permissions on the object itself
63 cluster_admin
= user
.is_superuser
or user
.has_perm('admin', cluster
)
66 if isinstance(obj
, (Cluster
, Node
)):
67 return render_403(request
, _("You do not have sufficient privileges"))
68 elif isinstance(obj
, (VirtualMachine
,)):
69 # object is a virtual machine, check perms on VM and on Cluster
70 if not (obj
.owner_id
== user
.get_profile().pk \
71 or user
.has_perm('admin', obj
) \
72 or user
.has_perm('admin', obj
.cluster
)):
73 return render_403(request
, _("You do not have sufficient privileges"))
77 Job
.objects
.filter(pk
=job
.pk
).update(cleared
=True)
79 # clear the job from the object, but only if it is the last job. It's
80 # possible another job was started after this job, and the error message
81 # just wasn't cleared.
83 # XXX object could be none, in which case we dont need to clear its last_job
85 ObjectModel
= obj
.__class
__
86 ObjectModel
.objects
.filter(pk
=job
.object_id
, last_job
=job
) \
87 .update(last_job
=None, ignore_cache
=False)
89 return HttpResponse('1', mimetype
='application/json')