Skip to content

Commit aeef568

Browse files
Dean TroyerSteve Martinelli
authored andcommitted
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
1 parent 3737c5a commit aeef568

4 files changed

Lines changed: 65 additions & 18 deletions

File tree

doc/source/command-objects/port.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ Create new port
1515
os port create
1616
--network <network>
1717
[--fixed-ip subnet=<subnet>,ip-address=<ip-address>]
18-
[--device-id <device-id>]
18+
[--device <device-id>]
1919
[--device-owner <device-owner>]
2020
[--vnic-type <vnic-type>]
2121
[--binding-profile <binding-profile>]
22-
[--host-id <host-id>]
22+
[--host <host-id>]
2323
[--enable | --disable]
2424
[--mac-address <mac-address>]
2525
[--project <project> [--project-domain <project-domain>]]
@@ -35,9 +35,9 @@ Create new port
3535
subnet=<subnet>,ip-address=<ip-address>
3636
(this option can be repeated)
3737
38-
.. option:: --device-id <device-id>
38+
.. option:: --device <device-id>
3939
40-
Device ID of this port
40+
Port device ID
4141
4242
.. option:: --device-owner <device-owner>
4343
@@ -53,9 +53,9 @@ Create new port
5353
Custom data to be passed as binding:profile: <key>=<value>
5454
(this option can be repeated)
5555
56-
.. option:: --host-id <host-id>
56+
.. option:: --host <host-id>
5757
58-
The ID of the host where the port is allocated
58+
Allocate port on host ``<host-id>`` (ID only)
5959
6060
.. option:: --enable
6161

openstackclient/network/v2/port.py

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,20 @@
1313

1414
"""Port action implementations"""
1515

16+
import argparse
17+
import logging
18+
1619
from openstackclient.common import command
1720
from openstackclient.common import exceptions
1821
from openstackclient.common import parseractions
1922
from openstackclient.common import utils
23+
from openstackclient.i18n import _ # noqa
2024
from openstackclient.identity import common as identity_common
2125

2226

27+
LOG = logging.getLogger(__name__)
28+
29+
2330
def _format_admin_state(state):
2431
return 'UP' if state else 'DOWN'
2532

@@ -57,10 +64,26 @@ def _get_columns(item):
5764
def _get_attrs(client_manager, parsed_args):
5865
attrs = {}
5966

67+
# Handle deprecated options
68+
# NOTE(dtroyer): --device-id and --host-id were deprecated in Mar 2016.
69+
# Do not remove before 3.x release or Mar 2017.
70+
if parsed_args.device_id:
71+
attrs['device_id'] = parsed_args.device_id
72+
LOG.warning(_(
73+
'The --device-id option is deprecated, '
74+
'please use --device instead.'
75+
))
76+
if parsed_args.host_id:
77+
attrs['binding:host_id'] = parsed_args.host_id
78+
LOG.warning(_(
79+
'The --host-id option is deprecated, '
80+
'please use --host instead.'
81+
))
82+
6083
if parsed_args.fixed_ip is not None:
6184
attrs['fixed_ips'] = parsed_args.fixed_ip
62-
if parsed_args.device_id is not None:
63-
attrs['device_id'] = parsed_args.device_id
85+
if parsed_args.device:
86+
attrs['device_id'] = parsed_args.device
6487
if parsed_args.device_owner is not None:
6588
attrs['device_owner'] = parsed_args.device_owner
6689
if parsed_args.admin_state is not None:
@@ -69,8 +92,8 @@ def _get_attrs(client_manager, parsed_args):
6992
attrs['binding:profile'] = parsed_args.binding_profile
7093
if parsed_args.vnic_type is not None:
7194
attrs['binding:vnic_type'] = parsed_args.vnic_type
72-
if parsed_args.host_id is not None:
73-
attrs['binding:host_id'] = parsed_args.host_id
95+
if parsed_args.host:
96+
attrs['binding:host_id'] = parsed_args.host
7497

7598
# The remaining options do not support 'port set' command, so they require
7699
# additional check
@@ -133,10 +156,19 @@ def _add_updatable_args(parser):
133156
help='Desired IP and/or subnet (name or ID) for this port: '
134157
'subnet=<subnet>,ip-address=<ip-address> '
135158
'(this option can be repeated)')
136-
parser.add_argument(
159+
# NOTE(dtroyer): --device-id is deprecated in Mar 2016. Do not
160+
# remove before 3.x release or Mar 2017.
161+
device_group = parser.add_mutually_exclusive_group()
162+
device_group.add_argument(
163+
'--device',
164+
metavar='<device-id>',
165+
help='Port device ID',
166+
)
167+
device_group.add_argument(
137168
'--device-id',
138169
metavar='<device-id>',
139-
help='Device ID of this port')
170+
help=argparse.SUPPRESS,
171+
)
140172
parser.add_argument(
141173
'--device-owner',
142174
metavar='<device-owner>',
@@ -155,10 +187,18 @@ def _add_updatable_args(parser):
155187
action=parseractions.KeyValueAction,
156188
help='Custom data to be passed as binding:profile: <key>=<value> '
157189
'(this option can be repeated)')
158-
parser.add_argument(
190+
# NOTE(dtroyer): --host-id is deprecated in Mar 2016. Do not
191+
# remove before 3.x release or Mar 2017.
192+
host_group = parser.add_mutually_exclusive_group()
193+
host_group.add_argument(
194+
'--host',
195+
metavar='<host-id>',
196+
help='Allocate port on host <host-id> (ID only)',
197+
)
198+
host_group.add_argument(
159199
'--host-id',
160200
metavar='<host-id>',
161-
help='The ID of the host where the port is allocated'
201+
help=argparse.SUPPRESS,
162202
)
163203

164204

openstackclient/tests/network/v2/test_port.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def test_create_full_options(self):
125125
'--mac-address', 'aa:aa:aa:aa:aa:aa',
126126
'--fixed-ip', 'subnet=%s,ip-address=10.0.0.2'
127127
% self.fake_subnet.id,
128-
'--device-id', 'deviceid',
128+
'--device', 'deviceid',
129129
'--device-owner', 'fakeowner',
130130
'--disable',
131131
'--vnic-type', 'macvtap',
@@ -141,7 +141,7 @@ def test_create_full_options(self):
141141
'fixed_ip',
142142
[{'subnet': self.fake_subnet.id, 'ip-address': '10.0.0.2'}]
143143
),
144-
('device_id', 'deviceid'),
144+
('device', 'deviceid'),
145145
('device_owner', 'fakeowner'),
146146
('admin_state', False),
147147
('vnic_type', 'macvtap'),
@@ -296,14 +296,14 @@ def test_set_that(self):
296296
'--enable',
297297
'--vnic-type', 'macvtap',
298298
'--binding-profile', 'foo=bar',
299-
'--host-id', 'binding-host-id-xxxx',
299+
'--host', 'binding-host-id-xxxx',
300300
self._port.name,
301301
]
302302
verifylist = [
303303
('admin_state', True),
304304
('vnic_type', 'macvtap'),
305305
('binding_profile', {'foo': 'bar'}),
306-
('host_id', 'binding-host-id-xxxx'),
306+
('host', 'binding-host-id-xxxx'),
307307
]
308308

309309
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
fixes:
3+
- Change the ``--device-id`` option to ``--device`` and the ``--host-id``
4+
option to ``--host`` for the ``port create`` and ``pot set`` commands.
5+
The original options are deprecated and maintained for backward compatibility
6+
until at least March 2017.
7+
[Bug `1558677 <https://bugs.launchpad.net/python-openstackclient/+bug/1558677>`_]

0 commit comments

Comments
 (0)