Add project field in image list subcommand
The motivation is to filter the image by owner Change-Id: I1f08da175a06e62a844f76b0ec18cb3332efef86
This commit is contained in:
parent
f5b185c357
commit
3c80b1b3b2
@ -591,6 +591,12 @@ class ListImage(command.Lister):
|
|||||||
"The supported options are: %s. ") %
|
"The supported options are: %s. ") %
|
||||||
', '.join(MEMBER_STATUS_CHOICES))
|
', '.join(MEMBER_STATUS_CHOICES))
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--project',
|
||||||
|
metavar='<project>',
|
||||||
|
help=_("Search by project (admin only) (name or ID)")
|
||||||
|
)
|
||||||
|
common.add_project_domain_option_to_parser(parser)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--tag',
|
'--tag',
|
||||||
metavar='<tag>',
|
metavar='<tag>',
|
||||||
@ -636,6 +642,7 @@ class ListImage(command.Lister):
|
|||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
|
identity_client = self.app.client_manager.identity
|
||||||
image_client = self.app.client_manager.image
|
image_client = self.app.client_manager.image
|
||||||
|
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
@ -659,6 +666,14 @@ class ListImage(command.Lister):
|
|||||||
kwargs['member_status'] = parsed_args.member_status
|
kwargs['member_status'] = parsed_args.member_status
|
||||||
if parsed_args.tag:
|
if parsed_args.tag:
|
||||||
kwargs['tag'] = parsed_args.tag
|
kwargs['tag'] = parsed_args.tag
|
||||||
|
project_id = None
|
||||||
|
if parsed_args.project:
|
||||||
|
project_id = common.find_project(
|
||||||
|
identity_client,
|
||||||
|
parsed_args.project,
|
||||||
|
parsed_args.project_domain,
|
||||||
|
).id
|
||||||
|
kwargs['owner'] = project_id
|
||||||
if parsed_args.long:
|
if parsed_args.long:
|
||||||
columns = (
|
columns = (
|
||||||
'ID',
|
'ID',
|
||||||
|
@ -769,6 +769,21 @@ class TestImageList(TestImage):
|
|||||||
self.assertEqual(self.columns, columns)
|
self.assertEqual(self.columns, columns)
|
||||||
self.assertEqual(ret_limit, len(tuple(data)))
|
self.assertEqual(ret_limit, len(tuple(data)))
|
||||||
|
|
||||||
|
def test_image_list_project_option(self):
|
||||||
|
self.client.find_image = mock.Mock(return_value=self._image)
|
||||||
|
arglist = [
|
||||||
|
'--project', 'nova',
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('project', 'nova'),
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
self.assertEqual(self.columns, columns)
|
||||||
|
self.assertItemsEqual(self.datalist, tuple(data))
|
||||||
|
|
||||||
@mock.patch('osc_lib.utils.find_resource')
|
@mock.patch('osc_lib.utils.find_resource')
|
||||||
def test_image_list_marker_option(self, fr_mock):
|
def test_image_list_marker_option(self, fr_mock):
|
||||||
# tangchen: Since image_fakes.IMAGE is a dict, it cannot offer a .id
|
# tangchen: Since image_fakes.IMAGE is a dict, it cannot offer a .id
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
Add ``--project`` and ``--project-domain``options to ``image list``
|
||||||
|
command to filter by owner.
|
Loading…
x
Reference in New Issue
Block a user