|
14 | 14 | """Security Group Rule action implementations""" |
15 | 15 |
|
16 | 16 | import argparse |
| 17 | +import logging |
17 | 18 |
|
18 | 19 | try: |
19 | 20 | from novaclient.v2 import security_group_rules as compute_secgroup_rules |
|
31 | 32 | from openstackclient.network import utils as network_utils |
32 | 33 |
|
33 | 34 |
|
| 35 | +LOG = logging.getLogger(__name__) |
| 36 | + |
| 37 | + |
34 | 38 | def _format_security_group_rule_show(obj): |
35 | 39 | data = network_utils.transform_compute_security_group_rule(obj) |
36 | 40 | return zip(*sorted(six.iteritems(data))) |
@@ -94,34 +98,30 @@ def update_parser_common(self, parser): |
94 | 98 | metavar='<group>', |
95 | 99 | help=_("Create rule in this security group (name or ID)") |
96 | 100 | ) |
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. |
100 | 101 | remote_group = parser.add_mutually_exclusive_group() |
101 | 102 | remote_group.add_argument( |
102 | 103 | "--remote-ip", |
103 | 104 | metavar="<ip-address>", |
104 | 105 | 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)"), |
112 | 107 | ) |
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. |
116 | 108 | remote_group.add_argument( |
117 | 109 | "--remote-group", |
118 | 110 | 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, |
120 | 120 | ) |
121 | 121 | remote_group.add_argument( |
122 | 122 | "--src-group", |
123 | 123 | metavar="<group>", |
124 | | - help=_("Source security group (name or ID)") |
| 124 | + help=argparse.SUPPRESS, |
125 | 125 | ) |
126 | 126 | return parser |
127 | 127 |
|
@@ -302,16 +302,31 @@ def take_action_network(self, client, parsed_args): |
302 | 302 | if parsed_args.icmp_code: |
303 | 303 | attrs['port_range_max'] = parsed_args.icmp_code |
304 | 304 |
|
| 305 | + # NOTE(dtroyer): --src-ip and --src-group were deprecated in Nov 2016. |
| 306 | + # Do not remove before 4.x release or Nov 2017. |
305 | 307 | if not (parsed_args.remote_group is None and |
306 | 308 | parsed_args.src_group is None): |
307 | 309 | attrs['remote_group_id'] = client.find_security_group( |
308 | 310 | parsed_args.remote_group or parsed_args.src_group, |
309 | 311 | ignore_missing=False |
310 | 312 | ).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 | + ) |
311 | 319 | elif not (parsed_args.remote_ip is None and |
312 | 320 | 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 | + ) |
315 | 330 | elif attrs['ethertype'] == 'IPv4': |
316 | 331 | attrs['remote_ip_prefix'] = '0.0.0.0/0' |
317 | 332 | attrs['security_group_id'] = security_group_id |
@@ -340,16 +355,31 @@ def take_action_compute(self, client, parsed_args): |
340 | 355 | from_port, to_port = -1, -1 |
341 | 356 | else: |
342 | 357 | 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. |
343 | 361 | remote_ip = None |
344 | 362 | if not (parsed_args.remote_group is None and |
345 | 363 | parsed_args.src_group is None): |
346 | 364 | parsed_args.remote_group = utils.find_resource( |
347 | 365 | client.security_groups, |
348 | 366 | parsed_args.remote_group or parsed_args.src_group, |
349 | 367 | ).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 | + ) |
350 | 374 | if not (parsed_args.remote_ip is None and |
351 | 375 | parsed_args.src_ip is None): |
352 | 376 | 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 | + ) |
353 | 383 | else: |
354 | 384 | remote_ip = '0.0.0.0/0' |
355 | 385 | obj = client.security_group_rules.create( |
|
0 commit comments