From 30ed9845147efa2012fd90f6fabf4eacc52a03da Mon Sep 17 00:00:00 2001 From: jakedahn Date: Tue, 21 Aug 2012 16:45:58 -0700 Subject: [PATCH] Syspanel volume list once again shows all volumes. * Fixes bug 1039788 * Was missing the all_tenants=1 search opt. Change-Id: I98647620690d8f79a65d92e47eef3fabeb3938e6 --- horizon/api/nova.py | 8 ++++++-- horizon/dashboards/nova/volumes/views.py | 21 ++++++++++++++------ horizon/dashboards/syspanel/volumes/tests.py | 3 ++- horizon/dashboards/syspanel/volumes/views.py | 7 +++++++ 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/horizon/api/nova.py b/horizon/api/nova.py index f7b83bdde..0df74c00b 100644 --- a/horizon/api/nova.py +++ b/horizon/api/nova.py @@ -508,8 +508,12 @@ def virtual_interfaces_list(request, instance_id): return novaclient(request).virtual_interfaces.list(instance_id) -def volume_list(request): - return cinderclient(request).volumes.list() +def volume_list(request, search_opts=None): + """ + To see all volumes in the cloud as an admin you can pass in a special + search option: {'all_tenants': 1} + """ + return cinderclient(request).volumes.list(search_opts=search_opts) def volume_get(request, volume_id): diff --git a/horizon/dashboards/nova/volumes/views.py b/horizon/dashboards/nova/volumes/views.py index 62f320a16..fa788da22 100644 --- a/horizon/dashboards/nova/volumes/views.py +++ b/horizon/dashboards/nova/volumes/views.py @@ -42,32 +42,41 @@ class IndexView(tables.DataTableView): table_class = VolumesTable template_name = 'nova/volumes/index.html' - def get_data(self): - # Gather our volumes + def _get_volumes(self, search_opts=None): try: - volumes = api.volume_list(self.request) + return api.volume_list(self.request, search_opts=search_opts) except: - volumes = [] exceptions.handle(self.request, _('Unable to retrieve volume list.')) + + def _get_instances(self): try: - instance_list = api.server_list(self.request) + return api.server_list(self.request) except: instance_list = [] exceptions.handle(self.request, _("Unable to retrieve volume/instance " "attachment information")) - instances = SortedDict([(inst.id, inst) for inst in instance_list]) + def _set_id_if_nameless(self, volumes, instances): for volume in volumes: # It is possible to create a volume with no name through the # EC2 API, use the ID in those cases. if not volume.display_name: volume.display_name = volume.id + def _set_attachments_string(self, volumes, instances): + instances = SortedDict([(inst.id, inst) for inst in instances]) + for volume in volumes: for att in volume.attachments: server_id = att.get('server_id', None) att['instance'] = instances.get(server_id, None) + + def get_data(self): + volumes = self._get_volumes() + instances = self._get_instances() + self._set_id_if_nameless(volumes, instances) + self._set_attachments_string(volumes, instances) return volumes diff --git a/horizon/dashboards/syspanel/volumes/tests.py b/horizon/dashboards/syspanel/volumes/tests.py index 9234ae287..22acdadec 100644 --- a/horizon/dashboards/syspanel/volumes/tests.py +++ b/horizon/dashboards/syspanel/volumes/tests.py @@ -25,7 +25,8 @@ from horizon import test class VolumeTests(test.BaseAdminViewTests): @test.create_stubs({api: ('server_list', 'volume_list',)}) def test_index(self): - api.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes.list()) + api.volume_list(IsA(http.HttpRequest), search_opts={ + 'all_tenants': 1}).AndReturn(self.volumes.list()) api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers.list()) self.mox.ReplayAll() diff --git a/horizon/dashboards/syspanel/volumes/views.py b/horizon/dashboards/syspanel/volumes/views.py index 4acd5582c..1406cbd25 100644 --- a/horizon/dashboards/syspanel/volumes/views.py +++ b/horizon/dashboards/syspanel/volumes/views.py @@ -27,6 +27,13 @@ class IndexView(_IndexView): table_class = VolumesTable template_name = "syspanel/volumes/index.html" + def get_data(self): + volumes = self._get_volumes(search_opts={'all_tenants': 1}) + instances = self._get_instances() + self._set_id_if_nameless(volumes, instances) + self._set_attachments_string(volumes, instances) + return volumes + class DetailView(_DetailView): template_name = "syspanel/volumes/detail.html"