summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtem Goncharov <artem.goncharov@gmail.com>2019-02-26 11:13:25 +0100
committerArtem Goncharov <artem.goncharov@gmail.com>2019-02-26 11:13:25 +0100
commit444a40c656b9f6007364ecd3bcf38964bbcd4556 (patch)
tree084765fddbc5d18a5093f384b8c1583779f7a0ad
parent0a187905c01f6bc2b9855081ac0042f00715dedf (diff)
downloadpython-openstackclient-444a40c656b9f6007364ecd3bcf38964bbcd4556.tar.gz
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
-rw-r--r--doc/source/cli/command-objects/image.rst7
-rw-r--r--openstackclient/image/v2/image.py13
-rw-r--r--openstackclient/tests/unit/image/v2/test_image.py43
-rw-r--r--releasenotes/notes/add-member-status-filter-2e118b2c93151223.yaml3
4 files changed, 66 insertions, 0 deletions
diff --git a/doc/source/cli/command-objects/image.rst b/doc/source/cli/command-objects/image.rst
index 95486e33..0c5b0333 100644
--- a/doc/source/cli/command-objects/image.rst
+++ b/doc/source/cli/command-objects/image.rst
@@ -209,6 +209,7 @@ List available images
[--property <key=value>]
[--name <name>]
[--status <status>]
+ [--member-status <member-status>]
[--tag <tag>]
[--long]
[--sort <key>[:<direction>]]
@@ -251,6 +252,12 @@ List available images
*Image version 2 only*
+.. option:: --member-status <member-status>
+
+ Filter images based on member status
+
+ *Image version 2 only*
+
.. option:: --tag <tag>
Filter images based on tag
diff --git a/openstackclient/image/v2/image.py b/openstackclient/image/v2/image.py
index 06eebe98..f4ab5bdc 100644
--- a/openstackclient/image/v2/image.py
+++ b/openstackclient/image/v2/image.py
@@ -37,6 +37,7 @@ DEFAULT_CONTAINER_FORMAT = 'bare'
DEFAULT_DISK_FORMAT = 'raw'
DISK_CHOICES = ["ami", "ari", "aki", "vhd", "vmdk", "raw", "qcow2", "vhdx",
"vdi", "iso", "ploop"]
+MEMBER_STATUS_CHOICES = ["accepted", "pending", "rejected", "all"]
LOG = logging.getLogger(__name__)
@@ -531,6 +532,16 @@ class ListImage(command.Lister):
help=_("Filter images based on status.")
)
parser.add_argument(
+ '--member-status',
+ metavar='<member-status>',
+ default=None,
+ type=lambda s: s.lower(),
+ choices=MEMBER_STATUS_CHOICES,
+ help=(_("Filter images based on member status. "
+ "The supported options are: %s. ") %
+ ', '.join(MEMBER_STATUS_CHOICES))
+ )
+ parser.add_argument(
'--tag',
metavar='<tag>',
default=None,
@@ -595,6 +606,8 @@ class ListImage(command.Lister):
kwargs['name'] = parsed_args.name
if parsed_args.status:
kwargs['status'] = parsed_args.status
+ if parsed_args.member_status:
+ kwargs['member_status'] = parsed_args.member_status
if parsed_args.tag:
kwargs['tag'] = parsed_args.tag
if parsed_args.long:
diff --git a/openstackclient/tests/unit/image/v2/test_image.py b/openstackclient/tests/unit/image/v2/test_image.py
index 170a7f03..087d8751 100644
--- a/openstackclient/tests/unit/image/v2/test_image.py
+++ b/openstackclient/tests/unit/image/v2/test_image.py
@@ -644,6 +644,49 @@ class TestImageList(TestImage):
self.assertEqual(self.columns, columns)
self.assertEqual(self.datalist, tuple(data))
+ def test_image_list_shared_member_status_option(self):
+ arglist = [
+ '--shared',
+ '--member-status', 'all'
+ ]
+ verifylist = [
+ ('public', False),
+ ('private', False),
+ ('community', False),
+ ('shared', True),
+ ('long', False),
+ ('member_status', 'all')
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ # In base command class Lister in cliff, abstract method take_action()
+ # returns a tuple containing the column names and an iterable
+ # containing the data to be listed.
+ columns, data = self.cmd.take_action(parsed_args)
+ self.api_mock.image_list.assert_called_with(
+ shared=True,
+ member_status='all',
+ marker=self._image.id,
+ )
+
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(self.datalist, tuple(data))
+
+ def test_image_list_shared_member_status_lower(self):
+ arglist = [
+ '--shared',
+ '--member-status', 'ALl'
+ ]
+ verifylist = [
+ ('public', False),
+ ('private', False),
+ ('community', False),
+ ('shared', True),
+ ('long', False),
+ ('member_status', 'all')
+ ]
+ self.check_parser(self.cmd, arglist, verifylist)
+
def test_image_list_long_option(self):
arglist = [
'--long',
diff --git a/releasenotes/notes/add-member-status-filter-2e118b2c93151223.yaml b/releasenotes/notes/add-member-status-filter-2e118b2c93151223.yaml
new file mode 100644
index 00000000..f7440df1
--- /dev/null
+++ b/releasenotes/notes/add-member-status-filter-2e118b2c93151223.yaml
@@ -0,0 +1,3 @@
+---
+features:
+ - Add ``--member-status`` option to ``image list`` command.