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
This commit is contained in:
		 Dean Troyer
					Dean Troyer
				
			
				
					committed by
					
						 Steve Martinelli
						Steve Martinelli
					
				
			
			
				
	
			
			
			 Steve Martinelli
						Steve Martinelli
					
				
			
						parent
						
							3737c5a842
						
					
				
				
					commit
					aeef568189
				
			| @@ -15,11 +15,11 @@ Create new port | |||||||
|     os port create |     os port create | ||||||
|         --network <network> |         --network <network> | ||||||
|         [--fixed-ip subnet=<subnet>,ip-address=<ip-address>] |         [--fixed-ip subnet=<subnet>,ip-address=<ip-address>] | ||||||
|         [--device-id <device-id>] |         [--device <device-id>] | ||||||
|         [--device-owner <device-owner>] |         [--device-owner <device-owner>] | ||||||
|         [--vnic-type <vnic-type>] |         [--vnic-type <vnic-type>] | ||||||
|         [--binding-profile <binding-profile>] |         [--binding-profile <binding-profile>] | ||||||
|         [--host-id <host-id>] |         [--host <host-id>] | ||||||
|         [--enable | --disable] |         [--enable | --disable] | ||||||
|         [--mac-address <mac-address>] |         [--mac-address <mac-address>] | ||||||
|         [--project <project> [--project-domain <project-domain>]] |         [--project <project> [--project-domain <project-domain>]] | ||||||
| @@ -35,9 +35,9 @@ Create new port | |||||||
|     subnet=<subnet>,ip-address=<ip-address> |     subnet=<subnet>,ip-address=<ip-address> | ||||||
|     (this option can be repeated) |     (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> | .. option:: --device-owner <device-owner> | ||||||
|  |  | ||||||
| @@ -53,9 +53,9 @@ Create new port | |||||||
|     Custom data to be passed as binding:profile: <key>=<value> |     Custom data to be passed as binding:profile: <key>=<value> | ||||||
|     (this option can be repeated) |     (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 | .. option:: --enable | ||||||
|  |  | ||||||
|   | |||||||
| @@ -13,13 +13,20 @@ | |||||||
|  |  | ||||||
| """Port action implementations""" | """Port action implementations""" | ||||||
|  |  | ||||||
|  | import argparse | ||||||
|  | import logging | ||||||
|  |  | ||||||
| from openstackclient.common import command | from openstackclient.common import command | ||||||
| from openstackclient.common import exceptions | from openstackclient.common import exceptions | ||||||
| from openstackclient.common import parseractions | from openstackclient.common import parseractions | ||||||
| from openstackclient.common import utils | from openstackclient.common import utils | ||||||
|  | from openstackclient.i18n import _  # noqa | ||||||
| from openstackclient.identity import common as identity_common | from openstackclient.identity import common as identity_common | ||||||
|  |  | ||||||
|  |  | ||||||
|  | LOG = logging.getLogger(__name__) | ||||||
|  |  | ||||||
|  |  | ||||||
| def _format_admin_state(state): | def _format_admin_state(state): | ||||||
|     return 'UP' if state else 'DOWN' |     return 'UP' if state else 'DOWN' | ||||||
|  |  | ||||||
| @@ -57,10 +64,26 @@ def _get_columns(item): | |||||||
| def _get_attrs(client_manager, parsed_args): | def _get_attrs(client_manager, parsed_args): | ||||||
|     attrs = {} |     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: |     if parsed_args.fixed_ip is not None: | ||||||
|         attrs['fixed_ips'] = parsed_args.fixed_ip |         attrs['fixed_ips'] = parsed_args.fixed_ip | ||||||
|     if parsed_args.device_id is not None: |     if parsed_args.device: | ||||||
|         attrs['device_id'] = parsed_args.device_id |         attrs['device_id'] = parsed_args.device | ||||||
|     if parsed_args.device_owner is not None: |     if parsed_args.device_owner is not None: | ||||||
|         attrs['device_owner'] = parsed_args.device_owner |         attrs['device_owner'] = parsed_args.device_owner | ||||||
|     if parsed_args.admin_state is not None: |     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 |         attrs['binding:profile'] = parsed_args.binding_profile | ||||||
|     if parsed_args.vnic_type is not None: |     if parsed_args.vnic_type is not None: | ||||||
|         attrs['binding:vnic_type'] = parsed_args.vnic_type |         attrs['binding:vnic_type'] = parsed_args.vnic_type | ||||||
|     if parsed_args.host_id is not None: |     if parsed_args.host: | ||||||
|         attrs['binding:host_id'] = parsed_args.host_id |         attrs['binding:host_id'] = parsed_args.host | ||||||
|  |  | ||||||
|     # The remaining options do not support 'port set' command, so they require |     # The remaining options do not support 'port set' command, so they require | ||||||
|     # additional check |     # additional check | ||||||
| @@ -133,10 +156,19 @@ def _add_updatable_args(parser): | |||||||
|             help='Desired IP and/or subnet (name or ID) for this port: ' |             help='Desired IP and/or subnet (name or ID) for this port: ' | ||||||
|                  'subnet=<subnet>,ip-address=<ip-address> ' |                  'subnet=<subnet>,ip-address=<ip-address> ' | ||||||
|                  '(this option can be repeated)') |                  '(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', |             '--device-id', | ||||||
|             metavar='<device-id>', |             metavar='<device-id>', | ||||||
|             help='Device ID of this port') |             help=argparse.SUPPRESS, | ||||||
|  |         ) | ||||||
|         parser.add_argument( |         parser.add_argument( | ||||||
|             '--device-owner', |             '--device-owner', | ||||||
|             metavar='<device-owner>', |             metavar='<device-owner>', | ||||||
| @@ -155,10 +187,18 @@ def _add_updatable_args(parser): | |||||||
|             action=parseractions.KeyValueAction, |             action=parseractions.KeyValueAction, | ||||||
|             help='Custom data to be passed as binding:profile: <key>=<value> ' |             help='Custom data to be passed as binding:profile: <key>=<value> ' | ||||||
|                  '(this option can be repeated)') |                  '(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', |             '--host-id', | ||||||
|             metavar='<host-id>', |             metavar='<host-id>', | ||||||
|             help='The ID of the host where the port is allocated' |             help=argparse.SUPPRESS, | ||||||
|         ) |         ) | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
| @@ -125,7 +125,7 @@ class TestCreatePort(TestPort): | |||||||
|             '--mac-address', 'aa:aa:aa:aa:aa:aa', |             '--mac-address', 'aa:aa:aa:aa:aa:aa', | ||||||
|             '--fixed-ip', 'subnet=%s,ip-address=10.0.0.2' |             '--fixed-ip', 'subnet=%s,ip-address=10.0.0.2' | ||||||
|             % self.fake_subnet.id, |             % self.fake_subnet.id, | ||||||
|             '--device-id', 'deviceid', |             '--device', 'deviceid', | ||||||
|             '--device-owner', 'fakeowner', |             '--device-owner', 'fakeowner', | ||||||
|             '--disable', |             '--disable', | ||||||
|             '--vnic-type', 'macvtap', |             '--vnic-type', 'macvtap', | ||||||
| @@ -141,7 +141,7 @@ class TestCreatePort(TestPort): | |||||||
|                 'fixed_ip', |                 'fixed_ip', | ||||||
|                 [{'subnet': self.fake_subnet.id, 'ip-address': '10.0.0.2'}] |                 [{'subnet': self.fake_subnet.id, 'ip-address': '10.0.0.2'}] | ||||||
|             ), |             ), | ||||||
|             ('device_id', 'deviceid'), |             ('device', 'deviceid'), | ||||||
|             ('device_owner', 'fakeowner'), |             ('device_owner', 'fakeowner'), | ||||||
|             ('admin_state', False), |             ('admin_state', False), | ||||||
|             ('vnic_type', 'macvtap'), |             ('vnic_type', 'macvtap'), | ||||||
| @@ -296,14 +296,14 @@ class TestSetPort(TestPort): | |||||||
|             '--enable', |             '--enable', | ||||||
|             '--vnic-type', 'macvtap', |             '--vnic-type', 'macvtap', | ||||||
|             '--binding-profile', 'foo=bar', |             '--binding-profile', 'foo=bar', | ||||||
|             '--host-id', 'binding-host-id-xxxx', |             '--host', 'binding-host-id-xxxx', | ||||||
|             self._port.name, |             self._port.name, | ||||||
|         ] |         ] | ||||||
|         verifylist = [ |         verifylist = [ | ||||||
|             ('admin_state', True), |             ('admin_state', True), | ||||||
|             ('vnic_type', 'macvtap'), |             ('vnic_type', 'macvtap'), | ||||||
|             ('binding_profile', {'foo': 'bar'}), |             ('binding_profile', {'foo': 'bar'}), | ||||||
|             ('host_id', 'binding-host-id-xxxx'), |             ('host', 'binding-host-id-xxxx'), | ||||||
|         ] |         ] | ||||||
|  |  | ||||||
|         parsed_args = self.check_parser(self.cmd, arglist, verifylist) |         parsed_args = self.check_parser(self.cmd, arglist, verifylist) | ||||||
|   | |||||||
							
								
								
									
										7
									
								
								releasenotes/notes/bug-1558677-a85f0c548306ba80.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								releasenotes/notes/bug-1558677-a85f0c548306ba80.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -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>`_] | ||||||
		Reference in New Issue
	
	Block a user