mirror of
https://github.com/ansible/awx.git
synced 2026-02-01 01:28:09 -03:30
Changed celery task reference to store the task_id only, capture traceback if task run fails, update admin to be able to run launch jobs.
This commit is contained in:
@@ -15,7 +15,13 @@
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
from django.conf.urls import *
|
||||
from django.contrib import admin
|
||||
from django.contrib.admin.util import unquote
|
||||
from django.contrib import messages
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from lib.main.models import *
|
||||
|
||||
@@ -146,17 +152,55 @@ class PermissionAdmin(admin.ModelAdmin):
|
||||
|
||||
class LaunchJobAdmin(admin.ModelAdmin):
|
||||
|
||||
list_display = ('name', 'description', 'active')
|
||||
list_display = ('name', 'description', 'active', 'get_start_link_display',
|
||||
'get_statuses_link_display')
|
||||
fieldsets = (
|
||||
(None, {'fields': ('name', 'active', 'created_by', 'description')}),
|
||||
(None, {'fields': ('name', 'active', 'created_by', 'description',
|
||||
'get_start_link_display', 'get_statuses_link_display')}),
|
||||
(_('Job Parameters'), {'fields': ('inventory', 'project', 'credential',
|
||||
'user', 'job_type')}),
|
||||
(_('Tags'), {'fields': ('tags',)}),
|
||||
(_('Audit Trail'), {'fields': ('creation_date', 'audit_trail',)}),
|
||||
)
|
||||
readonly_fields = ('creation_date', 'audit_trail')
|
||||
readonly_fields = ('creation_date', 'audit_trail', 'get_start_link_display',
|
||||
'get_statuses_link_display')
|
||||
filter_horizontal = ('tags',)
|
||||
|
||||
def get_start_link_display(self, obj):
|
||||
info = self.model._meta.app_label, self.model._meta.module_name
|
||||
start_url = reverse('admin:%s_%s_start' % info, args=(obj.pk,),
|
||||
current_app=self.admin_site.name)
|
||||
return '<a href="%s">Run Job</a>' % start_url
|
||||
get_start_link_display.short_description = _('Run')
|
||||
get_start_link_display.allow_tags = True
|
||||
|
||||
def get_statuses_link_display(self, obj):
|
||||
info = LaunchJobStatus._meta.app_label, LaunchJobStatus._meta.module_name
|
||||
statuses_url = reverse('admin:%s_%s_changelist' % info,
|
||||
current_app=self.admin_site.name)
|
||||
statuses_url += '?launch_job__id__exact=%d' % obj.pk
|
||||
return '<a href="%s">View Logs</a>' % statuses_url
|
||||
get_statuses_link_display.short_description = _('Logs')
|
||||
get_statuses_link_display.allow_tags = True
|
||||
|
||||
def get_urls(self):
|
||||
info = self.model._meta.app_label, self.model._meta.module_name
|
||||
urls = super(LaunchJobAdmin, self).get_urls()
|
||||
return patterns('',
|
||||
url(r'^(.+)/start/$',
|
||||
self.admin_site.admin_view(self.start_job_view),
|
||||
name='%s_%s_start' % info),
|
||||
) + urls
|
||||
|
||||
def start_job_view(self, request, object_id):
|
||||
obj = self.get_object(request, unquote(object_id))
|
||||
ljs = obj.start()
|
||||
info = ljs._meta.app_label, ljs._meta.module_name
|
||||
status_url = reverse('admin:%s_%s_change' % info, args=(ljs.pk,),
|
||||
current_app=self.admin_site.name)
|
||||
messages.success(request, '%s has been started.' % ljs)
|
||||
return HttpResponseRedirect(status_url)
|
||||
|
||||
class LaunchJobStatusEventInline(admin.StackedInline):
|
||||
|
||||
model = LaunchJobStatusEvent
|
||||
@@ -165,12 +209,23 @@ class LaunchJobStatusEventInline(admin.StackedInline):
|
||||
fields = ('created', 'event', 'event_data')
|
||||
readonly_fields = ('created', 'event', 'event_data')
|
||||
|
||||
def has_add_permission(self, request):
|
||||
return False
|
||||
|
||||
class LaunchJobStatusAdmin(admin.ModelAdmin):
|
||||
|
||||
list_display = ('name', 'description', 'active', 'status')
|
||||
list_display = ('name', 'launch_job', 'status')
|
||||
fields = ('name', 'launch_job', 'status', 'result_stdout', 'result_stderr',
|
||||
'result_traceback', 'celery_task_id', 'tags', 'created_by')
|
||||
readonly_fields = ('name', 'description', 'status', 'launch_job',
|
||||
'result_stdout', 'result_stderr', 'result_traceback',
|
||||
'celery_task_id', 'created_by', 'tags', 'audit_trail', 'active')
|
||||
filter_horizontal = ('tags',)
|
||||
inlines = [LaunchJobStatusEventInline]
|
||||
|
||||
def has_add_permission(self, request):
|
||||
return False
|
||||
|
||||
# FIXME: Add the rest of the models...
|
||||
|
||||
admin.site.register(Organization, OrganizationAdmin)
|
||||
|
||||
Reference in New Issue
Block a user