Revision fc517e59 snf-cyclades-app/synnefo/plankton/management/commands/image-show.py
b/snf-cyclades-app/synnefo/plankton/management/commands/image-show.py | ||
---|---|---|
28 | 28 |
# policies, either expressed or implied, of GRNET S.A. |
29 | 29 |
# |
30 | 30 |
|
31 |
from optparse import make_option |
|
31 | 32 |
from django.core.management.base import BaseCommand, CommandError |
32 | 33 |
|
34 |
from synnefo.management import common |
|
33 | 35 |
from synnefo.plankton.utils import image_backend |
34 | 36 |
from snf_django.management import utils |
35 | 37 |
|
... | ... | |
37 | 39 |
class Command(BaseCommand): |
38 | 40 |
args = "<image_id>" |
39 | 41 |
help = "Display available information about an image" |
42 |
option_list = BaseCommand.option_list + ( |
|
43 |
make_option( |
|
44 |
'--user-id', |
|
45 |
dest='userid', |
|
46 |
default=None, |
|
47 |
help="The UUID of the owner of the image. Required" |
|
48 |
" if image is not public"), |
|
49 |
) |
|
40 | 50 |
|
51 |
@common.convert_api_faults |
|
41 | 52 |
def handle(self, *args, **options): |
42 | 53 |
|
43 | 54 |
if len(args) != 1: |
44 | 55 |
raise CommandError("Please provide an image ID") |
45 | 56 |
image_id = args[0] |
57 |
user_id = options["userid"] |
|
46 | 58 |
|
47 |
with image_backend(None) as backend: |
|
48 |
images = backend._list_images(None) |
|
49 |
try: |
|
50 |
image = filter(lambda x: x["id"] == image_id, images)[0] |
|
51 |
except IndexError: |
|
52 |
raise CommandError("Image not found. Use snf-manage image-list" |
|
53 |
" to get the list of all images.") |
|
59 |
with image_backend(userid) as backend: |
|
60 |
image = backend.get_image(image_id) |
|
54 | 61 |
utils.pprint_table(out=self.stdout, table=[image.values()], |
55 | 62 |
headers=image.keys(), vertical=True) |
Also available in: Unified diff