Skip to content

Commit 444a40c

Browse files
committed
Add possibility to filter images using member_status
In order to see image sharing membership it is required to additionally pass member_status filter to API. Otherwise only those with status 'all' will be returned. Thus adding possibility to see images shared with project to be approved or rejected. Change-Id: Ifd6e13e5a4ef09fbc29e76d464c93fbdbb178ae4
1 parent 0a18790 commit 444a40c

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

doc/source/cli/command-objects/image.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ List available images
209209
[--property <key=value>]
210210
[--name <name>]
211211
[--status <status>]
212+
[--member-status <member-status>]
212213
[--tag <tag>]
213214
[--long]
214215
[--sort <key>[:<direction>]]
@@ -251,6 +252,12 @@ List available images
251252
252253
*Image version 2 only*
253254
255+
.. option:: --member-status <member-status>
256+
257+
Filter images based on member status
258+
259+
*Image version 2 only*
260+
254261
.. option:: --tag <tag>
255262
256263
Filter images based on tag

openstackclient/image/v2/image.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
DEFAULT_DISK_FORMAT = 'raw'
3838
DISK_CHOICES = ["ami", "ari", "aki", "vhd", "vmdk", "raw", "qcow2", "vhdx",
3939
"vdi", "iso", "ploop"]
40+
MEMBER_STATUS_CHOICES = ["accepted", "pending", "rejected", "all"]
4041

4142

4243
LOG = logging.getLogger(__name__)
@@ -530,6 +531,16 @@ def get_parser(self, prog_name):
530531
default=None,
531532
help=_("Filter images based on status.")
532533
)
534+
parser.add_argument(
535+
'--member-status',
536+
metavar='<member-status>',
537+
default=None,
538+
type=lambda s: s.lower(),
539+
choices=MEMBER_STATUS_CHOICES,
540+
help=(_("Filter images based on member status. "
541+
"The supported options are: %s. ") %
542+
', '.join(MEMBER_STATUS_CHOICES))
543+
)
533544
parser.add_argument(
534545
'--tag',
535546
metavar='<tag>',
@@ -595,6 +606,8 @@ def take_action(self, parsed_args):
595606
kwargs['name'] = parsed_args.name
596607
if parsed_args.status:
597608
kwargs['status'] = parsed_args.status
609+
if parsed_args.member_status:
610+
kwargs['member_status'] = parsed_args.member_status
598611
if parsed_args.tag:
599612
kwargs['tag'] = parsed_args.tag
600613
if parsed_args.long:

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,49 @@ def test_image_list_shared_option(self):
644644
self.assertEqual(self.columns, columns)
645645
self.assertEqual(self.datalist, tuple(data))
646646

647+
def test_image_list_shared_member_status_option(self):
648+
arglist = [
649+
'--shared',
650+
'--member-status', 'all'
651+
]
652+
verifylist = [
653+
('public', False),
654+
('private', False),
655+
('community', False),
656+
('shared', True),
657+
('long', False),
658+
('member_status', 'all')
659+
]
660+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
661+
662+
# In base command class Lister in cliff, abstract method take_action()
663+
# returns a tuple containing the column names and an iterable
664+
# containing the data to be listed.
665+
columns, data = self.cmd.take_action(parsed_args)
666+
self.api_mock.image_list.assert_called_with(
667+
shared=True,
668+
member_status='all',
669+
marker=self._image.id,
670+
)
671+
672+
self.assertEqual(self.columns, columns)
673+
self.assertEqual(self.datalist, tuple(data))
674+
675+
def test_image_list_shared_member_status_lower(self):
676+
arglist = [
677+
'--shared',
678+
'--member-status', 'ALl'
679+
]
680+
verifylist = [
681+
('public', False),
682+
('private', False),
683+
('community', False),
684+
('shared', True),
685+
('long', False),
686+
('member_status', 'all')
687+
]
688+
self.check_parser(self.cmd, arglist, verifylist)
689+
647690
def test_image_list_long_option(self):
648691
arglist = [
649692
'--long',
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
features:
3+
- Add ``--member-status`` option to ``image list`` command.

0 commit comments

Comments
 (0)