From a58db8503b17ec8efc5e07658a5da0e66e2b0345 Mon Sep 17 00:00:00 2001 From: John Postlethwait Date: Tue, 3 Apr 2012 14:03:04 -0700 Subject: [PATCH] Adding a user configurable log length. Fixes bug #963596 Change-Id: I730e8c23c3387121aeb9033937bb300d5102fc33 --- .../instances_and_volumes/instances/tabs.py | 4 ++- .../instances_and_volumes/instances/tests.py | 5 +-- .../instances_and_volumes/instances/views.py | 5 ++- .../instances/_detail_log.html | 22 +++++++++---- .../instances/detail.html | 27 +++++++--------- horizon/static/horizon/js/horizon.js | 32 +++++++++++++++++++ .../static/dashboard/css/style.css | 5 +++ 7 files changed, 74 insertions(+), 26 deletions(-) diff --git a/horizon/dashboards/nova/instances_and_volumes/instances/tabs.py b/horizon/dashboards/nova/instances_and_volumes/instances/tabs.py index 5c33fed787..94df3c5bf7 100644 --- a/horizon/dashboards/nova/instances_and_volumes/instances/tabs.py +++ b/horizon/dashboards/nova/instances_and_volumes/instances/tabs.py @@ -40,7 +40,9 @@ class LogTab(tabs.Tab): def get_context_data(self, request): instance = self.tab_group.kwargs['instance'] try: - data = api.server_console_output(request, instance.id) + data = api.server_console_output(request, + instance.id, + tail_length=35) except: data = _('Unable to get log for instance "%s".') % instance.id exceptions.handle(request, ignore=True) diff --git a/horizon/dashboards/nova/instances_and_volumes/instances/tests.py b/horizon/dashboards/nova/instances_and_volumes/instances/tests.py index 4f2fc2e46a..ed0077d20e 100644 --- a/horizon/dashboards/nova/instances_and_volumes/instances/tests.py +++ b/horizon/dashboards/nova/instances_and_volumes/instances/tests.py @@ -206,7 +206,8 @@ class InstanceViewTests(test.TestCase): self.mox.StubOutWithMock(api, 'server_console_output') api.server_console_output(IsA(http.HttpRequest), - server.id).AndReturn(CONSOLE_OUTPUT) + server.id, tail_length=None) \ + .AndReturn(CONSOLE_OUTPUT) self.mox.ReplayAll() url = reverse('horizon:nova:instances_and_volumes:instances:console', @@ -224,7 +225,7 @@ class InstanceViewTests(test.TestCase): self.mox.StubOutWithMock(api, 'server_console_output') exc = nova_exceptions.ClientException(500) api.server_console_output(IsA(http.HttpRequest), - server.id).AndRaise(exc) + server.id, tail_length=None).AndRaise(exc) self.mox.ReplayAll() url = reverse('horizon:nova:instances_and_volumes:instances:console', diff --git a/horizon/dashboards/nova/instances_and_volumes/instances/views.py b/horizon/dashboards/nova/instances_and_volumes/instances/views.py index 79f74b6dc6..d1a564ce87 100644 --- a/horizon/dashboards/nova/instances_and_volumes/instances/views.py +++ b/horizon/dashboards/nova/instances_and_volumes/instances/views.py @@ -43,7 +43,10 @@ LOG = logging.getLogger(__name__) def console(request, instance_id): try: # TODO(jakedahn): clean this up once the api supports tailing. - data = api.server_console_output(request, instance_id) + tail = request.GET.get('length', None) + data = api.server_console_output(request, + instance_id, + tail_length=tail) except: data = _('Unable to get log for instance "%s".') % instance_id exceptions.handle(request, ignore=True) diff --git a/horizon/dashboards/nova/templates/nova/instances_and_volumes/instances/_detail_log.html b/horizon/dashboards/nova/templates/nova/instances_and_volumes/instances/_detail_log.html index ac3a8b7b58..4eba3a0a91 100644 --- a/horizon/dashboards/nova/templates/nova/instances_and_volumes/instances/_detail_log.html +++ b/horizon/dashboards/nova/templates/nova/instances_and_volumes/instances/_detail_log.html @@ -1,9 +1,19 @@ {% load i18n %} +
-

Instance Console Log

-

- {% url horizon:nova:instances_and_volumes:instances:console instance.id as console_url %} - {% trans "View Full Log" %} -

+

Instance Console Log

+

+ {% url horizon:nova:instances_and_volumes:instances:console instance.id as console_url %} + {% trans "View Full Log" %} +

+ +
+ + + +
-
{{ console_log }}
+ +
+  {{ console_log }}
+
diff --git a/horizon/dashboards/nova/templates/nova/instances_and_volumes/instances/detail.html b/horizon/dashboards/nova/templates/nova/instances_and_volumes/instances/detail.html index b2f85ddfb3..410be0a63b 100644 --- a/horizon/dashboards/nova/templates/nova/instances_and_volumes/instances/detail.html +++ b/horizon/dashboards/nova/templates/nova/instances_and_volumes/instances/detail.html @@ -16,21 +16,16 @@ {% block js %} {{ block.super }} - {# FIXME: This JavaScript should live with the rest of the JS #} - + evt.preventDefault(); + }); + + setInterval(function() { + horizon.instances.getConsoleLog($("#tail_length"), false); + }, 10000); + {% endblock %} diff --git a/horizon/static/horizon/js/horizon.js b/horizon/static/horizon/js/horizon.js index 0fec7d86a6..8cf2be56c6 100644 --- a/horizon/static/horizon/js/horizon.js +++ b/horizon/static/horizon/js/horizon.js @@ -269,6 +269,34 @@ var Horizon = function() { } }; + horizon.instances = { + user_decided_length: false, + + getConsoleLog: function(form_element, via_user_submit) { + if(this.user_decided_length) { + var data = $(form_element).serialize(); + } else { + var data = "length=35"; + } + + $.ajax({ + url: $(form_element).attr('action'), + data: data, + method: 'get', + success: function(response_body) { + $('pre.logs').html(response_body); + }, + error: function(response) { + if(via_user_submit) { + horizon.clearErrorMessages(); + + horizon.alert('error', 'There was a problem communicating with the server, please try again.'); + } + } + }); + } + }; + horizon.alert = function (type, message) { var template = horizon.templates.compiled_templates["#alert_message_template"], params = {"type": type, @@ -277,6 +305,10 @@ var Horizon = function() { return $(template.render(params)).prependTo("#main_content .messages"); }; + horizon.clearErrorMessages = function() { + $('#main_content .messages .alert.alert-error').remove() + }; + /* Queued ajax handling for Horizon. * * Note: The number of concurrent AJAX connections hanlded in the queue diff --git a/openstack_dashboard/static/dashboard/css/style.css b/openstack_dashboard/static/dashboard/css/style.css index ac800547f5..e57c6dd395 100644 --- a/openstack_dashboard/static/dashboard/css/style.css +++ b/openstack_dashboard/static/dashboard/css/style.css @@ -1001,3 +1001,8 @@ iframe { padding: 10px; display: block; } + +label.log-length { + line-height: 28px; + margin-right: 10px; +}