Adding a user configurable log length.
Fixes bug #963596 Change-Id: I730e8c23c3387121aeb9033937bb300d5102fc33
This commit is contained in:
parent
c55567354b
commit
bf9abd5811
@ -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)
|
||||
|
@ -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',
|
||||
|
@ -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)
|
||||
|
@ -1,9 +1,19 @@
|
||||
{% load i18n %}
|
||||
|
||||
<div class="clearfix">
|
||||
<h3 class="pull-left">Instance Console Log</h3>
|
||||
<p class="pull-right">
|
||||
{% 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>
|
||||
</p>
|
||||
<h3 class="pull-left">Instance Console Log</h3>
|
||||
<p class="pull-right">
|
||||
{% 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>
|
||||
</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>
|
||||
<pre class="logs">{{ console_log }}</pre>
|
||||
|
||||
<pre class="logs">
|
||||
{{ console_log }}
|
||||
</pre>
|
||||
|
@ -16,21 +16,16 @@
|
||||
|
||||
{% block js %}
|
||||
{{ block.super }}
|
||||
{# FIXME: This JavaScript should live with the rest of the JS #}
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
$(function() {
|
||||
function getLog() {
|
||||
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();
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
$(document).on('submit', '#tail_length', function (evt) {
|
||||
horizon.instances.user_decided_length = true;
|
||||
horizon.instances.getConsoleLog(this, true);
|
||||
|
||||
setInterval(function() {
|
||||
getLog();
|
||||
}, 10000); // This value has to stay under Nova's API rate limiting.
|
||||
});
|
||||
</script>
|
||||
evt.preventDefault();
|
||||
});
|
||||
|
||||
setInterval(function() {
|
||||
horizon.instances.getConsoleLog($("#tail_length"), false);
|
||||
}, 10000);
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
@ -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
|
||||
|
@ -1001,3 +1001,8 @@ iframe {
|
||||
padding: 10px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
label.log-length {
|
||||
line-height: 28px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user