Net topology: Show console link only when useful

Right now we are showing the "open console" link on the
network topology screen for instances on each instance,
even if they are on a status that we know its not
going to allow the console to connect.

This patch makes it so the "open console" link will
only appear if the instance object has console data.

It also changes the order of getting the instance
data in the django part as to make less calls if we
dont need the console link.

Provides a list with known statuses that wont connect
to the console used to get the console data or not.

Change-Id: I536fee5186ac933b92a7dc01a2a5b82a6db0ae4c
Closes-Bug: #1543316
This commit is contained in:
Itxaka 2016-02-10 12:11:10 +01:00 committed by Itxaka
parent 250271e3fe
commit b5673ecd47
2 changed files with 20 additions and 13 deletions
openstack_dashboard/dashboards/project/network_topology
templates/network_topology/client_side
views.py

@ -15,12 +15,11 @@
<div class="footerInner">
<div class="cell link">
<a href="[[url]]">» [[view_details_label]]</a>
{% comment %}The Console link is available if settings.CONSOLE_TYPE is not set at all, or if it's set to any value other than None or False.{% endcomment %}
{% if console_type %}
[[#console_id]]
{% comment %}The console link will only appear if the console item is defined
on the javascript side while rendering the template.{% endcomment %}
[[#console]]
<a href="[[url]][[console]]" class="vnc_window">» [[open_console_label]]</a>
[[/console_id]]
{% endif %}
[[/console]]
</div>
[[#type]]
<div class="cell delete">

@ -77,6 +77,12 @@ from openstack_dashboard.dashboards.project.routers.tables import \
from openstack_dashboard.dashboards.project.routers import\
views as r_views
# List of known server statuses that wont connect to the console
console_invalid_status = {
'shutoff', 'suspended', 'resize', 'verify_resize',
'revert_resize', 'migrating', 'build', 'shelved',
'shelved_offloaded'}
class TranslationHelper(object):
"""Helper class to provide the translations of instances, networks,
@ -251,19 +257,21 @@ class JSONView(View):
console_type = getattr(settings, 'CONSOLE_TYPE', 'AUTO')
# lowercase of the keys will be used at the end of the console URL.
for server in servers:
try:
console = i_console.get_console(
request, console_type, server)[0].lower()
except exceptions.NotAvailable:
console = None
server_data = {'name': server.name,
'status': self.trans.instance[server.status],
'original_status': server.status,
'task': getattr(server, 'OS-EXT-STS:task_state'),
'id': server.id}
if console:
server_data['console'] = console
# Avoid doing extra calls for console if the server is in
# a invalid status for console connection
if server.status.lower() not in console_invalid_status:
try:
console = i_console.get_console(
request, console_type, server)[0].lower()
server_data['console'] = console
except exceptions.NotAvailable:
pass
data.append(server_data)
self.add_resource_url('horizon:project:instances:detail', data)
return data