Skip to content

Commit d10706a

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Add project field in image list subcommand"
2 parents 0fd090e + 3c80b1b commit d10706a

3 files changed

Lines changed: 35 additions & 0 deletions

File tree

openstackclient/image/v2/image.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,12 @@ def get_parser(self, prog_name):
591591
"The supported options are: %s. ") %
592592
', '.join(MEMBER_STATUS_CHOICES))
593593
)
594+
parser.add_argument(
595+
'--project',
596+
metavar='<project>',
597+
help=_("Search by project (admin only) (name or ID)")
598+
)
599+
common.add_project_domain_option_to_parser(parser)
594600
parser.add_argument(
595601
'--tag',
596602
metavar='<tag>',
@@ -636,6 +642,7 @@ def get_parser(self, prog_name):
636642
return parser
637643

638644
def take_action(self, parsed_args):
645+
identity_client = self.app.client_manager.identity
639646
image_client = self.app.client_manager.image
640647

641648
kwargs = {}
@@ -659,6 +666,14 @@ def take_action(self, parsed_args):
659666
kwargs['member_status'] = parsed_args.member_status
660667
if parsed_args.tag:
661668
kwargs['tag'] = parsed_args.tag
669+
project_id = None
670+
if parsed_args.project:
671+
project_id = common.find_project(
672+
identity_client,
673+
parsed_args.project,
674+
parsed_args.project_domain,
675+
).id
676+
kwargs['owner'] = project_id
662677
if parsed_args.long:
663678
columns = (
664679
'ID',

openstackclient/tests/unit/image/v2/test_image.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,21 @@ def test_image_list_limit_option(self):
769769
self.assertEqual(self.columns, columns)
770770
self.assertEqual(ret_limit, len(tuple(data)))
771771

772+
def test_image_list_project_option(self):
773+
self.client.find_image = mock.Mock(return_value=self._image)
774+
arglist = [
775+
'--project', 'nova',
776+
]
777+
verifylist = [
778+
('project', 'nova'),
779+
]
780+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
781+
782+
columns, data = self.cmd.take_action(parsed_args)
783+
784+
self.assertEqual(self.columns, columns)
785+
self.assertItemsEqual(self.datalist, tuple(data))
786+
772787
@mock.patch('osc_lib.utils.find_resource')
773788
def test_image_list_marker_option(self, fr_mock):
774789
# tangchen: Since image_fakes.IMAGE is a dict, it cannot offer a .id
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
features:
3+
- |
4+
Add ``--project`` and ``--project-domain``options to ``image list``
5+
command to filter by owner.

0 commit comments

Comments
 (0)