summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-06-15 12:12:10 +0000
committerGerrit Code Review <review@openstack.org>2017-06-15 12:12:10 +0000
commit4a4c50a78ecdd8fc44635f1b06a9c25864e416b1 (patch)
treeabc699c6f466e9745bbcfc0f114ecd71c38c300d
parent1fa431fdbec3dbc4e578893d690dc1c0e46df686 (diff)
parentddfa667d02c8e417102412df5c41580dd514630f (diff)
Merge "Add instance locked status on instances table"
-rw-r--r--openstack_dashboard/api/nova.py12
-rw-r--r--openstack_dashboard/dashboards/admin/instances/tables.py3
-rw-r--r--openstack_dashboard/dashboards/project/instances/tables.py21
-rw-r--r--openstack_dashboard/dashboards/project/instances/templates/instances/_detail_overview.html4
-rw-r--r--openstack_dashboard/test/api_tests/neutron_tests.py2
-rw-r--r--openstack_dashboard/test/api_tests/nova_tests.py14
-rw-r--r--openstack_dashboard/test/helpers.py5
-rw-r--r--releasenotes/notes/bug-1593903-8fb8721dc2449f71.yaml6
8 files changed, 63 insertions, 4 deletions
diff --git a/openstack_dashboard/api/nova.py b/openstack_dashboard/api/nova.py
index 4eb4973..56652a2 100644
--- a/openstack_dashboard/api/nova.py
+++ b/openstack_dashboard/api/nova.py
@@ -493,15 +493,21 @@ def server_delete(request, instance_id):
493 novaclient(request).servers.delete(instance_id) 493 novaclient(request).servers.delete(instance_id)
494 494
495 495
496def get_novaclient_with_locked_status(request):
497 microversion = get_microversion(request, "locked_attribute")
498 return novaclient(request, version=microversion)
499
500
496@profiler.trace 501@profiler.trace
497def server_get(request, instance_id): 502def server_get(request, instance_id):
498 return Server(novaclient(request).servers.get(instance_id), request) 503 return Server(get_novaclient_with_locked_status(request).servers.get(
504 instance_id), request)
499 505
500 506
501@profiler.trace 507@profiler.trace
502def server_list(request, search_opts=None, all_tenants=False, detailed=True): 508def server_list(request, search_opts=None, all_tenants=False, detailed=True):
509 nova_client = get_novaclient_with_locked_status(request)
503 page_size = utils.get_page_size(request) 510 page_size = utils.get_page_size(request)
504 c = novaclient(request)
505 paginate = False 511 paginate = False
506 if search_opts is None: 512 if search_opts is None:
507 search_opts = {} 513 search_opts = {}
@@ -515,7 +521,7 @@ def server_list(request, search_opts=None, all_tenants=False, detailed=True):
515 else: 521 else:
516 search_opts['project_id'] = request.user.tenant_id 522 search_opts['project_id'] = request.user.tenant_id
517 servers = [Server(s, request) 523 servers = [Server(s, request)
518 for s in c.servers.list(detailed, search_opts)] 524 for s in nova_client.servers.list(detailed, search_opts)]
519 525
520 has_more_data = False 526 has_more_data = False
521 if paginate and len(servers) > page_size: 527 if paginate and len(servers) > page_size:
diff --git a/openstack_dashboard/dashboards/admin/instances/tables.py b/openstack_dashboard/dashboards/admin/instances/tables.py
index 3791fc5..28c6476 100644
--- a/openstack_dashboard/dashboards/admin/instances/tables.py
+++ b/openstack_dashboard/dashboards/admin/instances/tables.py
@@ -152,6 +152,9 @@ class AdminInstancesTable(tables.DataTable):
152 status=True, 152 status=True,
153 status_choices=STATUS_CHOICES, 153 status_choices=STATUS_CHOICES,
154 display_choices=project_tables.STATUS_DISPLAY_CHOICES) 154 display_choices=project_tables.STATUS_DISPLAY_CHOICES)
155 locked = tables.Column(project_tables.render_locked,
156 verbose_name=_(" "),
157 sortable=False)
155 task = tables.Column("OS-EXT-STS:task_state", 158 task = tables.Column("OS-EXT-STS:task_state",
156 verbose_name=_("Task"), 159 verbose_name=_("Task"),
157 empty_value=project_tables.TASK_DISPLAY_NONE, 160 empty_value=project_tables.TASK_DISPLAY_NONE,
diff --git a/openstack_dashboard/dashboards/project/instances/tables.py b/openstack_dashboard/dashboards/project/instances/tables.py
index 3f52f6c..f2bf1ee 100644
--- a/openstack_dashboard/dashboards/project/instances/tables.py
+++ b/openstack_dashboard/dashboards/project/instances/tables.py
@@ -22,6 +22,7 @@ from django import shortcuts
22from django import template 22from django import template
23from django.template.defaultfilters import title 23from django.template.defaultfilters import title
24from django.utils.http import urlencode 24from django.utils.http import urlencode
25from django.utils.safestring import mark_safe
25from django.utils.translation import npgettext_lazy 26from django.utils.translation import npgettext_lazy
26from django.utils.translation import pgettext_lazy 27from django.utils.translation import pgettext_lazy
27from django.utils.translation import string_concat 28from django.utils.translation import string_concat
@@ -1183,6 +1184,23 @@ class InstancesFilterAction(tables.FilterAction):
1183 filter_choices = INSTANCE_FILTER_CHOICES 1184 filter_choices = INSTANCE_FILTER_CHOICES
1184 1185
1185 1186
1187def render_locked(instance):
1188 if not hasattr(instance, 'locked'):
1189 return ""
1190 if instance.locked:
1191 icon_classes = "fa fa-fw fa-lock"
1192 help_tooltip = _("This instance is currently locked. To enable more "
1193 "actions on it, please unlock it by selecting Unlock "
1194 "Instance from the actions menu.")
1195 else:
1196 icon_classes = "fa fa-fw fa-unlock text-muted"
1197 help_tooltip = _("This instance is unlocked.")
1198
1199 locked_status = ('<span data-toggle="tooltip" title="{}" class="{}">'
1200 '</span>').format(help_tooltip, icon_classes)
1201 return mark_safe(locked_status)
1202
1203
1186class InstancesTable(tables.DataTable): 1204class InstancesTable(tables.DataTable):
1187 TASK_STATUS_CHOICES = ( 1205 TASK_STATUS_CHOICES = (
1188 (None, True), 1206 (None, True),
@@ -1216,6 +1234,9 @@ class InstancesTable(tables.DataTable):
1216 status=True, 1234 status=True,
1217 status_choices=STATUS_CHOICES, 1235 status_choices=STATUS_CHOICES,
1218 display_choices=STATUS_DISPLAY_CHOICES) 1236 display_choices=STATUS_DISPLAY_CHOICES)
1237 locked = tables.Column(render_locked,
1238 verbose_name="",
1239 sortable=False)
1219 az = tables.Column("availability_zone", 1240 az = tables.Column("availability_zone",
1220 verbose_name=_("Availability Zone")) 1241 verbose_name=_("Availability Zone"))
1221 task = tables.Column("OS-EXT-STS:task_state", 1242 task = tables.Column("OS-EXT-STS:task_state",
diff --git a/openstack_dashboard/dashboards/project/instances/templates/instances/_detail_overview.html b/openstack_dashboard/dashboards/project/instances/templates/instances/_detail_overview.html
index fce3b05..6b1500f 100644
--- a/openstack_dashboard/dashboards/project/instances/templates/instances/_detail_overview.html
+++ b/openstack_dashboard/dashboards/project/instances/templates/instances/_detail_overview.html
@@ -8,6 +8,10 @@
8 <dd>{{ instance.id }}</dd> 8 <dd>{{ instance.id }}</dd>
9 <dt>{% trans "Status" %}</dt> 9 <dt>{% trans "Status" %}</dt>
10 <dd>{{ instance.status_label|title }}</dd> 10 <dd>{{ instance.status_label|title }}</dd>
11 {% if instance.locked != None %}
12 <dt>{% trans "Locked" %}</dt>
13 <dd>{{ instance.locked }}</dd>
14 {% endif %}
11 <dt>{% trans "Availability Zone" %}</dt> 15 <dt>{% trans "Availability Zone" %}</dt>
12 <dd>{{ instance.availability_zone|default:_("-") }}</dd> 16 <dd>{{ instance.availability_zone|default:_("-") }}</dd>
13 <dt>{% trans "Created" %}</dt> 17 <dt>{% trans "Created" %}</dt>
diff --git a/openstack_dashboard/test/api_tests/neutron_tests.py b/openstack_dashboard/test/api_tests/neutron_tests.py
index 0e288e4..2854f5d 100644
--- a/openstack_dashboard/test/api_tests/neutron_tests.py
+++ b/openstack_dashboard/test/api_tests/neutron_tests.py
@@ -1093,6 +1093,8 @@ class NeutronApiFloatingIpTests(NeutronApiTestBase):
1093 servers = self.servers.list() 1093 servers = self.servers.list()
1094 novaclient = self.stub_novaclient() 1094 novaclient = self.stub_novaclient()
1095 novaclient.servers = self.mox.CreateMockAnything() 1095 novaclient.servers = self.mox.CreateMockAnything()
1096 novaclient.versions = self.mox.CreateMockAnything()
1097 novaclient.versions.get_current().AndReturn("2.45")
1096 search_opts = {'project_id': self.request.user.tenant_id} 1098 search_opts = {'project_id': self.request.user.tenant_id}
1097 novaclient.servers.list(False, search_opts).AndReturn(servers) 1099 novaclient.servers.list(False, search_opts).AndReturn(servers)
1098 1100
diff --git a/openstack_dashboard/test/api_tests/nova_tests.py b/openstack_dashboard/test/api_tests/nova_tests.py
index 2583dee..1c5eefa 100644
--- a/openstack_dashboard/test/api_tests/nova_tests.py
+++ b/openstack_dashboard/test/api_tests/nova_tests.py
@@ -141,6 +141,8 @@ class ComputeApiTests(test.APITestCase):
141 141
142 novaclient = self.stub_novaclient() 142 novaclient = self.stub_novaclient()
143 novaclient.servers = self.mox.CreateMockAnything() 143 novaclient.servers = self.mox.CreateMockAnything()
144 novaclient.versions = self.mox.CreateMockAnything()
145 novaclient.versions.get_current().AndReturn("2.45")
144 novaclient.servers.list(True, {'all_tenants': True}).AndReturn(servers) 146 novaclient.servers.list(True, {'all_tenants': True}).AndReturn(servers)
145 self.mox.ReplayAll() 147 self.mox.ReplayAll()
146 148
@@ -154,6 +156,8 @@ class ComputeApiTests(test.APITestCase):
154 servers = self.servers.list() 156 servers = self.servers.list()
155 novaclient = self.stub_novaclient() 157 novaclient = self.stub_novaclient()
156 novaclient.servers = self.mox.CreateMockAnything() 158 novaclient.servers = self.mox.CreateMockAnything()
159 novaclient.versions = self.mox.CreateMockAnything()
160 novaclient.versions.get_current().AndReturn("2.45")
157 novaclient.servers.list(True, 161 novaclient.servers.list(True,
158 {'all_tenants': True, 162 {'all_tenants': True,
159 'marker': None, 163 'marker': None,
@@ -174,6 +178,8 @@ class ComputeApiTests(test.APITestCase):
174 servers = self.servers.list() 178 servers = self.servers.list()
175 novaclient = self.stub_novaclient() 179 novaclient = self.stub_novaclient()
176 novaclient.servers = self.mox.CreateMockAnything() 180 novaclient.servers = self.mox.CreateMockAnything()
181 novaclient.versions = self.mox.CreateMockAnything()
182 novaclient.versions.get_current().AndReturn("2.45")
177 novaclient.servers.list(True, 183 novaclient.servers.list(True,
178 {'all_tenants': True, 184 {'all_tenants': True,
179 'marker': None, 185 'marker': None,
@@ -267,6 +273,8 @@ class ComputeApiTests(test.APITestCase):
267 server = self.servers.first() 273 server = self.servers.first()
268 274
269 novaclient = self.stub_novaclient() 275 novaclient = self.stub_novaclient()
276 novaclient.versions = self.mox.CreateMockAnything()
277 novaclient.versions.get_current().AndReturn("2.45")
270 novaclient.servers = self.mox.CreateMockAnything() 278 novaclient.servers = self.mox.CreateMockAnything()
271 novaclient.servers.get(server.id).AndReturn(server) 279 novaclient.servers.get(server.id).AndReturn(server)
272 self.mox.ReplayAll() 280 self.mox.ReplayAll()
@@ -385,6 +393,8 @@ class ComputeApiTests(test.APITestCase):
385 novaclient = self.stub_novaclient() 393 novaclient = self.stub_novaclient()
386 server_uuid = hypervisor.servers[0]["uuid"] 394 server_uuid = hypervisor.servers[0]["uuid"]
387 395
396 novaclient.versions = self.mox.CreateMockAnything()
397 novaclient.versions.get_current().AndReturn("2.45")
388 novaclient.hypervisors = self.mox.CreateMockAnything() 398 novaclient.hypervisors = self.mox.CreateMockAnything()
389 novaclient.hypervisors.search('host', True).AndReturn([hypervisor]) 399 novaclient.hypervisors.search('host', True).AndReturn([hypervisor])
390 400
@@ -405,6 +415,8 @@ class ComputeApiTests(test.APITestCase):
405 novaclient = self.stub_novaclient() 415 novaclient = self.stub_novaclient()
406 server_uuid = hypervisor.servers[0]["uuid"] 416 server_uuid = hypervisor.servers[0]["uuid"]
407 417
418 novaclient.versions = self.mox.CreateMockAnything()
419 novaclient.versions.get_current().AndReturn("2.45")
408 novaclient.hypervisors = self.mox.CreateMockAnything() 420 novaclient.hypervisors = self.mox.CreateMockAnything()
409 novaclient.hypervisors.search('host', True).AndReturn([hypervisor]) 421 novaclient.hypervisors.search('host', True).AndReturn([hypervisor])
410 422
@@ -425,6 +437,8 @@ class ComputeApiTests(test.APITestCase):
425 novaclient = self.stub_novaclient() 437 novaclient = self.stub_novaclient()
426 server_uuid = hypervisor.servers[0]["uuid"] 438 server_uuid = hypervisor.servers[0]["uuid"]
427 439
440 novaclient.versions = self.mox.CreateMockAnything()
441 novaclient.versions.get_current().AndReturn("2.45")
428 novaclient.hypervisors = self.mox.CreateMockAnything() 442 novaclient.hypervisors = self.mox.CreateMockAnything()
429 novaclient.hypervisors.search('host', True).AndReturn([hypervisor]) 443 novaclient.hypervisors.search('host', True).AndReturn([hypervisor])
430 444
diff --git a/openstack_dashboard/test/helpers.py b/openstack_dashboard/test/helpers.py
index df5be0c..a775743 100644
--- a/openstack_dashboard/test/helpers.py
+++ b/openstack_dashboard/test/helpers.py
@@ -417,6 +417,9 @@ class APITestCase(TestCase):
417 """ 417 """
418 return self.stub_glanceclient() 418 return self.stub_glanceclient()
419 419
420 def fake_novaclient(request, version=None):
421 return self.stub_novaclient()
422
420 # Store the original clients 423 # Store the original clients
421 self._original_glanceclient = api.glance.glanceclient 424 self._original_glanceclient = api.glance.glanceclient
422 self._original_keystoneclient = api.keystone.keystoneclient 425 self._original_keystoneclient = api.keystone.keystoneclient
@@ -428,7 +431,7 @@ class APITestCase(TestCase):
428 # Replace the clients with our stubs. 431 # Replace the clients with our stubs.
429 api.glance.glanceclient = fake_glanceclient 432 api.glance.glanceclient = fake_glanceclient
430 api.keystone.keystoneclient = fake_keystoneclient 433 api.keystone.keystoneclient = fake_keystoneclient
431 api.nova.novaclient = lambda request: self.stub_novaclient() 434 api.nova.novaclient = fake_novaclient
432 api.neutron.neutronclient = lambda request: self.stub_neutronclient() 435 api.neutron.neutronclient = lambda request: self.stub_neutronclient()
433 api.cinder.cinderclient = lambda request: self.stub_cinderclient() 436 api.cinder.cinderclient = lambda request: self.stub_cinderclient()
434 api.heat.heatclient = (lambda request, password=None: 437 api.heat.heatclient = (lambda request, password=None:
diff --git a/releasenotes/notes/bug-1593903-8fb8721dc2449f71.yaml b/releasenotes/notes/bug-1593903-8fb8721dc2449f71.yaml
new file mode 100644
index 0000000..9f0403e
--- /dev/null
+++ b/releasenotes/notes/bug-1593903-8fb8721dc2449f71.yaml
@@ -0,0 +1,6 @@
1---
2features:
3 - |
4 Added a locked status column on admin/project instances table. It will
5 show a locked or unlocked icon if nova 2.9 or above is used. The locked
6 status is also available on instance details panel.