Skip to content

Commit ffa37ba

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Add is_shared to security_groups"
2 parents 9d3a956 + 1b2dfea commit ffa37ba

File tree

4 files changed

+53
-8
lines changed

4 files changed

+53
-8
lines changed

openstackclient/network/v2/security_group.py

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,7 @@ def _get_columns(item):
9090
column_map = {
9191
'security_group_rules': 'rules',
9292
}
93-
# FIXME(lajoskatona): Stop hiding is_shared when
94-
# https://review.opendev.org/c/openstack/openstacksdk/+/950305
95-
# is released and SDK version is bumped
96-
hidden_columns = ['location', 'tenant_id', 'is_shared']
93+
hidden_columns = ['location', 'tenant_id']
9794
return utils.get_osc_show_columns_for_sdk_resource(
9895
item, column_map, hidden_columns
9996
)
@@ -225,7 +222,14 @@ def take_action_compute(self, client, parsed_args):
225222
# the OSC minimum requirements include SDK 1.0.
226223
class ListSecurityGroup(common.NetworkAndComputeLister):
227224
_description = _("List security groups")
228-
FIELDS_TO_RETRIEVE = ['id', 'name', 'description', 'project_id', 'tags']
225+
FIELDS_TO_RETRIEVE = [
226+
'id',
227+
'name',
228+
'description',
229+
'project_id',
230+
'tags',
231+
'shared',
232+
]
229233

230234
def update_parser_network(self, parser):
231235
if not self.is_docs_build:
@@ -248,6 +252,23 @@ def update_parser_network(self, parser):
248252
identity_common.add_project_domain_option_to_parser(
249253
parser, enhance_help=self.enhance_help_neutron
250254
)
255+
256+
shared_group = parser.add_mutually_exclusive_group()
257+
shared_group.add_argument(
258+
'--share',
259+
action='store_true',
260+
dest='shared',
261+
default=None,
262+
help=_("List security groups shared between projects"),
263+
)
264+
shared_group.add_argument(
265+
'--no-share',
266+
action='store_false',
267+
dest='shared',
268+
default=None,
269+
help=_("List security groups not shared between projects"),
270+
)
271+
251272
_tag.add_tag_filtering_option_to_parser(
252273
parser, _('security group'), enhance_help=self.enhance_help_neutron
253274
)
@@ -275,13 +296,30 @@ def take_action_network(self, client, parsed_args):
275296
).id
276297
filters['project_id'] = project_id
277298

299+
if parsed_args.shared is not None:
300+
filters['shared'] = parsed_args.shared
301+
278302
_tag.get_tag_filtering_args(parsed_args, filters)
279303
data = client.security_groups(
280304
fields=self.FIELDS_TO_RETRIEVE, **filters
281305
)
282306

283-
columns = ("id", "name", "description", "project_id", "tags")
284-
column_headers = ("ID", "Name", "Description", "Project", "Tags")
307+
columns = (
308+
"id",
309+
"name",
310+
"description",
311+
"project_id",
312+
"tags",
313+
"is_shared",
314+
)
315+
column_headers = (
316+
"ID",
317+
"Name",
318+
"Description",
319+
"Project",
320+
"Tags",
321+
"Shared",
322+
)
285323
return (
286324
column_headers,
287325
(

openstackclient/tests/unit/network/v2/fakes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,6 +1412,7 @@ def create_one_security_group(attrs=None):
14121412
'security_group_rules': [],
14131413
'tags': [],
14141414
'location': 'MUNCHMUNCHMUNCH',
1415+
'is_shared': False,
14151416
}
14161417

14171418
# Overwrite default attributes.

openstackclient/tests/unit/network/v2/test_security_group_network.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class TestCreateSecurityGroupNetwork(TestSecurityGroupNetwork):
4242
'created_at',
4343
'description',
4444
'id',
45+
'is_shared',
4546
'name',
4647
'project_id',
4748
'revision_number',
@@ -55,6 +56,7 @@ class TestCreateSecurityGroupNetwork(TestSecurityGroupNetwork):
5556
_security_group.created_at,
5657
_security_group.description,
5758
_security_group.id,
59+
_security_group.is_shared,
5860
_security_group.name,
5961
_security_group.project_id,
6062
_security_group.revision_number,
@@ -274,6 +276,7 @@ class TestListSecurityGroupNetwork(TestSecurityGroupNetwork):
274276
'Description',
275277
'Project',
276278
'Tags',
279+
'Shared',
277280
)
278281

279282
data = []
@@ -285,6 +288,7 @@ class TestListSecurityGroupNetwork(TestSecurityGroupNetwork):
285288
grp.description,
286289
grp.project_id,
287290
grp.tags,
291+
grp.is_shared,
288292
)
289293
)
290294

@@ -524,6 +528,7 @@ class TestShowSecurityGroupNetwork(TestSecurityGroupNetwork):
524528
'created_at',
525529
'description',
526530
'id',
531+
'is_shared',
527532
'name',
528533
'project_id',
529534
'revision_number',
@@ -537,6 +542,7 @@ class TestShowSecurityGroupNetwork(TestSecurityGroupNetwork):
537542
_security_group.created_at,
538543
_security_group.description,
539544
_security_group.id,
545+
_security_group.is_shared,
540546
_security_group.name,
541547
_security_group.project_id,
542548
_security_group.revision_number,

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pbr!=2.1.0,>=2.0.0 # Apache-2.0
77
cryptography>=2.7 # BSD/Apache-2.0
88
cliff>=4.8.0 # Apache-2.0
99
iso8601>=0.1.11 # MIT
10-
openstacksdk>=4.5.0 # Apache-2.0
10+
openstacksdk>=4.6.0 # Apache-2.0
1111
osc-lib>=2.3.0 # Apache-2.0
1212
oslo.i18n>=3.15.3 # Apache-2.0
1313
python-keystoneclient>=3.22.0 # Apache-2.0

0 commit comments

Comments
 (0)