summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
Diffstat (limited to 'openstackclient')
-rw-r--r--openstackclient/network/v2/port.py10
-rw-r--r--openstackclient/tests/unit/network/v2/test_port.py26
2 files changed, 35 insertions, 1 deletions
diff --git a/openstackclient/network/v2/port.py b/openstackclient/network/v2/port.py
index 9536fe86..4b23b339 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=<subnet>,ip-address=<ip-address>',
action=parseractions.MultiKeyValueAction,
@@ -311,6 +312,11 @@ class CreatePort(command.ShowOne):
"subnet=<subnet>,ip-address=<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='<binding-profile>',
@@ -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 45e1045d..3f751818 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'}]