Merge "Add instance locked status on instances table"

This commit is contained in:
Jenkins 2017-06-15 12:12:10 +00:00 committed by Gerrit Code Review
commit 4a4c50a78e
8 changed files with 63 additions and 4 deletions

View File

@ -493,15 +493,21 @@ def server_delete(request, instance_id):
novaclient(request).servers.delete(instance_id) novaclient(request).servers.delete(instance_id)
def get_novaclient_with_locked_status(request):
microversion = get_microversion(request, "locked_attribute")
return novaclient(request, version=microversion)
@profiler.trace @profiler.trace
def server_get(request, instance_id): def server_get(request, instance_id):
return Server(novaclient(request).servers.get(instance_id), request) return Server(get_novaclient_with_locked_status(request).servers.get(
instance_id), request)
@profiler.trace @profiler.trace
def server_list(request, search_opts=None, all_tenants=False, detailed=True): def server_list(request, search_opts=None, all_tenants=False, detailed=True):
nova_client = get_novaclient_with_locked_status(request)
page_size = utils.get_page_size(request) page_size = utils.get_page_size(request)
c = novaclient(request)
paginate = False paginate = False
if search_opts is None: if search_opts is None:
search_opts = {} search_opts = {}
@ -515,7 +521,7 @@ def server_list(request, search_opts=None, all_tenants=False, detailed=True):
else: else:
search_opts['project_id'] = request.user.tenant_id search_opts['project_id'] = request.user.tenant_id
servers = [Server(s, request) servers = [Server(s, request)
for s in c.servers.list(detailed, search_opts)] for s in nova_client.servers.list(detailed, search_opts)]
has_more_data = False has_more_data = False
if paginate and len(servers) > page_size: if paginate and len(servers) > page_size:

View File

@ -152,6 +152,9 @@ class AdminInstancesTable(tables.DataTable):
status=True, status=True,
status_choices=STATUS_CHOICES, status_choices=STATUS_CHOICES,
display_choices=project_tables.STATUS_DISPLAY_CHOICES) display_choices=project_tables.STATUS_DISPLAY_CHOICES)
locked = tables.Column(project_tables.render_locked,
verbose_name=_(" "),
sortable=False)
task = tables.Column("OS-EXT-STS:task_state", task = tables.Column("OS-EXT-STS:task_state",
verbose_name=_("Task"), verbose_name=_("Task"),
empty_value=project_tables.TASK_DISPLAY_NONE, empty_value=project_tables.TASK_DISPLAY_NONE,

View File

@ -22,6 +22,7 @@ from django import shortcuts
from django import template from django import template
from django.template.defaultfilters import title from django.template.defaultfilters import title
from django.utils.http import urlencode from django.utils.http import urlencode
from django.utils.safestring import mark_safe
from django.utils.translation import npgettext_lazy from django.utils.translation import npgettext_lazy
from django.utils.translation import pgettext_lazy from django.utils.translation import pgettext_lazy
from django.utils.translation import string_concat from django.utils.translation import string_concat
@ -1183,6 +1184,23 @@ class InstancesFilterAction(tables.FilterAction):
filter_choices = INSTANCE_FILTER_CHOICES filter_choices = INSTANCE_FILTER_CHOICES
def render_locked(instance):
if not hasattr(instance, 'locked'):
return ""
if instance.locked:
icon_classes = "fa fa-fw fa-lock"
help_tooltip = _("This instance is currently locked. To enable more "
"actions on it, please unlock it by selecting Unlock "
"Instance from the actions menu.")
else:
icon_classes = "fa fa-fw fa-unlock text-muted"
help_tooltip = _("This instance is unlocked.")
locked_status = ('<span data-toggle="tooltip" title="{}" class="{}">'
'</span>').format(help_tooltip, icon_classes)
return mark_safe(locked_status)
class InstancesTable(tables.DataTable): class InstancesTable(tables.DataTable):
TASK_STATUS_CHOICES = ( TASK_STATUS_CHOICES = (
(None, True), (None, True),
@ -1216,6 +1234,9 @@ class InstancesTable(tables.DataTable):
status=True, status=True,
status_choices=STATUS_CHOICES, status_choices=STATUS_CHOICES,
display_choices=STATUS_DISPLAY_CHOICES) display_choices=STATUS_DISPLAY_CHOICES)
locked = tables.Column(render_locked,
verbose_name="",
sortable=False)
az = tables.Column("availability_zone", az = tables.Column("availability_zone",
verbose_name=_("Availability Zone")) verbose_name=_("Availability Zone"))
task = tables.Column("OS-EXT-STS:task_state", task = tables.Column("OS-EXT-STS:task_state",

View File

@ -8,6 +8,10 @@
<dd>{{ instance.id }}</dd> <dd>{{ instance.id }}</dd>
<dt>{% trans "Status" %}</dt> <dt>{% trans "Status" %}</dt>
<dd>{{ instance.status_label|title }}</dd> <dd>{{ instance.status_label|title }}</dd>
{% if instance.locked != None %}
<dt>{% trans "Locked" %}</dt>
<dd>{{ instance.locked }}</dd>
{% endif %}
<dt>{% trans "Availability Zone" %}</dt> <dt>{% trans "Availability Zone" %}</dt>
<dd>{{ instance.availability_zone|default:_("-") }}</dd> <dd>{{ instance.availability_zone|default:_("-") }}</dd>
<dt>{% trans "Created" %}</dt> <dt>{% trans "Created" %}</dt>

View File

@ -1093,6 +1093,8 @@ class NeutronApiFloatingIpTests(NeutronApiTestBase):
servers = self.servers.list() servers = self.servers.list()
novaclient = self.stub_novaclient() novaclient = self.stub_novaclient()
novaclient.servers = self.mox.CreateMockAnything() novaclient.servers = self.mox.CreateMockAnything()
novaclient.versions = self.mox.CreateMockAnything()
novaclient.versions.get_current().AndReturn("2.45")
search_opts = {'project_id': self.request.user.tenant_id} search_opts = {'project_id': self.request.user.tenant_id}
novaclient.servers.list(False, search_opts).AndReturn(servers) novaclient.servers.list(False, search_opts).AndReturn(servers)

View File

@ -141,6 +141,8 @@ class ComputeApiTests(test.APITestCase):
novaclient = self.stub_novaclient() novaclient = self.stub_novaclient()
novaclient.servers = self.mox.CreateMockAnything() novaclient.servers = self.mox.CreateMockAnything()
novaclient.versions = self.mox.CreateMockAnything()
novaclient.versions.get_current().AndReturn("2.45")
novaclient.servers.list(True, {'all_tenants': True}).AndReturn(servers) novaclient.servers.list(True, {'all_tenants': True}).AndReturn(servers)
self.mox.ReplayAll() self.mox.ReplayAll()
@ -154,6 +156,8 @@ class ComputeApiTests(test.APITestCase):
servers = self.servers.list() servers = self.servers.list()
novaclient = self.stub_novaclient() novaclient = self.stub_novaclient()
novaclient.servers = self.mox.CreateMockAnything() novaclient.servers = self.mox.CreateMockAnything()
novaclient.versions = self.mox.CreateMockAnything()
novaclient.versions.get_current().AndReturn("2.45")
novaclient.servers.list(True, novaclient.servers.list(True,
{'all_tenants': True, {'all_tenants': True,
'marker': None, 'marker': None,
@ -174,6 +178,8 @@ class ComputeApiTests(test.APITestCase):
servers = self.servers.list() servers = self.servers.list()
novaclient = self.stub_novaclient() novaclient = self.stub_novaclient()
novaclient.servers = self.mox.CreateMockAnything() novaclient.servers = self.mox.CreateMockAnything()
novaclient.versions = self.mox.CreateMockAnything()
novaclient.versions.get_current().AndReturn("2.45")
novaclient.servers.list(True, novaclient.servers.list(True,
{'all_tenants': True, {'all_tenants': True,
'marker': None, 'marker': None,
@ -267,6 +273,8 @@ class ComputeApiTests(test.APITestCase):
server = self.servers.first() server = self.servers.first()
novaclient = self.stub_novaclient() novaclient = self.stub_novaclient()
novaclient.versions = self.mox.CreateMockAnything()
novaclient.versions.get_current().AndReturn("2.45")
novaclient.servers = self.mox.CreateMockAnything() novaclient.servers = self.mox.CreateMockAnything()
novaclient.servers.get(server.id).AndReturn(server) novaclient.servers.get(server.id).AndReturn(server)
self.mox.ReplayAll() self.mox.ReplayAll()
@ -385,6 +393,8 @@ class ComputeApiTests(test.APITestCase):
novaclient = self.stub_novaclient() novaclient = self.stub_novaclient()
server_uuid = hypervisor.servers[0]["uuid"] server_uuid = hypervisor.servers[0]["uuid"]
novaclient.versions = self.mox.CreateMockAnything()
novaclient.versions.get_current().AndReturn("2.45")
novaclient.hypervisors = self.mox.CreateMockAnything() novaclient.hypervisors = self.mox.CreateMockAnything()
novaclient.hypervisors.search('host', True).AndReturn([hypervisor]) novaclient.hypervisors.search('host', True).AndReturn([hypervisor])
@ -405,6 +415,8 @@ class ComputeApiTests(test.APITestCase):
novaclient = self.stub_novaclient() novaclient = self.stub_novaclient()
server_uuid = hypervisor.servers[0]["uuid"] server_uuid = hypervisor.servers[0]["uuid"]
novaclient.versions = self.mox.CreateMockAnything()
novaclient.versions.get_current().AndReturn("2.45")
novaclient.hypervisors = self.mox.CreateMockAnything() novaclient.hypervisors = self.mox.CreateMockAnything()
novaclient.hypervisors.search('host', True).AndReturn([hypervisor]) novaclient.hypervisors.search('host', True).AndReturn([hypervisor])
@ -425,6 +437,8 @@ class ComputeApiTests(test.APITestCase):
novaclient = self.stub_novaclient() novaclient = self.stub_novaclient()
server_uuid = hypervisor.servers[0]["uuid"] server_uuid = hypervisor.servers[0]["uuid"]
novaclient.versions = self.mox.CreateMockAnything()
novaclient.versions.get_current().AndReturn("2.45")
novaclient.hypervisors = self.mox.CreateMockAnything() novaclient.hypervisors = self.mox.CreateMockAnything()
novaclient.hypervisors.search('host', True).AndReturn([hypervisor]) novaclient.hypervisors.search('host', True).AndReturn([hypervisor])

View File

@ -417,6 +417,9 @@ class APITestCase(TestCase):
""" """
return self.stub_glanceclient() return self.stub_glanceclient()
def fake_novaclient(request, version=None):
return self.stub_novaclient()
# Store the original clients # Store the original clients
self._original_glanceclient = api.glance.glanceclient self._original_glanceclient = api.glance.glanceclient
self._original_keystoneclient = api.keystone.keystoneclient self._original_keystoneclient = api.keystone.keystoneclient
@ -428,7 +431,7 @@ class APITestCase(TestCase):
# Replace the clients with our stubs. # Replace the clients with our stubs.
api.glance.glanceclient = fake_glanceclient api.glance.glanceclient = fake_glanceclient
api.keystone.keystoneclient = fake_keystoneclient api.keystone.keystoneclient = fake_keystoneclient
api.nova.novaclient = lambda request: self.stub_novaclient() api.nova.novaclient = fake_novaclient
api.neutron.neutronclient = lambda request: self.stub_neutronclient() api.neutron.neutronclient = lambda request: self.stub_neutronclient()
api.cinder.cinderclient = lambda request: self.stub_cinderclient() api.cinder.cinderclient = lambda request: self.stub_cinderclient()
api.heat.heatclient = (lambda request, password=None: api.heat.heatclient = (lambda request, password=None:

View File

@ -0,0 +1,6 @@
---
features:
- |
Added a locked status column on admin/project instances table. It will
show a locked or unlocked icon if nova 2.9 or above is used. The locked
status is also available on instance details panel.