diff options
author | vinay_m <vinay.harsha@tcs.com> | 2020-09-28 14:22:18 +0530 |
---|---|---|
committer | Tatiana Ovchinnikova <t.v.ovtchinnikova@gmail.com> | 2022-02-02 21:44:06 +0000 |
commit | 2e8e0abfa153c30d01f2b1cb937303d6237a5132 (patch) | |
tree | 2985f816424612ffec3227c43bdf082b631b92ac | |
parent | 7a5432de8d68eab5772dd3a23951d0953ba99ddb (diff) | |
download | horizon-2e8e0abfa153c30d01f2b1cb937303d6237a5132.tar.gz |
Non-api filters not working with admin instance tab
The issue was that the filtering opts like project_name, image_name,
flavor_name that are not supported by nova API (non-api filters) do
not work expectedly. These filters are mapped to their IDs [1], but
an instance list retrieved before resolving non-API filters is used [2].
This commit changes the logic to resolve non-API filters first and
then retrieve instances using the updated search_opts.
Note that the image list is handled a bit specially. If 'image_name'
is specified as a filter, we retrieve a corresponding image detail
first before fetching instances to resolve the image name into its ID.
Otherwise, we retrieve images only related to instances retrieved
and this happens after retrieving instances.
[1] https://opendev.org/openstack/horizon/src/commit/f90c3cd50174af4927737e29e2765cd2d7ca507f/openstack_dashboard/dashboards/admin/instances/views.py#L166
[2] https://opendev.org/openstack/horizon/src/commit/f90c3cd50174af4927737e29e2765cd2d7ca507f/openstack_dashboard/dashboards/admin/instances/views.py#L154
Closes-Bug: #1888490
Co-Authored-By: Akihiro Motoki <amotoki@gmail.com>
Change-Id: Id43adbd44778d3375c0d49da3f7530cbb99e16fe
(cherry picked from commit 6b79cdcc1b92a968c967286cc267bac39803c85e)
-rw-r--r-- | openstack_dashboard/dashboards/admin/instances/views.py | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/openstack_dashboard/dashboards/admin/instances/views.py b/openstack_dashboard/dashboards/admin/instances/views.py index 8ca198772..d8a6e2cb8 100644 --- a/openstack_dashboard/dashboards/admin/instances/views.py +++ b/openstack_dashboard/dashboards/admin/instances/views.py @@ -108,6 +108,12 @@ class AdminIndexView(tables.PagedTableMixin, tables.DataTableView): exceptions.handle(self.request, ignore=True) return {} + def _get_images_by_name(self, image_name): + result = api.glance.image_list_detailed( + self.request, filters={'name': image_name}) + images = result[0] + return dict((image.id, image) for image in images) + def _get_flavors(self): # Gather our flavors to correlate against IDs try: @@ -151,22 +157,32 @@ class AdminIndexView(tables.PagedTableMixin, tables.DataTableView): self._needs_filter_first = False - instances = self._get_instances(search_opts, sort_dir) results = futurist_utils.call_functions_parallel( - (self._get_images, [tuple(instances)]), self._get_flavors, self._get_tenants) - image_dict, flavor_dict, tenant_dict = results + flavor_dict, tenant_dict = results - non_api_filter_info = ( + non_api_filter_info = [ ('project', 'tenant_id', tenant_dict.values()), - ('image_name', 'image', image_dict.values()), ('flavor_name', 'flavor', flavor_dict.values()), - ) + ] + + filter_by_image_name = 'image_name' in search_opts + if filter_by_image_name: + image_dict = self._get_images_by_name(search_opts['image_name']) + non_api_filter_info.append( + ('image_name', 'image', image_dict.values()) + ) + if not views.process_non_api_filters(search_opts, non_api_filter_info): self._more = False return [] + instances = self._get_instances(search_opts, sort_dir) + + if not filter_by_image_name: + image_dict = self._get_images(tuple(instances)) + # Loop through instances to get image, flavor and tenant info. for inst in instances: if hasattr(inst, 'image') and isinstance(inst.image, dict): |