From 610798376191902c402890c24e39e4de2e240d2e Mon Sep 17 00:00:00 2001 From: Huan Xiong Date: Sat, 23 Sep 2017 00:41:15 +0800 Subject: [PATCH] Fix non-API bound filters in project and admin instance panels Filters like "image_name", "flavor_name" and "project" in instance panels are keys not supported in Nova List-Servers API directly, so they should be converted to "image", "flavor" and "project_id", respectively, before Horizon calling Nova List-Servers API. That used to work, but was broken in commit df194c8b4c25c6128f03a98fd0e628ba14b743ff because the code change messed up the order. This commit fixes it by converting those filters first and then calling Nova API with modified filters. Change-Id: I504caaab2b6f256e7eb8c2605acaec39c004e80f Closes-Bug: #1718725 --- .../dashboards/admin/instances/views.py | 11 +++------- .../dashboards/project/instances/views.py | 20 ++++++++++++++++--- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/openstack_dashboard/dashboards/admin/instances/views.py b/openstack_dashboard/dashboards/admin/instances/views.py index c4ea11cb3d..c23ef2c4db 100644 --- a/openstack_dashboard/dashboards/admin/instances/views.py +++ b/openstack_dashboard/dashboards/admin/instances/views.py @@ -162,17 +162,10 @@ class AdminIndexView(tables.DataTableView): message=_('Unable to retrieve IP addresses from Neutron.'), ignore=True) - with futurist.ThreadPoolExecutor(max_workers=4) as e: + with futurist.ThreadPoolExecutor(max_workers=3) as e: e.submit(fn=_task_get_tenants) e.submit(fn=_task_get_images) e.submit(fn=_task_get_flavors) - e.submit(fn=_task_get_instances) - - # This code gets activated only in case of filtering by nonexistent - # project, image or flavor. Executing it before _task_get_instances - # would make Horizon make less API calls, but as a drawback would make - # it impossible to parallelize the request. Executing it after is - # a tradeoff, as it happens less often to filter by nonexistent values. if 'project' in search_opts and \ not swap_filter(tenants, search_opts, 'project', 'tenant_id'): @@ -187,6 +180,8 @@ class AdminIndexView(tables.DataTableView): self._more = False return instances + _task_get_instances() + # Loop through instances to get flavor and tenant info. for inst in instances: flavor_id = inst.flavor["id"] diff --git a/openstack_dashboard/dashboards/project/instances/views.py b/openstack_dashboard/dashboards/project/instances/views.py index 6a21f363c5..eea4379ffd 100644 --- a/openstack_dashboard/dashboards/project/instances/views.py +++ b/openstack_dashboard/dashboards/project/instances/views.py @@ -71,7 +71,9 @@ class IndexView(tables.DataTableView): search_opts = self.get_filters({'marker': marker, 'paginate': True}) instances = [] + flavors = [] full_flavors = {} + images = [] image_map = {} def _task_get_instances(): @@ -100,7 +102,8 @@ class IndexView(tables.DataTableView): def _task_get_flavors(): # Gather our flavors to correlate our instances to them try: - flavors = api.nova.flavor_list(self.request) + tmp_flavors = api.nova.flavor_list(self.request) + flavors.extend(tmp_flavors) full_flavors.update([(str(flavor.id), flavor) for flavor in flavors]) except Exception: @@ -110,16 +113,27 @@ class IndexView(tables.DataTableView): # Gather our images to correlate our instances to them try: # TODO(gabriel): Handle pagination. - images = api.glance.image_list_detailed(self.request)[0] + tmp_images = api.glance.image_list_detailed(self.request)[0] + images.extend(tmp_images) image_map.update([(str(image.id), image) for image in images]) except Exception: exceptions.handle(self.request, ignore=True) with futurist.ThreadPoolExecutor(max_workers=3) as e: - e.submit(fn=_task_get_instances) e.submit(fn=_task_get_flavors) e.submit(fn=_task_get_images) + if 'image_name' in search_opts and \ + not swap_filter(images, search_opts, 'image_name', 'image'): + self._more = False + return instances + elif 'flavor_name' in search_opts and \ + not swap_filter(flavors, search_opts, 'flavor_name', 'flavor'): + self._more = False + return instances + + _task_get_instances() + # Loop through instances to get flavor info. for instance in instances: if hasattr(instance, 'image'):