From 9873c1c46b61cead62850fe54ad0d742f13949a1 Mon Sep 17 00:00:00 2001 From: nikunj2512 Date: Fri, 31 Oct 2014 15:31:23 +0530 Subject: [PATCH] Adds ability to set default log length By default if you view the log of an instance in Horizon it is 35 lines. This patch allows user to override the default log length. Change-Id: If7285ce31261f2442d3015161c445dda86240dfa Closes-bug: #1387629 --- doc/source/topics/settings.rst | 12 ++++++++++++ horizon/utils/functions.py | 15 +++++++++++++++ .../dashboards/project/instances/tabs.py | 7 +++++-- .../templates/instances/_detail_log.html | 2 +- .../dashboards/settings/user/forms.py | 7 +++++++ .../dashboards/settings/user/views.py | 3 ++- 6 files changed, 42 insertions(+), 4 deletions(-) diff --git a/doc/source/topics/settings.rst b/doc/source/topics/settings.rst index a3f8633adc..6b9628b2a7 100755 --- a/doc/source/topics/settings.rst +++ b/doc/source/topics/settings.rst @@ -300,6 +300,18 @@ and ``None`` (this latest value is available in version 2014.2(Juno) to allow deactivating the in-browser console). +``INSTANCE_LOG_LENGTH`` +----------------------- + +.. versionadded:: 2015.1(Kilo) + +Default: ``35`` + +This setting enables you to change the default number of lines displayed for +the log of an instance. +Valid value must be a positive integer. + + ``CREATE_INSTANCE_FLAVOR_SORT`` ------------------------------- diff --git a/horizon/utils/functions.py b/horizon/utils/functions.py index 85802f53ed..a74cf0a11d 100644 --- a/horizon/utils/functions.py +++ b/horizon/utils/functions.py @@ -69,6 +69,21 @@ def get_page_size(request, default=20): return page_size +def get_log_length(request, default=35): + session = request.session + cookies = request.COOKIES + try: + log_length = int(session.get( + 'instance_log_length', + cookies.get('instance_log_length', + getattr(settings, + 'INSTANCE_LOG_LENGTH', + default)))) + except ValueError: + log_length = session['instance_log_length'] = int(default) + return log_length + + def natural_sort(attr): return lambda x: [int(s) if s.isdigit() else s for s in re.split(r'(\d+)', getattr(x, attr, x))] diff --git a/openstack_dashboard/dashboards/project/instances/tabs.py b/openstack_dashboard/dashboards/project/instances/tabs.py index c8a773d609..98260e1b90 100644 --- a/openstack_dashboard/dashboards/project/instances/tabs.py +++ b/openstack_dashboard/dashboards/project/instances/tabs.py @@ -17,6 +17,7 @@ from django.utils.translation import ugettext_lazy as _ from horizon import exceptions from horizon import tabs +from horizon.utils import functions as utils from openstack_dashboard.dashboards.project.instances \ import audit_tables as a_tables @@ -43,15 +44,17 @@ class LogTab(tabs.Tab): def get_context_data(self, request): instance = self.tab_group.kwargs['instance'] + log_length = utils.get_log_length(request) try: data = api.nova.server_console_output(request, instance.id, - tail_length=35) + tail_length=log_length) except Exception: data = _('Unable to get log for instance "%s".') % instance.id exceptions.handle(request, ignore=True) return {"instance": instance, - "console_log": data} + "console_log": data, + "log_length": log_length} class ConsoleTab(tabs.Tab): diff --git a/openstack_dashboard/dashboards/project/instances/templates/instances/_detail_log.html b/openstack_dashboard/dashboards/project/instances/templates/instances/_detail_log.html index 686c3b4c21..67cd41dfb5 100644 --- a/openstack_dashboard/dashboards/project/instances/templates/instances/_detail_log.html +++ b/openstack_dashboard/dashboards/project/instances/templates/instances/_detail_log.html @@ -6,7 +6,7 @@
- + {% url 'horizon:project:instances:console' instance.id as console_url %} {% trans "View Full Log" %} diff --git a/openstack_dashboard/dashboards/settings/user/forms.py b/openstack_dashboard/dashboards/settings/user/forms.py index 77613361e3..9bf72e20ea 100644 --- a/openstack_dashboard/dashboards/settings/user/forms.py +++ b/openstack_dashboard/dashboards/settings/user/forms.py @@ -44,6 +44,9 @@ class UserSettingsForm(forms.SelfHandlingForm): 1000), help_text=_("Number of items to show per " "page")) + instance_log_length = forms.IntegerField( + label=_("Log Lines Per Instance"), min_value=1, + help_text=_("Number of log lines to be shown per instance")) @staticmethod def _sorted_zones(): @@ -116,6 +119,10 @@ class UserSettingsForm(forms.SelfHandlingForm): response.set_cookie('horizon_pagesize', data['pagesize'], expires=_one_year()) + request.session['instance_log_length'] = data['instance_log_length'] + response.set_cookie('instance_log_length', + data['instance_log_length'], expires=_one_year()) + with translation.override(lang_code): messages.success(request, encoding.force_text(_("Settings saved."))) diff --git a/openstack_dashboard/dashboards/settings/user/views.py b/openstack_dashboard/dashboards/settings/user/views.py index 37d4742d08..1f6361f0e5 100644 --- a/openstack_dashboard/dashboards/settings/user/views.py +++ b/openstack_dashboard/dashboards/settings/user/views.py @@ -32,7 +32,8 @@ class UserSettingsView(forms.ModalFormView): 'timezone': self.request.session.get( 'django_timezone', self.request.COOKIES.get('django_timezone', 'UTC')), - 'pagesize': utils.get_page_size(self.request)} + 'pagesize': utils.get_page_size(self.request), + 'instance_log_length': utils.get_log_length(self.request)} def form_valid(self, form): return form.handle(self.request, form.cleaned_data)