Skip to content

Commit e60bf28

Browse files
author
Jamie Lennox
committed
Use glanceclient's inbuilt images find
Glanceclient image listing was special cased as it wasn't implemented in glanceclient directly. This is no longer the case and we should use glanceclient's functions. Change-Id: If8d1246f1bd97c07f9f10f5457aa32124efa0be3
1 parent d5f2c50 commit e60bf28

1 file changed

Lines changed: 1 addition & 55 deletions

File tree

‎openstackclient/image/client.py‎

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515

1616
import logging
1717

18-
from glanceclient import exc as gc_exceptions
19-
from glanceclient.v1 import client as gc_v1_client
20-
from glanceclient.v1 import images as gc_v1_images
2118
from openstackclient.common import utils
2219

2320

@@ -27,7 +24,7 @@
2724
API_VERSION_OPTION = 'os_image_api_version'
2825
API_NAME = "image"
2926
API_VERSIONS = {
30-
"1": "openstackclient.image.client.Client_v1",
27+
"1": "glanceclient.v1.client.Client",
3128
"2": "glanceclient.v2.client.Client",
3229
}
3330

@@ -89,54 +86,3 @@ def build_option_parser(parser):
8986
DEFAULT_IMAGE_API_VERSION +
9087
' (Env: OS_IMAGE_API_VERSION)')
9188
return parser
92-
93-
94-
# NOTE(dtroyer): glanceclient.v1.image.ImageManager() doesn't have a find()
95-
# method so add one here until the common client libs arrive
96-
# A similar subclass will be required for v2
97-
98-
class Client_v1(gc_v1_client.Client):
99-
"""An image v1 client that uses ImageManager_v1"""
100-
101-
def __init__(self, *args, **kwargs):
102-
super(Client_v1, self).__init__(*args, **kwargs)
103-
self.images = ImageManager_v1(getattr(self, 'http_client', self))
104-
105-
106-
class ImageManager_v1(gc_v1_images.ImageManager):
107-
"""Add find() and findall() to the ImageManager class"""
108-
109-
def find(self, **kwargs):
110-
"""Find a single item with attributes matching ``**kwargs``.
111-
112-
This isn't very efficient: it loads the entire list then filters on
113-
the Python side.
114-
"""
115-
rl = self.findall(**kwargs)
116-
num = len(rl)
117-
118-
if num == 0:
119-
raise gc_exceptions.NotFound
120-
elif num > 1:
121-
raise gc_exceptions.NoUniqueMatch
122-
else:
123-
return rl[0]
124-
125-
def findall(self, **kwargs):
126-
"""Find all items with attributes matching ``**kwargs``.
127-
128-
This isn't very efficient: it loads the entire list then filters on
129-
the Python side.
130-
"""
131-
found = []
132-
searches = kwargs.items()
133-
134-
for obj in self.list():
135-
try:
136-
if all(getattr(obj, attr) == value
137-
for (attr, value) in searches):
138-
found.append(obj)
139-
except AttributeError:
140-
continue
141-
142-
return found

0 commit comments

Comments
 (0)