diff options
Diffstat (limited to 'openstackclient')
| -rw-r--r-- | openstackclient/network/v2/port.py | 56 | ||||
| -rw-r--r-- | openstackclient/tests/network/v2/test_port.py | 8 |
2 files changed, 52 insertions, 12 deletions
diff --git a/openstackclient/network/v2/port.py b/openstackclient/network/v2/port.py index b618a4b0..48e1cef5 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 7b1c655f..ad4ec824 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) |
