Browse Source

Adding a user configurable log length.

Fixes bug #963596

Change-Id: I730e8c23c3387121aeb9033937bb300d5102fc33
John Postlethwait 7 years ago
parent
commit
a58db8503b

+ 3
- 1
horizon/dashboards/nova/instances_and_volumes/instances/tabs.py View File

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

+ 3
- 2
horizon/dashboards/nova/instances_and_volumes/instances/tests.py View File

@@ -206,7 +206,8 @@ class InstanceViewTests(test.TestCase):
206 206
 
207 207
         self.mox.StubOutWithMock(api, 'server_console_output')
208 208
         api.server_console_output(IsA(http.HttpRequest),
209
-                                  server.id).AndReturn(CONSOLE_OUTPUT)
209
+                                  server.id, tail_length=None) \
210
+                                  .AndReturn(CONSOLE_OUTPUT)
210 211
         self.mox.ReplayAll()
211 212
 
212 213
         url = reverse('horizon:nova:instances_and_volumes:instances:console',
@@ -224,7 +225,7 @@ class InstanceViewTests(test.TestCase):
224 225
         self.mox.StubOutWithMock(api, 'server_console_output')
225 226
         exc = nova_exceptions.ClientException(500)
226 227
         api.server_console_output(IsA(http.HttpRequest),
227
-                                  server.id).AndRaise(exc)
228
+                                  server.id, tail_length=None).AndRaise(exc)
228 229
         self.mox.ReplayAll()
229 230
 
230 231
         url = reverse('horizon:nova:instances_and_volumes:instances:console',

+ 4
- 1
horizon/dashboards/nova/instances_and_volumes/instances/views.py View File

@@ -43,7 +43,10 @@ LOG = logging.getLogger(__name__)
43 43
 def console(request, instance_id):
44 44
     try:
45 45
         # TODO(jakedahn): clean this up once the api supports tailing.
46
-        data = api.server_console_output(request, instance_id)
46
+        tail = request.GET.get('length', None)
47
+        data = api.server_console_output(request,
48
+                                        instance_id,
49
+                                        tail_length=tail)
47 50
     except:
48 51
         data = _('Unable to get log for instance "%s".') % instance_id
49 52
         exceptions.handle(request, ignore=True)

+ 16
- 6
horizon/dashboards/nova/templates/nova/instances_and_volumes/instances/_detail_log.html View File

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

+ 11
- 16
horizon/dashboards/nova/templates/nova/instances_and_volumes/instances/detail.html View File

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

+ 32
- 0
horizon/static/horizon/js/horizon.js View File

@@ -269,6 +269,34 @@ var Horizon = function() {
269 269
     }
270 270
   };
271 271
 
272
+  horizon.instances = {
273
+    user_decided_length: false,
274
+
275
+    getConsoleLog: function(form_element, via_user_submit) {
276
+      if(this.user_decided_length) {
277
+        var data = $(form_element).serialize();
278
+      } else {
279
+        var data = "length=35";
280
+      }
281
+
282
+      $.ajax({
283
+        url: $(form_element).attr('action'),
284
+        data: data,
285
+        method: 'get',
286
+        success: function(response_body) {
287
+          $('pre.logs').html(response_body);
288
+        },
289
+        error: function(response) {
290
+          if(via_user_submit) {
291
+            horizon.clearErrorMessages();
292
+
293
+            horizon.alert('error', 'There was a problem communicating with the server, please try again.');
294
+          }
295
+        }
296
+      });
297
+    }
298
+  };
299
+
272 300
   horizon.alert = function (type, message) {
273 301
     var template = horizon.templates.compiled_templates["#alert_message_template"],
274 302
         params = {"type": type,
@@ -277,6 +305,10 @@ var Horizon = function() {
277 305
     return $(template.render(params)).prependTo("#main_content .messages");
278 306
   };
279 307
 
308
+  horizon.clearErrorMessages = function() {
309
+    $('#main_content .messages .alert.alert-error').remove()
310
+  };
311
+
280 312
   /* Queued ajax handling for Horizon.
281 313
    *
282 314
    * Note: The number of concurrent AJAX connections hanlded in the queue

+ 5
- 0
openstack_dashboard/static/dashboard/css/style.css View File

@@ -1001,3 +1001,8 @@ iframe {
1001 1001
   padding: 10px;
1002 1002
   display: block;
1003 1003
 }
1004
+
1005
+label.log-length {
1006
+  line-height: 28px;
1007
+  margin-right: 10px;
1008
+}

Loading…
Cancel
Save