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
This commit is contained in:
parent
3367e88944
commit
9873c1c46b
@ -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``
|
||||
-------------------------------
|
||||
|
||||
|
@ -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))]
|
||||
|
@ -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):
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
<form id="tail_length" action="{% url 'horizon:project:instances:console' instance.id %}" class="form-inline pull-right">
|
||||
<label for="tail_length_select">{% trans "Log Length" %}</label>
|
||||
<input class="span1" type="text" name="length" value="35" />
|
||||
<input class="span1" type="text" name="length" value="{{ log_length }}" />
|
||||
<button class="btn btn-default btn-sm btn-primary" type="submit">{% trans "Go" %}</button>
|
||||
{% url 'horizon:project:instances:console' instance.id as console_url %}
|
||||
<a class="btn btn-default btn-sm" target="_blank" href="{{ console_url }}">{% trans "View Full Log" %}</a>
|
||||
|
@ -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.")))
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user