Skip to content

Commit 135672b

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Remove dead nova-network utils"
2 parents 23deadb + 0b4d202 commit 135672b

2 files changed

Lines changed: 5 additions & 85 deletions

File tree

openstackclient/network/utils.py

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,47 +9,14 @@
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

14-
from collections.abc import Iterable, Sequence
1513
from typing import Any, cast
1614

1715
from osc_lib import exceptions
1816

1917
from openstackclient.i18n import _
2018

2119

22-
# Transform compute security group rule for display.
23-
def transform_compute_security_group_rule(
24-
sg_rule: dict[str, Any],
25-
) -> dict[str, Any]:
26-
info = {}
27-
info.update(sg_rule)
28-
from_port = info.pop('from_port')
29-
to_port = info.pop('to_port')
30-
if isinstance(from_port, int) and isinstance(to_port, int):
31-
port_range = {'port_range': f"{from_port}:{to_port}"}
32-
elif from_port is None and to_port is None:
33-
port_range = {'port_range': ""}
34-
else:
35-
port_range = {'port_range': f"{from_port}:{to_port}"}
36-
info.update(port_range)
37-
if 'cidr' in info['ip_range']:
38-
info['ip_range'] = info['ip_range']['cidr']
39-
else:
40-
info['ip_range'] = ''
41-
if info['ip_protocol'] is None:
42-
info['ip_protocol'] = ''
43-
elif info['ip_protocol'].lower() == 'icmp':
44-
info['port_range'] = ''
45-
group = info.pop('group')
46-
if 'name' in group:
47-
info['remote_security_group'] = group['name']
48-
else:
49-
info['remote_security_group'] = ''
50-
return info
51-
52-
5320
def str2bool(strbool: str | None) -> bool | None:
5421
if strbool is None:
5522
return None
@@ -88,14 +55,6 @@ def str2dict(strdict: str) -> dict[str, str]:
8855
return result
8956

9057

91-
def format_security_group_rule_show(
92-
obj: dict[str, Any],
93-
) -> tuple[Sequence[str], Iterable[Any]]:
94-
data = transform_compute_security_group_rule(obj)
95-
col_headers, col_data = zip(*sorted(data.items()))
96-
return col_headers, col_data
97-
98-
9958
def format_network_port_range(rule: dict[str, Any]) -> str:
10059
# Display port range or ICMP type and code. For example:
10160
# - ICMP type: 'type=3'

openstackclient/network/v2/security_group.py

Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
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

@@ -27,17 +26,15 @@
2726
from openstackclient.i18n import _
2827
from openstackclient.identity import common as identity_common
2928
from openstackclient.network import common
30-
from openstackclient.network import utils as network_utils
3129

3230
LOG = logging.getLogger(__name__)
3331

3432

3533
def _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-
7748
class 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-
9758
def _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

Comments
 (0)