From aeef56818941a72cc10e96669ad6ff317461046f Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Fri, 11 Mar 2016 15:42:17 -0600 Subject: [PATCH] Fix options in port create/set * --device-id should have been --device * --host-id should have been --host Old options are deprecated and retained for compatibility since they appear in a release. Closes-Bug: 1558677 Change-Id: Ic733523c8d57060f2cb5d420fdb1f7598e7d5e71 --- doc/source/command-objects/port.rst | 12 ++-- openstackclient/network/v2/port.py | 56 ++++++++++++++++--- openstackclient/tests/network/v2/test_port.py | 8 +-- .../notes/bug-1558677-a85f0c548306ba80.yaml | 7 +++ 4 files changed, 65 insertions(+), 18 deletions(-) create mode 100644 releasenotes/notes/bug-1558677-a85f0c548306ba80.yaml diff --git a/doc/source/command-objects/port.rst b/doc/source/command-objects/port.rst index e9c091736a..0ee6212b9c 100644 --- a/doc/source/command-objects/port.rst +++ b/doc/source/command-objects/port.rst @@ -15,11 +15,11 @@ Create new port os port create --network [--fixed-ip subnet=,ip-address=] - [--device-id ] + [--device ] [--device-owner ] [--vnic-type ] [--binding-profile ] - [--host-id ] + [--host ] [--enable | --disable] [--mac-address ] [--project [--project-domain ]] @@ -35,9 +35,9 @@ Create new port subnet=,ip-address= (this option can be repeated) -.. option:: --device-id +.. option:: --device - Device ID of this port + Port device ID .. option:: --device-owner @@ -53,9 +53,9 @@ Create new port Custom data to be passed as binding:profile: = (this option can be repeated) -.. option:: --host-id +.. option:: --host - The ID of the host where the port is allocated + Allocate port on host ```` (ID only) .. option:: --enable diff --git a/openstackclient/network/v2/port.py b/openstackclient/network/v2/port.py index b618a4b0c7..48e1cef583 100644 --- a/openstackclient/network/v2/port.py +++ b/openstackclient/network/v2/port.py @@ -13,13 +13,20 @@ """Port action implementations""" +import argparse +import logging + from openstackclient.common import command from openstackclient.common import exceptions from openstackclient.common import parseractions from openstackclient.common import utils +from openstackclient.i18n import _ # noqa from openstackclient.identity import common as identity_common +LOG = logging.getLogger(__name__) + + def _format_admin_state(state): return 'UP' if state else 'DOWN' @@ -57,10 +64,26 @@ def _get_columns(item): def _get_attrs(client_manager, parsed_args): attrs = {} + # Handle deprecated options + # NOTE(dtroyer): --device-id and --host-id were deprecated in Mar 2016. + # Do not remove before 3.x release or Mar 2017. + if parsed_args.device_id: + attrs['device_id'] = parsed_args.device_id + LOG.warning(_( + 'The --device-id option is deprecated, ' + 'please use --device instead.' + )) + if parsed_args.host_id: + attrs['binding:host_id'] = parsed_args.host_id + LOG.warning(_( + 'The --host-id option is deprecated, ' + 'please use --host instead.' + )) + if parsed_args.fixed_ip is not None: attrs['fixed_ips'] = parsed_args.fixed_ip - if parsed_args.device_id is not None: - attrs['device_id'] = parsed_args.device_id + if parsed_args.device: + attrs['device_id'] = parsed_args.device if parsed_args.device_owner is not None: attrs['device_owner'] = parsed_args.device_owner if parsed_args.admin_state is not None: @@ -69,8 +92,8 @@ def _get_attrs(client_manager, parsed_args): attrs['binding:profile'] = parsed_args.binding_profile if parsed_args.vnic_type is not None: attrs['binding:vnic_type'] = parsed_args.vnic_type - if parsed_args.host_id is not None: - attrs['binding:host_id'] = parsed_args.host_id + if parsed_args.host: + attrs['binding:host_id'] = parsed_args.host # The remaining options do not support 'port set' command, so they require # additional check @@ -133,10 +156,19 @@ def _add_updatable_args(parser): help='Desired IP and/or subnet (name or ID) for this port: ' 'subnet=,ip-address= ' '(this option can be repeated)') - parser.add_argument( + # NOTE(dtroyer): --device-id is deprecated in Mar 2016. Do not + # remove before 3.x release or Mar 2017. + device_group = parser.add_mutually_exclusive_group() + device_group.add_argument( + '--device', + metavar='', + help='Port device ID', + ) + device_group.add_argument( '--device-id', metavar='', - help='Device ID of this port') + help=argparse.SUPPRESS, + ) parser.add_argument( '--device-owner', metavar='', @@ -155,10 +187,18 @@ def _add_updatable_args(parser): action=parseractions.KeyValueAction, help='Custom data to be passed as binding:profile: = ' '(this option can be repeated)') - parser.add_argument( + # NOTE(dtroyer): --host-id is deprecated in Mar 2016. Do not + # remove before 3.x release or Mar 2017. + host_group = parser.add_mutually_exclusive_group() + host_group.add_argument( + '--host', + metavar='', + help='Allocate port on host (ID only)', + ) + host_group.add_argument( '--host-id', metavar='', - help='The ID of the host where the port is allocated' + help=argparse.SUPPRESS, ) diff --git a/openstackclient/tests/network/v2/test_port.py b/openstackclient/tests/network/v2/test_port.py index 7b1c655f67..ad4ec82401 100644 --- a/openstackclient/tests/network/v2/test_port.py +++ b/openstackclient/tests/network/v2/test_port.py @@ -125,7 +125,7 @@ class TestCreatePort(TestPort): '--mac-address', 'aa:aa:aa:aa:aa:aa', '--fixed-ip', 'subnet=%s,ip-address=10.0.0.2' % self.fake_subnet.id, - '--device-id', 'deviceid', + '--device', 'deviceid', '--device-owner', 'fakeowner', '--disable', '--vnic-type', 'macvtap', @@ -141,7 +141,7 @@ class TestCreatePort(TestPort): 'fixed_ip', [{'subnet': self.fake_subnet.id, 'ip-address': '10.0.0.2'}] ), - ('device_id', 'deviceid'), + ('device', 'deviceid'), ('device_owner', 'fakeowner'), ('admin_state', False), ('vnic_type', 'macvtap'), @@ -296,14 +296,14 @@ class TestSetPort(TestPort): '--enable', '--vnic-type', 'macvtap', '--binding-profile', 'foo=bar', - '--host-id', 'binding-host-id-xxxx', + '--host', 'binding-host-id-xxxx', self._port.name, ] verifylist = [ ('admin_state', True), ('vnic_type', 'macvtap'), ('binding_profile', {'foo': 'bar'}), - ('host_id', 'binding-host-id-xxxx'), + ('host', 'binding-host-id-xxxx'), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) diff --git a/releasenotes/notes/bug-1558677-a85f0c548306ba80.yaml b/releasenotes/notes/bug-1558677-a85f0c548306ba80.yaml new file mode 100644 index 0000000000..15451698f0 --- /dev/null +++ b/releasenotes/notes/bug-1558677-a85f0c548306ba80.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - Change the ``--device-id`` option to ``--device`` and the ``--host-id`` + option to ``--host`` for the ``port create`` and ``pot set`` commands. + The original options are deprecated and maintained for backward compatibility + until at least March 2017. + [Bug `1558677 `_]