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
df194c8b4c 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
This commit is contained in:
Huan Xiong 2017-09-23 00:41:15 +08:00
parent a4aed76ab9
commit 6107983761
2 changed files with 20 additions and 11 deletions

View File

@ -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"]

View File

@ -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'):