summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-03-17 22:58:36 +0000
committerGerrit Code Review <review@openstack.org>2016-03-17 22:58:36 +0000
commitd42bb4f7e221954bf119b7b8eab468c7aeaeb464 (patch)
tree43095afd5d4243912583d9e5bde89c94f0089abc
parenta60e31ad4b2a1b48e7b2db8f572072beb92d6cd1 (diff)
parentaeef56818941a72cc10e96669ad6ff317461046f (diff)
downloadpython-openstackclient-d42bb4f7e221954bf119b7b8eab468c7aeaeb464.tar.gz
Merge "Fix options in port create/set"
-rw-r--r--doc/source/command-objects/port.rst12
-rw-r--r--openstackclient/network/v2/port.py56
-rw-r--r--openstackclient/tests/network/v2/test_port.py8
-rw-r--r--releasenotes/notes/bug-1558677-a85f0c548306ba80.yaml7
4 files changed, 65 insertions, 18 deletions
diff --git a/doc/source/command-objects/port.rst b/doc/source/command-objects/port.rst
index 19107162..4d58745b 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 <network>
[--fixed-ip subnet=<subnet>,ip-address=<ip-address>]
- [--device-id <device-id>]
+ [--device <device-id>]
[--device-owner <device-owner>]
[--vnic-type <vnic-type>]
[--binding-profile <binding-profile>]
- [--host-id <host-id>]
+ [--host <host-id>]
[--enable | --disable]
[--mac-address <mac-address>]
[--project <project> [--project-domain <project-domain>]]
@@ -35,9 +35,9 @@ Create new port
subnet=<subnet>,ip-address=<ip-address>
(this option can be repeated)
-.. option:: --device-id <device-id>
+.. option:: --device <device-id>
- Device ID of this port
+ Port device ID
.. option:: --device-owner <device-owner>
@@ -53,9 +53,9 @@ Create new port
Custom data to be passed as binding:profile: <key>=<value>
(this option can be repeated)
-.. option:: --host-id <host-id>
+.. option:: --host <host-id>
- The ID of the host where the port is allocated
+ Allocate port on host ``<host-id>`` (ID only)
.. option:: --enable
diff --git a/openstackclient/network/v2/port.py b/openstackclient/network/v2/port.py
index 98a4f3de..23350cf8 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=<subnet>,ip-address=<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='<device-id>',
+ help='Port device ID',
+ )
+ device_group.add_argument(
'--device-id',
metavar='<device-id>',
- help='Device ID of this port')
+ help=argparse.SUPPRESS,
+ )
parser.add_argument(
'--device-owner',
metavar='<device-owner>',
@@ -155,10 +187,18 @@ def _add_updatable_args(parser):
action=parseractions.KeyValueAction,
help='Custom data to be passed as binding:profile: <key>=<value> '
'(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='<host-id>',
+ help='Allocate port on host <host-id> (ID only)',
+ )
+ host_group.add_argument(
'--host-id',
metavar='<host-id>',
- 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 54f82853..5532fed5 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'),
@@ -318,14 +318,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 00000000..15451698
--- /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 <https://bugs.launchpad.net/python-openstackclient/+bug/1558677>`_]