Merge "Add more columns to image list output"
This commit is contained in:
commit
7b70143695
@ -291,6 +291,12 @@ class ListImage(lister.Lister):
|
||||
metavar="<size>",
|
||||
help="Number of images to request in each paginated request",
|
||||
)
|
||||
parser.add_argument(
|
||||
'--long',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help='List additional fields in output',
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
@ -303,7 +309,11 @@ class ListImage(lister.Lister):
|
||||
kwargs["page_size"] = parsed_args.page_size
|
||||
|
||||
data = image_client.images.list(**kwargs)
|
||||
columns = ["ID", "Name"]
|
||||
if parsed_args.long:
|
||||
columns = ('ID', 'Name', 'Disk Format', 'Container Format',
|
||||
'Size', 'Status')
|
||||
else:
|
||||
columns = ("ID", "Name")
|
||||
|
||||
return (columns, (utils.get_item_properties(s, columns) for s in data))
|
||||
|
||||
|
@ -63,6 +63,12 @@ class ListImage(lister.Lister):
|
||||
metavar="<size>",
|
||||
help="Number of images to request in each paginated request",
|
||||
)
|
||||
parser.add_argument(
|
||||
'--long',
|
||||
action='store_true',
|
||||
default=False,
|
||||
help='List additional fields in output',
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
@ -75,7 +81,11 @@ class ListImage(lister.Lister):
|
||||
kwargs["page_size"] = parsed_args.page_size
|
||||
|
||||
data = image_client.images.list(**kwargs)
|
||||
columns = ["ID", "Name"]
|
||||
if parsed_args.long:
|
||||
columns = ('ID', 'Name', 'Disk Format', 'Container Format',
|
||||
'Size', 'Status')
|
||||
else:
|
||||
columns = ("ID", "Name")
|
||||
|
||||
return (columns, (utils.get_item_properties(s, columns) for s in data))
|
||||
|
||||
|
@ -446,3 +446,48 @@ class TestImageSet(TestImage):
|
||||
image_fakes.image_id,
|
||||
**kwargs
|
||||
)
|
||||
|
||||
|
||||
class TestImageList(TestImage):
|
||||
|
||||
def setUp(self):
|
||||
super(TestImageList, self).setUp()
|
||||
|
||||
# This is the return value for utils.find_resource()
|
||||
self.images_mock.list.return_value = [
|
||||
fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(image_fakes.IMAGE),
|
||||
loaded=True,
|
||||
),
|
||||
]
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = image.ListImage(self.app, None)
|
||||
|
||||
def test_image_list_long_option(self):
|
||||
arglist = [
|
||||
'--long',
|
||||
]
|
||||
verifylist = [
|
||||
('long', True),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
# DisplayCommandBase.take_action() returns two tuples
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
self.images_mock.list.assert_called_with()
|
||||
|
||||
collist = ('ID', 'Name', 'Disk Format', 'Container Format',
|
||||
'Size', 'Status')
|
||||
|
||||
self.assertEqual(columns, collist)
|
||||
datalist = ((
|
||||
image_fakes.image_id,
|
||||
image_fakes.image_name,
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
), )
|
||||
self.assertEqual(datalist, tuple(data))
|
||||
|
@ -61,3 +61,48 @@ class TestImageDelete(TestImage):
|
||||
self.images_mock.delete.assert_called_with(
|
||||
image_fakes.image_id,
|
||||
)
|
||||
|
||||
|
||||
class TestImageList(TestImage):
|
||||
|
||||
def setUp(self):
|
||||
super(TestImageList, self).setUp()
|
||||
|
||||
# This is the return value for utils.find_resource()
|
||||
self.images_mock.list.return_value = [
|
||||
fakes.FakeResource(
|
||||
None,
|
||||
copy.deepcopy(image_fakes.IMAGE),
|
||||
loaded=True,
|
||||
),
|
||||
]
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = image.ListImage(self.app, None)
|
||||
|
||||
def test_image_list_long_option(self):
|
||||
arglist = [
|
||||
'--long',
|
||||
]
|
||||
verifylist = [
|
||||
('long', True),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
# DisplayCommandBase.take_action() returns two tuples
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
self.images_mock.list.assert_called_with()
|
||||
|
||||
collist = ('ID', 'Name', 'Disk Format', 'Container Format',
|
||||
'Size', 'Status')
|
||||
|
||||
self.assertEqual(columns, collist)
|
||||
datalist = ((
|
||||
image_fakes.image_id,
|
||||
image_fakes.image_name,
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
), )
|
||||
self.assertEqual(datalist, tuple(data))
|
||||
|
Loading…
Reference in New Issue
Block a user