99# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1010# License for the specific language governing permissions and limitations
1111# under the License.
12- #
1312
1413"""Security Group action implementations"""
1514
2726from openstackclient .i18n import _
2827from openstackclient .identity import common as identity_common
2928from openstackclient .network import common
30- from openstackclient .network import utils as network_utils
3129
3230LOG = logging .getLogger (__name__ )
3331
3432
3533def _format_network_security_group_rules (
3634 sg_rules : list [dict [str , Any ]],
3735) -> str :
38- # For readability and to align with formatting compute security group
39- # rules, trim keys with caller known (e.g. security group and tenant ID)
40- # or empty values.
36+ # For readability, trim keys with caller known (e.g. security group and
37+ # tenant ID) or empty values.
4138 for sg_rule in sg_rules :
4239 empty_keys = [k for k , v in sg_rule .items () if not v ]
4340 for key in empty_keys :
@@ -48,52 +45,16 @@ def _format_network_security_group_rules(
4845 return utils .format_list_of_dicts (sg_rules ) or ""
4946
5047
51- def _format_compute_security_group_rule (sg_rule : dict [str , Any ]) -> str :
52- info = network_utils .transform_compute_security_group_rule (sg_rule )
53- # Trim parent security group ID since caller has this information.
54- info .pop ('parent_group_id' , None )
55- # Trim keys with empty string values.
56- keys_to_trim = [
57- 'ip_protocol' ,
58- 'ip_range' ,
59- 'port_range' ,
60- 'remote_security_group' ,
61- ]
62- for key in keys_to_trim :
63- if key in info and not info [key ]:
64- info .pop (key )
65- return utils .format_dict (info )
66-
67-
68- def _format_compute_security_group_rules (
69- sg_rules : list [dict [str , Any ]],
70- ) -> str :
71- rules = []
72- for sg_rule in sg_rules :
73- rules .append (_format_compute_security_group_rule (sg_rule ))
74- return utils .format_list (rules , separator = '\n ' ) or ""
75-
76-
7748class NetworkSecurityGroupRulesColumn (cliff_columns .FormattableColumn [Any ]):
7849 def human_readable (self ) -> str :
7950 return _format_network_security_group_rules (self ._value )
8051
8152
82- class ComputeSecurityGroupRulesColumn (cliff_columns .FormattableColumn [Any ]):
83- def human_readable (self ) -> str :
84- return _format_compute_security_group_rules (self ._value )
85-
86-
87- _formatters_network = {
53+ _formatters = {
8854 'security_group_rules' : NetworkSecurityGroupRulesColumn ,
8955}
9056
9157
92- _formatters_compute = {
93- 'rules' : ComputeSecurityGroupRulesColumn ,
94- }
95-
96-
9758def _get_columns (item : Any ) -> tuple [tuple [str , ...], tuple [str , ...]]:
9859 # We still support Nova managed security groups, where we have tenant_id.
9960 column_map = {
@@ -176,7 +137,7 @@ def take_action(
176137 _tag .update_tags_for_set (client , obj , parsed_args )
177138 display_columns , property_columns = _get_columns (obj )
178139 data = utils .get_item_properties (
179- obj , property_columns , formatters = _formatters_network
140+ obj , property_columns , formatters = _formatters
180141 )
181142 return (display_columns , data )
182143
@@ -394,7 +355,7 @@ def take_action(
394355 )
395356 display_columns , property_columns = _get_columns (obj )
396357 data = utils .get_item_properties (
397- obj , property_columns , formatters = _formatters_network
358+ obj , property_columns , formatters = _formatters
398359 )
399360 return (display_columns , data )
400361
0 commit comments