summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
authorDean Troyer <dtroyer@gmail.com>2016-11-16 07:37:40 -0600
committerDean Troyer <dtroyer@gmail.com>2016-11-16 07:53:30 -0600
commit0ac4370c09567b80cda84d022068642047576e32 (patch)
tree284989ca422efc4801c4fb02839b4b3f34839303 /openstackclient
parent0b5655fae87b9cf278231fac8febe3114175ff9c (diff)
downloadpython-openstackclient-0ac4370c09567b80cda84d022068642047576e32.tar.gz
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
Diffstat (limited to 'openstackclient')
-rw-r--r--openstackclient/network/v2/security_group_rule.py64
1 files changed, 47 insertions, 17 deletions
diff --git a/openstackclient/network/v2/security_group_rule.py b/openstackclient/network/v2/security_group_rule.py
index f71edce8..b7ca0eaf 100644
--- a/openstackclient/network/v2/security_group_rule.py
+++ b/openstackclient/network/v2/security_group_rule.py
@@ -14,6 +14,7 @@
"""Security Group Rule action implementations"""
import argparse
+import logging
try:
from novaclient.v2 import security_group_rules as compute_secgroup_rules
@@ -31,6 +32,9 @@ from openstackclient.network import common
from openstackclient.network import utils as network_utils
+LOG = logging.getLogger(__name__)
+
+
def _format_security_group_rule_show(obj):
data = network_utils.transform_compute_security_group_rule(obj)
return zip(*sorted(six.iteritems(data)))
@@ -94,34 +98,30 @@ class CreateSecurityGroupRule(common.NetworkAndComputeShowOne):
metavar='<group>',
help=_("Create rule in this security group (name or ID)")
)
- # NOTE(yujie): Support either remote-ip option name for now.
- # However, consider deprecating and then removing --src-ip in
- # a future release.
remote_group = parser.add_mutually_exclusive_group()
remote_group.add_argument(
"--remote-ip",
metavar="<ip-address>",
help=_("Remote IP address block (may use CIDR notation; "
- "default for IPv4 rule: 0.0.0.0/0)")
- )
- remote_group.add_argument(
- "--src-ip",
- metavar="<ip-address>",
- help=_("Source IP address block (may use CIDR notation; "
- "default for IPv4 rule: 0.0.0.0/0)")
+ "default for IPv4 rule: 0.0.0.0/0)"),
)
- # NOTE(yujie): Support either remote-group option name for now.
- # However, consider deprecating and then removing --src-group in
- # a future release.
remote_group.add_argument(
"--remote-group",
metavar="<group>",
- help=_("Remote security group (name or ID)")
+ help=_("Remote security group (name or ID)"),
+ )
+ # Handle deprecated options
+ # NOTE(dtroyer): --src-ip and --src-group were deprecated in Nov 2016.
+ # Do not remove before 4.x release or Nov 2017.
+ remote_group.add_argument(
+ "--src-ip",
+ metavar="<ip-address>",
+ help=argparse.SUPPRESS,
)
remote_group.add_argument(
"--src-group",
metavar="<group>",
- help=_("Source security group (name or ID)")
+ help=argparse.SUPPRESS,
)
return parser
@@ -302,16 +302,31 @@ class CreateSecurityGroupRule(common.NetworkAndComputeShowOne):
if parsed_args.icmp_code:
attrs['port_range_max'] = parsed_args.icmp_code
+ # NOTE(dtroyer): --src-ip and --src-group were deprecated in Nov 2016.
+ # Do not remove before 4.x release or Nov 2017.
if not (parsed_args.remote_group is None and
parsed_args.src_group is None):
attrs['remote_group_id'] = client.find_security_group(
parsed_args.remote_group or parsed_args.src_group,
ignore_missing=False
).id
+ if parsed_args.src_group:
+ LOG.warning(
+ _("The %(old)s option is deprecated, "
+ "please use %(new)s instead.") %
+ {'old': '--src-group', 'new': '--remote-group'},
+ )
elif not (parsed_args.remote_ip is None and
parsed_args.src_ip is None):
- attrs['remote_ip_prefix'] = (parsed_args.remote_ip or
- parsed_args.src_ip)
+ attrs['remote_ip_prefix'] = (
+ parsed_args.remote_ip or parsed_args.src_ip
+ )
+ if parsed_args.src_ip:
+ LOG.warning(
+ _("The %(old)s option is deprecated, "
+ "please use %(new)s instead.") %
+ {'old': '--src-ip', 'new': '--remote-ip'},
+ )
elif attrs['ethertype'] == 'IPv4':
attrs['remote_ip_prefix'] = '0.0.0.0/0'
attrs['security_group_id'] = security_group_id
@@ -340,6 +355,9 @@ class CreateSecurityGroupRule(common.NetworkAndComputeShowOne):
from_port, to_port = -1, -1
else:
from_port, to_port = parsed_args.dst_port
+
+ # NOTE(dtroyer): --src-ip and --src-group were deprecated in Nov 2016.
+ # Do not remove before 4.x release or Nov 2017.
remote_ip = None
if not (parsed_args.remote_group is None and
parsed_args.src_group is None):
@@ -347,9 +365,21 @@ class CreateSecurityGroupRule(common.NetworkAndComputeShowOne):
client.security_groups,
parsed_args.remote_group or parsed_args.src_group,
).id
+ if parsed_args.src_group:
+ LOG.warning(
+ _("The %(old)s option is deprecated, "
+ "please use %(new)s instead.") %
+ {'old': '--src-group', 'new': '--remote-group'},
+ )
if not (parsed_args.remote_ip is None and
parsed_args.src_ip is None):
remote_ip = parsed_args.remote_ip or parsed_args.src_ip
+ if parsed_args.src_ip:
+ LOG.warning(
+ _("The %(old)s option is deprecated, "
+ "please use %(new)s instead.") %
+ {'old': '--src-ip', 'new': '--remote-ip'},
+ )
else:
remote_ip = '0.0.0.0/0'
obj = client.security_group_rules.create(