Skip to content

Commit de23ab8

Browse files
Hongbin LuDean Troyer
authored andcommitted
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
1 parent a452c9d commit de23ab8

4 files changed

Lines changed: 45 additions & 2 deletions

File tree

doc/source/cli/command-objects/port.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Create new port
1919
openstack port create
2020
--network <network>
2121
[--description <description>]
22-
[--fixed-ip subnet=<subnet>,ip-address=<ip-address>]
22+
[--fixed-ip subnet=<subnet>,ip-address=<ip-address> | --no-fixed-ip]
2323
[--device <device-id>]
2424
[--device-owner <device-owner>]
2525
[--vnic-type <vnic-type>]
@@ -50,6 +50,10 @@ Create new port
5050
subnet=<subnet>,ip-address=<ip-address>
5151
(repeat option to set multiple fixed IP addresses)
5252
53+
.. option:: --no-fixed-ip
54+
55+
No IP or subnet for this port
56+
5357
.. option:: --device <device-id>
5458
5559
Port device ID

openstackclient/network/v2/port.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,8 @@ def get_parser(self, prog_name):
302302
help=_("Network this port belongs to (name or ID)")
303303
)
304304
_add_updatable_args(parser)
305-
parser.add_argument(
305+
fixed_ip = parser.add_mutually_exclusive_group()
306+
fixed_ip.add_argument(
306307
'--fixed-ip',
307308
metavar='subnet=<subnet>,ip-address=<ip-address>',
308309
action=parseractions.MultiKeyValueAction,
@@ -311,6 +312,11 @@ def get_parser(self, prog_name):
311312
"subnet=<subnet>,ip-address=<ip-address> "
312313
"(repeat option to set multiple fixed IP addresses)")
313314
)
315+
fixed_ip.add_argument(
316+
'--no-fixed-ip',
317+
action='store_true',
318+
help=_("No IP or subnet for this port.")
319+
)
314320
parser.add_argument(
315321
'--binding-profile',
316322
metavar='<binding-profile>',
@@ -402,6 +408,8 @@ def take_action(self, parsed_args):
402408

403409
if parsed_args.fixed_ip:
404410
attrs['fixed_ips'] = parsed_args.fixed_ip
411+
elif parsed_args.no_fixed_ip:
412+
attrs['fixed_ips'] = []
405413

406414
if parsed_args.security_group:
407415
attrs['security_group_ids'] = [client.find_security_group(

openstackclient/tests/unit/network/v2/test_port.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,32 @@ def test_create_with_no_security_groups(self):
356356
self.assertEqual(self.columns, columns)
357357
self.assertEqual(self.data, data)
358358

359+
def test_create_with_no_fixed_ips(self):
360+
arglist = [
361+
'--network', self._port.network_id,
362+
'--no-fixed-ip',
363+
'test-port',
364+
]
365+
verifylist = [
366+
('network', self._port.network_id),
367+
('enable', True),
368+
('no_fixed_ip', True),
369+
('name', 'test-port'),
370+
]
371+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
372+
373+
columns, data = (self.cmd.take_action(parsed_args))
374+
375+
self.network.create_port.assert_called_once_with(**{
376+
'admin_state_up': True,
377+
'network_id': self._port.network_id,
378+
'fixed_ips': [],
379+
'name': 'test-port',
380+
})
381+
382+
self.assertEqual(self.columns, columns)
383+
self.assertEqual(self.data, data)
384+
359385
def test_create_port_with_allowed_address_pair_ipaddr(self):
360386
pairs = [{'ip_address': '192.168.1.123'},
361387
{'ip_address': '192.168.1.45'}]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- |
4+
Add ``--no-fixed-ip`` option to ``port create`` command.
5+
[Bug `1717829 <https://launchpad.net/bugs/1717829>`_]

0 commit comments

Comments
 (0)