From 0e4b38ffafdbc6ceb318ec0c4b888125e32b227e Mon Sep 17 00:00:00 2001 From: Zhenguo Niu Date: Wed, 17 May 2017 16:32:12 +0800 Subject: [PATCH] Add console support Change-Id: I0b845d8d2ac9bee30676b1d6e01609c71ffeae48 --- mogan_ui/api/mogan.py | 10 +++++++ mogan_ui/content/project/servers/tabs.py | 23 +++++++++++++++- .../templates/servers/_detail_console.html | 26 +++++++++++++++++++ .../servers/workflows/create_server.py | 2 -- 4 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 mogan_ui/content/project/servers/templates/servers/_detail_console.html diff --git a/mogan_ui/api/mogan.py b/mogan_ui/api/mogan.py index c207696..0416161 100644 --- a/mogan_ui/api/mogan.py +++ b/mogan_ui/api/mogan.py @@ -203,3 +203,13 @@ def flavor_get(request, flavor_id): """ flavor_manager = moganclient(request).flavor return flavor_manager.get(flavor_id) + + +def console_get(request, server_id): + """Get serial console for a server. + + :param request: HTTP request. + :param server_id: The uuid of the server. + """ + server_manager = moganclient(request).server + return server_manager.get_serial_console(server_id) diff --git a/mogan_ui/content/project/servers/tabs.py b/mogan_ui/content/project/servers/tabs.py index b376556..1030dad 100644 --- a/mogan_ui/content/project/servers/tabs.py +++ b/mogan_ui/content/project/servers/tabs.py @@ -15,8 +15,11 @@ from django.utils.translation import ugettext_lazy as _ +from horizon import exceptions from horizon import tabs +from mogan_ui.api import mogan + class OverviewTab(tabs.Tab): name = _("Overview") @@ -29,7 +32,25 @@ class OverviewTab(tabs.Tab): "is_superuser": request.user.is_superuser} +class ConsoleTab(tabs.Tab): + name = _("Console") + slug = "console" + template_name = "project/servers/_detail_console.html" + preload = False + + def get_context_data(self, request): + server = self.tab_group.kwargs['server'] + console_url = None + try: + console = mogan.console_get(request, server.uuid) + console_url = console.console['url'] + except Exception: + exceptions.handle(request, ignore=True, force_log=True) + + return {'console_url': console_url, 'server_id': server.uuid} + + class ServerDetailTabs(tabs.DetailTabsGroup): slug = "server_details" - tabs = (OverviewTab,) + tabs = (OverviewTab, ConsoleTab) sticky = True diff --git a/mogan_ui/content/project/servers/templates/servers/_detail_console.html b/mogan_ui/content/project/servers/templates/servers/_detail_console.html new file mode 100644 index 0000000..70ede30 --- /dev/null +++ b/mogan_ui/content/project/servers/templates/servers/_detail_console.html @@ -0,0 +1,26 @@ +{% load i18n %} + +

{% trans "Server Console" %}

+{% if console_url %} +

+{% blocktrans %}If console is not responding to keyboard input: click the grey status bar below.{% endblocktrans %} +{% trans "Click here to show only console" %}
+ {% trans "To exit the fullscreen mode, click the browser's back button." %}

+ + +{% else %} + +
{% blocktrans %}Unable to load console. Please reload page to try again.{% endblocktrans %}
+{% endif %} diff --git a/mogan_ui/content/project/servers/workflows/create_server.py b/mogan_ui/content/project/servers/workflows/create_server.py index 82fbf3e..e5fac3c 100644 --- a/mogan_ui/content/project/servers/workflows/create_server.py +++ b/mogan_ui/content/project/servers/workflows/create_server.py @@ -118,8 +118,6 @@ class SetServerDetailsAction(workflows.Action): flavor_list.sort() if not flavor_list: flavor_list.insert(0, ("", _("No flavors found"))) - elif len(flavor_list) > 1: - flavor_list.insert(0, ("", _("Select Flavor"))) return flavor_list def populate_availability_zone_choices(self, request, context):