Added orchestration logging

This commit is contained in:
Marc Aymerich 2016-07-19 22:45:04 +00:00
parent df99f8d745
commit aa5935ba34
4 changed files with 21 additions and 5 deletions

View File

@ -29,6 +29,8 @@ def retry_backend(modeladmin, request, queryset):
else: else:
logs = Operation.execute(operations) logs = Operation.execute(operations)
message_user(request, logs) message_user(request, logs)
for backendlog in queryset:
modeladmin.log_change(request, backendlog, 'Retried')
return return
opts = modeladmin.model._meta opts = modeladmin.model._meta
display_objects = [] display_objects = []
@ -100,11 +102,14 @@ def orchestrate(modeladmin, request, queryset):
result.append(operation) result.append(operation)
operations = result operations = result
if not operations: if not operations:
messages.warning(request, _("No operations.")) messages.warning(request, _("No related operations."))
return
if request.POST.get('post') == 'generic_confirmation': if request.POST.get('post') == 'generic_confirmation':
logs = Operation.execute(operations) logs = Operation.execute(operations)
message_user(request, logs) message_user(request, logs)
for obj in queryset:
modeladmin.log_change(request, obj, 'Orchestrated')
return return
opts = modeladmin.model._meta opts = modeladmin.model._meta
@ -126,3 +131,4 @@ def orchestrate(modeladmin, request, queryset):
'obj': get_object_from_url(modeladmin, request), 'obj': get_object_from_url(modeladmin, request),
} }
return render(request, 'admin/orchestration/orchestrate.html', context) return render(request, 'admin/orchestration/orchestrate.html', context)
orchestrate.help_text = _("Execute all related operations on the server(s)")

View File

@ -40,6 +40,7 @@ class RouteAdmin(ExtendedModelAdmin):
add_fields = ('backend', 'host', 'match', 'async', 'is_active') add_fields = ('backend', 'host', 'match', 'async', 'is_active')
change_form = RouteForm change_form = RouteForm
actions = (orchestrate,) actions = (orchestrate,)
change_view_actions = actions
BACKEND_HELP_TEXT = helpers.get_backends_help_text(ServiceBackend.get_backends()) BACKEND_HELP_TEXT = helpers.get_backends_help_text(ServiceBackend.get_backends())
DEFAULT_MATCH = { DEFAULT_MATCH = {
@ -171,10 +172,11 @@ class BackendLogAdmin(ChangeViewActionsMixin, admin.ModelAdmin):
return False return False
class ServerAdmin(admin.ModelAdmin): class ServerAdmin(ExtendedModelAdmin):
list_display = ('name', 'address', 'os', 'display_ping', 'display_uptime') list_display = ('name', 'address', 'os', 'display_ping', 'display_uptime')
list_filter = ('os',) list_filter = ('os',)
actions = (orchestrate,) actions = (orchestrate,)
change_view_actions = actions
def display_ping(self, instance): def display_ping(self, instance):
return self._remote_state[instance.pk][0] return self._remote_state[instance.pk][0]

View File

@ -4,11 +4,10 @@
{% block display_objects %} {% block display_objects %}
<ul> <ul>
{% for backend, operations in display_objects.items %} {% for backend, operations in display_objects.items %}
<li>{{ backend }} <li>Backend: {{ backend }}
<ul> <ul>
{% for operation in operations %} {% for operation in operations %}
<li><a href="{{ operation.instance|admin_url }}">{{ operation.instance }}</a>: <li>{{ operation.instance|admin_link }} @ {% for route in operation.routes %}{{ route.host|admin_link }}</a>{% if not forloop.last %},{% endif %} {% endfor %}</li>
into {% for route in operation.routes %}<a href="{{ route.host|admin_url }}">{{ route.host }}</a>{% if not forloop.last %},{% endif %} {% endfor %}</li>
{% endfor %} {% endfor %}
</ul> </ul>
</li> </li>

View File

@ -96,6 +96,15 @@ def admin_url(obj):
return change_url(obj) return change_url(obj)
@register.filter
def admin_link(obj):
try:
url = change_url(obj)
except NoReverseMatch:
return str(obj)
return mark_safe('<a href="%s">%s</a>' % (url, obj))
@register.filter @register.filter
def isactive(obj): def isactive(obj):
return getattr(obj, 'is_active', True) return getattr(obj, 'is_active', True)