Skip to content

Instantly share code, notes, and snippets.

@zioproto
Created May 29, 2017 07:39
Show Gist options
  • Save zioproto/9a12cf426eac1fce58f756048a62ad77 to your computer and use it in GitHub Desktop.
Save zioproto/9a12cf426eac1fce58f756048a62ad77 to your computer and use it in GitHub Desktop.
lp1671693.patch
commit 99f7c8c9ad26539473f65f30547ba548c02ab4fe
Author: Mark Mielke <[email protected]>
Date: Thu Mar 9 23:16:51 2017 -0500
Image list function should normalize owner filter
The api.glance.image_list_detailed() function accepts a list of
filters which it then translates into a form that is acceptable for
Glance v1 or Glance v2. These translations included support for
mapping 'is_public' to 'visibility', but did not include support for
mapping 'property-owner_id' to 'owner'.
This changes adds support for mapping 'property-owner_id' to 'owner'
for Glance v2, and mapping 'owner' to 'property-owner_id' for Glance
v1.
Before this fix, "rebuild instance" from the instances page did not
properly list project-specific images as options. After this fix,
"rebuild instance" is working as expected.
Change-Id: Ica750f8b36bdbadd02a81aed41fd250864a49a66
Closes-Bug: 1671693
(cherry picked from commit 445117eb1fa1cd67e21e69243fbbe12c453192fa)
diff --git a/openstack_dashboard/api/glance.py b/openstack_dashboard/api/glance.py
index 6627124b3..97bb54fbe 100644
--- a/openstack_dashboard/api/glance.py
+++ b/openstack_dashboard/api/glance.py
@@ -160,20 +160,42 @@ def _normalize_is_public_filter(filters):
if not filters:
return
+ # Glance v1 uses filter 'is_public' (True, False).
+ # Glance v2 uses filter 'visibility' ('public', 'private', ...).
if VERSIONS.active >= 2:
if 'is_public' in filters:
+ # Glance v2: Replace 'is_public' with 'visibility'.
visibility = PUBLIC_TO_VISIBILITY_MAP[filters['is_public']]
del filters['is_public']
if visibility is not None:
filters['visibility'] = visibility
elif 'visibility' in filters:
+ # Glance v1: Replace 'visibility' with 'is_public'.
filters['is_public'] = (
getattr(filters, 'visibility', None) == "public")
- del filter['visibility']
+ del filters['visibility']
+
+
+def _normalize_owner_id_filter(filters):
+ if not filters:
+ return
+
+ # Glance v1 uses filter 'property-owner_id' (Project ID).
+ # Glance v2 uses filter 'owner' (Project ID).
+ if VERSIONS.active >= 2:
+ if 'property-owner_id' in filters:
+ # Glance v2: Replace 'property-owner_id' with 'owner'.
+ filters['owner'] = filters['property-owner_id']
+ del filters['property-owner_id']
+ elif 'owner' in filters:
+ # Glance v1: Replace 'owner' with 'property-owner_id'.
+ filters['property-owner_id'] = filters['owner']
+ del filters['owner']
def _normalize_list_input(filters, **kwargs):
_normalize_is_public_filter(filters)
+ _normalize_owner_id_filter(filters)
if VERSIONS.active < 2:
# Glance v1 client processes some keywords specifically.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment