From 66f94dca5c524cbe80dfa669cd5422cbb2663fbd Mon Sep 17 00:00:00 2001 From: reedip Date: Fri, 1 Apr 2016 13:48:57 +0900 Subject: [PATCH] Add name option to 'port set' Port's name can be updated in NeutronClient and it is a very good feature for a user to have the ability to rename a port. This was missing in the openstackclient, and the same has been added in this patch. Change-Id: I6e712ef08ab1c0a23786c4bb6972d3e0f8f0f999 Implements: blueprint neutron-client --- doc/source/command-objects/port.rst | 5 +++++ openstackclient/network/v2/port.py | 9 +++++++-- openstackclient/tests/network/v2/test_port.py | 3 +++ .../notes/add-name-to-port-set-eefa081225bf8b49.yaml | 4 ++++ 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/add-name-to-port-set-eefa081225bf8b49.yaml diff --git a/doc/source/command-objects/port.rst b/doc/source/command-objects/port.rst index 4d58745bc3..46bd6339ae 100644 --- a/doc/source/command-objects/port.rst +++ b/doc/source/command-objects/port.rst @@ -130,6 +130,7 @@ Set port properties [--binding-profile ] [--host-id ] [--enable | --disable] + [--name ] .. option:: --fixed-ip subnet=,ip-address= @@ -168,6 +169,10 @@ Set port properties Disable port +.. option:: --name + + Set port name + .. _port_set-port: .. describe:: diff --git a/openstackclient/network/v2/port.py b/openstackclient/network/v2/port.py index 45ad1c72ba..d7866cccdf 100644 --- a/openstackclient/network/v2/port.py +++ b/openstackclient/network/v2/port.py @@ -97,10 +97,11 @@ def _get_attrs(client_manager, parsed_args): if parsed_args.host: attrs['binding:host_id'] = parsed_args.host + # It is possible that name is not updated during 'port set' + if parsed_args.name is not None: + attrs['name'] = str(parsed_args.name) # The remaining options do not support 'port set' command, so they require # additional check - if 'name' in parsed_args and parsed_args.name is not None: - attrs['name'] = str(parsed_args.name) if 'mac_address' in parsed_args and parsed_args.mac_address is not None: attrs['mac_address'] = parsed_args.mac_address if 'network' in parsed_args and parsed_args.network is not None: @@ -342,6 +343,10 @@ class SetPort(command.Command): action='store_true', help='Disable port', ) + parser.add_argument( + '--name', + metavar="", + help=('Set port name')) parser.add_argument( 'port', metavar="", diff --git a/openstackclient/tests/network/v2/test_port.py b/openstackclient/tests/network/v2/test_port.py index cb1af2b86e..31454dba57 100644 --- a/openstackclient/tests/network/v2/test_port.py +++ b/openstackclient/tests/network/v2/test_port.py @@ -319,6 +319,7 @@ class TestSetPort(TestPort): '--vnic-type', 'macvtap', '--binding-profile', 'foo=bar', '--host', 'binding-host-id-xxxx', + '--name', 'newName', self._port.name, ] verifylist = [ @@ -326,6 +327,7 @@ class TestSetPort(TestPort): ('vnic_type', 'macvtap'), ('binding_profile', {'foo': 'bar'}), ('host', 'binding-host-id-xxxx'), + ('name', 'newName') ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -336,6 +338,7 @@ class TestSetPort(TestPort): 'binding:vnic_type': 'macvtap', 'binding:profile': {'foo': 'bar'}, 'binding:host_id': 'binding-host-id-xxxx', + 'name': 'newName', } self.network.update_port.assert_called_once_with(self._port, **attrs) self.assertIsNone(result) diff --git a/releasenotes/notes/add-name-to-port-set-eefa081225bf8b49.yaml b/releasenotes/notes/add-name-to-port-set-eefa081225bf8b49.yaml new file mode 100644 index 0000000000..13ecad265a --- /dev/null +++ b/releasenotes/notes/add-name-to-port-set-eefa081225bf8b49.yaml @@ -0,0 +1,4 @@ +--- +features: + - | + Port name can now be updated using ``port set`` \ No newline at end of file