Support --community in openstack image list · openstack/python-openstackclient@860639a · GitHub
Skip to content

Commit 860639a

Browse files
nobuto-mDean Troyer
authored andcommitted
Support --community in openstack image list
"--community" was added to "image create" and "image set" previously, but was missed in "image list". Change-Id: I959fdd7f67ae62c8326659ce52389228152ec019 Story: 2001925 Task: 14453
1 parent e4b8c31 commit 860639a

5 files changed

Lines changed: 60 additions & 7 deletions

File tree

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

Lines changed: 7 additions & 1 deletion

openstackclient/api/image_v2.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def image_list(
3131
detailed=False,
3232
public=False,
3333
private=False,
34+
community=False,
3435
shared=False,
3536
**filter
3637
):
@@ -44,25 +45,29 @@ def image_list(
4445
Return public images if True
4546
:param private:
4647
Return private images if True
48+
:param community:
49+
Return commuity images if True
4750
:param shared:
4851
Return shared images if True
4952
50-
If public, private and shared are all True or all False then all
51-
images are returned. All arguments False is equivalent to no filter
52-
and all images are returned. All arguments True is a filter that
53-
includes all public, private and shared images which is the same set
54-
as all images.
53+
If public, private, community and shared are all True or all False
54+
then all images are returned. All arguments False is equivalent to no
55+
filter and all images are returned. All arguments True is a filter
56+
that includes all public, private, community and shared images which
57+
is the same set as all images.
5558
5659
http://docs.openstack.org/api/openstack-image-service/2.0/content/list-images.html
5760
"""
5861

59-
if not public and not private and not shared:
62+
if not public and not private and not community and not shared:
6063
# No filtering for all False
6164
filter.pop('visibility', None)
6265
elif public:
6366
filter['visibility'] = 'public'
6467
elif private:
6568
filter['visibility'] = 'private'
69+
elif community:
70+
filter['visibility'] = 'community'
6671
elif shared:
6772
filter['visibility'] = 'shared'
6873

openstackclient/image/v2/image.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,13 @@ def get_parser(self, prog_name):
439439
default=False,
440440
help=_("List only private images"),
441441
)
442+
public_group.add_argument(
443+
"--community",
444+
dest="community",
445+
action="store_true",
446+
default=False,
447+
help=_("List only community images"),
448+
)
442449
public_group.add_argument(
443450
"--shared",
444451
dest="shared",
@@ -516,6 +523,8 @@ def take_action(self, parsed_args):
516523
kwargs['public'] = True
517524
if parsed_args.private:
518525
kwargs['private'] = True
526+
if parsed_args.community:
527+
kwargs['community'] = True
519528
if parsed_args.shared:
520529
kwargs['shared'] = True
521530
if parsed_args.limit:

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ def test_image_list_no_options(self):
527527
verifylist = [
528528
('public', False),
529529
('private', False),
530+
('community', False),
530531
('shared', False),
531532
('long', False),
532533
]
@@ -550,6 +551,7 @@ def test_image_list_public_option(self):
550551
verifylist = [
551552
('public', True),
552553
('private', False),
554+
('community', False),
553555
('shared', False),
554556
('long', False),
555557
]
@@ -574,6 +576,7 @@ def test_image_list_private_option(self):
574576
verifylist = [
575577
('public', False),
576578
('private', True),
579+
('community', False),
577580
('shared', False),
578581
('long', False),
579582
]
@@ -591,13 +594,39 @@ def test_image_list_private_option(self):
591594
self.assertEqual(self.columns, columns)
592595
self.assertEqual(self.datalist, tuple(data))
593596

597+
def test_image_list_community_option(self):
598+
arglist = [
599+
'--community',
600+
]
601+
verifylist = [
602+
('public', False),
603+
('private', False),
604+
('community', True),
605+
('shared', False),
606+
('long', False),
607+
]
608+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
609+
610+
# In base command class Lister in cliff, abstract method take_action()
611+
# returns a tuple containing the column names and an iterable
612+
# containing the data to be listed.
613+
columns, data = self.cmd.take_action(parsed_args)
614+
self.api_mock.image_list.assert_called_with(
615+
community=True,
616+
marker=self._image.id,
617+
)
618+
619+
self.assertEqual(self.columns, columns)
620+
self.assertEqual(self.datalist, tuple(data))
621+
594622
def test_image_list_shared_option(self):
595623
arglist = [
596624
'--shared',
597625
]
598626
verifylist = [
599627
('public', False),
600628
('private', False),
629+
('community', False),
601630
('shared', True),
602631
('long', False),
603632
]
Lines changed: 4 additions & 0 deletions

0 commit comments

Comments
 (0)