summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Postlethwait <john.postlethwait@nebula.com>2012-04-03 14:03:04 -0700
committerDevin Carlen <devin.carlen@gmail.com>2012-04-03 19:03:17 -0700
commita58db8503b17ec8efc5e07658a5da0e66e2b0345 (patch)
treefad335d2b3e80975ca768b047bcca47abcb93706
parent6da7f69044221ba0ba305d8faac4a6ea51f6208d (diff)
downloadhorizon-essex-rc2.tar.gz
Adding a user configurable log length.essex-rc22012.1
Fixes bug #963596 Change-Id: I730e8c23c3387121aeb9033937bb300d5102fc33
-rw-r--r--horizon/dashboards/nova/instances_and_volumes/instances/tabs.py4
-rw-r--r--horizon/dashboards/nova/instances_and_volumes/instances/tests.py5
-rw-r--r--horizon/dashboards/nova/instances_and_volumes/instances/views.py5
-rw-r--r--horizon/dashboards/nova/templates/nova/instances_and_volumes/instances/_detail_log.html22
-rw-r--r--horizon/dashboards/nova/templates/nova/instances_and_volumes/instances/detail.html27
-rw-r--r--horizon/static/horizon/js/horizon.js32
-rw-r--r--openstack_dashboard/static/dashboard/css/style.css5
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 5c33fed78..94df3c5bf 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 4f2fc2e46..ed0077d20 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 79f74b6dc..d1a564ce8 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 ac3a8b7b5..4eba3a0a9 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 %}
+
<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>
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 b2f85ddfb..410be0a63 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 #}
- <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 %}
diff --git a/horizon/static/horizon/js/horizon.js b/horizon/static/horizon/js/horizon.js
index 0fec7d86a..8cf2be56c 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 ac800547f..e57c6dd39 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;
+}