@@ -91,6 +91,56 @@ def _get_columns(item):
9191 return tuple (display_columns ), property_columns
9292
9393
94+ class CreateSecurityGroup (common .NetworkAndComputeShowOne ):
95+ """Create a new security group"""
96+
97+ def update_parser_common (self , parser ):
98+ parser .add_argument (
99+ "name" ,
100+ metavar = "<name>" ,
101+ help = "New security group name" ,
102+ )
103+ parser .add_argument (
104+ "--description" ,
105+ metavar = "<description>" ,
106+ help = "Security group description" ,
107+ )
108+ return parser
109+
110+ def _get_description (self , parsed_args ):
111+ if parsed_args .description is not None :
112+ return parsed_args .description
113+ else :
114+ return parsed_args .name
115+
116+ def take_action_network (self , client , parsed_args ):
117+ attrs = {}
118+ attrs ['name' ] = parsed_args .name
119+ attrs ['description' ] = self ._get_description (parsed_args )
120+ obj = client .create_security_group (** attrs )
121+ display_columns , property_columns = _get_columns (obj )
122+ data = utils .get_item_properties (
123+ obj ,
124+ property_columns ,
125+ formatters = _formatters_network
126+ )
127+ return (display_columns , data )
128+
129+ def take_action_compute (self , client , parsed_args ):
130+ description = self ._get_description (parsed_args )
131+ obj = client .security_groups .create (
132+ parsed_args .name ,
133+ description ,
134+ )
135+ display_columns , property_columns = _get_columns (obj ._info )
136+ data = utils .get_dict_properties (
137+ obj ._info ,
138+ property_columns ,
139+ formatters = _formatters_compute
140+ )
141+ return (display_columns , data )
142+
143+
94144class DeleteSecurityGroup (common .NetworkAndComputeCommand ):
95145 """Delete a security group"""
96146
0 commit comments