Skip to content

Commit 4c91e7c

Browse files
committed
Use the cliff framework's ShowOne as intended for show image.
Also reformat code to follow newer PEP8 version. Full cleanup and PEP8 version bump coming in later patch. Change-Id: Ida3dd9a89660b9c4a91449846dd2d6e223ef187a
1 parent 8d64cc2 commit 4c91e7c

1 file changed

Lines changed: 15 additions & 18 deletions

File tree

‎openstackclient/image/v2/image.py‎

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from cliff import command
2121
from cliff import lister
22+
from cliff import show
2223

2324
from glanceclient.common import utils as gc_utils
2425
from openstackclient.common import utils
@@ -35,12 +36,12 @@ def get_parser(self, prog_name):
3536
parser.add_argument(
3637
"--page-size",
3738
metavar="<size>",
38-
help="Number of images to request in each paginated request.",
39-
)
39+
help="Number of images to request in each paginated request.")
4040
return parser
4141

4242
def take_action(self, parsed_args):
4343
self.log.debug("take_action(%s)" % parsed_args)
44+
4445
image_client = self.app.client_manager.image
4546

4647
kwargs = {}
@@ -50,11 +51,7 @@ def take_action(self, parsed_args):
5051
data = image_client.images.list(**kwargs)
5152
columns = ["ID", "Name"]
5253

53-
return (columns,
54-
(utils.get_item_properties(
55-
s, columns,
56-
) for s in data),
57-
)
54+
return (columns, (utils.get_item_properties(s, columns) for s in data))
5855

5956

6057
class SaveImage(command.Command):
@@ -68,26 +65,25 @@ def get_parser(self, prog_name):
6865
parser.add_argument(
6966
"--file",
7067
metavar="<file>",
71-
help="Local file to save downloaded image data to. "
72-
"If this is not specified the image data will be "
73-
"written to stdout.",
74-
)
68+
help="Local file to save downloaded image data "
69+
"to. If this is not specified the image "
70+
"data will be written to stdout.")
7571
parser.add_argument(
7672
"id",
7773
metavar="<image_id>",
78-
help="ID of image to describe.",
79-
)
74+
help="ID of image to describe.")
8075
return parser
8176

8277
def take_action(self, parsed_args):
8378
self.log.debug("take_action(%s)" % parsed_args)
84-
image_client = self.app.client_manager.image
8579

80+
image_client = self.app.client_manager.image
8681
data = image_client.images.data(parsed_args.id)
82+
8783
gc_utils.save_image(data, parsed_args.file)
8884

8985

90-
class ShowImage(command.Command):
86+
class ShowImage(show.ShowOne):
9187
"""Show image command"""
9288

9389
api = "image"
@@ -98,12 +94,13 @@ def get_parser(self, prog_name):
9894
parser.add_argument(
9995
"id",
10096
metavar="<image_id>",
101-
help="ID of image to describe.",
102-
)
97+
help="ID of image to describe.")
10398
return parser
10499

105100
def take_action(self, parsed_args):
106101
self.log.debug("take_action(%s)" % parsed_args)
102+
107103
image_client = self.app.client_manager.image
104+
data = image_client.images.get(parsed_args.id)
108105

109-
gc_utils.print_dict(image_client.images.get(parsed_args.id))
106+
return zip(*sorted(data.iteritems()))

0 commit comments

Comments
 (0)