Skip to content

Commit 0ac4370

Browse files
author
Dean Troyer
committed
Do proper deprecation for security group rule create
Review I03fd0e14e470e7272930ac2651e73263b83bd4e1 renamed the --src-group and --src-ip options to --remote-group and --remote-ip but did not properly deprecate the old option names. Add deprecation warnings when the old option names are used. Also, format the warnings using the new proposed translation guideline for marking substrings to not be translated, such as literal names and option names. Change-Id: I63d085d190fc28b8637e7686016eda4efbdda1be
1 parent 0b5655f commit 0ac4370

2 files changed

Lines changed: 53 additions & 22 deletions

File tree

openstackclient/network/v2/security_group_rule.py

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"""Security Group Rule action implementations"""
1515

1616
import argparse
17+
import logging
1718

1819
try:
1920
from novaclient.v2 import security_group_rules as compute_secgroup_rules
@@ -31,6 +32,9 @@
3132
from openstackclient.network import utils as network_utils
3233

3334

35+
LOG = logging.getLogger(__name__)
36+
37+
3438
def _format_security_group_rule_show(obj):
3539
data = network_utils.transform_compute_security_group_rule(obj)
3640
return zip(*sorted(six.iteritems(data)))
@@ -94,34 +98,30 @@ def update_parser_common(self, parser):
9498
metavar='<group>',
9599
help=_("Create rule in this security group (name or ID)")
96100
)
97-
# NOTE(yujie): Support either remote-ip option name for now.
98-
# However, consider deprecating and then removing --src-ip in
99-
# a future release.
100101
remote_group = parser.add_mutually_exclusive_group()
101102
remote_group.add_argument(
102103
"--remote-ip",
103104
metavar="<ip-address>",
104105
help=_("Remote IP address block (may use CIDR notation; "
105-
"default for IPv4 rule: 0.0.0.0/0)")
106-
)
107-
remote_group.add_argument(
108-
"--src-ip",
109-
metavar="<ip-address>",
110-
help=_("Source IP address block (may use CIDR notation; "
111-
"default for IPv4 rule: 0.0.0.0/0)")
106+
"default for IPv4 rule: 0.0.0.0/0)"),
112107
)
113-
# NOTE(yujie): Support either remote-group option name for now.
114-
# However, consider deprecating and then removing --src-group in
115-
# a future release.
116108
remote_group.add_argument(
117109
"--remote-group",
118110
metavar="<group>",
119-
help=_("Remote security group (name or ID)")
111+
help=_("Remote security group (name or ID)"),
112+
)
113+
# Handle deprecated options
114+
# NOTE(dtroyer): --src-ip and --src-group were deprecated in Nov 2016.
115+
# Do not remove before 4.x release or Nov 2017.
116+
remote_group.add_argument(
117+
"--src-ip",
118+
metavar="<ip-address>",
119+
help=argparse.SUPPRESS,
120120
)
121121
remote_group.add_argument(
122122
"--src-group",
123123
metavar="<group>",
124-
help=_("Source security group (name or ID)")
124+
help=argparse.SUPPRESS,
125125
)
126126
return parser
127127

@@ -302,16 +302,31 @@ def take_action_network(self, client, parsed_args):
302302
if parsed_args.icmp_code:
303303
attrs['port_range_max'] = parsed_args.icmp_code
304304

305+
# NOTE(dtroyer): --src-ip and --src-group were deprecated in Nov 2016.
306+
# Do not remove before 4.x release or Nov 2017.
305307
if not (parsed_args.remote_group is None and
306308
parsed_args.src_group is None):
307309
attrs['remote_group_id'] = client.find_security_group(
308310
parsed_args.remote_group or parsed_args.src_group,
309311
ignore_missing=False
310312
).id
313+
if parsed_args.src_group:
314+
LOG.warning(
315+
_("The %(old)s option is deprecated, "
316+
"please use %(new)s instead.") %
317+
{'old': '--src-group', 'new': '--remote-group'},
318+
)
311319
elif not (parsed_args.remote_ip is None and
312320
parsed_args.src_ip is None):
313-
attrs['remote_ip_prefix'] = (parsed_args.remote_ip or
314-
parsed_args.src_ip)
321+
attrs['remote_ip_prefix'] = (
322+
parsed_args.remote_ip or parsed_args.src_ip
323+
)
324+
if parsed_args.src_ip:
325+
LOG.warning(
326+
_("The %(old)s option is deprecated, "
327+
"please use %(new)s instead.") %
328+
{'old': '--src-ip', 'new': '--remote-ip'},
329+
)
315330
elif attrs['ethertype'] == 'IPv4':
316331
attrs['remote_ip_prefix'] = '0.0.0.0/0'
317332
attrs['security_group_id'] = security_group_id
@@ -340,16 +355,31 @@ def take_action_compute(self, client, parsed_args):
340355
from_port, to_port = -1, -1
341356
else:
342357
from_port, to_port = parsed_args.dst_port
358+
359+
# NOTE(dtroyer): --src-ip and --src-group were deprecated in Nov 2016.
360+
# Do not remove before 4.x release or Nov 2017.
343361
remote_ip = None
344362
if not (parsed_args.remote_group is None and
345363
parsed_args.src_group is None):
346364
parsed_args.remote_group = utils.find_resource(
347365
client.security_groups,
348366
parsed_args.remote_group or parsed_args.src_group,
349367
).id
368+
if parsed_args.src_group:
369+
LOG.warning(
370+
_("The %(old)s option is deprecated, "
371+
"please use %(new)s instead.") %
372+
{'old': '--src-group', 'new': '--remote-group'},
373+
)
350374
if not (parsed_args.remote_ip is None and
351375
parsed_args.src_ip is None):
352376
remote_ip = parsed_args.remote_ip or parsed_args.src_ip
377+
if parsed_args.src_ip:
378+
LOG.warning(
379+
_("The %(old)s option is deprecated, "
380+
"please use %(new)s instead.") %
381+
{'old': '--src-ip', 'new': '--remote-ip'},
382+
)
353383
else:
354384
remote_ip = '0.0.0.0/0'
355385
obj = client.security_group_rules.create(
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
upgrade:
2-
-
3-
Changed the ``security group rule create`` command ``--src-ip``
4-
option to ``--remote-ip``, ``--src-group`` option to ``--remote-group``.
5-
Using the ``--src-ip`` ``--src-group`` option is still supported, but
6-
is no longer documented and may be deprecated in a future release.
2+
- |
3+
Rename the ``--src-group`` and ``--src-ip`` options in the
4+
``security group rule create`` command to ``--remote-group``
5+
and ``--remote-ip``.
6+
The ``--src-group`` and ``--src-ip`` options are deprecated but still
7+
supported, and will be removed in a future release.
78
[Bug `1637365 <https://bugs.launchpad.net/python-openstackclient/+bug/1637365>`_]

0 commit comments

Comments
 (0)