1515
1616import argparse
1717
18+ from osc_lib .command import command
1819from osc_lib import utils
1920import six
2021
2324from openstackclient .network import common
2425from openstackclient .network import sdk_utils
2526from openstackclient .network import utils as network_utils
27+ from openstackclient .network .v2 import _tag
2628
2729
2830def _format_network_security_group_rules (sg_rules ):
@@ -106,6 +108,7 @@ def update_parser_network(self, parser):
106108 help = _ ("Owner's project (name or ID)" )
107109 )
108110 identity_common .add_project_domain_option_to_parser (parser )
111+ _tag .add_tag_option_to_parser_for_create (parser , _ ('security group' ))
109112 return parser
110113
111114 def _get_description (self , parsed_args ):
@@ -130,6 +133,8 @@ def take_action_network(self, client, parsed_args):
130133
131134 # Create the security group and display the results.
132135 obj = client .create_security_group (** attrs )
136+ # tags cannot be set when created, so tags need to be set later.
137+ _tag .update_tags_for_set (client , obj , parsed_args )
133138 display_columns , property_columns = _get_columns (obj )
134139 data = utils .get_item_properties (
135140 obj ,
@@ -198,6 +203,7 @@ def update_parser_network(self, parser):
198203 "(name or ID)" )
199204 )
200205 identity_common .add_project_domain_option_to_parser (parser )
206+ _tag .add_tag_filtering_option_to_parser (parser , _ ('security group' ))
201207 return parser
202208
203209 def update_parser_compute (self , parser ):
@@ -220,19 +226,23 @@ def take_action_network(self, client, parsed_args):
220226 ).id
221227 filters ['tenant_id' ] = project_id
222228 filters ['project_id' ] = project_id
229+
230+ _tag .get_tag_filtering_args (parsed_args , filters )
223231 data = client .security_groups (** filters )
224232
225233 columns = (
226234 "ID" ,
227235 "Name" ,
228236 "Description" ,
229- "Project ID"
237+ "Project ID" ,
238+ "tags"
230239 )
231240 column_headers = (
232241 "ID" ,
233242 "Name" ,
234243 "Description" ,
235- "Project"
244+ "Project" ,
245+ "Tags"
236246 )
237247 return (column_headers ,
238248 (utils .get_item_properties (
@@ -282,6 +292,10 @@ def update_parser_common(self, parser):
282292 )
283293 return parser
284294
295+ def update_parser_network (self , parser ):
296+ _tag .add_tag_option_to_parser_for_set (parser , _ ('security group' ))
297+ return parser
298+
285299 def take_action_network (self , client , parsed_args ):
286300 obj = client .find_security_group (parsed_args .group ,
287301 ignore_missing = False )
@@ -295,6 +309,9 @@ def take_action_network(self, client, parsed_args):
295309 # the update.
296310 client .update_security_group (obj , ** attrs )
297311
312+ # tags is a subresource and it needs to be updated separately.
313+ _tag .update_tags_for_set (client , obj , parsed_args )
314+
298315 def take_action_compute (self , client , parsed_args ):
299316 data = client .api .security_group_find (parsed_args .group )
300317
@@ -344,3 +361,25 @@ def take_action_compute(self, client, parsed_args):
344361 formatters = _formatters_compute
345362 )
346363 return (display_columns , data )
364+
365+
366+ class UnsetSecurityGroup (command .Command ):
367+ _description = _ ("Unset security group properties" )
368+
369+ def get_parser (self , prog_name ):
370+ parser = super (UnsetSecurityGroup , self ).get_parser (prog_name )
371+ parser .add_argument (
372+ 'group' ,
373+ metavar = "<group>" ,
374+ help = _ ("Security group to modify (name or ID)" )
375+ )
376+ _tag .add_tag_option_to_parser_for_unset (parser , _ ('security group' ))
377+ return parser
378+
379+ def take_action (self , parsed_args ):
380+ client = self .app .client_manager .network
381+ obj = client .find_security_group (parsed_args .group ,
382+ ignore_missing = False )
383+
384+ # tags is a subresource and it needs to be updated separately.
385+ _tag .update_tags_for_unset (client , obj , parsed_args )
0 commit comments