From 4493b6f75ff40c7f12f2bd0b4305bc2562b468a6 Mon Sep 17 00:00:00 2001 From: Shu Muto Date: Thu, 15 Jun 2017 18:06:47 +0900 Subject: [PATCH] Enable to set protocols of WebSocket for serial console This patch enables to set protocols of WebSocket for serial console. Also, this enables to use serial console not only from instance but also plugins. e.g. Zun UI can access container console provided by docker. Change-Id: Ib0df9ddfc74f98bfea75abce3b5d5479e3cd47bd Needed-By: I41f236f2762613e56748bb05eb7ce0e4c26158d2 Closes-Bug: #1698092 --- .../dashboards/project/instances/views.py | 8 ++++---- .../js/angular/directives/serialConsole.js | 18 ++++++++---------- .../serial_console.html | 4 ++-- 3 files changed, 14 insertions(+), 16 deletions(-) rename openstack_dashboard/{dashboards/project/instances/templates/instances => templates}/serial_console.html (85%) diff --git a/openstack_dashboard/dashboards/project/instances/views.py b/openstack_dashboard/dashboards/project/instances/views.py index 904271e8f1..1c8ef8799b 100644 --- a/openstack_dashboard/dashboards/project/instances/views.py +++ b/openstack_dashboard/dashboards/project/instances/views.py @@ -222,11 +222,10 @@ def rdp(request, instance_id): class SerialConsoleView(generic.TemplateView): - template_name = 'project/instances/serial_console.html' + template_name = 'serial_console.html' def get_context_data(self, **kwargs): context = super(SerialConsoleView, self).get_context_data(**kwargs) - context['instance_id'] = self.kwargs['instance_id'] instance = None try: instance = api.nova.server_get(self.request, @@ -236,13 +235,14 @@ class SerialConsoleView(generic.TemplateView): "Cannot find instance %s.") % self.kwargs['instance_id'] # name is unknown, so leave it blank for the window title # in full-screen mode, so only the instance id is shown. - context['instance_name'] = '' + context['page_title'] = self.kwargs['instance_id'] return context - context['instance_name'] = instance.name + context['page_title'] = "%s (%s)" % (instance.name, instance.id) try: console_url = project_console.get_console(self.request, "SERIAL", instance)[1] context["console_url"] = console_url + context["protocols"] = "['binary', 'base64']" except exceptions.NotAvailable: context["error_message"] = _( "Cannot get console for instance %s.") % self.kwargs[ diff --git a/openstack_dashboard/static/js/angular/directives/serialConsole.js b/openstack_dashboard/static/js/angular/directives/serialConsole.js index e886aebab2..8101e79281 100644 --- a/openstack_dashboard/static/js/angular/directives/serialConsole.js +++ b/openstack_dashboard/static/js/angular/directives/serialConsole.js @@ -19,10 +19,6 @@ limitations under the License. 'use strict'; angular.module('serialConsoleApp', []) - .constant('protocols', [ - 'binary', - 'base64' - ]) .constant('states', [ gettext('Connecting'), gettext('Open'), @@ -36,16 +32,17 @@ limitations under the License. * * @description * The serial-console element creates a terminal based on the widely-used term.js. - * The "connection" attribute is input to a WebSocket object, which connects - * to a server. In Horizon, this directive is used to connect to nova-serialproxy, - * opening a serial console to any instance. Each key the user types is transmitted - * to the instance, and each character the instance reponds with is displayed. + * The "connection" and "protocols" attributes are input to a WebSocket object, + * which connects to a server. In Horizon, this directive is used to connect to + * nova-serialproxy, opening a serial console to any instance. Each key the user + * types is transmitted to the instance, and each character the instance reponds + * with is displayed. */ .directive('serialConsole', serialConsole); - serialConsole.$inject = ['protocols', 'states']; + serialConsole.$inject = ['states']; - function serialConsole(protocols, states) { + function serialConsole(states) { return { scope: true, template: '

{{statusMessage()}}', @@ -53,6 +50,7 @@ limitations under the License. link: function postLink(scope, element, attrs) { var connection = scope.$eval(attrs.connection); + var protocols = scope.$eval(attrs.protocols); var term = new Terminal(); var socket = new WebSocket(connection, protocols); diff --git a/openstack_dashboard/dashboards/project/instances/templates/instances/serial_console.html b/openstack_dashboard/templates/serial_console.html similarity index 85% rename from openstack_dashboard/dashboards/project/instances/templates/instances/serial_console.html rename to openstack_dashboard/templates/serial_console.html index a852da5255..13c1fc5159 100644 --- a/openstack_dashboard/dashboards/project/instances/templates/instances/serial_console.html +++ b/openstack_dashboard/templates/serial_console.html @@ -4,7 +4,7 @@ - {{instance_name}} ({{instance_id}}) + {{page_title}} @@ -17,7 +17,7 @@ {% if error_message %} {{ error_message }} {% else %} - + {% endif %}