Adding a user configurable log length.

Fixes bug #963596

Change-Id: I730e8c23c3387121aeb9033937bb300d5102fc33
This commit is contained in:
John Postlethwait 2012-04-03 14:03:04 -07:00 committed by Devin Carlen
parent 6da7f69044
commit a58db8503b
7 changed files with 74 additions and 26 deletions

View File

@ -40,7 +40,9 @@ class LogTab(tabs.Tab):
def get_context_data(self, request): def get_context_data(self, request):
instance = self.tab_group.kwargs['instance'] instance = self.tab_group.kwargs['instance']
try: try:
data = api.server_console_output(request, instance.id) data = api.server_console_output(request,
instance.id,
tail_length=35)
except: except:
data = _('Unable to get log for instance "%s".') % instance.id data = _('Unable to get log for instance "%s".') % instance.id
exceptions.handle(request, ignore=True) exceptions.handle(request, ignore=True)

View File

@ -206,7 +206,8 @@ class InstanceViewTests(test.TestCase):
self.mox.StubOutWithMock(api, 'server_console_output') self.mox.StubOutWithMock(api, 'server_console_output')
api.server_console_output(IsA(http.HttpRequest), api.server_console_output(IsA(http.HttpRequest),
server.id).AndReturn(CONSOLE_OUTPUT) server.id, tail_length=None) \
.AndReturn(CONSOLE_OUTPUT)
self.mox.ReplayAll() self.mox.ReplayAll()
url = reverse('horizon:nova:instances_and_volumes:instances:console', url = reverse('horizon:nova:instances_and_volumes:instances:console',
@ -224,7 +225,7 @@ class InstanceViewTests(test.TestCase):
self.mox.StubOutWithMock(api, 'server_console_output') self.mox.StubOutWithMock(api, 'server_console_output')
exc = nova_exceptions.ClientException(500) exc = nova_exceptions.ClientException(500)
api.server_console_output(IsA(http.HttpRequest), api.server_console_output(IsA(http.HttpRequest),
server.id).AndRaise(exc) server.id, tail_length=None).AndRaise(exc)
self.mox.ReplayAll() self.mox.ReplayAll()
url = reverse('horizon:nova:instances_and_volumes:instances:console', url = reverse('horizon:nova:instances_and_volumes:instances:console',

View File

@ -43,7 +43,10 @@ LOG = logging.getLogger(__name__)
def console(request, instance_id): def console(request, instance_id):
try: try:
# TODO(jakedahn): clean this up once the api supports tailing. # 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: except:
data = _('Unable to get log for instance "%s".') % instance_id data = _('Unable to get log for instance "%s".') % instance_id
exceptions.handle(request, ignore=True) exceptions.handle(request, ignore=True)

View File

@ -1,9 +1,19 @@
{% load i18n %} {% load i18n %}
<div class="clearfix"> <div class="clearfix">
<h3 class="pull-left">Instance Console Log</h3> <h3 class="pull-left">Instance Console Log</h3>
<p class="pull-right"> <p class="pull-right">
{% url horizon:nova:instances_and_volumes:instances:console instance.id as console_url %} {% url horizon:nova:instances_and_volumes:instances:console instance.id as console_url %}
<a class="btn btn-small" target="_blank" href="{{ console_url }}">{% trans "View Full Log" %}</a> <a class="btn btn-small" target="_blank" href="{{ console_url }}">{% trans "View Full Log" %}</a>
</p> </p>
<form id="tail_length" action="{% url horizon:nova:instances_and_volumes:instances:console instance.id %}" class="span3 pull-right">
<label class="pull-left log-length" for="tail_length_select">Log Length</label>
<input class="span1" type="text" name="length" value="35" />
<input value="Go" class="btn-small btn-primary" type="submit" />
</form>
</div> </div>
<pre class="logs">{{ console_log }}</pre>
<pre class="logs">
{{ console_log }}
</pre>

View File

@ -16,21 +16,16 @@
{% block js %} {% block js %}
{{ block.super }} {{ block.super }}
{# FIXME: This JavaScript should live with the rest of the JS #} <script type="text/javascript" charset="utf-8">
<script type="text/javascript" charset="utf-8"> $(document).on('submit', '#tail_length', function (evt) {
$(function() { horizon.instances.user_decided_length = true;
function getLog() { horizon.instances.getConsoleLog(this, true);
if ($("#instance_details__log .logs").length) {
$.get("{% url horizon:nova:instances_and_volumes:instances:console instance.id %}?length=25", function(data) {
$("#instance_details__log .logs").html(data);
});
}
}
getLog();
setInterval(function() { evt.preventDefault();
getLog(); });
}, 10000); // This value has to stay under Nova's API rate limiting.
}); setInterval(function() {
</script> horizon.instances.getConsoleLog($("#tail_length"), false);
}, 10000);
</script>
{% endblock %} {% endblock %}

View File

@ -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) { horizon.alert = function (type, message) {
var template = horizon.templates.compiled_templates["#alert_message_template"], var template = horizon.templates.compiled_templates["#alert_message_template"],
params = {"type": type, params = {"type": type,
@ -277,6 +305,10 @@ var Horizon = function() {
return $(template.render(params)).prependTo("#main_content .messages"); return $(template.render(params)).prependTo("#main_content .messages");
}; };
horizon.clearErrorMessages = function() {
$('#main_content .messages .alert.alert-error').remove()
};
/* Queued ajax handling for Horizon. /* Queued ajax handling for Horizon.
* *
* Note: The number of concurrent AJAX connections hanlded in the queue * Note: The number of concurrent AJAX connections hanlded in the queue

View File

@ -1001,3 +1001,8 @@ iframe {
padding: 10px; padding: 10px;
display: block; display: block;
} }
label.log-length {
line-height: 28px;
margin-right: 10px;
}