diff --git a/openstackclient/image/v1/image.py b/openstackclient/image/v1/image.py index 92d0995344..cd746cf53e 100644 --- a/openstackclient/image/v1/image.py +++ b/openstackclient/image/v1/image.py @@ -291,6 +291,12 @@ class ListImage(lister.Lister): metavar="", 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)) diff --git a/openstackclient/image/v2/image.py b/openstackclient/image/v2/image.py index 67cb16b697..ec023b6448 100644 --- a/openstackclient/image/v2/image.py +++ b/openstackclient/image/v2/image.py @@ -63,6 +63,12 @@ class ListImage(lister.Lister): metavar="", 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)) diff --git a/openstackclient/tests/image/v1/test_image.py b/openstackclient/tests/image/v1/test_image.py index b014482a84..3f97b151c2 100644 --- a/openstackclient/tests/image/v1/test_image.py +++ b/openstackclient/tests/image/v1/test_image.py @@ -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)) diff --git a/openstackclient/tests/image/v2/test_image.py b/openstackclient/tests/image/v2/test_image.py index 9dbdad5cbc..3e9eeebb1d 100644 --- a/openstackclient/tests/image/v2/test_image.py +++ b/openstackclient/tests/image/v2/test_image.py @@ -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))