Revision 2d1202ee kamaki/cli/commands/image.py
b/kamaki/cli/commands/image.py | ||
---|---|---|
175 | 175 |
class image_list(_init_image, _optional_json): |
176 | 176 |
"""List images accessible by user""" |
177 | 177 |
|
178 |
PERMANENTS = ( |
|
179 |
'id', 'name', |
|
180 |
'status', 'container_format', 'disk_format', 'size') |
|
181 |
|
|
178 | 182 |
arguments = dict( |
179 | 183 |
detail=FlagArgument('show detailed output', ('-l', '--details')), |
180 | 184 |
container_format=ValueArgument( |
... | ... | |
203 | 207 |
more=FlagArgument( |
204 | 208 |
'output results in pages (-n to set items per page, default 10)', |
205 | 209 |
'--more'), |
206 |
enum=FlagArgument('Enumerate results', '--enumerate') |
|
210 |
enum=FlagArgument('Enumerate results', '--enumerate'), |
|
211 |
prop=KeyValueArgument('filter by property key=value', ('--property')) |
|
207 | 212 |
) |
208 | 213 |
|
209 | 214 |
def _filtered_by_owner(self, detail, *list_params): |
... | ... | |
225 | 230 |
(not ns) or img['name'].lower().endswith(ns.lower())) and ( |
226 | 231 |
(not nl) or nl.lower() in img['name'].lower())] |
227 | 232 |
|
233 |
def _filtered_by_properties(self, images): |
|
234 |
new_images = [] |
|
235 |
for img in images: |
|
236 |
if set(self['prop'].items()).difference(img['properties'].items()): |
|
237 |
continue |
|
238 |
if self['detail']: |
|
239 |
new_images.append(dict(img)) |
|
240 |
else: |
|
241 |
new_images.append(dict()) |
|
242 |
for k in set(img).intersection(self.PERMANENTS): |
|
243 |
new_images[-1][k] = img[k] |
|
244 |
return new_images |
|
245 |
|
|
228 | 246 |
@errors.generic.all |
229 | 247 |
@errors.cyclades.connection |
230 | 248 |
def _run(self): |
... | ... | |
240 | 258 |
filters[arg] = self[arg] |
241 | 259 |
|
242 | 260 |
order = self['order'] |
243 |
detail = self['detail'] |
|
261 |
detail = self['detail'] or self['prop']
|
|
244 | 262 |
if self['owner']: |
245 | 263 |
images = self._filtered_by_owner(detail, filters, order) |
246 | 264 |
else: |
247 | 265 |
images = self.client.list_public(detail, filters, order) |
248 | 266 |
|
249 | 267 |
images = self._filtered_by_name(images) |
268 |
if self['prop']: |
|
269 |
images = self._filtered_by_properties(images) |
|
250 | 270 |
kwargs = dict(with_enumeration=self['enum']) |
251 | 271 |
if self['more']: |
252 | 272 |
kwargs['page_size'] = self['limit'] or 10 |
Also available in: Unified diff