summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHuan Xiong <huan.xiong@hxt-semitech.com>2017-09-26 14:38:55 +0800
committerAkihiro Motoki <amotoki@gmail.com>2017-12-16 12:41:48 +0000
commitf929d39ab471e2462a2bfcd35d880e2aafb724bb (patch)
tree54b795f57a8d20220b21de72004518aaa78e4430
parent79b7b50a966e153569b85fe04161b8d13ccba083 (diff)
Do not make duplicate requests to Glance for image names in admin panel
Admin panel generates duplicate (N per instance) requests to Glance for instances that boot from image. The commit fixes it by getting all images information in one shot. Change-Id: I360aef8c34304f3abe76a90787ab63647cd78491 Closes-Bug: #1711486
Notes
Notes (review): Code-Review+2: Akihiro Motoki <amotoki@gmail.com> Workflow+1: Akihiro Motoki <amotoki@gmail.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Sat, 16 Dec 2017 13:40:11 +0000 Reviewed-on: https://review.openstack.org/507388 Project: openstack/horizon Branch: refs/heads/master
-rw-r--r--openstack_dashboard/dashboards/admin/instances/views.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/openstack_dashboard/dashboards/admin/instances/views.py b/openstack_dashboard/dashboards/admin/instances/views.py
index 4c270dc..7db917c 100644
--- a/openstack_dashboard/dashboards/admin/instances/views.py
+++ b/openstack_dashboard/dashboards/admin/instances/views.py
@@ -86,6 +86,7 @@ class AdminIndexView(tables.DataTableView):
86 tenants = [] 86 tenants = []
87 tenant_dict = {} 87 tenant_dict = {}
88 images = [] 88 images = []
89 image_map = {}
89 flavors = [] 90 flavors = []
90 full_flavors = {} 91 full_flavors = {}
91 92
@@ -124,6 +125,7 @@ class AdminIndexView(tables.DataTableView):
124 try: 125 try:
125 tmp_images = api.glance.image_list_detailed(self.request)[0] 126 tmp_images = api.glance.image_list_detailed(self.request)[0]
126 images.extend(tmp_images) 127 images.extend(tmp_images)
128 image_map.update([(image.id, image) for image in images])
127 except Exception: 129 except Exception:
128 msg = _("Unable to retrieve image list.") 130 msg = _("Unable to retrieve image list.")
129 exceptions.handle(self.request, msg) 131 exceptions.handle(self.request, msg)
@@ -169,8 +171,17 @@ class AdminIndexView(tables.DataTableView):
169 171
170 _task_get_instances() 172 _task_get_instances()
171 173
172 # Loop through instances to get flavor and tenant info. 174 # Loop through instances to get image, flavor and tenant info.
173 for inst in instances: 175 for inst in instances:
176 if hasattr(inst, 'image') and isinstance(inst.image, dict):
177 if inst.image.get('id') in image_map:
178 inst.image = image_map[inst.image.get('id')]
179 # In case image not found in image_map, set name to empty
180 # to avoid fallback API call to Glance in api/nova.py
181 # until the call is deprecated in api itself
182 else:
183 inst.image['name'] = _("-")
184
174 flavor_id = inst.flavor["id"] 185 flavor_id = inst.flavor["id"]
175 try: 186 try:
176 if flavor_id in full_flavors: 187 if flavor_id in full_flavors: