1313
1414"""Port action implementations"""
1515
16+ import argparse
17+ import logging
18+
1619from openstackclient .common import command
1720from openstackclient .common import exceptions
1821from openstackclient .common import parseractions
1922from openstackclient .common import utils
23+ from openstackclient .i18n import _ # noqa
2024from openstackclient .identity import common as identity_common
2125
2226
27+ LOG = logging .getLogger (__name__ )
28+
29+
2330def _format_admin_state (state ):
2431 return 'UP' if state else 'DOWN'
2532
@@ -57,10 +64,26 @@ def _get_columns(item):
5764def _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
0 commit comments