Revision 236e7d08 kamaki/cli/commands/image_cli.py
b/kamaki/cli/commands/image_cli.py | ||
---|---|---|
212 | 212 |
class image_members(_init_image): |
213 | 213 |
"""Get image members""" |
214 | 214 |
|
215 |
def main(self, image_id): |
|
216 |
super(self.__class__, self).main() |
|
217 |
try: |
|
218 |
members = self.client.list_members(image_id) |
|
219 |
except ClientError as ce: |
|
220 |
raise_if_connection_error(ce, base_url='image.url') |
|
221 |
raiseCLIError(ce) |
|
222 |
except Exception as err: |
|
223 |
raiseCLIError(err) |
|
215 |
@errors.generic.all |
|
216 |
@errors.plankton.connection |
|
217 |
@errors.plankton.id |
|
218 |
def _run(self, image_id): |
|
219 |
members = self.client.list_members(image_id) |
|
224 | 220 |
print_items(members) |
225 | 221 |
|
222 |
def main(self, image_id): |
|
223 |
super(self.__class__, self)._run() |
|
224 |
self._run(image_id) |
|
225 |
|
|
226 | 226 |
|
227 | 227 |
@command(image_cmds) |
228 | 228 |
class image_shared(_init_image): |
229 | 229 |
"""List images shared by a member""" |
230 | 230 |
|
231 |
def main(self, member): |
|
232 |
super(self.__class__, self).main() |
|
233 |
try: |
|
234 |
images = self.client.list_shared(member) |
|
235 |
except ClientError as ce: |
|
236 |
raise_if_connection_error(ce, base_url='image.url') |
|
237 |
raiseCLIError(ce) |
|
238 |
except Exception as err: |
|
239 |
raiseCLIError(err) |
|
231 |
@errors.generic.all |
|
232 |
@errors.plankton.connection |
|
233 |
def _run(self, member): |
|
234 |
images = self.client.list_shared(member) |
|
240 | 235 |
print_items(images) |
241 | 236 |
|
237 |
def main(self, member): |
|
238 |
super(self.__class__, self)._run() |
|
239 |
self._run(member) |
|
240 |
|
|
242 | 241 |
|
243 | 242 |
@command(image_cmds) |
244 | 243 |
class image_addmember(_init_image): |
245 | 244 |
"""Add a member to an image""" |
246 | 245 |
|
247 |
def main(self, image_id, member): |
|
248 |
super(self.__class__, self).main() |
|
249 |
try: |
|
246 |
@errors.generic.all |
|
247 |
@errors.plankton.connection |
|
248 |
@errors.plankton.id |
|
249 |
def _run(self, image_id, member): |
|
250 | 250 |
self.client.add_member(image_id, member) |
251 |
except ClientError as ce: |
|
252 |
if ce.status == 404: |
|
253 |
raiseCLIError(ce, |
|
254 |
'No image with id %s found' % image_id, |
|
255 |
details=about_image_id) |
|
256 |
raise_if_connection_error(ce, base_url='image.url') |
|
257 |
raiseCLIError(ce) |
|
258 |
except Exception as err: |
|
259 |
raiseCLIError(err) |
|
251 |
|
|
252 |
def main(self, image_id, member): |
|
253 |
super(self.__class__, self)._run() |
|
254 |
self._run(image_id, member) |
|
260 | 255 |
|
261 | 256 |
|
262 | 257 |
@command(image_cmds) |
263 | 258 |
class image_delmember(_init_image): |
264 | 259 |
"""Remove a member from an image""" |
265 | 260 |
|
266 |
def main(self, image_id, member): |
|
267 |
super(self.__class__, self).main() |
|
268 |
try: |
|
261 |
@errors.generic.all |
|
262 |
@errors.plankton.connection |
|
263 |
@errors.plankton.id |
|
264 |
def _run(self, image_id, member): |
|
269 | 265 |
self.client.remove_member(image_id, member) |
270 |
except ClientError as ce: |
|
271 |
if ce.status == 404: |
|
272 |
raiseCLIError(ce, |
|
273 |
'No image with id %s found' % image_id, |
|
274 |
details=about_image_id) |
|
275 |
raise_if_connection_error(ce, base_url='image.url') |
|
276 |
raiseCLIError(ce) |
|
277 |
except Exception as err: |
|
278 |
raiseCLIError(err) |
|
266 |
|
|
267 |
def main(self, image_id, member): |
|
268 |
super(self.__class__, self)._run() |
|
269 |
self._run(image_id, member) |
|
279 | 270 |
|
280 | 271 |
|
281 | 272 |
@command(image_cmds) |
282 | 273 |
class image_setmembers(_init_image): |
283 | 274 |
"""Set the members of an image""" |
284 | 275 |
|
285 |
def main(self, image_id, *member): |
|
286 |
super(self.__class__, self).main() |
|
287 |
try: |
|
288 |
self.client.set_members(image_id, member) |
|
289 |
except ClientError as ce: |
|
290 |
if ce.status == 404: |
|
291 |
raiseCLIError(ce, |
|
292 |
'No image with id %s found' % image_id, |
|
293 |
details=about_image_id) |
|
294 |
raise_if_connection_error(ce, base_url='image.url') |
|
295 |
raiseCLIError(ce) |
|
296 |
except Exception as err: |
|
297 |
raiseCLIError(err) |
|
276 |
@errors.generic.all |
|
277 |
@errors.plankton.connection |
|
278 |
@errors.plankton.id |
|
279 |
def _run(self, image_id, *members): |
|
280 |
self.client.set_members(image_id, members) |
|
281 |
|
|
282 |
def main(self, image_id, *members): |
|
283 |
super(self.__class__, self)._run() |
|
284 |
self._run(image_id, members) |
|
298 | 285 |
|
299 | 286 |
|
300 | 287 |
@command(image_cmds) |
... | ... | |
314 | 301 |
if 'metadata' in img: |
315 | 302 |
img['metadata'] = img['metadata']['values'] |
316 | 303 |
|
304 |
@errors.generic.all |
|
305 |
@errors.cyclades.connection |
|
306 |
def _run(self): |
|
307 |
images = self.client.list_images(self['detail']) |
|
308 |
if self['detail']: |
|
309 |
self._make_results_pretty(images) |
|
310 |
if self['more']: |
|
311 |
print_items(images, |
|
312 |
page_size=self['limit'] if self['limit'] else 10) |
|
313 |
elif self['limit']: |
|
314 |
print_items(images[:self['limit']]) |
|
315 |
else: |
|
316 |
print_items(images) |
|
317 |
|
|
317 | 318 |
def main(self): |
318 |
super(self.__class__, self).main() |
|
319 |
try: |
|
320 |
images = self.client.list_images(self['detail']) |
|
321 |
if self['detail']: |
|
322 |
self._make_results_pretty(images) |
|
323 |
if self['more']: |
|
324 |
print_items(images, |
|
325 |
page_size=self['limit'] if self['limit'] else 10) |
|
326 |
elif self['limit']: |
|
327 |
print_items(images[:self['limit']]) |
|
328 |
else: |
|
329 |
print_items(images) |
|
330 |
except ClientError as ce: |
|
331 |
raise_if_connection_error(ce) |
|
332 |
raiseCLIError(ce) |
|
333 |
except Exception as err: |
|
334 |
raiseCLIError(err) |
|
319 |
super(self.__class__, self)._run() |
|
320 |
self._run() |
|
335 | 321 |
|
336 | 322 |
|
337 | 323 |
@command(image_cmds) |
338 | 324 |
class image_info(_init_cyclades): |
339 | 325 |
"""Get detailed information on an image""" |
340 | 326 |
|
341 |
@classmethod |
|
342 |
def _make_results_pretty(self, image): |
|
327 |
@errors.generic.all |
|
328 |
@errors.cyclades.connection |
|
329 |
@errors.plankton.id |
|
330 |
def _run(self, image_id): |
|
331 |
image = self.client.get_image_details(image_id) |
|
343 | 332 |
if 'metadata' in image: |
344 | 333 |
image['metadata'] = image['metadata']['values'] |
334 |
print_dict(image) |
|
345 | 335 |
|
346 | 336 |
def main(self, image_id): |
347 |
super(self.__class__, self).main() |
|
348 |
try: |
|
349 |
image = self.client.get_image_details(image_id) |
|
350 |
self._make_results_pretty(image) |
|
351 |
except ClientError as ce: |
|
352 |
if ce.status == 404 and 'image' in ('%s' % ce).lower(): |
|
353 |
raiseCLIError(ce, |
|
354 |
'No image with id %s found' % image_id, |
|
355 |
details=about_image_id) |
|
356 |
raise_if_connection_error(ce) |
|
357 |
raiseCLIError(ce) |
|
358 |
except Exception as err: |
|
359 |
raiseCLIError(err) |
|
360 |
print_dict(image) |
|
337 |
super(self.__class__, self)._run() |
|
338 |
self._run(image_id) |
|
361 | 339 |
|
362 | 340 |
|
363 | 341 |
@command(image_cmds) |
364 | 342 |
class image_delete(_init_cyclades): |
365 | 343 |
"""Delete an image (image file remains intact)""" |
366 | 344 |
|
345 |
@errors.generic.all |
|
346 |
@errors.cyclades.connection |
|
347 |
@errors.plankton.id |
|
348 |
def _run(self, image_id): |
|
349 |
self.client.delete_image(image_id) |
|
350 |
|
|
367 | 351 |
def main(self, image_id): |
368 |
super(self.__class__, self).main() |
|
369 |
try: |
|
370 |
self.client.delete_image(image_id) |
|
371 |
except ClientError as ce: |
|
372 |
if ce.status == 404 and 'image' in ('%s' % ce).lower(): |
|
373 |
raiseCLIError(ce, |
|
374 |
'No image with id %s found' % image_id, |
|
375 |
details=about_image_id) |
|
376 |
raise_if_connection_error(ce) |
|
377 |
raiseCLIError(ce) |
|
378 |
except Exception as err: |
|
379 |
raiseCLIError(err) |
|
352 |
super(self.__class__, self)._run() |
|
353 |
self._run(image_id) |
|
380 | 354 |
|
381 | 355 |
|
382 | 356 |
@command(image_cmds) |
383 | 357 |
class image_properties(_init_cyclades): |
384 | 358 |
"""Get properties related to OS installation in an image""" |
385 | 359 |
|
360 |
@errors.generic.all |
|
361 |
@errors.cyclades.connection |
|
362 |
@errors.plankton.id |
|
363 |
@errors.plankton.metadata |
|
364 |
def _run(self, image_id, key): |
|
365 |
r = self.client.get_image_metadata(image_id, key) |
|
366 |
print_dict(r) |
|
367 |
|
|
386 | 368 |
def main(self, image_id, key=''): |
387 |
super(self.__class__, self).main() |
|
388 |
try: |
|
389 |
reply = self.client.get_image_metadata(image_id, key) |
|
390 |
except ClientError as ce: |
|
391 |
if ce.status == 404: |
|
392 |
if 'image' in ('%s' % ce).lower(): |
|
393 |
raiseCLIError(ce, |
|
394 |
'No image with id %s found' % image_id, |
|
395 |
details=about_image_id) |
|
396 |
elif 'metadata' in ('%s' % ce).lower(): |
|
397 |
raiseCLIError(ce, |
|
398 |
'No properties with key %s in this image' % key) |
|
399 |
raise_if_connection_error(ce) |
|
400 |
raiseCLIError(ce) |
|
401 |
except Exception as err: |
|
402 |
raiseCLIError(err) |
|
403 |
print_dict(reply) |
|
369 |
super(self.__class__, self)._run() |
|
370 |
self._run(image_id, key) |
|
404 | 371 |
|
405 | 372 |
|
406 | 373 |
@command(image_cmds) |
407 | 374 |
class image_addproperty(_init_cyclades): |
408 | 375 |
"""Add an OS-related property to an image""" |
409 | 376 |
|
377 |
@errors.generic.all |
|
378 |
@errors.cyclades.connection |
|
379 |
@errors.plankton.id |
|
380 |
def _run(self, image_id, key, val): |
|
381 |
r = self.client.create_image_metadata(image_id, key, val) |
|
382 |
print_dict(r) |
|
383 |
|
|
410 | 384 |
def main(self, image_id, key, val): |
411 |
super(self.__class__, self).main() |
|
412 |
try: |
|
413 |
assert(key) |
|
414 |
reply = self.client.create_image_metadata(image_id, key, val) |
|
415 |
except ClientError as ce: |
|
416 |
if ce.status == 404 and 'image' in ('%s' % ce).lower(): |
|
417 |
raiseCLIError(ce, |
|
418 |
'No image with id %s found' % image_id, |
|
419 |
details=about_image_id) |
|
420 |
raise_if_connection_error(ce) |
|
421 |
raiseCLIError(ce) |
|
422 |
except Exception as err: |
|
423 |
raiseCLIError(err) |
|
424 |
print_dict(reply) |
|
385 |
super(self.__class__, self)._run() |
|
386 |
self._run(image_id, key, val) |
|
425 | 387 |
|
426 | 388 |
|
427 | 389 |
@command(image_cmds) |
428 | 390 |
class image_setproperty(_init_cyclades): |
429 | 391 |
"""Update an existing property in an image""" |
430 | 392 |
|
431 |
def main(self, image_id, key, val): |
|
432 |
super(self.__class__, self).main() |
|
393 |
@errors.generic.all |
|
394 |
@errors.cyclades.connection |
|
395 |
@errors.plankton.id |
|
396 |
def _run(self, image_id, key, val): |
|
433 | 397 |
metadata = {key: val} |
434 |
try: |
|
435 |
reply = self.client.update_image_metadata(image_id, **metadata) |
|
436 |
except ClientError as ce: |
|
437 |
if ce.status == 404 and 'image' in ('%s' % ce).lower(): |
|
438 |
raiseCLIError(ce, |
|
439 |
'No image with id %s found' % image_id, |
|
440 |
details=about_image_id) |
|
441 |
raise_if_connection_error(ce) |
|
442 |
raiseCLIError(ce) |
|
443 |
except Exception as err: |
|
444 |
raiseCLIError(err) |
|
445 |
print_dict(reply) |
|
398 |
r = self.client.update_image_metadata(image_id, **metadata) |
|
399 |
print_dict(r) |
|
400 |
|
|
401 |
def main(self, image_id, key, val): |
|
402 |
super(self.__class__, self)._run() |
|
403 |
self._run(image_id, key, val) |
|
446 | 404 |
|
447 | 405 |
|
448 | 406 |
@command(image_cmds) |
449 | 407 |
class image_delproperty(_init_cyclades): |
450 | 408 |
"""Delete a property of an image""" |
451 | 409 |
|
410 |
@errors.generic.all |
|
411 |
@errors.cyclades.connection |
|
412 |
@errors.plankton.id |
|
413 |
@errors.plankton.metadata |
|
414 |
def _run(self, image_id, key): |
|
415 |
self.client.delete_image_metadata(image_id, key) |
|
416 |
|
|
452 | 417 |
def main(self, image_id, key): |
453 |
super(self.__class__, self).main() |
|
454 |
try: |
|
455 |
self.client.delete_image_metadata(image_id, key) |
|
456 |
except ClientError as ce: |
|
457 |
if ce.status == 404: |
|
458 |
if 'image' in ('%s' % ce).lower(): |
|
459 |
raiseCLIError(ce, |
|
460 |
'No image with id %s found' % image_id, |
|
461 |
details=about_image_id) |
|
462 |
elif 'metadata' in ('%s' % ce).lower(): |
|
463 |
raiseCLIError(ce, |
|
464 |
'No properties with key %s in this image' % key) |
|
465 |
raise_if_connection_error(ce) |
|
466 |
raiseCLIError(ce) |
|
467 |
except Exception as err: |
|
468 |
raiseCLIError(err) |
|
418 |
super(self.__class__, self)._run() |
|
419 |
self._run(image_id, key) |
Also available in: Unified diff