From de23ab8d75fe89c164b3b084c53f01c25b9040ca Mon Sep 17 00:00:00 2001 From: Hongbin Lu Date: Mon, 18 Sep 2017 01:41:32 +0000 Subject: [PATCH] Support creating unaddress neutron port Introduce an option '--no-fixed-ip' on port create command. If this option is specified and '--fixed-ip' is unspecified, OSC will send a request to neutron with 'fixed_ips' as an empty list, which will create an unaddress neutron port. Note: The use cases of unaddress port was outlined in: https://specs.openstack.org/openstack/neutron-specs/specs/liberty/unaddressed-port.html (dtroyer: add Depends-On for Zuul v3 test) Depends-On: I39e8e49243ab0bda631600715c971c55a34e2fd9 Change-Id: Ibe38598acbbcd0d353c952fc2a6fa67780762151 Closes-Bug: #1717829 --- doc/source/cli/command-objects/port.rst | 6 ++++- openstackclient/network/v2/port.py | 10 ++++++- .../tests/unit/network/v2/test_port.py | 26 +++++++++++++++++++ .../notes/bug-1717829-c1de1d777d3abaf9.yaml | 5 ++++ 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/bug-1717829-c1de1d777d3abaf9.yaml diff --git a/doc/source/cli/command-objects/port.rst b/doc/source/cli/command-objects/port.rst index c2da09b32..cf29bb2cb 100644 --- a/doc/source/cli/command-objects/port.rst +++ b/doc/source/cli/command-objects/port.rst @@ -19,7 +19,7 @@ Create new port openstack port create --network [--description ] - [--fixed-ip subnet=,ip-address=] + [--fixed-ip subnet=,ip-address= | --no-fixed-ip] [--device ] [--device-owner ] [--vnic-type ] @@ -50,6 +50,10 @@ Create new port subnet=,ip-address= (repeat option to set multiple fixed IP addresses) +.. option:: --no-fixed-ip + + No IP or subnet for this port + .. option:: --device Port device ID diff --git a/openstackclient/network/v2/port.py b/openstackclient/network/v2/port.py index 9536fe868..4b23b339c 100644 --- a/openstackclient/network/v2/port.py +++ b/openstackclient/network/v2/port.py @@ -302,7 +302,8 @@ class CreatePort(command.ShowOne): help=_("Network this port belongs to (name or ID)") ) _add_updatable_args(parser) - parser.add_argument( + fixed_ip = parser.add_mutually_exclusive_group() + fixed_ip.add_argument( '--fixed-ip', metavar='subnet=,ip-address=', action=parseractions.MultiKeyValueAction, @@ -311,6 +312,11 @@ class CreatePort(command.ShowOne): "subnet=,ip-address= " "(repeat option to set multiple fixed IP addresses)") ) + fixed_ip.add_argument( + '--no-fixed-ip', + action='store_true', + help=_("No IP or subnet for this port.") + ) parser.add_argument( '--binding-profile', metavar='', @@ -402,6 +408,8 @@ class CreatePort(command.ShowOne): if parsed_args.fixed_ip: attrs['fixed_ips'] = parsed_args.fixed_ip + elif parsed_args.no_fixed_ip: + attrs['fixed_ips'] = [] if parsed_args.security_group: attrs['security_group_ids'] = [client.find_security_group( diff --git a/openstackclient/tests/unit/network/v2/test_port.py b/openstackclient/tests/unit/network/v2/test_port.py index 45e1045da..3f751818b 100644 --- a/openstackclient/tests/unit/network/v2/test_port.py +++ b/openstackclient/tests/unit/network/v2/test_port.py @@ -356,6 +356,32 @@ class TestCreatePort(TestPort): self.assertEqual(self.columns, columns) self.assertEqual(self.data, data) + def test_create_with_no_fixed_ips(self): + arglist = [ + '--network', self._port.network_id, + '--no-fixed-ip', + 'test-port', + ] + verifylist = [ + ('network', self._port.network_id), + ('enable', True), + ('no_fixed_ip', True), + ('name', 'test-port'), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + columns, data = (self.cmd.take_action(parsed_args)) + + self.network.create_port.assert_called_once_with(**{ + 'admin_state_up': True, + 'network_id': self._port.network_id, + 'fixed_ips': [], + 'name': 'test-port', + }) + + self.assertEqual(self.columns, columns) + self.assertEqual(self.data, data) + def test_create_port_with_allowed_address_pair_ipaddr(self): pairs = [{'ip_address': '192.168.1.123'}, {'ip_address': '192.168.1.45'}] diff --git a/releasenotes/notes/bug-1717829-c1de1d777d3abaf9.yaml b/releasenotes/notes/bug-1717829-c1de1d777d3abaf9.yaml new file mode 100644 index 000000000..19ea4ea50 --- /dev/null +++ b/releasenotes/notes/bug-1717829-c1de1d777d3abaf9.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Add ``--no-fixed-ip`` option to ``port create`` command. + [Bug `1717829 `_]