diff --git a/openstackclient/network/v2/security_group.py b/openstackclient/network/v2/security_group.py index ceca341f89..6fb98c6f63 100644 --- a/openstackclient/network/v2/security_group.py +++ b/openstackclient/network/v2/security_group.py @@ -90,10 +90,7 @@ def _get_columns(item): column_map = { 'security_group_rules': 'rules', } - # FIXME(lajoskatona): Stop hiding is_shared when - # https://review.opendev.org/c/openstack/openstacksdk/+/950305 - # is released and SDK version is bumped - hidden_columns = ['location', 'tenant_id', 'is_shared'] + hidden_columns = ['location', 'tenant_id'] return utils.get_osc_show_columns_for_sdk_resource( item, column_map, hidden_columns ) @@ -225,7 +222,14 @@ class DeleteSecurityGroup(common.NetworkAndComputeDelete): # the OSC minimum requirements include SDK 1.0. class ListSecurityGroup(common.NetworkAndComputeLister): _description = _("List security groups") - FIELDS_TO_RETRIEVE = ['id', 'name', 'description', 'project_id', 'tags'] + FIELDS_TO_RETRIEVE = [ + 'id', + 'name', + 'description', + 'project_id', + 'tags', + 'shared', + ] def update_parser_network(self, parser): if not self.is_docs_build: @@ -248,6 +252,23 @@ class ListSecurityGroup(common.NetworkAndComputeLister): identity_common.add_project_domain_option_to_parser( parser, enhance_help=self.enhance_help_neutron ) + + shared_group = parser.add_mutually_exclusive_group() + shared_group.add_argument( + '--share', + action='store_true', + dest='shared', + default=None, + help=_("List security groups shared between projects"), + ) + shared_group.add_argument( + '--no-share', + action='store_false', + dest='shared', + default=None, + help=_("List security groups not shared between projects"), + ) + _tag.add_tag_filtering_option_to_parser( parser, _('security group'), enhance_help=self.enhance_help_neutron ) @@ -275,13 +296,30 @@ class ListSecurityGroup(common.NetworkAndComputeLister): ).id filters['project_id'] = project_id + if parsed_args.shared is not None: + filters['shared'] = parsed_args.shared + _tag.get_tag_filtering_args(parsed_args, filters) data = client.security_groups( fields=self.FIELDS_TO_RETRIEVE, **filters ) - columns = ("id", "name", "description", "project_id", "tags") - column_headers = ("ID", "Name", "Description", "Project", "Tags") + columns = ( + "id", + "name", + "description", + "project_id", + "tags", + "is_shared", + ) + column_headers = ( + "ID", + "Name", + "Description", + "Project", + "Tags", + "Shared", + ) return ( column_headers, ( diff --git a/openstackclient/tests/unit/network/v2/fakes.py b/openstackclient/tests/unit/network/v2/fakes.py index d58f6e190e..16bbfa5ea3 100644 --- a/openstackclient/tests/unit/network/v2/fakes.py +++ b/openstackclient/tests/unit/network/v2/fakes.py @@ -1412,6 +1412,7 @@ def create_one_security_group(attrs=None): 'security_group_rules': [], 'tags': [], 'location': 'MUNCHMUNCHMUNCH', + 'is_shared': False, } # Overwrite default attributes. diff --git a/openstackclient/tests/unit/network/v2/test_security_group_network.py b/openstackclient/tests/unit/network/v2/test_security_group_network.py index 62b87642c0..9bf1f672f9 100644 --- a/openstackclient/tests/unit/network/v2/test_security_group_network.py +++ b/openstackclient/tests/unit/network/v2/test_security_group_network.py @@ -42,6 +42,7 @@ class TestCreateSecurityGroupNetwork(TestSecurityGroupNetwork): 'created_at', 'description', 'id', + 'is_shared', 'name', 'project_id', 'revision_number', @@ -55,6 +56,7 @@ class TestCreateSecurityGroupNetwork(TestSecurityGroupNetwork): _security_group.created_at, _security_group.description, _security_group.id, + _security_group.is_shared, _security_group.name, _security_group.project_id, _security_group.revision_number, @@ -274,6 +276,7 @@ class TestListSecurityGroupNetwork(TestSecurityGroupNetwork): 'Description', 'Project', 'Tags', + 'Shared', ) data = [] @@ -285,6 +288,7 @@ class TestListSecurityGroupNetwork(TestSecurityGroupNetwork): grp.description, grp.project_id, grp.tags, + grp.is_shared, ) ) @@ -524,6 +528,7 @@ class TestShowSecurityGroupNetwork(TestSecurityGroupNetwork): 'created_at', 'description', 'id', + 'is_shared', 'name', 'project_id', 'revision_number', @@ -537,6 +542,7 @@ class TestShowSecurityGroupNetwork(TestSecurityGroupNetwork): _security_group.created_at, _security_group.description, _security_group.id, + _security_group.is_shared, _security_group.name, _security_group.project_id, _security_group.revision_number, diff --git a/requirements.txt b/requirements.txt index 2fe51f5f0f..9a9c79a98e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,7 @@ pbr!=2.1.0,>=2.0.0 # Apache-2.0 cryptography>=2.7 # BSD/Apache-2.0 cliff>=4.8.0 # Apache-2.0 iso8601>=0.1.11 # MIT -openstacksdk>=4.5.0 # Apache-2.0 +openstacksdk>=4.6.0 # Apache-2.0 osc-lib>=2.3.0 # Apache-2.0 oslo.i18n>=3.15.3 # Apache-2.0 python-keystoneclient>=3.22.0 # Apache-2.0